From Server Knowledge Base
Revision as of 14:27, 2 August 2015 by Rootadminacc (talk | contribs) (→‎Migrating to a new server)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Useful areas for customisation are: /wiki/Special:AllMessages and Built-in system messages. You can normally just click the link from the list to edit the text.

Asynchronous snippet

From here

cd extensions/googleAnalytics
cp googleAnalytics.php googleAnalytics.php.backup
vim googleAnalytics.php

Enter the below text into the file and replace the UA- value below with your own.

if ( !defined( 'MEDIAWIKI' ) ) {
        die( 'This file is a MediaWiki extension, it is not a valid entry point' );

$wgExtensionCredits['other'][] = array(
        'path'           => __FILE__,
        'name'           => 'Google Analytics Integration',
        'version'        => '2.0.2',
        'author'         => 'Tim Laqua',
        'descriptionmsg' => 'googleanalytics-desc',
        'url'            => '',

$wgExtensionMessagesFiles['googleAnalytics'] = dirname(__FILE__) . '/googleAnalytics.i18n.php';

$wgHooks['BeforePageDisplay'][]  = 'efGoogleAnalyticsHookText';
$wgHooks['ParserAfterTidy'][] = 'efGoogleAnalyticsASAC';

# registered account
$wgGoogleAnalyticsAccount = "UA-XXXXX-X";

# to be used in case we had AdSense as well and have linked accounts, to enable tracking set this to true
$wgGoogleAnalyticsAddASAC = false;
$wgGoogleAnalyticsIgnoreSysops = true;
$wgGoogleAnalyticsIgnoreBots = true;

function efGoogleAnalyticsASAC( &$parser, &$text ) {
        global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC;

        if( !empty($wgGoogleAnalyticsAccount) && $wgGoogleAnalyticsAddASAC ) {
                $wgOut->addScript('<script type="text/javascript">window.google_analytics_uacct = "' . $wgGoogleAnalyticsAccount . '";</script>');

        return true;

function efGoogleAnalyticsHookText( $out ) {
        $out->addScript( efAddGoogleAnalytics() );
        return true;

function efAddGoogleAnalytics() {
        global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser;
        if (!$wgUser->isAllowed('bot') || !$wgGoogleAnalyticsIgnoreBots) {
                if (!$wgUser->isAllowed('protect') || !$wgGoogleAnalyticsIgnoreSysops) {
                        if ( !empty($wgGoogleAnalyticsAccount) ) {
                                $funcOutput = <<<GASCRIPT
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '$wgGoogleAnalyticsAccount']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                        } else {
                                $funcOutput = "\n<!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. -->";
                } else {
                        $funcOutput = "\n<!-- Google Analytics tracking is disabled for users with 'protect' rights (I.E. sysops) -->";
        } else {
                $funcOutput = "\n<!-- Google Analytics tracking is disabled for bots -->";

        return $funcOutput;

///Alias for efAddGoogleAnalytics - backwards compatibility.
function addGoogleAnalytics() { return efAddGoogleAnalytics(); }


On Unix Debian based (so Ubuntu as well), do the following:

mkdir /var/www/sites/
cd /var/www/sites/
tar xvzf mediawiki-*.tar.gz
cd mediawiki-1.20.2
mv mediawiki-1.20.2/* .
mv .gitreview .jshintignore .jshintrc ..
apt-get install mysql-server build-essential
apt-get install php5-mysql php-pear php5-dev php5-gd php5-imagick php5-intl libcurl3-openssl-dev libicu-dev gobjc++
pecl install intl
apt-get install memcached libmemcached-dev php-auth php-mail php-mail-mime
pecl install Memcache
pear install net_smtp
vim /etc/php5/apache2/php.ini # you need Apache installed first)
# as well as
vim /etc/php5/cli/php.ini

Add in the following lines:

Choose a caching software between APC and xcache. If you want APC, use this. If you want xcache, do:

apt-get install php5-xcache
memcached -u root -d -m 2048 -l -p 11211
/etc/init.d/apache2 restart
cd /var/www/sites
chown root:root -R
cd /var/www/sites/
chmod 700 LocalSettings.php
apt-get install qmail

It will state:

qmail will refuse to accept SMTP messages except to `hostname`.
Make sure to change rcpthosts if you add hosts to locals or virtualdomains!

Then check this:

And go to and run through the configuration. Then download the LocalSettings.php file.

Account confirmation

Upload the .tar.gz to /var/www/sites/

tar -xzf ConfirmAccount.tar.gz
vim LocalSettings.php

Exit the file and run php maintenance/update.php

To turn off "Your biography must be at least 50 words long.", as this does not use $wgAccountRequestMinWords any more:

vim /var/www/sites/


'Biography'       => array( 'enabled' => true, 'minWords' => 50 ),

If you get the below error when approving an account:

Could not create directory "mwstore://accountcreds-backend/accountcreds-public/1/12/123".
chown www-data:www-data images/ -R
chmod 755 images/ -R

Also check your "$wgFileExtensions = {'gif', 'png');" entry

You may need to create an array, something like this:

$wgFileExtensions = array('gif','png');

Capitalise headers and tab titles


.portlet h5 {
        background: transparent;
        padding: 0 1em 0 .5em;
        display: inline;
        height: 1em;
/*      text-transform: lowercase; /* force text to lowercase */
/*      text-transform: uppercase; /* force text to uppercase */
        text-transform: capitalize; /* force text to proper case */
        font-size: 91%;
        font-weight: normal;
        white-space: nowrap;
.portlet h6 {
        background: #ffae2e;
        border: 1px solid #2f6fab;
        border-style: solid solid none solid;
        padding: 0 1em 0 1em;
/*      text-transform: lowercase; /* force text to lowercase */
/*      text-transform: uppercase; /* force text to uppercase */
        text-transform: capitalize; /* force text to proper case */
        display: block;

<pre>#p-personal ul {
        text-transform: capitalize;
#p-cactions li a {
/*      text-transform: lowercase; */
        text-transform: capitalize; /* force text to proper case */

Edit the Sidebar

Go to

Recaptcha installation

First go here and obtain a public and private key for your wiki.

Add the following to LocalSettings.php, below the inclusion of ConfirmEdit:

$wgCaptchaClass = 'ReCaptcha';
$wgReCaptchaPublicKey = 'your public key here';
$wgReCaptchaPrivateKey = 'your private key here';

Short URL configuration

vim LocalSettings.php
$wgScriptPath       = "";
$wgArticlePath      = '/wiki/$1';
$wgUsePathInfo      = true;
$wgScriptExtension  = ".php";
a2enmod rewrite
/etc/init.d/apache2 restart
vim /etc/apache2/sites-available/
    RewriteEngine On
    RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/index.php [L]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteRule ^/?images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2 [L,QSA,B]

    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteRule ^/?images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]

Configure your Virtual Host extras here and add the config to the file above and LocalSettings.php:

Old edited Special:AllMessages

"To protect the wiki against automated account creation, we kindly ask you to solve the simple sum below and enter the answer in the box (more info):"

with the following extract from /extensions/ConfirmEdit/ReCaptcha.i18n.php

"To help protect against automated page creation, please type the two words you see in the box below (more info):"

Migrating to a new server

On the original server, do this:

mysqldump --default-character-set=binary --user=root --password=EnterPasswordHere databasename > dbdump.txt
mysqldump --default-character-set=binary --user=root databasename > dbdump.txt -p

Then copy all your content and the dbdump.txt file across to the new server.

To delete a useless database, do this from within MySQL:


You will need to create an empty database first:

create database DatabaseName;

Then on the new server do:

mysql --silent --local --password=EnterPasswordHere DatabaseName < dbdump.txt
mysql --silent --local DatabaseName < dbdump.txt -p

Go into MySQL and create the MySQL user from the old server (specified in LocalSettings.php on the original server) by doing:

create user 'DatabaseUser'@'localhost' identified by 'password';

Edit your LocalSettings.php to ensure the following setting are correct:

$wgDBtype = "mysql";
$wgDBserver = "localhost";
$wgDBname = "DatabaseName";
$wgDBuser = "DatabaseUser";
$wgDBpassword = "DatabaseUserPassword*";


cp maintenance/generateSitemap.php maintenance/generateSitemap.php.bak
vim maintenance/generateSitemap.php (from here)