User:Stefahn/Docu

From MediaWiki.org
Jump to: navigation, search

On this page I collect useful stuff for running great MediaWiki websites :)
(This page is ever-growing)

MediaWiki Docu[edit]

Stying up-to-date / Newsletters:

Running a MediaWiki site[edit]

MediaWiki Support[edit]

Here you can get free support for MediaWiki:

Finding MediaWiki Consultants:

SEO[edit]

Short URLs[edit]

  • very important!
  • Docu: Short URL
  • What I use in my .htaccess files:
RewriteRule ^wiki/(.*)$ /mediawiki/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /mediawiki/index.php [L,QSA]
RewriteRule ^/*$ /mediawiki/index.php [L,QSA]
Last line redirects domain.com to domain.com/wiki/Mainpage
  • Not tested yet, but looks helpful to setup short URLs for MediaWiki: http://shorturls.redwerks.org/
  • Related to URL: If you set your wiki to private and you're not logged in, the homepage won't be redirected to domain.com/wiki/Mainpage but stay at domain.com. This is useful for testing the pagespeed at https://www.pagespeed.de/

URLs with / without capitals[edit]

Default behavior:

  • URLs are case sensitive
  • However, the first character of the page name is case-insensitive - Example: http://secret-wiki.de/wiki/gesetz_der_Anziehung redirects to http://secret-wiki.de/wiki/Gesetz_der_Anziehung (this is also the case on Wikimedia projects)
  • http://secret-wiki.de/wiki/Gesetz_der_anziehung gives an error (also http://secret-wiki.de/wiki/Gesetz_der_anziehung) - this might be a problem if a user enters the URL this way (without capitals)

One can change behavior of links and allowed URLs with $wgCapitalLinks. Setting $wgCapitalLinks to false...

  • ...doesn't change anything about the existing pages with capitals!
  • ....enables links like small (which would link to a page "small" not "Small")
  • ...enable pages/URLs that start with a small letter

I still don't know if URLs with capitals are a bad thing in terms of SEO. If someone knows more about it please mail me at info AT interspirit.de

Sitemap[edit]

Possibilities to generate a sitemap:

Debugging & Hacking[edit]

If you get an empty page, chances are there is a fatal PHP error:

  • Add the following in LocalSettings.php to turn on error messages:
error_reporting( -1 );
ini_set( 'display_errors', 1 );
This corresponds to
error_reporting = E_ALL
display_errors = On
in your php.ini.

My debugging "setup":

  • in my php.ini I had (and have) :
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
  • If my website is live I don't have any "debugging lines". If I want to debug something I temporarily add this code to my LocalSettings.php:
error_reporting( -1 );
ini_set( 'display_errors', 1 );
$wgShowExceptionDetails = true; 
$wgDebugLogFile = "/tmp/debug-{$wgDBname}.log";

Become a MediaWiki hacker:

Hosting[edit]

  • Never go for windows hosting for Meadiawiki.[2]

Memory limit:

  • "The minimum amount of memory that MediaWiki "needs" is 50 megabyte."[3]
  • "The minimal limit should be something like 20 MB, but if you want MediaWiki to work correctly, consider using at least 50 MB."[4]

PHP Version:

Speeding up MediaWiki:

  • Manual:Performance tuning
  • $wgDBserver: Use IP addresses where possible to avoid the overhead of a DNS lookup for every single connection to the wiki.

Permissions:

  • If you have root or sudo access:
    • chown everything to the apache user/group (recursively). In Ubuntu: chown -R www-data:www-data your-mediawiki-directory
    • chmod LocalSettings.php to 600. Leaving everything else as default should be fine (644 for files and 755 for directories).
  • If you do not have root or sudo access:
    • chown LocalSettings.php and the images directory (recursively) so it is in your name but the apache group
    • chmod LocalSettings.php to 640 and chmod the images directory to 775 (recursively). Leaving everything else as the default should be fine.

Database[edit]

Upgrading / Updating[edit]

This is how I do big upgrades on my wikis:

  1. Backup all MediaWiki databases and all FTP files that I adapted (for example these files).
  2. Access the command line by connecting to my server via Putty/SSH.
  3. Navigate to my html folder.
  4. Download the new package via wget https://releases.wikimedia.org/mediawiki/1.2x/mediawiki-1.2x.y.tar.gz
  5. Extract the file via tar -xvzf mediawiki-1.2x.y.tar.gz (this will create a new folder)
  6. Copy the folder to my website folder (which contains the old mediawiki folder).
  7. Upload/copy all adapted FTP files into the copied mediawiki folder.
  8. In the release notes for the new version, see if any changes need to be made to LocalSettings.php.
  9. Rename the old mediawiki folder to mediawiki-old.
  10. Rename the copied mediawiki folder to mediawiki.
  11. Update any extensions if there are updates
  12. Run the update script with php /mediawiki/maintenance/update.php.
  13. Check my wiki if all works like it should:
    1. Viewing pages
    2. Editing pages
    3. Uploading a file
    4. Visit Special:Version and check that the version shown is correctly and that my extensions are present.
This is how I do minor version upgrades:
  1. Backup all MediaWiki databases and all FTP files that I adapted (for example these files).
  2. Access the command line by connecting to my server via Putty/SSH.
  3. Navigate to my html folder.
  4. Download the new patch file via wget https://releases.wikimedia.org/mediawiki/1.xx/mediawiki-1.xx.x.patch.gz
  5. Extract the file via gunzip mediawiki-1.xx.x.patch.gz
  6. Navigate to the mediawiki folder of the wiki.
  7. Run patch -p1 --dry-run -i ../../mediawiki-1.xx.x.patch to check what will be patched.
  8. If all is fine, run patch -p1 -i ../../mediawiki-1.xx.x.patch
  9. Visit Special:Version and check that the version shown is correctly and that my extensions are present.
  10. Repeat the last 4 steps for every wiki.

Web updater:

  • Useful if you don't have SSH access. Instead of the update script you can use the web updater.
  • Accessible at domain.com/mediawiki/mw-config
  • Manual:Upgrading#Web_updater
  • This is not recommended since the web update can timeout (see [2])

Essential changes (to me):

Maintenance scripts[edit]

  • Manual:Maintenance scripts
  • Helpful after importing data into your wiki (fixes categories for example): Manual:rebuildall.php
  • if you get an PHP Notice like "Undefined index: SERVER_NAME in /yourfolder/mediawiki/includes/GlobalFunctions.php on line 1471" you can try this on the console[5]
SERVER_NAME=yourdomain.com
export SERVER_NAME
php update.php 
If php update.php doesn't work, try php_cli update.php

Manual:RunJobs.php:

  • one can also run it with php srv/directory/mediawiki/maintenance/runJobs.php
  • SMW recommends parameter --maxjobs 1000

Moving entire wiki[edit]

Steps to change the domain of the wiki:

  • Point the new domain to your FTP folder
  • In LocalSetting.php change the domain under $wgServer
  • Done :)

Caching[edit]


Extensions[edit]

All Extensions:

Misc:

  • Snippets - small pieces of code to provide additional functionality whether interactive, visual or both.
  • Cite: It's okay to use <ref name="foo"></ref> and define foo only later.

Useful extensions[edit]

Show a list of users who have contributed to an article:

  • Extension:Contributors: used often, works after this and this hack, in includable version contributors are sorted by edits, but not linked and there is no number of edits -> managed to hack the code so that users are linked and number of edits are shown :)
  • Extension:Contribution_Credits: ordered by username, stable, used 6 times (works!), managed to remove certain usernames by hacking extension
  • Extension:Uniwiki_Authors: old, unordered list, hack to show only users who contributed certain number of bytes, according to Wikipiary: not used
  • Extension:PageBy: excludes bots and anons, ordered by edits?, very old, used 6 times (but couldn't see it on two of those wikis)
  • Extension:AuthorInfo: limit number of shown users, not used, code completely outdated
  • Extension:Semantic_Extra_Special_Properties: unordered, output as a property (I can adapt it via ask function)

Extensions that (in my eyes) could provide a good commenting service (as of 23.7.2016):

  • Extension:Comments - works good. Anons can comment too, but they can only leave a text (not their name, not their website).
  • Extension:PageDisqus - integrates the Disqus commenting service to every page, right after the content area
  • Extension:Widgets - with Facebook and Disqus widgets

Failed extensions[edit]

Extensions I tried and didn't find to be useful (so far).

Extension My purpose Issue Solution
Extension:Multi-Category_Search Find pages that are in certain categories (more than one) None Found Semantic MediaWiki which suits my needs far better :)
smw-searchprofile Combine full text search with semantic search Doesn't offer it Use Extension:SolrStore instead
Extension:UniversalSuggester Add function to toolbar to search for certain templates and pages Problem with (standard) toolbar in 1.19.2 - and: doesn't work with WikiEditor toolbar - also see Extension_talk:UniversalSuggester#Where_is_the_toolbar.3F_19440 TO DO: Customize WikiEditor

Hooking / Building custom extensions[edit]

Ways to add HTML output[edit]

Don't quote me on that, I might be wrong / not completely right.

If OutputPage object ($output) is passed to function

  • Use &$out in function definition, like function myFunction (&$out).
  • Then use one of the following:
    • $out->addHTML('<div id="yeah">bla</div>');
    • $out->addHTML("<div id=\"yeah\">bla</div>");

If OutputPage object ($output) is not passed to function

  • Use: global $wgOut;
  • Then use one of the following:
    • $wgOut->addHTML('<div id="yeah">bla</div>');
    • $wgOut->addHTML("<div id=\"yeah\">bla</div>");

CSS[edit]

Tables:

table.your_zebra_class > tbody > tr:nth-child(2n) > td {
    background-color: #F3F5F5;
}

Sidebar tricks[edit]

  • Highlight a sidebar entry:
#p-Name-Of-Sidebar-Entry h5 a {
    background-color: yellow;
}
  • Add picture before sidebar entry:
#n-Name-Of-Sidebar-Entry > a {
    background: url("http://upload.wikimedia.org/wikipedia/commons/7/7b/Neu.png") no-repeat scroll -1px 1px transparent;
    padding-left: 23px;
}
  • Show a certain entry (or a group of entries) only to a certain user group:
Add to your Common.css:
#n-Name-Of-Sidebar-Entry { 
    display: none;
}
Add to MediaWiki:Group-groupname.css (for example for bureaucrats: MediaWiki:Group-bureaucrat.css, more examples at Manual:User group CSS and Javascript) :
#n-Name-Of-Sidebar-Entry { 
    display: block !important;
}

Design & Skins[edit]

Footer:

Mobile skinning:

Learn skinning:

Cool skins[edit]

My favorites:

Other skins:

Ideas:

Show content only to logged-in users[edit]

Ways to show content only to logged-in users and not to anons ("show" means "print on screen"):

Working solution: CSS
In MW 1.16.2 I used this code to load a custom CSS sheet (in my PHP skin file) - this code still works with 1.19.2:

global $wgUser;
if (!$wgUser->isLoggedIn()) {
    $out->addStyle( 'vector/anon.css', 'screen' );
}

Create a file "anon.css" (in the skins/vector directory) and add:

.noanon {
   display: none;
}

Then in your wikitext add the following class if you don't want to show content to anons (that means if you want to show content only to logged-in users):

bla bla (visible to everyone)
<div class="noanon">
Only visible to logged-in users
</div>

Working solution: Extension:UserFunctions
Use parser function {{#ifanon:then|else}}.

Possible solution: common.js (not working for me)

use something like <div class="anononly>your wikitext</div>; in MediaWiki:common.css add: .anononly { display: none; } 
and in MediaWiki:common.js add if ( !mw.user.isAnon() ) { $( '.anononly' ).removeClass( 'anononly' ); }

Tried it and failed - tried the example shown here and replaced isanon with anonymous (since I used 1.19.2) but still no message.

Possible solution: user group CSS
One can load a CSS file for certain user groups via Manual:User_group_CSS_and_Javascript - this works fine for all user groups except for anons (see this discussion).
User group CSS file seems to be case sensitive (I had to name the file MediaWiki:Group-Mitschreiber.css instead of MediaWiki:Group-mitschreiber.css to get it working).

Show content only to a certain group (in PHP files)[edit]

The following worked for me - I added this code in my skin PHP file:

global $wgUser;
if (in_array("YourUserGroupName", $wgUser->getEffectiveGroups())) {
   dosomething;
}

Images[edit]

Thumbnails:

Uploads:

  • Bulk upload is possible with Extension:UploadWizard
  • Uploading within the editor is possible with the VisualEditor
  • Fix issues with uploading files in MW 1.26.2: in Ubuntu chown everything to www-data: chown -R www-data:www-data mediawiki

Other technical stuff:

  • Renaming (a lot of) images with the API: /api.php?action=move&from=File:old.jpg&to=File:new.jpg&token=xxxx
  • Manual:Image_administration#Deletion_of_images
  • Images URLs: To use absolute URLs instead of relative URLs place the domain in the variable $wgScriptPath. This is useful if you embed the wiki content on another domain but want the images to be loaded from the original (wiki) URL.

JavaScript & jQuery[edit]

JavaScript:

$wgHooks['BeforePageDisplay'][] ='MyFunction';
function MyFunction(&$out, &$skin) {
    $script = "<script type='text/javascript'>Your JavaScript code</script>";
    $out->addHeadItem("My script", $script);
    return true;
};

Loading JavaScript that is required for other modules:
Since MediaWiki 1.26 all of MediaWiki's JavaScript is loaded asynchronously. If one doesn't load the external code through the ResourceLoader and declare dependencies, you have no guarantee that jQuery (or anything else) will be available at the time you load your code.[9]
-> Possibilities:

jQuery:

  • jQuery has been introduced in MediaWiki core as of MediaWiki 1.16 and is loaded by default on every page as of 1.17 (see JavaScript).
  • One doesn't find any "jquery" term within the source code of the page though.
  • Add jquery ready function to Mediawiki:Common.js: just write $(document).ready(function() { without script tags.
  • If you add $(document).ready(function() { to the wikitext of a page, you'll get an error.
  • If you add a script.js (that contains jQuery) somewhere in your php files, there might be an error "$ is not defined". If you load the script via Mediawiki:Common.js there is no problem.

Search[edit]

The Wikimedia Foundation uses CirrusSearch (ElasticSearch). More info:

"Usual" MediaWiki uses LuceneSearch:

  • "The search functionality can be considered to operate on whole words." -> You won't get the desired results if you enter only a part of a word :(
    Good workaround: Use the search function of Extension:Replace Text (without replacing anything, i.e. don't carry out the 2nd step, just do the 1st one). It also finds part of a word :)
  • See Help:Searching#How_it_works for more info

Other search engines:

Misc:

Users[edit]

  • If admin creates a user account (for someone else):
    Benutzerkonto anlegen = use PW that was entered before
    Per E-Mail = use random PW and mail it to new user
  • Account names are case sensitive.
  • Change email address of an user: [7]
  • Mass delete (spam) users: Possible with Extension:BlockAndNuke in combination with Extension:UserMerge - see this paragraph

Permissions[edit]

Groups

  • To define a new group just use a line in LocalSettings.php with $wgGroupPermissions['Test-Gruppe']['right'] = true; (it's not necessary to create a page MediaWiki:Group-Test-Gruppe, but it's recommened - see here)
  • How to add bureaucrats to protection groups
  • To disable for everyone and also users that don't belong to a certain group "Test-Gruppe":
# Disable for everyone.
$wgGroupPermissions['*']['edit']              = false;
# IMPORTANT: Disable for users too: by default 'user' is allowed to edit, even if '*' is not.
$wgGroupPermissions['user']['edit']           = false;
# Allow for Test-Gruppe:
$wgGroupPermissions['Test-Gruppe']['edit'] = true;

Feed[edit]

Multilingual Wiki[edit]

Namespaces[edit]

  • To see all namespaces used on a wiki (with their numbers): use URL mediawiki/api.php?action=query&meta=siteinfo&siprop=namespaces
  • All namespaces used by MediaWiki itself and its extensions: Extension default namespaces

Custom namespaces:

API[edit]

  • Get the content part of a page via the API: api.php?page=Albert_Einstein&action=parse&format=json
  • Special:ApiSandbox
  • Other stuff: search for api on this page

Connecting WordPress with MediaWiki[edit]

Single Sign-On

Run MW and WP on the same domain (without subdomains)
Say you want your wiki to be located at example.com/wiki and at the same time you want your WordPress pages to be at example.com/word and example.com/press - and: the homepage example.com should be also a WordPress page.

This worked for me:

  • Install MediaWiki in folder root/mediawiki and WordPress in root/wordpress.
  • In WP Dashboard -> Settings -> General set the following:
  • Copy the index.php from root/wordpress to root/ and change the line require('./wp-blog-header.php'); to require('./wordpress/wp-blog-header.php'); (see also [11])
  • Now comes the magic: Copy the content of root/wordpress/.htaccess and generate the following .htaccess file in root/ :
# BEGIN MediaWiki
RewriteEngine On
# for Short Wiki URL:
RewriteRule ^wiki/(.*)$ /mediawiki/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /mediawiki/index.php [L,QSA]
# To redirect all users to access the site WITHOUT the www. prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# adapt and uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
#END MediaWiki

# Copy the content of root/wordpress/.htaccess and add it below:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
  • Make sure that you do not add a line like the RewriteRule ^/*$ /mediawiki/index.php [L,QSA] since this would forward the homepage to your wiki (we don't want this since we want a WordPress homepage).
  • This tutorial assumes that you use Short URLs for your wiki - I use the following lines in my LocalSettings.php:
$wgScriptPath       = "/mediawiki";
$wgArticlePath = "/wiki/$1";  
$wgUsePathInfo = true;
  • You don't have to delete the original .htaccess file in root/wordpress/.htaccess.

Messages / Languages[edit]

  • If you want to see system messages in another language add ?uselang=language to the URL (for english use ?uselang=en for example)
  • You can find the message you want to change by adding ?uselang=qqx to the URL.
  • MediaWiki:Copyright is only shown if $wgRightsText is set to something else than "" (also works if one uses $wgRightsText = " "; but in this case an empty image is put into the footer)

Misc[edit]

Timezone issues:

Security:

Creating content[edit]

Some special wikitext:

Templates[edit]

Parameters[edit]

Including[edit]

  • If the source is in the Template namespace, just use the name itself, alone: {{Bla}}
  • If the source is in the Main article namespace, you must put a colon (:) in front of the name, thus: {{:Cat}}
  • If the source is in any other namespace (e.g., "User:Example"), you must use the full name, including the namespace, thus: {{User:Example}}
  • Noinclude, includeonly, onlyinclude:
    • noinclude: displayed only when the template page is being viewed directly; will not be included; useful for a description how to use the template and for [[Category: Template]]
    • includeonly: displayed only when the page is being included. Useful for adding all pages containing a given template to a category, but not the template itself.
    • onlyinclude: only text surrounded by "onlyinclude" markup should be transcluded onto another page. It often overrules the other include tags: If there is at least one pair of "onlyinclude" tags on a page, then whenever this page is transcluded, it is only the material within the "onlyinclude" tags which gets transcluded.
  • If you want to know on which pages you've included a certain other page (with {{:Page}}):
    Go the page, click on "What links here" and "Hide Links" and "Hide redirects". Then one can see the transclusions easily.

Discussions & Watch/Unwatch[edit]

Liquid Threads[edit]

Update: Extension:LiquidThreads (LQT) is no longer maintained and replaced by Flow

Old stuff (just for the record):

  • Namespaces that LQT adds: Extension_default_namespaces#LiquidThreads
  • How to prevent anons from using LiquidThreads
  • Header
    • If a LQT thread is started in a discussion page, the LQT header seems to be generated (red "Kopfbereich ergänzen" changes to "Bearbeiten Versionen Löschen")
    • If one adds LQT to a page, the Edit and Delete links at the top disappear. You can find them in the LQT header (Discussion).
  • There are 2 user preferences (see Manual:$wgDefaultUserOptions at the very end of the table):
    • lqt-watch-threads: Selbst erstellte oder von mir bearbeitete Themen beobachten (true by default)
    • lqtnotifytalk: Bei Antworten zu beobachteten Themen E-Mails senden (false by default)
  • Problems (with 2.0 alpha):
    • lqt-watch-threads works - but after replying to a thread you have to refresh the page (clear cache) to see "unwatch" instead of "watch" (if you start a new thread it works just fine).

Parser functions[edit]

  • Check if a "certain string" contains a certain "search-string": {{#ifeq:{{#pos:certain string|search-string}}| |not found|found}}
  • Documentation for parser function #if: Help:Extension:ParserFunctions#.23if
  • Doing math / calculation / calculating: See https://meta.wikimedia.org/wiki/Help:Calculation
  • Check if a date is in the past or not:{{#ifeq:{{#expr:{{#time:U|DATE}}>{{#time:U}}}}|0|In the past|In the future}}
  • #if and tables: To prevent empty paragraphs and breaks, use this code (notice the <br />):
|-
| usual cells
| without if {{#if:{{{Foo|}}}|<br />
{{!}}-
{{!}} cells that are shown 
{{!}} only if Foo is not empty
|}}

Images & Files[edit]

  • Turn off link to image description page: |link= (see also Help:Images#Display_image.2C_turn_off_link)
  • Directly link to a PDF instead of its description page: use [[Media:Filename.pdf]] instead of [[File:Filename.pdf]]
  • Get path to file: {{filepath:File.pdf}} - see here
  • Licensing

HTML[edit]

TOC / Headlines[edit]

Categories[edit]

Linking[edit]

Misc[edit]

Market share:

References[edit]