Mediawiki

From Segfault
Jump to: navigation, 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

    yum 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.24/mediawiki-1.24.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.

Git

As of v1.18.2, Mediawiki moved to Git. Let's checkout the source via git and export it to the document root:

git clone https://git.wikimedia.org/git/mediawiki/core.git
cd mediawiki-git
git archive --format=tar 1.24.0 | tar -C /var/www/mediawiki -xf -

Now we create symlinks in our document root:

cd /var/www/mediawiki
sudo chown -R www-data:www-data images cache

Use a browser to open the Wiki URL and installation should generate the LocalSettings.php. After the wiki is up & running, we can remove some bits:

rm -rf COPYING CREDITS FAQ HISTORY INSTALL README README.mediawiki RELEASE-NOTES* UPGRADE *.php5 docs maintenance mw-config serialized tests

Skins

Starting with v1.24, skins are no longer discovered automatically but have to be installed manually.[1]. To install the Vector Skin (or any other skin):

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

Add the following to LocalSettings.php

require_once("skins/vector/Vector.php");

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

Git

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

Note: upgrading to v1.25 requires external libraries to be installed first:

WIKIDIR=/var/www/mediawiki
git clone https://gerrit.wikimedia.org/r/mediawiki/vendor mediawiki-vendor-git
cd mediawiki-vendor-git
git archive --format=tar --prefix=vendor/ origin/REL1_25 | tar -C $WIKIDIR -xf -

Display the currently installed version:

$ grep wgVersion $WIKIDIR/includes/DefaultSettings.php
$wgVersion = '1.25.0';

Export a new stable version via git:

WIKIDIR=/var/www/mediawiki
cd mediawiki-git
git checkout master && git pull && git clean -dfx

git archive --format=tar 1.25.1 | sudo tar -C $WIKIDIR -xf -                               # sudo may or may not be needed!

Run update process:

cd $WIKIDIR
script -a -c "date; php maintenance/update.php --conf `pwd`/LocalSettings.php" ~/mwupdate.log        # Logs all output

If this fails, try setting MW_INSTALL_PATH:

MW_INSTALL_PATH=`pwd` php maintenance/update.php

Remove unnecessary files:

rm -rf COPYING CREDITS FAQ HISTORY INSTALL README README.mediawiki RELEASE-NOTES* UPGRADE *.php5 docs maintenance mw-config serialized tests

Updating the extensions too:

TAG=origin/REL1_24

cd ../mediawiki-Cite-git && git checkout master && git pull && git clean -dfx
git archive --format=tar $TAG | tar -C $WIKIDIR/extensions/Cite -xf -

cd ../mediawiki-RecentPages-git && git checkout master && git pull && git clean -dfx
git archive --format=tar master | tar -C $WIKIDIR/extensions/RecentPages -xf -

cd ../mediawiki-SyntaxHighlight_GeSHi-git && git checkout master && git pull && git clean -dfx
git archive --format=tar $TAG | tar -C $WIKIDIR/extensions/SyntaxHighlight_GeSHi -xf -

cd ../piwik-mediawiki-extension-git && git checkout master && git pull && git clean -dfx
git archive --format=tar master | tar -C $WIKIDIR/extensions/piwik-mediawiki-extension -xf -

cd ../mediawiki-MobileFrontend-git && git checkout master && git pull && git clean -dfx
git archive --format=tar $TAG | tar -C $WIKIDIR/extensions/MobileFrontend -xf -

cd ../mediawiki-PrivatePageProtection-svn && svn update
svn export --force .  $WIKIDIR/extensions/PrivatePageProtection                      # Unmaintained as of March 2014![2][3]

Update the skin, as it's not part of mediawiki-core in a Git checkout:

cd ../mediawiki-skins-Vector-git && git checkout master && git pull && git clean -dfx
git archive --format=tar $TAG | tar -C $WIKIDIR/skins/vector -xf -

Tarballs

Update from the latest tarball:

wget https://releases.wikimedia.org/mediawiki/1.30/mediawiki-1.30.0.tar.gz{,.sig}
gpg --verify mediawiki*tar.gz.sig

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

umask 0022
sudo chown -R $USER .
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" ~/.log/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 uneccessary cruft:

chmod 0 docs/ maintenance/ mw-config/ tests/
rm -vf COPYING CODE_OF_CONDUCT.md CREDITS FAQ HISTORY INSTALL README* RELEASE-NOTES* UPGRADE *.php5

sudo chmod 0750                 cache/ images/ sitemap/
sudo chown -R 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

 $ 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

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

  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

Scripts

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