Difference between revisions of "MediaWiki"

From wiki
(Page cache)
(PHP7.0)
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{WIP}}{{Debian}}
+
{{DISPLAYTITLE:MediaWiki installation guide}}
== Install Mediawiki ==
+
{{WIP}}
{{Warning|Debian packages are currently unmaintained and outdated. This guide will install mediawiki from source. For your security, don't forget to follow upstream releases and update your installation.}}
+
{{Debian}}
  
=== Prerequisite ===
+
== Prerequisite ==
 +
Before using this guide, you will need
 +
* [[MariaDB]] as a database
 +
* [[Nginx]] as a webserver
 +
* A domain name for your wiki pointing to your server. We will use wiki.example.org in this guide.
  
==== DNS ====
+
== Install MediaWiki ==
This guide assume that you are using a dedicated subdomain for your wiki like https://wiki.example.com. Don't forget to point that domain to your webserver.
+
{{Warning|Debian packages are currently unmaintained and outdated. This guide will install MediaWiki from source. For your security, don't forget to follow upstream releases and update your installation.}}
 
 
==== Database ====
 
You will need a database server store all dynamic data (users, articles…). You can check the [[Install/MariaDB|MariaDB installation guide]].
 
 
 
==== Nginx ====
 
In this guide, we will use Nginx as a web server. Please check the [[Install/Nginx|Nginx installation guide]].
 
  
 
=== Get source ===
 
=== Get source ===
<syntaxhighlight lang="console">
+
Get the link to the latest stable version from [https://www.mediawiki.org/wiki/Download MediaWiki]<syntaxhighlight lang="console">
 
# cd /var/www
 
# cd /var/www
# curl https://releases.wikimedia.org/mediawiki/1.26/mediawiki-1.26.2.tar.gz | tar xz
+
# curl https://releases.wikimedia.org/mediawiki/1.28/mediawiki-1.28.0.tar.gz | tar xz
# chown -R www-data: mediawiki*
+
# mv mediawiki 1.28.0 mediawiki
 +
# chown -R www-data: mediawiki
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Configure PHP ===
 +
{{PHP/open basedir|folders=/var/www/mediawiki/}}
  
 
=== Configure Nginx ===
 
=== Configure Nginx ===
create certificate
+
{{Nginx/New Site|domain=wiki.example.org|config=server {
 +
    include snippets/listen-http.conf;
 +
    server_name wiki.example.org;
 +
 
 +
    access_log /var/log/nginx/wiki.access.log;
 +
    error_log /var/log/nginx/wiki.error.log info;
 +
 
 +
    include snippets/acme-challenge.conf;
 +
    include snippets/https-permanent-redirect.conf;
 +
}
 +
 
 +
server {
 +
    include snippets/listen-https.conf;
 +
 
 +
    server_name wiki.example.org;
 +
 
 +
    access_log /var/log/nginx/wiki.access.log;
 +
    error_log /var/log/nginx/wiki.error.log info;
 +
 
 +
    include snippets/acme-challenge.conf;
 +
    #include snippets/ssl.conf;
 +
    #ssl_certificate      /etc/letsencrypt/live/wiki.example.org/fullchain.pem;
 +
    #ssl_certificate_key  /etc/letsencrypt/live/wiki.example.org/privkey.pem;
 +
    #include snippets/hsts.conf;
 +
 
 +
    root /var/www/mediawiki;
 +
    index index.php;
 +
 
 +
    client_max_body_size 5m;
 +
    client_body_timeout 60;
 +
 
 +
    location / {
 +
        try_files $uri /index.php?$args;
 +
    }
 +
 
 +
    location /images {
 +
        location ~ \.php$ {return 403;}
 +
    }
 +
 
 +
    location ~ \.php$ {
 +
        try_files $uri =404;
 +
        include fastcgi.conf;
 +
        fastcgi_pass php;
 +
    }
 +
 
 +
    location ~* \.(js{{!}}css{{!}}png{{!}}jpg{{!}}jpeg{{!}}gif{{!}}ico)$ {
 +
        try_files $uri /index.php;
 +
        expires max;
 +
        log_not_found off;
 +
    }
  
update nginx config
+
    location = /_.gif {
 +
        expires max;
 +
        empty_gif;
 +
    }
  
 +
    # Mark all of these directories as "internal", which means that they cannot
 +
    # be explicitly accessed by clients. However, the web server can still use
 +
    # and serve the files inside of them. This keeps people from poking around
 +
    # in the wiki's internals.
 +
    location ^~ /cache/ { internal; }
 +
    location ^~ /docs/ { internal; }
 +
    location ^~ /extensions/ { internal; }
 +
    location ^~ /includes/ { internal; }
 +
    location ^~ /languages/ { internal; }
 +
    location ^~ /maintenance/ { internal; }
 +
    #location ^~ /mw-config/ { internal; } #Uncomment after installation
 +
    location ^~ /tests/ { internal; }
 +
<nowiki>}</nowiki>
 +
}}
 +
 +
=== Configure ===
 
/mw-config
 
/mw-config
 
<syntaxhighlight lang="console">
 
chown root:www-data /etc/mediawiki/LocalSettings.php
 
chmod 640 /etc/mediawiki/LocalSettings.php
 
</syntaxhighlight>
 
  
 
== Install Extensions ==
 
== Install Extensions ==
  
 
=== ParserFunctions ===
 
=== ParserFunctions ===
This extension is bundled by default with mediawiki. You just need to activate it.
+
This extension is bundled by default with MediaWiki. You just need to activate it.
  
Add the line <code>wfLoadExtension( 'ParserFunctions' );</code> to the file <code>/var/www/mediawiki*/LocalSettings.php</code>
+
Add the line <code>wfLoadExtension( 'ParserFunctions' );</code> to the file <code>/var/www/mediawiki/LocalSettings.php</code>
  
 
=== SyntaxHighlight ===
 
=== SyntaxHighlight ===
This extension is bundled by default with mediawiki. You just need to activate it.
+
This extension is bundled by default with MediaWiki. You just need to activate it.
  
Add the line <code>wfLoadExtension( 'SyntaxHighlight_GeSHi' );</code> to the file <code>/var/www/mediawiki*/LocalSettings.php</code>
+
Add the line <code>wfLoadExtension( 'SyntaxHighlight_GeSHi' );</code> to the file <code>/var/www/mediawiki/LocalSettings.php</code>
  
 
=== TemplateData ===
 
=== TemplateData ===
Line 51: Line 116:
  
 
=== VisualEditor ===
 
=== VisualEditor ===
 +
 +
==== Parsoid ====
 +
 +
The VisualEditor extension require Parsoid to be installed.
 +
 +
===== Install =====
 +
 +
The project is still you and instruction might change. See [https://www.mediawiki.org/wiki/Parsoid/Setup#Ubuntu_.2F_Debian mediawiki instructions].
 +
 +
===== Configuration =====
 +
 +
====== Connect to MediaWiki ======
 +
 +
Edit configuration in <code>/etc/mediawiki/parsoid/config.yaml</code> and change the following lines
 +
<syntaxhighlight lang="yaml">
 +
        # Configure Parsoid to point to your MediaWiki instances.
 +
        mwApis:
 +
        - # This is the only required parameter,
 +
          # the URL of you MediaWiki API endpoint.
 +
          uri: 'https://wiki.example.org:443/api.php'
 +
          # The "domain" is used for communication with Visual Editor
 +
          # and RESTBase.  It defaults to the hostname portion of
 +
          # the `uri` property below, but you can manually set it
 +
          # to an arbitrary string.
 +
          domain: 'wiki.example.org'
 +
          # To specify a proxy (or proxy headers) specific to this prefix
 +
          # (which overrides defaultAPIProxyURI). Alternatively, set `proxy`
 +
          # to `null` to override and force no proxying when a default proxy
 +
          # has been set.
 +
          #proxy:
 +
          #    uri: 'http://my.proxy:1234/'
 +
          #    headers:  # optional
 +
          #        'X-Forwarded-Proto': 'https'
 +
 +
</syntaxhighlight>
 +
 +
{{Warning}} If you have changed the listening port of your webserver (you are using [[sslh]]), you might need to change the <code>443</code> in the line above.
 +
 +
You can check your ports using
 +
<syntaxhighlight lang="console">
 +
# netstat -plnt |grep nginx
 +
tcp        0      0 203.0.113.23:4433          0.0.0.0:*              LISTEN      1462/nginx: worker
 +
tcp        0      0 203.0.113.23:80            0.0.0.0:*              LISTEN      1462/nginx: worker
 +
tcp6      0      0 2001:db8:3:47d0::2e:7::443 :::*                    LISTEN      1462/nginx: worker
 +
tcp6      0      0 2001:db8:3:47d0::2e:7::80  :::*                    LISTEN      1462/nginx: worker
 +
</syntaxhighlight>
 +
Parsoid seems to pick the IPV4 port. 4433 in this case
 +
 +
====== Restarting ======
 +
 +
After changing the config, you need to restart Parsoid.
 +
<syntaxhighlight lang="console">
 +
# service parsoid restart
 +
</syntaxhighlight>
 +
 +
==== php-curl ====
 +
VisualEditor require the curl PHP extension<syntaxhighlight lang="console">
 +
$ sudo apt install php-curl
 +
</syntaxhighlight>
 +
 +
=== MobileFrontend ===
 +
Because a lot of your traffic will come from mobile devices.
 +
 +
* [https://www.mediawiki.org/wiki/Special:ExtensionDistributor/MobileFrontend Download MobileFrontend]
 +
* Extract it in <code>/var/www/mediawiki/extensions/</code>
 +
* Add the following to <code>/var/www/mediawiki/LocalSettings.php</code><syntaxhighlight lang="php">
 +
require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";
 +
$wgMFAutodetectMobileView = true;
 +
# disable talk and watch features
 +
$wgMFPageActions = array( 'edit', 'upload' );
 +
</syntaxhighlight>
 +
 +
For more information, check the [https://www.mediawiki.org/wiki/Extension:MobileFrontend extension documentation]
 +
 +
=== Cite ===
 +
This extension is bundled by default with MediaWiki. You just need to activate it.
 +
 +
Add the line <code>wfLoadExtension( 'Cite' );</code> to the file <code>/var/www/mediawiki/LocalSettings.php</code>
 +
 +
=== TitleKey ===
 +
The [https://www.mediawiki.org/wiki/Extension:TitleKey TitleKey] extension allows search suggestion to be case insensitive.
 +
* Download extension from https://www.mediawiki.org/wiki/Special:ExtensionDistributor/TitleKey
 +
* Unzip the extension in <code>/var/www/mediawiki/extensions</code>
 +
* Add the line <code>require_once "$IP/extensions/TitleKey/TitleKey.php";</code>  to the file <code>/var/www/mediawiki/LocalSettings.php</code>
 +
* Create tables by running the following commands<syntaxhighlight lang="console">
 +
$ sudo -u www-data /usr/bin/php /var/www/mediawiki/maintenance/update.php
 +
$ sudo -u www-data /usr/bin/php /var/www/mediawiki/extensions/TitleKey/rebuildTitleKeys.php
 +
</syntaxhighlight>
  
 
== Speedup ==
 
== Speedup ==
By default the mediawiki installation is pretty slow.
+
By default the MediaWiki installation is pretty slow.
  
 
=== Localisation cache ===
 
=== Localisation cache ===
Uncomment the line about <code>$wgCacheDirectory</code> in <code>/var/www/mediawiki*/LocalSettings.php.</code><syntaxhighlight lang="php">
+
Uncomment the line about <code>$wgCacheDirectory</code> in <code>/var/www/mediawiki/LocalSettings.php</code>.
 +
<syntaxhighlight lang="php">
 
## Set $wgCacheDirectory to a writable directory on the web server
 
## Set $wgCacheDirectory to a writable directory on the web server
 
## to make your wiki go slightly faster. The directory should not
 
## to make your wiki go slightly faster. The directory should not
Line 76: Line 230:
 
# chmod 640 /var/log/mediawiki-runJobs.log
 
# chmod 640 /var/log/mediawiki-runJobs.log
 
</syntaxhighlight>Then add the following line in <code>/etc/crontab</code><syntaxhighlight lang="text">
 
</syntaxhighlight>Then add the following line in <code>/etc/crontab</code><syntaxhighlight lang="text">
0  0    * * *  www-data /usr/bin/php /var/www/mediawiki-1.26.2/maintenance/runJobs.php > /var/log/mediawiki-runJobs.log
+
0  0    * * *  www-data /usr/bin/php /var/www/mediawiki/maintenance/runJobs.php > /var/log/mediawiki-runJobs.log
</syntaxhighlight>Finally you can disable jobs running on user visits in <code>/var/www/mediawiki*/LocalSettings.php</code><syntaxhighlight lang="php">
+
</syntaxhighlight>Finally you can disable jobs running on user visits in <code>/var/www/mediawiki/LocalSettings.php</code><syntaxhighlight lang="php">
 
# Jobs are run by the cronjob. No need to run them on use visits
 
# Jobs are run by the cronjob. No need to run them on use visits
 
# https://www.mediawiki.org/wiki/Manual:$wgJobRunRate
 
# https://www.mediawiki.org/wiki/Manual:$wgJobRunRate
 
$wgJobRunRate = 0;
 
$wgJobRunRate = 0;
</syntaxhighlight>You can check the number of jobs in the queue at https://wiki.example.com/api.php?action=query&meta=siteinfo&siprop=statistics&format=jsonfm
+
</syntaxhighlight>You can check the number of jobs in the queue at <nowiki>https://wiki.example.org/api.php?action=query&meta=siteinfo&siprop=statistics&format=jsonfm</nowiki>
 +
 
 +
== Other Settings ==
 +
 
 +
=== Canonical links ===
 +
Page in MediaWiki can be accessed by several URLs. For example the main page of this wiki can be accessed with
 +
* https://wiki.meurisse.org/
 +
* https://wiki.meurisse.org/wiki/Main_Page
 +
* https://wiki.meurisse.org/index.php?title=Main_Page
 +
* https://wiki.meurisse.org/index.php?title=Main_Page&mobileaction=toggle_view_desktop
 +
To avoid issues with duplicated content in search engines, it is possible to add a canonical link to all pages<syntaxhighlight lang="php">
 +
$wgEnableCanonicalServerLink = true;
 +
</syntaxhighlight>
 +
 
 +
=== Capital Links ===
 +
 
 +
By default, MediaWiki forces the first letter of a page title to be upper case. The advantage of it is that you can omit the first capital in links,
 +
 
 +
Eg. You have a page named <code>Test</code>. You can link to it like <code>This is a <nowiki>[[test]]</nowiki></code>.
 +
 
 +
The drawback is that you can't create a page with lower case title.
 +
 
 +
Change that in <code>/var/www/mediawiki/LocalSettings.php</code>.
 +
<syntaxhighlight lang="php">
 +
$wgCapitalLinks = false;
 +
</syntaxhighlight>
 +
 
 +
=== Footer ===
 +
By default the footer contain several links that we want to configure.
 +
 
 +
==== Licence ====
 +
The license is controlled by these parameters<syntaxhighlight lang="php">
 +
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
 +
$wgRightsUrl = "https://creativecommons.org/licenses/by-sa/4.0/";
 +
$wgRightsText = "Creative Commons Attribution-ShareAlike";
 +
$wgRightsIcon = "$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png";
 +
</syntaxhighlight>The text of the link itself is the content of the page <nowiki>https://wiki.example.org/wiki/MediaWiki:Copyright</nowiki>
 +
 
 +
==== About / Disclaimers / Privacy ====
 +
The three other default links in the footer are controlled by this pages:
 +
 
 +
<nowiki>https://wiki.example.org/wiki/MediaWiki:Aboutsite</nowiki>
 +
 
 +
<nowiki>https://wiki.example.org/wiki/MediaWiki:Disclaimers</nowiki>
 +
 
 +
<nowiki>https://wiki.example.org/wiki/MediaWiki:Privacy</nowiki>
 +
 
 +
To remove one of the link set the content of the page to <code>-</code>.
 +
 
 +
=== No-nofollow ===
 +
[https://www.mediawiki.org/wiki/Manual:$wgNoFollowLinks By default] MediaWiki adds <code>rel="nofollow"</code> to all external links. While it's usage for real wikis [https://www.mediawiki.org/wiki/Manual:Nofollow is discussed], it is counterproductive for a personal wiki. It can be disabled in <code>LocalSettings.php</code>.<syntaxhighlight lang="php">
 +
$wgNoFollowLinks = false;
 +
</syntaxhighlight>
 +
 
 +
=== Subpages ===
 +
[https://www.mediawiki.org/wiki/Manual:$wgNamespacesWithSubpages Subpages] are only enabled for some namespaces. Others can be enabled in <code>LocalSettings.php</code>.<syntaxhighlight lang="php">
 +
$wgNamespacesWithSubpages[NS_MAIN] = true;
 +
</syntaxhighlight>
 +
 
 +
=== Page Title ===
 +
<code><nowiki>{{DISPLAYTITLE}}</nowiki></code> allows you to change the title of a page (the default is to use the same as the URL). However by default only minor changes are allowed like the case of the title.
 +
 
 +
If you want to do more changes to the page title (eg. keep a short URL but have an explicit title like this page), you can enable this<syntaxhighlight lang="php">
 +
$wgRestrictDisplayTitle = false;
 +
</syntaxhighlight>
 +
 
 +
=== Sitemap ===
 +
SItemaps are good for SEO as they allow search engines to find pages faster on your site.
 +
 
 +
Mediawiki comes included with a script that can generate the sitemaps files; but it requires a bit of setup before using it.
 +
# In <code>/var/www/mediawiki/LocalSettings.php</code> add the following lines<syntaxhighlight lang="php">
 +
# Only generate Sitemap for Main(0) and Category(14) namespaces
 +
$wgSitemapNamespaces = array(0, 14);
 +
</syntaxhighlight>
 +
# Create a folder named <code>sitemap</code> at the root of your installation
 +
# Add this line to <code>/etc/crontab</code><syntaxhighlight lang="text">
 +
15 0    * * *  www-data /usr/bin/php /var/www/mediawiki/maintenance/generateSitemap.php --fspath=/var/www/mediawiki/sitemap --urlpath=https://wiki.example.org/sitemap/ --server=https://wiki.example.org --skip-redirects > /dev/null
 +
</syntaxhighlight>You can also force an initial generation of the sitemap files using this command<syntaxhighlight lang="console">
 +
$ sudo -u www-data /usr/bin/php /var/www/mediawiki/maintenance/generateSitemap.php --fspath=/var/www/mediawiki/sitemap --urlpath=https://wiki.example.org/sitemap/ --server=https://wiki.example.org --skip-redirects
 +
</syntaxhighlight>
 +
# Your sitemap will then be accessible at <nowiki>https://wiki.example.org/sitemap/sitemap-index-wiki.xml</nowiki>
 +
# Add this sitemap in the webmaster tools of the targeted search engines
 +
 
 +
[[Category:Linux Server]]

Latest revision as of 09:27, 24 June 2017


Warning Warning: This page is a work in progress and is not completed. Important informations might be missing or wrong.
Warning Warning: These instructions were only tested on Debian. It will probably work for other Linux distributions, but you might need to adapt the provided instructions.

Prerequisite

Before using this guide, you will need

  • MariaDB as a database
  • Nginx as a webserver
  • A domain name for your wiki pointing to your server. We will use wiki.example.org in this guide.

Install MediaWiki

Warning Warning: Debian packages are currently unmaintained and outdated. This guide will install MediaWiki from source. For your security, don't forget to follow upstream releases and update your installation.

Get source

Get the link to the latest stable version from MediaWiki

# cd /var/www
# curl https://releases.wikimedia.org/mediawiki/1.28/mediawiki-1.28.0.tar.gz | tar xz
# mv mediawiki 1.28.0 mediawiki
# chown -R www-data: mediawiki

Configure PHP

Edit file /etc/php/7.0/mods-available/local-common.ini and add /var/www/mediawiki/ to the open_basedir setting.

Reload PHP:

$ sudo systemctl reload php7.0-fpm.service

Configure Nginx

  1. Create the config file /etc/nginx/sites-available/wiki.example.org
    server {
        include snippets/listen-http.conf;
        server_name wiki.example.org;
    
        access_log /var/log/nginx/wiki.access.log;
        error_log /var/log/nginx/wiki.error.log info;
    
        include snippets/acme-challenge.conf;
        include snippets/https-permanent-redirect.conf;
    }
    
    server {
        include snippets/listen-https.conf;
    
        server_name wiki.example.org;
    
        access_log /var/log/nginx/wiki.access.log;
        error_log /var/log/nginx/wiki.error.log info;
    
        include snippets/acme-challenge.conf;
        #include snippets/ssl.conf;
        #ssl_certificate      /etc/letsencrypt/live/wiki.example.org/fullchain.pem;
        #ssl_certificate_key  /etc/letsencrypt/live/wiki.example.org/privkey.pem;
        #include snippets/hsts.conf;
    
        root /var/www/mediawiki;
        index index.php;
    
        client_max_body_size 5m;
        client_body_timeout 60;
    
        location / {
            try_files $uri /index.php?$args;
        }
    
        location /images {
            location ~ \.php$ {return 403;}
        }
    
        location ~ \.php$ {
            try_files $uri =404;
            include fastcgi.conf;
            fastcgi_pass php;
        }
    
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            try_files $uri /index.php;
            expires max;
            log_not_found off;
        }
    
        location = /_.gif {
            expires max;
            empty_gif;
        }
    
        # Mark all of these directories as "internal", which means that they cannot
        # be explicitly accessed by clients. However, the web server can still use
        # and serve the files inside of them. This keeps people from poking around
        # in the wiki's internals.
        location ^~ /cache/ { internal; }
        location ^~ /docs/ { internal; }
        location ^~ /extensions/ { internal; }
        location ^~ /includes/ { internal; }
        location ^~ /languages/ { internal; }
        location ^~ /maintenance/ { internal; }
        #location ^~ /mw-config/ { internal; } #Uncomment after installation
        location ^~ /tests/ { internal; }
    }
    
  2. Activate the configuration with
    $ sudo nginx_modsite -e wiki.example.org
    Would you like to reload the Nginx configuration now? (Y/n) Y
    
  3. Edit file /usr/local/etc/certmanage/main.json and add the following to the list
    {
        "domains": ["wiki.example.org"],
        "reload": [["/bin/systemctl", "reload", "nginx.service"]]
    }
    
  4. Get your certificate
    $ sudo /usr/local/sbin/certmanage
    Renewing certificate for wiki.example.org that will expire on 0001-01-01
    
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
    Obtaining a new certificate
    Performing the following challenges:
    http-01 challenge for wiki.example.org
    Using the webroot path /var/www/acme-challenge for all unmatched domains.
    Waiting for verification...
    Cleaning up challenges
    Generating key (2048 bits): /etc/letsencrypt/keys/1764_key-certbot.pem
    Creating CSR: /etc/letsencrypt/csr/1764_csr-certbot.pem
    
    IMPORTANT NOTES:
     - Congratulations! Your certificate and chain have been saved at
       /etc/letsencrypt/live/wiki.example.org/fullchain.pem. Your cert
       will expire on 2025-02-19. To obtain a new or tweaked version of
       this certificate in the future, simply run certbot again. To
       non-interactively renew *all* of your certificates, run "certbot
       renew"
     - If you like Certbot, please consider supporting our work by:
    
       Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
       Donating to EFF:                    https://eff.org/donate-le
    
    Restarting services:
    systemctl reload nginx.service
    
  5. Uncomment the ssl related lines in /etc/nginx/sites-available/wiki.example.org and run
    $ sudo systemctl reload nginx.service
    

Configure

/mw-config

Install Extensions

ParserFunctions

This extension is bundled by default with MediaWiki. You just need to activate it.

Add the line wfLoadExtension( 'ParserFunctions' ); to the file /var/www/mediawiki/LocalSettings.php

SyntaxHighlight

This extension is bundled by default with MediaWiki. You just need to activate it.

Add the line wfLoadExtension( 'SyntaxHighlight_GeSHi' ); to the file /var/www/mediawiki/LocalSettings.php

TemplateData

Allows you to describe your templates using structured data for a better experience with the VisualEditor.

https://www.mediawiki.org/wiki/Extension:TemplateData

VisualEditor

Parsoid

The VisualEditor extension require Parsoid to be installed.

Install

The project is still you and instruction might change. See mediawiki instructions.

Configuration
Connect to MediaWiki

Edit configuration in /etc/mediawiki/parsoid/config.yaml and change the following lines

        # Configure Parsoid to point to your MediaWiki instances.
        mwApis:
        - # This is the only required parameter,
          # the URL of you MediaWiki API endpoint.
          uri: 'https://wiki.example.org:443/api.php'
          # The "domain" is used for communication with Visual Editor
          # and RESTBase.  It defaults to the hostname portion of
          # the `uri` property below, but you can manually set it
          # to an arbitrary string.
          domain: 'wiki.example.org'
          # To specify a proxy (or proxy headers) specific to this prefix
          # (which overrides defaultAPIProxyURI). Alternatively, set `proxy`
          # to `null` to override and force no proxying when a default proxy
          # has been set.
          #proxy:
          #    uri: 'http://my.proxy:1234/'
          #    headers:  # optional
          #        'X-Forwarded-Proto': 'https'


Warning Warning: If you have changed the listening port of your webserver (you are using sslh), you might need to change the 443 in the line above.

You can check your ports using

# netstat -plnt |grep nginx
tcp        0      0 203.0.113.23:4433          0.0.0.0:*               LISTEN      1462/nginx: worker 
tcp        0      0 203.0.113.23:80            0.0.0.0:*               LISTEN      1462/nginx: worker 
tcp6       0      0 2001:db8:3:47d0::2e:7::443 :::*                    LISTEN      1462/nginx: worker 
tcp6       0      0 2001:db8:3:47d0::2e:7::80  :::*                    LISTEN      1462/nginx: worker

Parsoid seems to pick the IPV4 port. 4433 in this case

Restarting

After changing the config, you need to restart Parsoid.

# service parsoid restart

php-curl

VisualEditor require the curl PHP extension

$ sudo apt install php-curl

MobileFrontend

Because a lot of your traffic will come from mobile devices.

  • Download MobileFrontend
  • Extract it in /var/www/mediawiki/extensions/
  • Add the following to /var/www/mediawiki/LocalSettings.php
    require_once "$IP/extensions/MobileFrontend/MobileFrontend.php";
    $wgMFAutodetectMobileView = true;
    # disable talk and watch features
    $wgMFPageActions = array( 'edit', 'upload' );
    

For more information, check the extension documentation

Cite

This extension is bundled by default with MediaWiki. You just need to activate it.

Add the line wfLoadExtension( 'Cite' ); to the file /var/www/mediawiki/LocalSettings.php

TitleKey

The TitleKey extension allows search suggestion to be case insensitive.

  • Download extension from https://www.mediawiki.org/wiki/Special:ExtensionDistributor/TitleKey
  • Unzip the extension in /var/www/mediawiki/extensions
  • Add the line require_once "$IP/extensions/TitleKey/TitleKey.php"; to the file /var/www/mediawiki/LocalSettings.php
  • Create tables by running the following commands
    $ sudo -u www-data /usr/bin/php /var/www/mediawiki/maintenance/update.php
    $ sudo -u www-data /usr/bin/php /var/www/mediawiki/extensions/TitleKey/rebuildTitleKeys.php
    

Speedup

By default the MediaWiki installation is pretty slow.

Localisation cache

Uncomment the line about $wgCacheDirectory in /var/www/mediawiki/LocalSettings.php.

## Set $wgCacheDirectory to a writable directory on the web server
## to make your wiki go slightly faster. The directory should not
## be publically accessible from the web.
$wgCacheDirectory = "$IP/cache";

Page cache

# Enable generated page cache
$wgUseFileCache = true;
$wgFileCacheDirectory = "$IP/cache";

Enable CronJob

First create the log file

# touch /var/log/mediawiki-runJobs.log
# chown www-data:adm /var/log/mediawiki-runJobs.log
# chmod 640 /var/log/mediawiki-runJobs.log

Then add the following line in /etc/crontab

0  0    * * *   www-data /usr/bin/php /var/www/mediawiki/maintenance/runJobs.php > /var/log/mediawiki-runJobs.log

Finally you can disable jobs running on user visits in /var/www/mediawiki/LocalSettings.php

# Jobs are run by the cronjob. No need to run them on use visits
# https://www.mediawiki.org/wiki/Manual:$wgJobRunRate
$wgJobRunRate = 0;

You can check the number of jobs in the queue at https://wiki.example.org/api.php?action=query&meta=siteinfo&siprop=statistics&format=jsonfm

Other Settings

Canonical links

Page in MediaWiki can be accessed by several URLs. For example the main page of this wiki can be accessed with

To avoid issues with duplicated content in search engines, it is possible to add a canonical link to all pages

$wgEnableCanonicalServerLink = true;

Capital Links

By default, MediaWiki forces the first letter of a page title to be upper case. The advantage of it is that you can omit the first capital in links,

Eg. You have a page named Test. You can link to it like This is a [[test]].

The drawback is that you can't create a page with lower case title.

Change that in /var/www/mediawiki/LocalSettings.php.

$wgCapitalLinks = false;

Footer

By default the footer contain several links that we want to configure.

Licence

The license is controlled by these parameters

$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
$wgRightsUrl = "https://creativecommons.org/licenses/by-sa/4.0/";
$wgRightsText = "Creative Commons Attribution-ShareAlike";
$wgRightsIcon = "$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png";

The text of the link itself is the content of the page https://wiki.example.org/wiki/MediaWiki:Copyright

About / Disclaimers / Privacy

The three other default links in the footer are controlled by this pages:

https://wiki.example.org/wiki/MediaWiki:Aboutsite

https://wiki.example.org/wiki/MediaWiki:Disclaimers

https://wiki.example.org/wiki/MediaWiki:Privacy

To remove one of the link set the content of the page to -.

No-nofollow

By default MediaWiki adds rel="nofollow" to all external links. While it's usage for real wikis is discussed, it is counterproductive for a personal wiki. It can be disabled in LocalSettings.php.

$wgNoFollowLinks = false;

Subpages

Subpages are only enabled for some namespaces. Others can be enabled in LocalSettings.php.

$wgNamespacesWithSubpages[NS_MAIN] = true;

Page Title

{{DISPLAYTITLE}} allows you to change the title of a page (the default is to use the same as the URL). However by default only minor changes are allowed like the case of the title.

If you want to do more changes to the page title (eg. keep a short URL but have an explicit title like this page), you can enable this

$wgRestrictDisplayTitle = false;

Sitemap

SItemaps are good for SEO as they allow search engines to find pages faster on your site.

Mediawiki comes included with a script that can generate the sitemaps files; but it requires a bit of setup before using it.

  1. In /var/www/mediawiki/LocalSettings.php add the following lines
    # Only generate Sitemap for Main(0) and Category(14) namespaces
    $wgSitemapNamespaces = array(0, 14);
    
  2. Create a folder named sitemap at the root of your installation
  3. Add this line to /etc/crontab
    15 0    * * *   www-data /usr/bin/php /var/www/mediawiki/maintenance/generateSitemap.php --fspath=/var/www/mediawiki/sitemap --urlpath=https://wiki.example.org/sitemap/ --server=https://wiki.example.org --skip-redirects > /dev/null
    
    You can also force an initial generation of the sitemap files using this command
    $ sudo -u www-data /usr/bin/php /var/www/mediawiki/maintenance/generateSitemap.php --fspath=/var/www/mediawiki/sitemap --urlpath=https://wiki.example.org/sitemap/ --server=https://wiki.example.org --skip-redirects
    
  4. Your sitemap will then be accessible at https://wiki.example.org/sitemap/sitemap-index-wiki.xml
  5. Add this sitemap in the webmaster tools of the targeted search engines