Debian MethodMediaWikiNginxPostgreSQLSecurityWeb Server
MediaWiki: Installation and Configuration
Introduction
A wiki is a content management system for websites that allows pages to be freely and equally editable by all authorized visitors. Wikis are used to facilitate collaborative document writing with minimal constraints. The wiki was invented by Ward Cunningham in 1995, for a section of a website on computer programming that he called WikiWikiWeb. The word "wiki" comes from the Hawaiian term wiki wiki, which means "fast" or "informal". By the mid-2000s, wikis had reached a good level of maturity and are associated with Web 2.0. Created in 2001, Wikipedia has become the world's most visited wiki.
MediaWiki is a Wiki engine written in PHP and created by Magnus Manske. Initially developed for Wikipedia (which has been using it since 2002), it also serves as the foundation for other WikiMedia Foundation projects (Wiktionary, Wikisource, Wikibooks or Wikiquote). Other associations have adopted it (e.g., Wikitravel, Mozilla or Ekopedia).
Installation
I'm describing here 2 ways to install Mediawiki. Choose the best for your needs, but I recommend the manual method.
Manual Method
First of all, download the current version with git:
I strongly recommend as well to use git to get all your extensions. You don't need to download all available as it takes some disk space, but you can choose them one by one like that:
Alternatively, you can install it manually from the main site.
PostgreSQL
If after installation you don't want to use MySQL but Postgres as a database, you'll certainly encounter some issues. Refer to this link and look at the FAQ. If it still doesn't work, if you encounter other types of errors, then try this:
If you are using Postgres, you will need to either have a database and user created for you, or simply supply the name of a Postgres user with "superuser" privileges to the configuration form. Often, this is the database user named postgres.
The database that MediaWiki will use needs to have both plpgsql and tsearch2 installed. The installer script will try and install plpgsql, but you may need to install tsearch2 yourself. (tsearch2 is used for searching the text of your wiki). Here's one way to do most of the setup. This is for a Unix-like system, and assumes that you have already installed the plpgsql and tsearch2 modules. In this example, we'll create a database named wikidb, owned by a user named wikiuser. From the command-line, as the postgres user, perform the following steps.
createuser -S -D -R -P -E wikiuser (then enter the password)
createdb -O wikiuser wikidb
createlang plpgsql wikidb
Adding tsearch2 to the database is not a simple step, but hopefully it will already be done for you by whatever packaging process installed the tsearch2 module. In any case, the installer will let you know right away if it cannot find tsearch2.
The above steps are not all necessary, as the installer will try and do some of them for you if supplied with a superuser name and password.
For installing tsearch2 to the wikidb database under Windows, do the following steps:
Find tsearch2.sql (probably under .\PostgreSQL\8.x\share\contrib) and copy it to the postgresql\8.x\bin directory;
From a command prompt at the postgresql\8.x\bin directory, type:
Point (2) seems only to work on windows, because on debian linux 4.0 (etch) only user postgres is allowed to use language c. So there it must be called by:
su - postgres
psql -d wikidb -c "grant select on pg_ts_cfg to wikiuser;"
psql -d wikidb -c "grant select on pg_ts_cfgmap to wikiuser;"
psql -d wikidb -c "grant select on pg_ts_dict to wikiuser;"
psql -d wikidb -c "grant select on pg_ts_parser to wikiuser;"
psql -d wikidb -c "update pg_ts_cfg set locale = current_setting('lc_collate') where ts_name = 'default' and prs_name='default';"
If you receive an error similar to "ERROR: relation "pg_ts_cfg" does not exist" when executing the above statements, try installing tsearch2 to the wikidb database again, but instead use these two separate steps (and then try the grant statements again):
That's all, your MediaWiki core is now up to date. You now need look at extensions.
Extensions upgrade
To upgrade you extensions, you've used git, that's why it will be easy. Anyway, some of them may not be managed with git, but the old repository version (SVN). I've wrote a little script to handle that:
For setting up Mediawiki with Nginx and short URLs, here is the configuration to adopt. I also added SSL and forced redirects from the login page to SSL:
server{includelisten_port.conf;listen443ssl;ssl_certificate/etc/nginx/ssl/deimos.fr/server-unified.crt;ssl_certificate_key/etc/nginx/ssl/deimos.fr/server.key;ssl_session_timeout5m;server_namewiki.deimos.frwiki.m.deimos.fr;root/usr/share/nginx/www/deimos.fr/mytechnotebook;client_max_body_size5m;client_body_timeout60;access_log/var/log/nginx/wiki.deimos.fr_access.log;error_log/var/log/nginx/wiki.deimos.fr_error.log;location/{rewrite^/$$scheme://$host/index.phppermanent;# Short URL redirecttry_files$uri$uri/@rewrite;}location@rewrite{if(!-f$request_filename){rewrite^/(.*)$/index.php?title=$1&$args;}}# Force SSL Loginset$ssl_requested0;if($arg_title~Sp%C3%A9cial:Connexion){set$ssl_requested1;}if($scheme=https){set$ssl_requested0;}if($ssl_requested=1){return301https://$host$request_uri;}# Drop configincludedrop.conf;# Deny direct access to specific folderslocation^~/(maintenance|images)/{return403;}location~\.php${fastcgi_cachemycache;fastcgi_cache_key$request_method$host$request_uri;fastcgi_cache_validany1h;includefastcgi_params;fastcgi_passunix:/var/run/php5-fpm.sock;}location=/_.gif{expiresmax;empty_gif;}location^~/cache/{denyall;}location/dumps{root/usr/share/nginx/www/deimos.fr/mytechnotebook/local;autoindexon;}# BEGIN W3TC Browser Cachegzipon;gzip_typestext/cssapplication/x-javascripttext/x-componenttext/richtextimage/svg+xmltext/plaintext/xsdtext/xsltext/xmlimage/x-icon;location~\.(css|js|htc)${expires31536000s;add_headerPragma"public";add_headerCache-Control"public, must-revalidate, proxy-revalidate";add_headerX-Powered-By"W3 Total Cache/0.9.2.4";}location~\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)${expires3600s;add_headerPragma"public";add_headerCache-Control"public, must-revalidate, proxy-revalidate";add_headerX-Powered-By"W3 Total Cache/0.9.2.4";}location~\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)${expires31536000s;add_headerPragma"public";add_headerCache-Control"public, must-revalidate, proxy-revalidate";add_headerX-Powered-By"W3 Total Cache/0.9.2.4";try_files$uri$uri/@rewrite;}# END W3TC Browser Cache}
One instance, multiple wikis (multi-tenant / wiki-family)
Method 1
If for example you want to do multi-languages or simply have multiple databases and not make n updates for each of your bases, then opt for this solution.
The goal is to modify the code of the LocalSettings.php file in order to be able to detect in the http header (URL), a succession of characters that can refer to one base or another.
Proceed like this:
Run a wiki setup. Once the LocalSettings.php file is created, rename it to fr.php for example.
Run another wiki setup. Once the LocalSettings.php file is created, rename it to en.php for example.
Create the LocalSettings.php file, then insert and adapt the following:
<?php$callingurl=strtolower($_SERVER['SERVER_NAME']);// identify the asking urlif($callingurl=="fr.deimos.fr"){require_once('fr.php');}if($callingurl=="en.deimos.fr"){require_once('en.php');}?>
<?phplist($null,$toplevel,$dontcare)=explode('/',strtolower($_SERVER['REQUEST_URI']));if(is_file("LocalSettings-$toplevel.php")){require_once("LocalSettings-$toplevel.php");}else{print<<<EOF<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>wiki not found </title></head><body><p>The wiki you were looking for was not found.</p></body>EOF;}?>
All you have to do is create your configurations like this:
LocalSettings-wiki1.php
LocalSettings-wiki2.php
LocalSettings-wiki3.php
URL Change
You may have wanted to start a wiki with a certain name and then want to change the folder name later. This means that the url has changed. Let me explain:
By default, searching for terms in mediawiki doesn't take into account words of 3 letters or less. However, in computing, words like XEN, VNC, etc. are very common.
Mediawiki uses mysql's full-text search functionality for its searches. This option allows indexing certain text fields to perform advanced searches that respect certain language constraints. So that the indexes don't take up too much space, the default configuration ignores words with fewer than 4 letters. This is the ft_min_word_len parameter
Modify the /etc/mysql/my.cnf file to modify the ft_min_word_len parameter
/** CSS placed here will be applied to all appearances. */.page-Accueil*.firstHeading,.page-Accueil*h3#siteSub,.page-Accueil*#contentSub{display:none;}
Limit User Creation
This will prohibit user creation, and editing from anonymous users. To be put in your LocalSettings.php file:
# This snippet prevents new registrations from anonymous users
# (Sysops can still create user accounts)
$wgGroupPermissions['*']['createaccount'] = false;
# This snippet prevents editing from anonymous users
$wgGroupPermissions['*']['edit'] = false;
require_once( "includes/DefaultSettings.php" );
File Import
To authorize certain extensions, edit these few lines in your LocalSettings.php file:
<divstyle="clear:both; font-size:.85em; line-height:1.4em; margin-left:2em"><u>Note</u>: Information sent during this connection will not be encrypted.<br/> For more security, it is possible to connect via the
[https://{{SERVERNAME}}/mytechnotebook/index.php?title=Sp%C3%A9cial:Connexion&returnto=Accueil
secure server]. ---
<u>Note</u>: The information sent during this connection will not be
encrypted.<br/> For more security, it is possible to connect through the
[https://{{SERVERNAME}}/mytechnotebook/index.php?title=Sp%C3%A9cial:Connexion&returnto=Accueil
secure server].
</div>
Stay on SSL
The $wgServer value allows you to define the address of the wiki, which will be regularly used to access certain pages. If like me, you have forced authentication in SSL, you will notice that you return to non-encrypted just after logging in. And this is not necessarily the desired case. If you want to stay on SSL when you start using it, edit your configuration on the $wgServer part and replace it with this:
If you need to modify all the pages of your wiki so that the header is identical everywhere, you should use hooks. For this hook (ArticlePageDataBefore), just add this at the end of the LocalSettings.php file:
Here I have an ArticleHeader template that will be displayed in all articles.
Hide Version Information
For Non-Connected Users
You don't necessarily want everyone to be able to get information about the platform on which MediaWiki runs, or information about the MediaWiki version itself. Here's how to remove the Version page for non-connected people:
# Hide Version Special Pagefunction DisableSpecialPages(&$SpecialPageslist){ global $wgUser; if ( !$wgUser->isAllowed('protect') ) { unset( $SpecialPageslist['Version'] ); return true; } return true;}$wgHooks['SpecialPage_initList'][]='DisableSpecialPages';
Hide Sidebar During Edits
It is possible to hide the sidebar when a connected user makes modifications. I found this solution using JavaScript that I liked. The problem is that it's for each user, you have to edit a file that is specific to them. So I modified this JavaScript somewhat to make it work for all users once installed. I also added a tab for file uploads. To set it up, it's quite simple and I remind you that it's only compatible with the Vector theme. Edit this page https://wiki.deimos.fr/MediaWiki:Vector.js and insert this:
/* hide-vector-sidebar.js: Adds a button to toggle visibility of the Vector sidebar. Written by PleaseStand. Public domain; all copyright claims waived as described in http://en.wikipedia.org/wiki/Template:PD-self Modified by Deimosfr <xxx@mycompany.com>*//*global document, window, addOnloadHook, addPortletLink, skin*/varsidebarSwitch;functionsidebarHide(){document.getElementById("mw-panel").style.visibility="hidden";document.getElementById("mw-head-base").style.marginLeft="0";document.getElementById("content").style.marginLeft="0";document.getElementById("left-navigation").style.left="0";document.getElementById("footer").style.marginLeft="0";if(typeofsidebarSwitch=="object"){sidebarSwitch.parentNode.removeChild(sidebarSwitch);}sidebarSwitch=addPortletLink("p-cactions","javascript:sidebarShow()","Show sidebar","ca-sidebar","Show the navigation links","a");}functionsidebarShow(){document.getElementById("mw-panel").style.visibility="";document.getElementById("mw-head-base").style.marginLeft="";document.getElementById("content").style.marginLeft="";document.getElementById("left-navigation").style.left="";document.getElementById("footer").style.marginLeft="";if(typeofsidebarSwitch=="object"){sidebarSwitch.parentNode.removeChild(sidebarSwitch);}sidebarSwitch=addPortletLink("p-cactions","javascript:sidebarHide()","Hide sidebar","ca-sidebar","Hide the navigation links","a");}functioncreateTab(){addPortletLink("p-cactions",wgArticlePath.replace("$1","Special:Upload"),"Import a file");}// Only activate on Vector skinif(skin=="vector"){addOnloadHook(function(){if(document.getElementById("editform")){// Change this if you want to show the sidebar by defaultsidebarHide();// Add custom tabaddOnloadHook(createTab);}});}
And there you go :-). Edit a page to see the result! You can simply show and hide the sidebar from the tabs.
It is possible to struggle somewhat with setting up certain extensions. To address this, you need to activate the superb debug mode by adding these lines to your LocalSettings.php:
You've certainly seen on Wikipedia or other mediawiki windows at the top left of articles presenting certain information. This is called an infobox. While browsing the web, I could see infoboxes more complicated than others requiring plugins when in fact it is possible to create very beautiful ones without plugins.
/* CSS placed here will be applied to all appearances. *//* Hide Acceuil page on the main page */.page-Accueil*.firstHeading,.page-Accueil*h3#siteSub,.page-Accueil*#contentSub{display:none;}/* Set default colors for geshi addon */div.mw-geshi{background-color:#f9f9f9;padding:1em;margin:1em0;border:1pxdashed#2f6fab;}/* Change default background image */body{background:whiteurl("images/a/a6/Headbg.jpg")0px0pxno-repeat;}/* Rounding corners for Firefox and Mozilla browser. Warning: This could make your website slower */.pBody{padding:0.3em0.3em;-moz-border-radius-topright:0.5em;-moz-border-radius-bottomright:0.5em;}.portleth5{-moz-border-radius-topright:0.5em;}#p-cactionsulli,#p-cactionsullia{-moz-border-radius-topright:0.5em;-moz-border-radius-topleft:0.5em;}#content{-moz-border-radius-topleft:0.5em;-moz-border-radius-bottomleft:0.5em;}/* Changing background opacity */.ns-0*#content,.ns-0*#p-cactionsli,.ns-0*#p-cactionslia{filter:alpha(opacity=90);}
Disable Skins
To disable skins, it's very simple, just add this to your LocalSettings:
# To remove various skins from the User Preferences choices$wgSkipSkins = array("standard", "cologneblue", "modern", "monobook", "myskin", "nostalgia", "simple");
FAQ
Here's the site info: View the User Guide for more information on using this software.