MediaWiki

From WebarchDocs
Jump to navigation Jump to search

MediaWiki notes for sites running on Webarchitects servers.

Install

The notes for a manual install follow, see our Ansible playbooks for automating most of the install.

Install the MediaWiki code in ~/sites/default/w/ (you will need to create this directory) and then set these variables in LocalSettings.php:

$wgScriptPath = "/w"; 
$wgArticlePath = "/wiki/$1";  

Edit your ~/sites/default/.htaccess file:

## http://www.mediawiki.org/wiki/Manual:Short_URL/Apache
<IfModule mod_rewrite.c>
  # Enable the rewrite engine
  RewriteEngine On
  # Short url for wiki pages
  RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
  # Redirect / to Main Page
  RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
</IfModule>

The above will result in URL's like this: https://docs.webarch.net/wiki/Main_Page and this is the recomended way to set it up.

If however you want to have http://example.org/Main_Page (please note that this not recomended), then install the MediaWiki code in ~/sites/default/ and then set these variables in LocalSettings.php:

$wgScriptPath = "";
$wgArticlePath = "/$1";

Edit your ~/sites/default/.htaccess file:

# https://www.mediawiki.org/wiki/Manual:Short_URL/Page_title_--_Windows_%26_Apache_without_403_on_Special_Pages
<IfModule mod_rewrite.c>
  # Enable the rewrite engine
  RewriteEngine On
  # If the request isn't for a file
  RewriteCond %{REQUEST_FILENAME} !-f
  # If the request isn't for a directory
  RewriteCond %{REQUEST_FILENAME} !-d
  # Then send the request to index.php with the PATH_INFO
  RewriteRule ^(.*) index.php?title=$1 [L,QSA]
</IfModule>

Note that you will need to edit the w/images/.htaccess file to comment this line out:

#Options +FollowSymLinks

As the Webarchitects servers don't allow clients to set Apache Options in .htaccess files, without this change uploaded files cannot be served without generating errors.

HTTPS

If you have a HTTPS certificate you can add this to LocalSettings.php:

# https://www.mediawiki.org/wiki/Extension:HttpsLogin
$wgSecureLogin = true;

Also make sure you don't have the protocol set to http:// for the $wgServer, for example, set it to be agnostic:

## The protocol and server name to use in fully-qualified URLs
$wgServer = "//wiki.example.org";

Or better set it to use HTTPS:

## The protocol and server name to use in fully-qualified URLs
$wgServer = "https://wiki.example.org";

And add this to your ~/sites/default/.htaccess file:

# STS Header
# https://stackoverflow.com/questions/24144552/how-to-set-hsts-header-from-htaccess-only-on-https
Header set Strict-Transport-Security "max-age=31536000" env=HTTPS

If you do the above things then people using a modern web browser, who login, will only access the site via encrypted connections.

VisualEditor

We have a Parsiod server available for use by client sites, you will need to contact us to ask for this to be made available for your site. Following are the steps you will need to follow to use it.

Install the VisualEditor extension and add these settings to your LocalSettings.php, note that you will need to change wiki.example.org to the domain name of your MediaWiki site:

// https://www.mediawiki.org/wiki/Extension:VisualEditor
require_once "$IP/extensions/VisualEditor/VisualEditor.php";

// Enable by default for everybody
$wgDefaultUserOptions['visualeditor-enable'] = 1;

// Don't allow users to disable it
$wgHiddenPrefs[] = 'visualeditor-enable';

// OPTIONAL: Enable VisualEditor's experimental code features
#$wgDefaultUserOptions['visualeditor-enable-experimental'] = 1;

// URL to the Parsoid instance
// MUST NOT end in a slash due to Parsoid bug
// Use port 8142 if you use the Debian package
$wgVisualEditorParsoidURL = 'http://parsoid.webarch.net:8142';

// Interwiki prefix to pass to the Parsoid instance
// Parsoid will be called as $url/$prefix/$pagename
//$wgVisualEditorParsoidPrefix = 'wiki.example.org';
$wgVirtualRestConfig['modules']['parsoid'] = array(
  'url' => 'http://parsoid.webarch.net:8142',
  'domain' => 'docs.webarch.net',
  'prefix' => 'docs.webarch.net'
);

If you are running MediaWiki 23.x or older you will need to install the Parsoid extension and add the following to LocalSettings.php:

// https://www.mediawiki.org/wiki/Extension:Parsoid
require_once "$IP/extensions/Parsoid/Parsoid.php";

HTTP Authentication

If your MediaWiki site is using HTTP Authentication and HTTPS then the Parsoid server isn't going to be able to connect to the API of the wiki, so you need to edit the ~/.sites/default/htaccess file to allow the IP address of the Parsiod to have unauthenticated access, for example:

AuthUserFile /home/example/private/.htpasswd
AuthType Basic
AuthName "My Private Wiki"
require valid-user
# for Parsoid server
Order deny,allow
Deny from all
Allow from 81.95.52.9 
Satisfy any

Or for Apache 2.4:

<If "%{REMOTE_ADDR} != '81.95.52.9'">
  AuthUserFile /home/example/private/.htpasswd
  AuthType Basic
  AuthName "My Private Wiki"
  Require valid-user
</If>

Parsoid Server Settings

Before the VisualEditor will work your domain will need adding to the /etc/mediawiki/parsoid/config.yaml file on the Parsoid server, please contact us at info@webarch.net to ask for this to be done, for example (note that spaces not tabs are needed for the whitespace):

        - # docs.webarch.net
          uri: 'https://docs.webarch.net/w/api.php'
          domain: 'docs.webarch.net'

After making the changes the service will need restarting, service parsoid restart, in addition the IP address of the server might need adding to /etc/iptables/rules.v4, for example:

 -A INPUT -p tcp --dport 8142 -s 81.95.52.6 -j ACCEPT

Piwik

If you want to use our Piwik server then install the Piwik extension and ask for your site to be added to the Piwik server and get the site id and then add the following to LocalSettings.php, where XX is your site ID:

// Piwik
// https://www.mediawiki.org/wiki/Extension:Piwik_Integration
require_once "$IP/extensions/Piwik/Piwik.php";
$wgPiwikURL = "stats.webarch.net";
$wgPiwikIDSite = "XX";

Customise

Some notes on common customisations for MediaWiki.

Footer

To add "Hosted by Webarchitects" to the footer and for it to link to a Webarchitects page on the wiki add the following to LocalSettings.php:

// https://www.mediawiki.org/wiki/Manual:Footer
// MediaWiki:Footerpage should contain the name of the page to link to, eg "Webarchitects"
// MediaWiki:Footertext should contain the text to be hyperlinked, eg "Hosted by Webarchitects"
$wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'lfFooterLink';
function lfFooterLink( $sk, &$tpl ) {
    $tpl->set( 'footertext', $sk->footerLink( 'footertext', 'footerpage' ) );
    $tpl->data['footerlinks']['places'][] = 'footertext';
    return true;
}

And create MediaWiki:Webarchitectspage‎‎ with the name of the page to link to, in this case Webarchitects and a MediaWiki:Webarchitects page with "Hosted by Webarchitects" in it.

Mobile Phone Support

Install Extension:MobileFrontend for a better experience on mobile devices.

FileTypes

To enable additional file types to be uploaded add this to the LocalSettings.php file:

# Add several file types to the default array
# https://www.mediawiki.org/wiki/Manual:$wgFileExtensions
$wgFileExtensions = array_merge(
    $wgFileExtensions, array(
            'svg', 'ppt', 'pdf', 'psd', 'mp3', 'xls', 'xlsx', 'swf', 'doc',
            'docx', 'odt', 'odc', 'odp', 'odg', 'mpp'
    )
);

Enable Large Thumbnails

The default is quite low, add this to the LocalSettings.php file:

# https://www.mediawiki.org/wiki/Manual:$wgMaxImageArea
$wgMaxImageArea = "100000000";

Sidebar

See MediaWiki Sidebar and create MediaWiki:Sidebar to add / remove items from the side navigation bar.

SVG Thumbnails

The permissions needed by the MediaWiki extensions for thumbnailing SVG graphics (for example creating symlinks) are not allowed by the Webarchitects Shared Hosting servers, so the best option is to install and use the NativeSvgHandler extension, download and extract it to the extensions directory and then add the followig to the LocalSettings.php file:

# https://www.mediawiki.org/wiki/Extension:NativeSvgHandler
require_once "$IP/extensions/NativeSvgHandler/NativeSvgHandler.php";
# https://www.mediawiki.org/wiki/Manual:Image_administration#SVG
$wgAllowTitlesInSVG = true;

Hide history

If you want to make some content which was posted in error unavailable in the history of a page (for example some personal details) then enable the RevisionDelete functionality by adding this to LocalSettings.php:

$wgGroupPermissions['sysop']['deletelogentry'] = true;
$wgGroupPermissions['sysop']['deleterevision'] = true;

And then sysops have more options via the View History page.