MediaWiki
MediaWiki is an opensource wiki engine written in PHP by the Wikimedia Foundation. It is used by both Wikipedia and this site.
Visit the project website at:
Running inside Docker
You can run MediaWiki from a Docker container. A proof of concept can be found at:
Data that would need to be imported to support customizations would include:
- Images / Uploads
- Extensions
- Skins
- The
LocalSettings.phpconfiguration file - Database (on a remote server / container / microservice), or a SQLite file on a volume
Configuration
MediaWiki only has a single configuration file at LocalSettings.php.
If you wish to run a wiki on the root of a domain, you need to set wgScriptPath empty.
$wgScriptPath = "";
$wgArticlePath = "/$1";
Extensions
Extensions are placed under the /extensions directory. Common extensions are bundled with the base installation of MediaWiki but not enabled by default. Extentions that are bundled can be enabled by adding a wfLoadExtention('extention') call to the LocalSettings.php file.
There are some extensions that this wiki requires:
- Intersection
- https://github.com/wikimedia/mediawiki-extensions-intersection.git
- Generates dynamic lists
- Scribunto
- https://github.com/wikimedia/mediawiki-extensions-Scribunto.git
- Generates scripted outputs using Lua
- Math
- https://extdist.wmflabs.org/dist/extensions/Math-REL1_30-e13d2d5.tar.gz
- Generates math formulas
- NativeSvgHandler
- https://github.com/wikimedia/mediawiki-extensions-NativeSvgHandler.git
- Embeds SVG files as an image for client-side rendering. Requires appending
http://www.w3.org/tr/rec-rdf-syntax/to$validNamespacesinUploadBase.php.
Skins
Skins are placed under the /skins directory. Modern skins are loaded with the wfLoadSkin('skin') call in LocalSettings.php, which reads the skin's skin.json manifest file in the skin's directory. The manifest file contains the skin's name, autoload class files, as well as which resource modules to load loaded, including the stylesheets and javascript files that are part of the skin.
MediaWiki's guide on skinning is relatively up to date albeit a little confusing to understand at first.
The Reader skin used on this wiki:
The OutputPage object is the thing that handles all HTML generation as well as linking javascript and CSS modules. You can use this to inject HTML or certain code to the page with some method calls. See: https://www.mediawiki.org/wiki/Manual:OutputPage.php
Transcluded Pages
There are some pages that are used by the MediaWiki software itself, including:
Some resources are also loaded from pages including:
Skins should be able to handle contents on these MediaWiki pages which are typically shown somewhere on the page. Of course, custom skins can also reference their own set of pages such as:
Tasks
Enabling Visual Editor
Visual Editor is an extension that enables the WYSIWYG editor. This extension requires parsoid in order to properly save changes.
To install the Visual Editor extension and configure it:
- Download the extension to the extensions directory (wget https://extdist.wmflabs.org/dist/extensions/VisualEditor-REL1_34-74116a7.tar.gz)
- Edit LocalSettings.php and enable the extension.
No code provided.
I recommend running Parsoid in a docker container to simplify installation. There is one built at thenets/parsoid which works just fine. A clone of that project is available at https://git.steamr.com/docker/parsoid. The container takes in an environment variables to configure which domains Parsoid is to work for. An example docker-compose file with everything working is given below.
Inserting a custom script in <head>
If using a custom skin, use the OutputPage and call addHeadItem('name', '<script>...</script') to inject a custom script block within the document head.
Alternatively, write a specific OutputPageBeforeHTML hook, and from there call addInlineScript.
Adding a custom button to WikiEditor Toolbar
To add a custom button to the WikiEditor toolbar next to the existing bold and italic buttons, edit the MediaWiki:Common.js file. This file can only be changed by interface administrator users. Membership to this group can be assigned at Special:UserRights/username.
The Common.js file used to add the Code and SyntaxHighlight templates used on this wiki is given below.
var customizeToolbar = function () {
$('#wpTextbox1').wikiEditor('addToToolbar', {
'section': 'main',
'group': 'format',
'tools': {
'code': {
label: 'code',
type: 'button',
oouiIcon: 'code',
action: {
type: 'encapsulate',
options: {
pre: "<code>",
post: "</code>"
}
}
}
}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
'section': 'main',
'group': 'format',
'tools': {
'terminal': {
label: 'highlight',
type: 'button',
oouiIcon: 'tag',
action: {
type: 'encapsulate',
options: {
pre: "'"`UNIQ--syntaxhighlight-00000004-QINU`"'"
}
}
}
}
});
};
Documentation for this can be found at:
Troubleshooting
Scribunto Lua Failures
If templates cause this error:
Lua error: Internal error: The interpreter exited with status 127.
This likely means that you do not have Lua installed or it is not in the PATH. You will need to specify the Lua path in LocalSettings.php with this line:
$wgScribuntoEngineConf['luastandalone']['luaPath'] = "/usr/bin/lua5.1";
Database Import Incomplete
Database imports from MySQL 5.7.27 to a MariaDB 10.4.7 seems to fail. Imports only appear to complete if the database dump was made without Enclose export in a transaction enabled in PHPMyAdmin but subsequent edits on the destination wiki will result in this error message:
The revision #0 of the page named "some-article" does not exist.
This is usually caused by following an outdated history link to a page that has been deleted. Details can be found in the deletion log.
Solution
It turns out the destination database server (mariadb:10.4.7, in docker) was not set up properly after being upgraded from MariaDB-10.1. On start up, it showed the following error messages:
2019-09-01 21:14:44 0 [Note] Server socket created on IP: '::'.
2019-09-01 21:14:44 0 [Warning] 'user' entry 'root@localhost.localdomain' ignored in --skip-name-resolve mode.
2019-09-01 21:14:44 0 [Warning] 'proxies_priv' entry '@% root@localhost.localdomain' ignored in --skip-name-resolve mode.
2019-09-01 21:14:44 0 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
2019-09-01 21:14:44 0 [ERROR] Incorrect definition of table mysql.event: expected column 'sql_mode' at position 14 to have type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH','EMPTY_STRING_IS_NULL','SIMULTANEOUS_ASSIGNMENT'), found type set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALU
2019-09-01 21:14:44 0 [ERROR] mysqld: Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
2019-09-01 21:14:44 6 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
2019-09-01 21:14:44 0 [Note] Reading of all Master_info entries succeeded
2019-09-01 21:14:44 0 [Note] Added new Master_info '' to hash table
2019-09-01 21:14:44 0 [Note] mysqld: ready for connections.
Version: '10.4.7-MariaDB-1:10.4.7+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
2019-09-01 21:14:46 0 [Note] InnoDB: Buffer pool(s) load completed at 190901 21:14:46
2019-09-01 21:14:49 8 [ERROR] InnoDB: Table `mysql`.`innodb_table_stats` not found.
2019-09-01 21:14:49 8 [ERROR] Transaction not registered for MariaDB 2PC, but transaction is active
2019-09-01 21:15:13 9 [ERROR] Transaction not registered for MariaDB 2PC, but transaction is active
2019-09-01 21:15:13 9 [ERROR] Transaction not registered for MariaDB 2PC, but transaction is active
2019-09-01 21:15:13 9 [ERROR] Transaction not registered for MariaDB 2PC, but transaction is active
Running mysql_upgrade fixed these errors and a subsequent database import was successful.
Math Extension
Using the latest Math extension, formulas constantly return errors similar to:
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle V=IR}
I installed Mathoid and tried to set the $wgMathFullRestbaseURL to the service to no avail since $wgMathFullRestbaseURL required the Restbase API rather than the Mathoid API. I did not want to install Restbase for a simple wiki and requiring Restbase will make hosting it on a shared hosting environment tricky.
Solution
It turns out that the Math extension versions 1.30 and prior works.
Save yourself the headache and use MathML, then set the RestbaseURL and MathML URL to Wikipedia's.
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';
$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org/';