Mediawiki

From Segfault
Jump to navigation Jump to search

Installation

This is described in detail under Manual:Installing MediaWiki, a short version follows.

Prerequisites

apt-get install httpd php5-cgi php5-mysql php5-gd php5-xcache           # Debian, Ubuntu
    dnf install lighttpd lighttpd-fastcgi php-mysql php-gd php-pecl-apc # Fedora

pkgutil -i CSWlighttpd CSWphp5-mysql CSWmysql5 CSWphp5-session \        # Solaris
           CSWphp5-ctype CSWphp5-gd CSWphp5-apc

Tarball

wget https://releases.wikimedia.org/mediawiki/1.34/mediawiki-1.34.0.tar.gz{,.sig}
wget https://www.mediawiki.org/keys/keys.txt -O - | gpg --import

gpg --verify mediawiki*.sig
gzip -dc mediawiki*tar.gz | tar -C /var/www/ -xf -                      # Use GNU/Tar on Solaris systems!

See the Version lifecycle for its release policy.

Skins

Skin autodiscovery has been removed[1] and additional skins have to be downloaded and activated:

git clone https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue MinervaNeue-git
cd MinervaNeue-git
git archive --format=tar --prefix=MinervaNeue/ origin/REL1_34 | tar -C /var/www/mediawiki/skins/ -xf -

Add the following to LocalSettings.php

wfLoadSkin('MinervaNeue');

Backup

From Manual:Backing up a wiki:

cd /var/www/mediawiki
tar -cf ~/backup/wiki.tar extensions/ images/
mysqldump -u USERNAME --password       DATABASE > ~/backup/wiki.sql
mysqldump -u USERNAME --password --xml DATABASE > ~/backup/wiki.xml

Restore

cd /var/www/mediawiki
tar -xf ~/backup/wiki.tar extensions/ images/
mysql -u USERNAME --password -D DATABASE < ~/backup/wiki.sql

Upgrading

Update from the latest tarball:

wget https://releases.wikimedia.org/mediawiki/1.34/mediawiki-1.34.0.tar.gz{,.sig}

gpg --tofu-policy good 1D98867E82982C8FE0ABC25F9B69B3109D3BB7B0
gpg --trust-model tofu --verify mediawiki*tar.gz.sig

DOCROOT=/var/www/
cd $DOCROOT/mediawiki

umask 0022
sudo chown -R $USER . && chmod -R u+rwX .
tar --strip-components=1 -xzf ~/mediawiki*.tar.gz

Update the existing Mediawiki installation, including database updates:

script -a -c "date; php maintenance/update.php --conf `pwd`/LocalSettings.php" ~/mwupdate.log

Generate a fresh sitemap:

MW_INSTALL_PATH=`pwd` php maintenance/generateSitemap.php --conf `pwd`/LocalSettings.php \
     --fspath `pwd`/sitemap --server https://www.example.org/ \
     --urlpath https://www.example.org/mediawiki/sitemap --skip-redirects

Disable some cruft, allow only certain elements:

sudo chmod -cR 0 *
     chmod -cR a+rX LocalSettings.php api.php extensions img_auth.php includes index.php languages load.php resources skins thumb.php thumb_handler.php composer.json vendor

Fix permissions:

chmod -c  0750                   cache/ images/ sitemap/
sudo chown -cR www-data:www-data cache/ images/ sitemap/

Configuration

Permissions

 $ cat LocalSettings.php
 [...]
 $wgGroupPermissions['*']['edit'] = false;
 $wgGroupPermissions['*']['read'] = true;
 $wgGroupPermissions['*']['createaccount'] = true;

Email

 $ sudo apt-get install php-mail php-net-smtp
 $ cat LocalSettings.php
 [...]
  $wgSMTP = array(
    'host' => "foo",
    'port' => "25",
    'auth' => true,
    'username' => "bar",
    'password' => "baz"
   );

Misc settings

 $ cat LocalSettings.php
 $wgLogo                 = "/wiki/images/logo.jpg";
 $wgAllowExternalImages  = true;
 $wgShowExceptionDetails = true;
 
 $wgNamespacesWithSubpages[NS_MAIN] = true;
 $wgAllowCopyUploads = true;
 $wgFileExtensions   = array_merge( $wgFileExtensions, array( 'pdf', 'txt', 'gz', 'bz2', 'deb' ));
 # $wgVerifyMimeType = false;
 # $wgDisableUploadScriptChecks = true;
 # $wgEnableProfileInfo = true;
 # array_push( $wgUrlProtocols, "file://" );
 # Auto Logout is controlled
 # by the session.gc_maxlifetime variable, which in turn is honored by the /etc/cron.d/php5 cronjob:
 # grep ^session.gc_maxlifetime /etc/php5/apache2/php.ini 
 session.gc_maxlifetime = 86400

CategoryPage.php

I wanted to have my category pages to show its members in columns rather than in an endless bulletpoint list. A similar problem lead me to do this:

--- mediawiki/includes/CategoryPage.php.orig    2010-04-26 02:06:39.508995407 +0200
+++ mediawiki/includes/CategoryPage.php 2010-04-26 02:01:16.998997496 +0200
@@ -358,7 +358,7 @@
         * @return String
         * @private
         */
-       function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
+       function formatList( $articles, $articles_start_char, $cutoff = 3 ) {
                if ( count ( $articles ) > $cutoff ) {
                        return $this->columnList( $articles, $articles_start_char );
                } elseif ( count( $articles ) > 0 ) {

I don't think this (hardcoded?) parameter can be set in LocalSettings.php, though :-\

Short URLs

Short URLs[2][3] for our MediaWiki installation:

 $ cat LocalSettings.php
 [...]
 $wgScriptPath  = "/mediawiki";   # This will be the real (relative) path, don't touch this!
 
 $wgArticlePath = "/wiki/$1";     # This will be the rewritten (relative) path and 
                                  # must be different from the real pathname (wgScriptPath)
 $wgUsePathInfo = true;

Apache

When using Apache, one can put mod_rewrite rules in .htaccess files. Be sure to set AllowOverride to at least FileInfo and Options:

$ cat $DocumentRoot/.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^w/(.*)$ /wiki/index.php?title=$1 [PT,L,QSA]
RewriteRule ^w/*$ /wiki/index.php [L,QSA]

Lighttpd

Lighttpd solution:

url.rewrite-once += (
    "^/w/([^?]*)(?:\?(.*))?" => "/wiki/index.php?title=$1&$2",
    "^/w$"                   => "/wiki/index.php",
)

As an alternative we could use url.rewrite-if-not-file to check if the virtual path exists on the filesystem:

url.rewrite-if-not-file += ( 
    "^/w/(mw-)?config/?"     => "$0",
    "^/w/([^?]*)(?:\?(.*))?" => "/wiki/index.php?title=$1&$2",
    "^/w/([^?]*)"            => "/wiki/index.php?title=$1" 
)

Nginx

Nginx solution:

  location /w {
      index index.php;
      rewrite "^/w/([^?]*)(?:\?(.*))?" /wiki/index.php?title=$1&$args last;
      }

SVG

To use SVG images, an SVG converter is needed:

apt-get install librsvg2-bin

This will install a bunch of nasty dependencies:

libatk1.0-0 libavahi-common-data libavahi-common3 libdbus-1-3 libavahi-client3 libcups2 
libgsf-1-common libgsf-1-114 libgtk2.0-common libxcomposite1 libxcursor1 libxi6 libxrandr2
libgtk2.0-0 librsvg2-2 librsvg2-bin

...unfortunately, we might be unable to forcefully deinstall any of these:

$ ldd `which rsvg-convert` | wc -l
38

MediaWiki:Common.css

→ Edit MediaWiki:Common.css

 /* prevent ugly horizontal page expansion */
 pre { overflow: auto; }

De-Orphan

Not needed/used any more, but here it goes:

SQL: module_deps

After moving the webserver's document root to another place, the module_deps table needs to be cleared, otherwise the websever may look for images (e.g. skins/common/images/sort_down.gif) in their old (cached?) places.

Extensions

# https://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi
require_once("$IP/extensions/SyntaxHighlight_GeSHi-git/SyntaxHighlight_GeSHi.php");

#
# https://www.mediawiki.org/wiki/Extension:ConfirmEdit
#
require_once("$IP/extensions/ConfirmEdit-git/ConfirmEdit.php");
#
### FancyCaptcha
# $ sudo apt-get install python-imaging
# $ python extensions/ConfirmEdit/captcha.py --font=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf \
#       --wordlist=/usr/share/dict/words --key=s3cr3t --output=cache/FancyCaptcha/ \
#       --count=100 --dirs=2 --verbose
require_once("$IP/extensions/ConfirmEdit-git/FancyCaptcha.php");
$wgCaptchaClass     = 'FancyCaptcha';
$wgCaptchaDirectory = "$IP/cache/FancyCaptcha";
$wgCaptchaDirectoryLevels = 2;
$wgCaptchaSecret    = "s3cr3t";

### ReCaptcha
# https://www.google.com/recaptcha
# require_once("$IP/extensions/ConfirmEdit-git/ReCaptcha.php");
# $wgCaptchaClass        = 'ReCaptcha';
# $wgReCaptchaPublicKey  = 'xxx';
# $wgReCaptchaPrivateKey = 'yyy';

# https://www.mediawiki.org/wiki/Extension:RSS
# require_once("$IP/extensions/RSS-git/RSS.php");

# https://www.mediawiki.org/wiki/Extension:PdfBook
# $ sudo apt-get install htmldoc
# require_once( "$IP/extensions/PdfBook-svn/PdfBook.php" );
# $wgPdfBookTab    = true;
# $wgPdfBookFormat = "single";

# https://www.mediawiki.org/wiki/Extension:Piwik_Integration
# require_once("$IP/extensions/Piwik-svn/Piwik.php");
# $wgPiwikURL = "www.example.com/piwik/";
# $wgPiwikIDSite = "4";

# https://www.mediawiki.org/wiki/Extension:PageSecurity
# require_once( "$IP/extensions/PageSecurity/PageSecurity.php" );
# $wgGroupPermissions['*']['read'] = false;
# $wgGroupPermissions['*']['edit'] = false;
# $wgWhitelistRead = array( "Main Page", "Special:Userlogin", "-", "MediaWiki:Monobook.css" );
# $wgShowIPinHeader = false;
# $wgFeedClasses = array();
# $wgEnableParserCache = false;
# $wgCachePages = false;

Special Pages

Sitemap

With generateSitemap.php it is possible to generate a sitemap for the wiki:

mkdir 0770 sitemap
sudo chgrp www-data sitemap
sudo -u www-data MW_INSTALL_PATH=`pwd` php ../../maintenance/generateSitemap.php \
        --conf `pwd`/LocalSettings.php \
        --fspath /var/www/example.com/wiki/sitemap \
        --server https://example.com \
        --urlpath https://example.com/wiki/sitemap \
        --identifier mywiki \
        --compress yes

Reference Tooltips

Reference Tooltips are little JavaScript popup windows when hovering over citation references. To install, we need to do the following:

0. Install Extension:Gadgets
require_once( "extensions/Gadgets-git/Gadgets.php" );
  1. Create MediaWiki:Gadget-ReferenceTooltips.css
  2. Create MediaWiki:Gadget-ReferenceTooltips.js
  3. Create MediaWiki:Gadgets-definition with the following content:
ReferenceTooltips|ReferenceTooltips.js‎|ReferenceTooltips.css

With all that in place, Gadgets should appear under Preferences

Links

References