Difference between revisions of "Mediawiki"
Line 2: | Line 2: | ||
== Installation == | == Installation == | ||
− | This assumes Ubuntu | + | This assumes Ubuntu 20.04 LTS, the new Mediawiki LTS version 1.35 and a passing familiarity with [[Git]]. First, some prerequisites: |
− | apt-get install git apache2 libapache2-mod- | + | apt-get install git apache2 libapache2-mod-php7.4 php7.4-curl php7.4-mysql curl |
− | Now clone | + | Now clone Mediawiki with git: |
− | git clone <nowiki> | + | git clone <nowiki>https://phabricator.wikimedia.org/source/mediawiki.git</nowiki> |
− | Next, we need to pull in | + | Next, we need to pull in PHP library dependencies with [https://getcomposer.org/download/ PHP composer]. First install composer from the download page, then use it to pull dependencies into MediaWiki: |
cd mediawiki | cd mediawiki | ||
− | composer install | + | composer install --no-dev |
+ | |||
+ | This assumes a production instance; if this is a developer instance and you need debugging tools, leave off the no-dev option. | ||
=== Managing skins and extensions === | === Managing skins and extensions === | ||
− | MediaWiki has two directories for these: <tt>skins</tt> and <tt>extensions</tt>. There are several ways to manage them, | + | MediaWiki has two directories for these: <tt>skins</tt> and <tt>extensions</tt>. There are several ways to manage them, but to keep things simple either: |
− | # manually download the skins and extensions you need from the Mediawiki [https://www.mediawiki.org/wiki/Special:SkinDistributor Skin] and [https://www.mediawiki.org/wiki/Special:ExtensionDistributor Extension] Distributor pages and unzip them into the codebase, | + | # manually download the skins and extensions you need from the Mediawiki [https://www.mediawiki.org/wiki/Special:SkinDistributor Skin] and [https://www.mediawiki.org/wiki/Special:ExtensionDistributor Extension] Distributor pages and unzip them into the codebase, or |
− | # manage | + | # manage skins and extensions using git submodules, sourced from the upstream git repositories. |
− | |||
− | Let's do | + | Let's do the second way because it's easier to automate later, and some formerly built-in skins and extensions are already set up this way. Of these, you'll need the default Vector skin right off the bat, and you might like to switch to the Timeless skin, which is responsive and a lot more mobile-friendly: |
− | git | + | git submodule update --init --recursive skins/Vector skins/Timeless |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Now when we want an extension, say the ''Cite'' extension, we add the git submodule: | |
− | + | git submodule add -b REL1_35 <nowiki>https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite</nowiki> extensions/Cite | |
− | git submodule | + | git submodule update --init --recursive extensions/Cite |
− | |||
− | |||
− | + | Enable the skins and extensions requires editing the <tt>LocalSettings.php</tt> file, for example: | |
− | + | $wgDefaultSkin = 'Timeless'; | |
− | + | wfLoadSkin('Timeless'); | |
− | + | wfLoadExtension('Cite'); | |
− | |||
− | You should now be able to point Apache | + | You should now be able to point Apache at the <tt>mediawiki</tt> directory and install it using the browser; you will probably need to set up a PostgreSQL or MySQL database and user first. |
== Visual Editor == | == Visual Editor == | ||
Line 77: | Line 68: | ||
mwApis: | mwApis: | ||
- | - | ||
− | uri: <nowiki>'https:// | + | uri: <nowiki>'https://</nowiki>'''yourwiki.example.com'''/w/api.php' |
− | domain: ' | + | domain: '''yourwiki.example.com''' |
=== Install the required MediaWiki extensions === | === Install the required MediaWiki extensions === | ||
− | Install Visual Editor and its dependent extension (UniversalLanguageSelector) | + | Install the Visual Editor extension and its dependent extension (UniversalLanguageSelector): |
− | + | git submodule add -b REL1_35 <nowiki>https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor</nowiki> extensions/VisualEditor | |
− | git submodule | + | git submodule add -b REL1_35 <nowiki>https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector</nowiki> extensions/UniversalLanguageSelector |
− | + | git submodule update --init --recursive extensions/VisualEditor extensions/UniversalLanguageSelector | |
− | |||
− | |||
Then edit <tt>LocalSettings.php</tt> and add this at the bottom: | Then edit <tt>LocalSettings.php</tt> and add this at the bottom: | ||
Line 142: | Line 131: | ||
sudo mkdir -p /var/cache/mediawiki | sudo mkdir -p /var/cache/mediawiki | ||
sudo chown www-data:www-data /var/cache/mediawiki | sudo chown www-data:www-data /var/cache/mediawiki | ||
+ | |||
+ | == Upgrading == | ||
+ | |||
+ | Whenever the base code is updated, we need to make sure that PHP dependencies, skins, extensions and the database schema are all updated too. It looks a bit like this: | ||
+ | |||
+ | # after updating code, or moving to a new release: | ||
+ | composer update --no-dev | ||
+ | git submodule update --init --recursive | ||
+ | sudo -u www-data /usr/bin/php maintenance/update.php | ||
+ | # (look for any new updateXXX.php commands in the maintenance directory) | ||
+ | |||
+ | Given that Wikipedia itself runs on this code, you can bet upgrades have been tested up the waazoo, so this runs very reliably. | ||
== Troubleshooting == | == Troubleshooting == | ||
# Having 'file:' in your $wgUrlProtocols is not just bad, it will clobber all your <tt><nowiki>[[File:whatever.jpg]]</nowiki></tt> images. | # Having 'file:' in your $wgUrlProtocols is not just bad, it will clobber all your <tt><nowiki>[[File:whatever.jpg]]</nowiki></tt> images. |
Revision as of 00:50, 2 September 2020
Installation
This assumes Ubuntu 20.04 LTS, the new Mediawiki LTS version 1.35 and a passing familiarity with Git. First, some prerequisites:
apt-get install git apache2 libapache2-mod-php7.4 php7.4-curl php7.4-mysql curl
Now clone Mediawiki with git:
git clone https://phabricator.wikimedia.org/source/mediawiki.git
Next, we need to pull in PHP library dependencies with PHP composer. First install composer from the download page, then use it to pull dependencies into MediaWiki:
cd mediawiki composer install --no-dev
This assumes a production instance; if this is a developer instance and you need debugging tools, leave off the no-dev option.
Managing skins and extensions
MediaWiki has two directories for these: skins and extensions. There are several ways to manage them, but to keep things simple either:
- manually download the skins and extensions you need from the Mediawiki Skin and Extension Distributor pages and unzip them into the codebase, or
- manage skins and extensions using git submodules, sourced from the upstream git repositories.
Let's do the second way because it's easier to automate later, and some formerly built-in skins and extensions are already set up this way. Of these, you'll need the default Vector skin right off the bat, and you might like to switch to the Timeless skin, which is responsive and a lot more mobile-friendly:
git submodule update --init --recursive skins/Vector skins/Timeless
Now when we want an extension, say the Cite extension, we add the git submodule:
git submodule add -b REL1_35 https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite extensions/Cite git submodule update --init --recursive extensions/Cite
Enable the skins and extensions requires editing the LocalSettings.php file, for example:
$wgDefaultSkin = 'Timeless'; wfLoadSkin('Timeless'); wfLoadExtension('Cite');
You should now be able to point Apache at the mediawiki directory and install it using the browser; you will probably need to set up a PostgreSQL or MySQL database and user first.
Visual Editor
Install Parsoid
Parsoid is a small Node.js REST service that parses between MediaWiki syntax and HTML DOM. Add the apt repository:
apt-key advanced --keyserver keys.gnupg.net --recv-keys 90E9F83F22250DD7 apt-add-repository 'deb https://releases.wikimedia.org/debian jessie-mediawiki main' apt-get update
Then install and configure Parsoid:
apt-get install parsoid vi /etc/mediawiki/parsoid/config.yaml # change URL to point to installed api.php
Example config.yaml looks like:
worker_heartbeat_timeout: 300000 logging: level: info services: - module: ../src/lib/index.js entrypoint: apiServiceWorker conf: useSelser: true mwApis: - uri: 'https://yourwiki.example.com/w/api.php' domain: yourwiki.example.com
Install the required MediaWiki extensions
Install the Visual Editor extension and its dependent extension (UniversalLanguageSelector):
git submodule add -b REL1_35 https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor extensions/VisualEditor git submodule add -b REL1_35 https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector extensions/UniversalLanguageSelector git submodule update --init --recursive extensions/VisualEditor extensions/UniversalLanguageSelector
Then edit LocalSettings.php and add this at the bottom:
wfLoadExtension('UniversalLanguageSelector'); wfLoadExtension('VisualEditor.php'); # VisualEditor extension configuration $wgDefaultUserOptions['visualeditor-enable'] = 1; $wgDefaultUserOptions['visualeditor-editor'] = "visualeditor"; $wgSessionsInObjectCache = true; $wgVisualEditorAvailableNamespaces = [ NS_MAIN => true, NS_USER => true, NS_TEMPLATE => false, "_merge_strategy" => "array_plus", ]; # VisualEditor connection to the parsoid service $wgVirtualRestConfig['modules']['parsoid'] = [ 'url' => 'http://localhost:8142', 'domain' => 'your.wiki.nz', 'forwardCookies' => true, ];
Caching
PHP opcache
Like any PHP application, use the opcache. If your PHP version is < 5.5 install php5-xcache, otherwise enable the built-in opcache by adding this in php.ini:
[opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.use_cwd=1 opcache.validate_timestamps=1 opcache.revalidate_freq=0 opcache.fast_shutdown=0
MediaWiki file cache
Use the file cache, Luke. It's simple but effective. In LocalSettings.php:
$wgUseFileCache = true; $wgFileCacheDirectory = "/var/cache/mediawiki"; $wgShowIPinHeader = false;
And create the appropriate cache directory:
sudo mkdir -p /var/cache/mediawiki sudo chown www-data:www-data /var/cache/mediawiki
Upgrading
Whenever the base code is updated, we need to make sure that PHP dependencies, skins, extensions and the database schema are all updated too. It looks a bit like this:
# after updating code, or moving to a new release: composer update --no-dev git submodule update --init --recursive sudo -u www-data /usr/bin/php maintenance/update.php # (look for any new updateXXX.php commands in the maintenance directory)
Given that Wikipedia itself runs on this code, you can bet upgrades have been tested up the waazoo, so this runs very reliably.
Troubleshooting
- Having 'file:' in your $wgUrlProtocols is not just bad, it will clobber all your [[File:whatever.jpg]] images.