Difference between revisions of "MediaWiki"

From YobiWiki
Jump to navigation Jump to search
 
(9 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==

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: