Skip to content

Commit

Permalink
Merge pull request #6 from arthurpsmith/master
Browse files Browse the repository at this point in the history
Docker support
  • Loading branch information
vrandezo committed May 7, 2020
2 parents b58ea54 + 8400e50 commit 53b7990
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docker_support/AdditionalLocalSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include_once 'DockerLocalSettings.php';

$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis' ) );
wfLoadExtension( 'UniversalLanguageSelector' );
wfLoadExtension( 'AbstractText' );
91 changes: 91 additions & 0 deletions docker_support/DockerLocalSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/*
* Based on Mediawiki-Vagrant LocalSettings file...
*/

// Enable error reporting
error_reporting( -1 );
ini_set( 'display_errors', 1 );

$wgMaxShellMemory = 1024 * 512;

// Show the debug toolbar if 'debug' is set on the request, either as a
// parameter or a cookie.
if ( !empty( $_REQUEST['debug'] ) ) {
$wgDebugToolbar = true;
}

// Expose debug info for PHP errors.
$wgShowExceptionDetails = true;

$logDir = '/var/log';
foreach ( [ 'exception', 'runJobs', 'JobQueueRedis' ] as $logGroup ) {
$wgDebugLogGroups[$logGroup] = "{$logDir}/mediawiki-{$logGroup}.log";
}

// Calls to deprecated methods will trigger E_USER_DEPRECATED errors
// in the PHP error log.
$wgDevelopmentWarnings = true;

// Expose debug info for SQL errors.
$wgDebugDumpSql = true;
$wgShowDBErrorBacktrace = true;
$wgShowSQLErrors = true;

// Profiling
$wgDebugProfiling = false;

$wgUseInstantCommons = true;
$wgEnableUploads = true;

// User settings and permissions
$wgAllowUserJs = true;
$wgAllowUserCss = true;

$wgEnotifWatchlist = true;
$wgEnotifUserTalk = true;

// Eligibility for autoconfirmed group
$wgAutoConfirmAge = 3600 * 24; // one day
$wgAutoConfirmCount = 5; // five edits

$wgLegacyJavaScriptGlobals = false;
$wgEnableJavaScriptTest = true;

// Bug 73037: handmade gzipping sometimes makes error messages impossible to
// see in HHVM
$wgDisableOutputCompression = true;

// Don't gloss over errors in class name letter-case.
$wgAutoloadAttemptLowercase = false;

// Enable CORS between wikis. Ideally we'd limit this to wikis in the farm,
// but iterating resource names is super cumbersome in Puppet.
$wgCrossSiteAJAXdomains = [ '*' ];

// ====================================================================
// NOTE: anything after this point is 'immutable' config that can not be
// overridden by a role or a user managed file in settings.d
// ====================================================================

// XXX: Is this a bug in core? (ori-l, 27-Aug-2013)
$wgHooks['GetIP'][] = function ( &$ip ) {
if ( PHP_SAPI === 'cli' ) {
$ip = '127.0.0.1';
}
return true;
};

// Allow 'vagrant' password for all users regardless of password
// policies that are configured.
$wgHooks['isValidPassword'][] = function ( $password, &$result, $user ) {
if ( $password === 'vagrant' ) {
$result = true;
}
return true;
};

// Ensure that full LoggerFactory configuration is applied
MediaWiki\Logger\LoggerFactory::registerProvider(
\Wikimedia\ObjectFactory::getObjectFromSpec( $wgMWLoggerDefaultSpi )
);
33 changes: 33 additions & 0 deletions docker_support/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM mediawiki:stable
LABEL maintainer="arthurpsmith@gmail.com"

RUN apt-get update && apt-get install -q -y git curl nodejs npm
RUN npm install npm@latest -g

RUN cd /var/www/html/extensions && \
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector.git && \
git clone https://github.com/google/abstracttext.git && \
mv abstracttext AbstractText

RUN cd /var/www/html/extensions/AbstractText/eneyj && \
npm install && \
npm install uuid && \
mkdir config && \
mkdir config/runs && \
node src/scripts/labelMap.js && \
cp src/scripts/calibration-initial.json config/calibration.json && \
node src/scripts/measure.js --chatty && \
node src/scripts/calibrate.js

COPY DockerLocalSettings.php /var/www/html/DockerLocalSettings.php
COPY AdditionalLocalSettings.php /tmp/AdditionalLocalSettings.php
COPY admin_passwd /tmp/admin_passwd

RUN cd /var/www/html && \
php maintenance/install.php --server http://localhost:8081 --dbtype sqlite --dbpath /var/www/data --scriptpath "" --passfile /tmp/admin_passwd "Lambda" "admin"
RUN cat /tmp/AdditionalLocalSettings.php >> /var/www/html/LocalSettings.php

RUN cd /var/www/html && \
php maintenance/importTextFiles.php -s "Import data" --prefix "M:" --overwrite extensions/AbstractText/eneyj/data/Z*

RUN chown -R www-data /var/www/data
23 changes: 23 additions & 0 deletions docker_support/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# AbstractText - Docker Support

To build a container with the Mediawiki AbstractText support built in use
the Dockerfile in this directory.

```
> docker build -t repo/wikilambda .
```

This may take some time as it processes all the Z* files.

Then to run the resulting container use a standard docker command like:

```
docker run --name wikilambda -p 8081:80 -d -v "$PWD/..":/var/www/html/extensions/AbstractText repo/wikilambda
```

(the -v option replaces the version of AbstractText on the server with the local copy)

The wiki is then available at http://localhost:8081, with content for example at:

http://localhost:8081/index.php/M:Z67

1 change: 1 addition & 0 deletions docker_support/admin_passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wikiLambda$0
14 changes: 11 additions & 3 deletions includes/AbstractTextContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function getParserOutput(
}

public function getMultilingualTextValue($key, $data, $zlang) {
if ($data == NULL) return NULL;
if (!array_key_exists($key, $data)) return NULL;
if (!array_key_exists('Z12K1', $data[$key])) return NULL;
foreach ($data[$key]['Z12K1'] as $label)
Expand Down Expand Up @@ -294,7 +295,10 @@ public function getFunctionDisplayText($data, $zlang, $lang, $title_name) {
public function getFunctionCallDisplayText( $data, $impl, $zlang ) {
if ( $impl['Z1K1'] != 'Z7') return 'TODO';
if (!array_key_exists('Z7K1', $impl)) return 'TODO';
$result = $this->getLinkText( $impl['Z7K1'], $zlang );
$result = '';
if (! is_array($impl['Z7K1']) ) {
$result .= $this->getLinkText( $impl['Z7K1'], $zlang );
}
$result .= '( ';

$first = true;
Expand All @@ -306,7 +310,7 @@ public function getFunctionCallDisplayText( $data, $impl, $zlang ) {
} else {
$result .= ', ';
}
if (is_array( $value )) {
if (is_array( $value ) && array_key_exists('Z1K1', $value)) {
if ($value['Z1K1'] == 'Z7') {
$result .= $this->getFunctionCallDisplayText( $data, $value, $zlang );
} elseif ($value['Z1K1'] == 'Z18') {
Expand All @@ -323,7 +327,11 @@ public function getFunctionCallDisplayText( $data, $impl, $zlang ) {
$result .= 'TODO';
}
} else {
$result .= $this->getLinkText( $value, $zlang );
if (is_array($value) ) {
$result .= 'TODO';
} else {
$result .= $this->getLinkText( $value, $zlang );
}
}
}

Expand Down

0 comments on commit 53b7990

Please sign in to comment.