Difference between revisions of "MediaWiki"

From YobiWiki
Jump to navigation Jump to search
 
(20 intermediate revisions by the same user not shown)
Line 15: Line 15:
 
Easy to get:
 
Easy to get:
 
* http://meta.wikimedia.org/wiki/Preventing_Access#1.5_Upwards
 
* http://meta.wikimedia.org/wiki/Preventing_Access#1.5_Upwards
  +
==Prevent spam on public wiki==
  +
* http://www.mediawiki.org/wiki/Manual:Combating_spam
  +
  +
I chose two measures on this public wiki, bored by the creation of new fake accounts and new wikipages (about 4 new users per day!):
  +
* Prevent new users to create new pages, they need to ask me to be powerusers (but a new user can still edit an existing page)
  +
** /etc/mediawiki/LocalSettings.php:
  +
$wgGroupPermissions['*']['edit'] = false;
  +
$wgGroupPermissions['*']['upload'] = false;
  +
$wgGroupPermissions['*']['createpage'] = false;
  +
$wgGroupPermissions['*']['createtalk'] = false;
  +
$wgGroupPermissions['user']['upload'] = false;
  +
$wgGroupPermissions['user']['createpage'] = false;
  +
$wgGroupPermissions['user']['createtalk'] = false;
  +
$wgGroupPermissions['poweruser']['upload'] = true;
  +
$wgGroupPermissions['poweruser']['createpage'] = true;
  +
$wgGroupPermissions['poweruser']['createtalk'] = true;
  +
* Add captcha with http://www.mediawiki.org/wiki/Extension:ConfirmEdit
  +
** There is a Debian package but it comes with dependencies to latex & image manipulation suites so to keep it simple I installed it manually, using only SimpleCaptcha.
  +
** But SimpleCaptcha (a simple addition) is too simple for what I suspect to be farms of humans solving captcha... So I customized it a bit in /etc/mediawiki/extensions/ConfirmEdit/Captcha.php:
  +
<source lang=php>
  +
function getCaptcha() {
  +
$a = mt_rand(0xa, 0x2f);
  +
$b = mt_rand(0xa, 0x1f);
  +
$op = '+';
  +
$test = "0x" . strtoupper(dechex($a)) . " $op ";
  +
$test .= "0x" . strtoupper(dechex($b)) . " in base10";
  +
$answer = $a + $b;
  +
return array('question' => $test, 'answer' => $answer);
  +
}
  +
</source>
  +
which asks you e.g. "0x1C + 0x1F in base10="
  +
  +
Hmmm actually I discovered Google is smart enough to solve this captcha, let's hope spammers are more stupid ;-)
  +
* https://www.google.be/search?q=0x1C+%2B+0x1F+in+base%2010%20%3D
  +
So here is a slightly improved version
  +
<source lang=php>
  +
function getCaptcha() {
  +
$a = mt_rand(0xa, 0x2f);
  +
$b = mt_rand(0xa, 0x1f);
  +
$c = chr(mt_rand(65,90));
  +
$op = '+';
  +
$test = "0x" . strtoupper(dechex($a)) . " $op ";
  +
$test .= "0x" . strtoupper(dechex($b)) . " in base10, prefixed with \"" . $c . "\"";
  +
$answer = $c . ($a + $b);
  +
return array( 'question' => $test, 'answer' => $answer );
  +
}
  +
</source>
  +
which asks you e.g. 0x1C + 0x1F in base10, prefixed with "K"
   
 
==Customisation==
 
==Customisation==
Line 33: Line 81:
   
 
Here is the script I used to import my phpwiki pages:
 
Here is the script I used to import my phpwiki pages:
  +
<source lang=bash>
<pre>
 
 
#!/bin//bash
 
#!/bin//bash
   
Line 65: Line 113:
 
done
 
done
   
</pre>
+
</source>
 
==Upgrade to 1.11==
 
==Upgrade to 1.11==
 
A big jump from 1.5...
 
A big jump from 1.5...
Line 71: Line 119:
 
<br>Strangely apt-get wanted to install mysql-server even if the package just recommends it.
 
<br>Strangely apt-get wanted to install mysql-server even if the package just recommends it.
 
<br>So I downloaded the package and used dpkg -i
 
<br>So I downloaded the package and used dpkg -i
  +
==Upgrade to 1.12==
  +
Debian did a transparent upgrade but things were a bit broken, for some special or unknown pages I got a SQL error about a missing protected_titles table.
  +
<br>Solution is in this [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=472831 bugreport]: run
  +
php /var/lib/mediawiki/maintenance/update.php
  +
==Upgrade to 1.14==
  +
Same story...
  +
<br>Debian did a transparent upgrade but things were a bit broken, for some special or unknown pages I got a SQL error about a missing protected_titles table.
  +
<br>Solution: run
  +
php /var/lib/mediawiki/maintenance/update.php
   
  +
==Extensions==
==[[OpenID]] support==
 
  +
===[[OpenID]] support===
 
I installed the following extension:
 
I installed the following extension:
 
* http://www.mediawiki.org/wiki/Extension:OpenID
 
* http://www.mediawiki.org/wiki/Extension:OpenID
Line 90: Line 148:
   
 
I had to patch the extension as apparently the API of php-OpenID changed since
 
I had to patch the extension as apparently the API of php-OpenID changed since
  +
<source lang=diff>
<pre>
 
 
--- Consumer.php.orig 2008-03-09 00:00:09.000000000 +0100
 
--- Consumer.php.orig 2008-03-09 00:00:09.000000000 +0100
 
+++ Consumer.php 2008-03-09 00:00:33.000000000 +0100
 
+++ Consumer.php 2008-03-09 00:00:33.000000000 +0100
Line 131: Line 189:
 
} else {
 
} else {
 
return $openid;
 
return $openid;
</pre>
+
</source>
 
Normally the extension makes your personal page an OpenID server as well but I didn't try
 
Normally the extension makes your personal page an OpenID server as well but I didn't try
 
<br>Now you can login via [[Special:OpenIDLogin]] or associate your OpenID URL to your existing account via [[Special:OpenIDConvert]]
 
<br>Now you can login via [[Special:OpenIDLogin]] or associate your OpenID URL to your existing account via [[Special:OpenIDConvert]]
 
<br>BTW initially I didn't know about [[Special:OpenIDConvert]] and I manipulated directly the SQL table ${wgDBprefix}user_openid
 
<br>BTW initially I didn't know about [[Special:OpenIDConvert]] and I manipulated directly the SQL table ${wgDBprefix}user_openid
==Google Gears support==
+
===Google Gears LocalServer===
  +
cf [[Mediawiki LocalServer]] extension
This is an attempt to provide an offline version of the wiki.
 
  +
===SyntaxHighlight GeSHi===
<br>Inspired by [http://andreas.schmidt.name/blog/2007/10/google-gears-hack-mediawiki-offline-functionality-in-less-than-one-hour.html this blog post]
 
  +
This is the extension that provides all the nice syntax highlighting you can find in this wiki
<br>Using [http://gears.google.com/ Google Gears] technology
 
  +
<br>Very easy to install and to use
  +
<br>cf [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi the official page]
  +
===Raw Snippet===
  +
Get a download link aside a code, pre, source or nowiki paragraph to be able to download it easily
  +
<br>cf [[Mediawiki RawSnippet]]
  +
===Piwik===
   
  +
Here is a small extension to install under extensions/Piwik/Piwik.php, you can [{{#file: Piwik.php}} download it here]:
You must first install the plugin [http://code.google.com/apis/gears/install.html available here], note that it does a stupid browser detection and refuses my Iceweasel 2.0 so I had to cheat with my User Agent Switch extension and mimick Firefox 2.0 ;-)
 
  +
<source lang=php>
 
On the Mediawiki server:
 
* Create a folder gears in your MediaWiki installation directory
 
** I created /etc/mediawiki/gears <- /var/lib/mediawiki/gears <- /usr/share/mediawiki/gears
 
** As I'm using rewriting rules, I had to add to /etc/apache2/sites-available/wiki.yobi.be:
 
RewriteCond %{REQUEST_URI} !/gears/
 
* Download the [http://code.google.com/apis/gears/gears_init.js gears_init.js] from the Google Gears web site and place it in the newly created folder
 
* Download the [http://code.google.com/apis/gears/tutorials/go_offline.js gears_offline.js] from the Google Gears tutorial
 
* Modify the manifest file name in this file to:
 
var MANIFEST_FILENAME = "/gears/manifest.php";
 
* Create the manifest.php that creates the file list on the fly (based on access to the database):
 
<pre>
 
{
 
"betaManifestVersion": 1,
 
<?php
 
require_once("../DBSettings.php");
 
$l = mysql_connect($wgDBserver,$wgDBuser,$wgDBpassword);
 
mysql_selectdb($wgDBname);
 
$q = "SELECT max(rc_timestamp) from ".$wgDBprefix."recentchanges";
 
$r = mysql_query($q);
 
$t = mysql_fetch_row($r);
 
echo ' "version": "' . $t[0] . '",';
 
?>
 
 
"entries": [
 
<?php
 
$q = "SELECT page_title from ".$wgDBprefix."page";
 
$r = mysql_query($q);
 
while ($t = mysql_fetch_row($r))
 
{
 
echo ' { "url": "/wiki/' . $t[0] . '" },';
 
}
 
?>
 
{ "url": "/wiki/Main_Page" },
 
{ "url": "/gears/go_offline.js"},
 
{ "url": "/gears/gears_init.js"}
 
]
 
}
 
</pre>
 
Note that I moved my DB settings from LocalSettings.php to DBSettings.php, replaced now by a
 
require_once("DBSettings.php");
 
And at the end of LocalSettings.php I add a link to my new extension:
 
require_once("$IP/extensions/GGears/ggears.php");
 
So that means another new directory /etc/mediawiki/extensions/GGears with the file ggears.php:
 
<pre>
 
 
<?php
 
<?php
   
 
if (defined('MEDIAWIKI')) {
 
if (defined('MEDIAWIKI')) {
   
function fnMyGGearsHook($out) {
+
function fnPiwikHookJS($out) {
  +
global $wgPiwikURL;
$gearjs='<script type="text/javascript" src="/gears/gears_init.js"></script>';
 
  +
global $wgPiwikActionName;
$out->addScript($gearjs);
 
  +
global $wgPiwikIdSite;
$gearjs='<script type="text/javascript" src="/gears/go_offline.js"></script>';
 
  +
$piwikcode ="\n".'<!-- Piwik -->';
$out->addScript($gearjs);
 
  +
$piwikcode.="\n".'<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">';
$gearinit='init()';
 
  +
$piwikcode.="\n".'<script language="javascript" src="'.$wgPiwikURL.'/piwik.js" type="text/javascript"></script>';
$out->addInlineScript($gearinit);
 
  +
$piwikcode.="\n".'<script type="text/javascript">';
return true;
 
  +
$piwikcode.="\n".'<!--';
}
 
  +
$piwikcode.="\n".'piwik_action_name = '.$wgPiwikActionName.';';
 
  +
$piwikcode.="\n".'piwik_idsite = '.$wgPiwikIdSite.';';
function fnMyGGearsHook2() {
 
  +
$piwikcode.="\n".'piwik_url = "'.$wgPiwikURL.'/piwik.php";';
echo '<li><a href="#" onclick="createStore();">create Store</a></li>';
 
  +
$piwikcode.="\n".'piwik_log(piwik_action_name, piwik_idsite, piwik_url);';
echo '<li><a href="#" onclick="capture();">capture</a></li>';
 
  +
$piwikcode.="\n".'//-->';
echo '<li><a href="#" onclick="uncapture();">uncapture</a></li>';
 
  +
$piwikcode.="\n".'</script><object>';
echo '<li><a href="#" onclick="removeStore();">remove Store</a></li>';
 
  +
$piwikcode.="\n".'<noscript><p>Web analytics <img src="'.$wgPiwikURL.'/piwik.php" style="border:0" alt="piwik"/></p>';
echo '<span id="textOut"></span>';
 
  +
$piwikcode.="\n".'</noscript></object></a>';
  +
$piwikcode.="\n".'<!-- /Piwik -->';
  +
$piwikcode.="\n";
  +
$out->addScript($piwikcode);
 
return true;
 
return true;
 
}
 
}
   
$wgExtensionCredits['other'][] = array('name' => 'GGears',
+
$wgExtensionCredits['other'][] = array('name' => 'Piwik',
 
'version' => '0.1',
 
'version' => '0.1',
 
'author' => 'Philippe Teuwen',
 
'author' => 'Philippe Teuwen',
'url' => 'http://www.mediawiki.org/wiki/Extension:GGears',
+
// 'url' => 'http://www.mediawiki.org/wiki/Extension:Piwik',
'description' => 'Allows Google Gears to work offline');
+
'url' => 'http://wiki.yobi.be/wiki/Piwik',
  +
'description' => 'Injects Piwik JS');
$wgHooks['BeforePageDisplay'][] = 'fnMyGGearsHook';
 
$wgHooks['MonoBookTemplateToolboxEnd'][] = 'fnMyGGearsHook2';
+
$wgHooks['BeforePageDisplay'][] = 'fnPiwikHookJS';
 
}
 
}
   
 
?>
 
?>
</pre>
+
</source>
  +
Then add the following to the bottom of your LocalSettings.php, customized according to what Piwik told you:
'''TODO'''
 
  +
<source lang=php>
<br>There is always a complete replication of online content as soon as some change occurred (this could be made smarter by not leaving everything to Gears, but implementing your own update strategy) and moreover I've to refresh the page :-( so it makes it quite impractical as such...
 
  +
$wgPiwikURL='http://mywebsite/piwik';
<br>Check also http://code.google.com/apis/gears/samples/hello_world_managedstore/managed_store.html
 
  +
$wgPiwikActionName='document.title';
<br>Having a CSS trick to see clearly when we're offline could help
 
  +
$wgPiwikIdSite=1;
  +
require_once("$IP/extensions/Piwik/Piwik.php");
  +
</source>
   
 
==Tips==
 
==Tips==
Line 232: Line 259:
 
* [http://www.mediawiki.org/wiki/Help:FAQ MediaWiki FAQ]
 
* [http://www.mediawiki.org/wiki/Help:FAQ MediaWiki FAQ]
 
Useful pages:
 
Useful pages:
  +
* http://www.mediawiki.org/wiki/Sysadmin_hub
 
* http://www.mediawiki.org/wiki/Manual:Backing_up_a_wiki
 
* http://www.mediawiki.org/wiki/Manual:Backing_up_a_wiki
 
* http://www.mediawiki.org/wiki/Manual:AdminSettings.php
 
* http://www.mediawiki.org/wiki/Manual:AdminSettings.php
 
* http://www.mediawiki.org/wiki/Manual:Upgrading_to_1.11
 
* http://www.mediawiki.org/wiki/Manual:Upgrading_to_1.11
  +
* http://www.mediawiki.org/wiki/Manual:Upgrading
 
* http://www.mediawiki.org/wiki/Manual:Short_URL/wiki/Page_title_--_with_aliases--root_access
 
* http://www.mediawiki.org/wiki/Manual:Short_URL/wiki/Page_title_--_with_aliases--root_access
 
* http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
 
* http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
 
* http://www.mediawiki.org/wiki/Manual:%24wgLanguageCode
 
* http://www.mediawiki.org/wiki/Manual:%24wgLanguageCode
 
* http://www.mediawiki.org/wiki/Manual:%24wgUseAjax
 
* http://www.mediawiki.org/wiki/Manual:%24wgUseAjax
  +
* http://www.mediawiki.org/wiki/Extension:ConfirmEdit#FancyCaptcha_addon

Latest revision as of 09:23, 7 November 2013

Install

Version 1.5 was not yet on amd64 feeds but v1.4.x reclaimed php4 so I took mediawiki v1.5 from the i386 feeds as anyway mediawiki is all arch.

  • Raise the PHP memory limit: create /var/lib/mediawiki1.5/.htaccess with
php_value memory_limit 32M

Preventing access to pages

Better solution seems to use this patch:

Or as refered on http://meta.wikimedia.org/wiki/Hidden_pages this one:

Disable anonymous reading

Easy to get:

Prevent spam on public wiki

I chose two measures on this public wiki, bored by the creation of new fake accounts and new wikipages (about 4 new users per day!):

  • Prevent new users to create new pages, they need to ask me to be powerusers (but a new user can still edit an existing page)
    • /etc/mediawiki/LocalSettings.php:
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['upload'] = false;
$wgGroupPermissions['*']['createpage'] = false;
$wgGroupPermissions['*']['createtalk'] = false;
$wgGroupPermissions['user']['upload'] = false;
$wgGroupPermissions['user']['createpage'] = false;
$wgGroupPermissions['user']['createtalk'] = false;
$wgGroupPermissions['poweruser']['upload'] = true;
$wgGroupPermissions['poweruser']['createpage'] = true;
$wgGroupPermissions['poweruser']['createtalk'] = true;
  • Add captcha with http://www.mediawiki.org/wiki/Extension:ConfirmEdit
    • There is a Debian package but it comes with dependencies to latex & image manipulation suites so to keep it simple I installed it manually, using only SimpleCaptcha.
    • But SimpleCaptcha (a simple addition) is too simple for what I suspect to be farms of humans solving captcha... So I customized it a bit in /etc/mediawiki/extensions/ConfirmEdit/Captcha.php:
function getCaptcha() {
    $a = mt_rand(0xa, 0x2f);
    $b = mt_rand(0xa, 0x1f);
    $op = '+';
    $test = "0x" . strtoupper(dechex($a)) . " $op ";
    $test .= "0x" . strtoupper(dechex($b)) . " in base10";
    $answer = $a + $b;
    return array('question' => $test, 'answer' => $answer);
}

which asks you e.g. "0x1C + 0x1F in base10="

Hmmm actually I discovered Google is smart enough to solve this captcha, let's hope spammers are more stupid ;-)

So here is a slightly improved version

function getCaptcha() {
    $a = mt_rand(0xa, 0x2f);
    $b = mt_rand(0xa, 0x1f);
    $c = chr(mt_rand(65,90));
    $op = '+';
    $test = "0x" . strtoupper(dechex($a)) . " $op ";
    $test .= "0x" . strtoupper(dechex($b)) . " in base10, prefixed with \"" . $c . "\"";
    $answer = $c . ($a + $b);
    return array( 'question' => $test, 'answer' => $answer );
}

which asks you e.g. 0x1C + 0x1F in base10, prefixed with "K"

Customisation

Logo

  • I created a symlink from /var/lib/mediawiki1.5/local to /etc/mediawiki1.5/localdata
  • In LocalSettings.php: $wgLogo = "$wgScriptPath/local/mylogo.png";

Menus

Import/Export

HTML-WikiConverter

apt-get install libhtml-wikiconverter-perl

Dialogs are not yet packaged, cf bugreports 419918 and 448912, so for now:

perl -MCPAN -e 'install HTML::WikiConverter::MediaWiki'

Here is the script I used to import my phpwiki pages:

#!/bin//bash


for i in lists/*; do
    mkdir -p $(basename $i)
    cd $(basename $i)
    for p in $(cat ../$i); do
	echo $p
	if [ ! -e "$p.html" ]; then
	    wget -q -O - "http://wiki.teuwen.org/$p" > "$p.html"
	fi
	cat > "$p.txt" <<EOF
''Converted with [[MediaWiki#HTML-WikiConverter|HTML::WikiConverter::MediaWiki]] from my old phpwiki site''
----
EOF
	cat "$p.html"|\
	   awk '
		/class=.wikitext/ {b=1};
		/Begin browse-footer/ {b=0};
		b==1' \
	 | sed 's/<div class="wikitext">//g' \
	 | sed 's/<span style="white-space: nowrap">//g' \
	 | sed 's/<span class="wikipage">//g' \
	 | sed 's/<img src="\/phpwikidata\/themes\/[a-zA-Z0-9]\+\/images\/[a-zA-Z0-9]\+.png" alt="" class="linkicon" border="0" \/>//g' \
	 | sed 's/\x92/\x27/g' \
	 |html2wiki --encoding iso-8859-1 --dialect MediaWiki >> "$p.txt"
#	  >> "$p.txt"
    done
    cd ..
done

Upgrade to 1.11

A big jump from 1.5...
Now the package is simply called mediawiki instead of mediawiki1.x
Strangely apt-get wanted to install mysql-server even if the package just recommends it.
So I downloaded the package and used dpkg -i

Upgrade to 1.12

Debian did a transparent upgrade but things were a bit broken, for some special or unknown pages I got a SQL error about a missing protected_titles table.
Solution is in this bugreport: run

php /var/lib/mediawiki/maintenance/update.php

Upgrade to 1.14

Same story...
Debian did a transparent upgrade but things were a bit broken, for some special or unknown pages I got a SQL error about a missing protected_titles table.
Solution: run

php /var/lib/mediawiki/maintenance/update.php

Extensions

OpenID support

I installed the following extension:

I installed the extension into /etc/mediawiki/extensions and made a symlink from /var/lib/mediawiki/extensions
I created the extra SQL table:

mysql -uroot -p mediawiki < openid_table.sql

But I had first to edit openid_table.sql to add my table prefix (cf $wgDBprefix)
I installed php-openid:

apt-get install php-openid

Some modifications in /etc/mediawiki/LocalSettings.php:

# Adding /usr/share/php in the include_path to find the Debian php-openid package:
ini_set( "include_path", ".:$IP:$IP/includes:$IP/languages".":/usr/share/php" );
require_once("$IP/extensions/OpenID/OpenID.php");
$wgTrustRoot = "http://wiki.yobi.be/";
$wgOpenIDLoginLogoUrl = "local/login-bg.gif";

(the logo was downloaded from http://www.openid.net/login-bg.gif)

I had to patch the extension as apparently the API of php-OpenID changed since

--- Consumer.php.orig   2008-03-09 00:00:09.000000000 +0100
+++ Consumer.php        2008-03-09 00:00:33.000000000 +0100
@@ -144,7 +144,7 @@
 
                 default: # No parameter, returning from a server
 
-                       $response = $consumer->complete($_GET);
+                       $response = $consumer->complete($_GET['openid_return_to']);
 
                        if (!isset($response)) {
                                $wgOut->errorpage('openiderror', 'openiderrortext');
@@ -162,7 +162,7 @@
                         case Auth_OpenID_SUCCESS:
                                // This means the authentication succeeded.
                                $openid = $response->identity_url;
-                               $sreg = $response->extensionResponse('sreg');
+                               $sreg = $response->extensionResponse('sreg', true);
 
                                if (!isset($openid)) {
                                        $wgOut->errorpage('openiderror', 'openiderrortext');
@@ -558,7 +558,7 @@
        }
 
        function OpenIDToUserName($openid) {
-        if (Services_Yadis_identifierScheme($openid) == 'XRI') {
+        if (Auth_Yadis_identifierScheme($openid) == 'XRI') {
                        wfDebug("OpenID: Handling an XRI: $openid\n");
                        return OpenIDToUserNameXri($openid);
                } else {
--- OpenID.php.orig     2008-03-08 22:41:02.000000000 +0100
+++ OpenID.php  2008-03-09 00:09:13.000000000 +0100
@@ -226,7 +226,7 @@
 
        function OpenIDToUrl($openid) {
                /* ID is either an URL already or an i-name */
-        if (Services_Yadis_identifierScheme($openid) == 'XRI') {
+        if (Auth_Yadis_identifierScheme($openid) == 'XRI') {
                        return OpenIDXriToUrl($openid);
                } else {
                        return $openid;

Normally the extension makes your personal page an OpenID server as well but I didn't try
Now you can login via Special:OpenIDLogin or associate your OpenID URL to your existing account via Special:OpenIDConvert
BTW initially I didn't know about Special:OpenIDConvert and I manipulated directly the SQL table ${wgDBprefix}user_openid

Google Gears LocalServer

cf Mediawiki LocalServer extension

SyntaxHighlight GeSHi

This is the extension that provides all the nice syntax highlighting you can find in this wiki
Very easy to install and to use
cf the official page

Raw Snippet

Get a download link aside a code, pre, source or nowiki paragraph to be able to download it easily
cf Mediawiki RawSnippet

Piwik

Here is a small extension to install under extensions/Piwik/Piwik.php, you can [{{#file: Piwik.php}} download it here]:

<?php

if (defined('MEDIAWIKI')) {

function fnPiwikHookJS($out) {
    global $wgPiwikURL;
    global $wgPiwikActionName;
    global $wgPiwikIdSite;
    $piwikcode ="\n".'<!-- Piwik -->';
    $piwikcode.="\n".'<a href="http://piwik.org" title="Web analytics" onclick="window.open(this.href);return(false);">';
    $piwikcode.="\n".'<script language="javascript" src="'.$wgPiwikURL.'/piwik.js" type="text/javascript"></script>';
    $piwikcode.="\n".'<script type="text/javascript">';
    $piwikcode.="\n".'<!--';
    $piwikcode.="\n".'piwik_action_name = '.$wgPiwikActionName.';';
    $piwikcode.="\n".'piwik_idsite = '.$wgPiwikIdSite.';';
    $piwikcode.="\n".'piwik_url = "'.$wgPiwikURL.'/piwik.php";';
    $piwikcode.="\n".'piwik_log(piwik_action_name, piwik_idsite, piwik_url);';
    $piwikcode.="\n".'//-->';
    $piwikcode.="\n".'</script><object>';
    $piwikcode.="\n".'<noscript><p>Web analytics <img src="'.$wgPiwikURL.'/piwik.php" style="border:0" alt="piwik"/></p>';
    $piwikcode.="\n".'</noscript></object></a>';
    $piwikcode.="\n".'<!-- /Piwik -->';
    $piwikcode.="\n";
    $out->addScript($piwikcode);
    return true;
}

$wgExtensionCredits['other'][] = array('name' => 'Piwik',
                           'version' => '0.1',
                           'author' => 'Philippe Teuwen',
//                         'url' => 'http://www.mediawiki.org/wiki/Extension:Piwik',
                           'url' => 'http://wiki.yobi.be/wiki/Piwik',
                           'description' => 'Injects Piwik JS');
$wgHooks['BeforePageDisplay'][] = 'fnPiwikHookJS';
}

?>

Then add the following to the bottom of your LocalSettings.php, customized according to what Piwik told you:

$wgPiwikURL='http://mywebsite/piwik';
$wgPiwikActionName='document.title';
$wgPiwikIdSite=1;
require_once("$IP/extensions/Piwik/Piwik.php");

Tips

When developing extensions I had the problem that cached pages didn't get refreshed properly even if they claim it shouldn't concern logged users.
It is possible to force one individual page to be invalidated and refreshed by using ?action=purge

References

Useful pages: