User:Stefahn/Docu
On this page I collect useful stuff for running great MediaWiki websites :)
(This page is ever-growing)
MediaWiki Docu
edit- Manual:FAQ
- Manual:LocalSettings.php
- How to become a MediaWiki hacker
- Manual
- Book "Working with MediaWiki" (by Yaron Koren): workingwithmediawiki.com
- List of configuration variables
- Lots of advice: http://wiki.laub-home.de/wiki/MediaWiki (German)
- Mailinglist of new MediaWiki versions
- Commoncraft explains how Wikipedia works
Stying up-to-date / Newsletters:
Installing
editUseful: MediaWiki core code on Github: https://github.com/wikimedia/mediawiki/
Core
editThis is how I install MediaWiki Core (as of 2021):
- Create a database at your host and copy the database name, database user, password and host.
- Connect to Server via SSH
- Go to the root folder of the domain (not in the
/mediawiki
folder).- If I use GIT (preferred):
git clone https://gerrit.wikimedia.org/r/mediawiki/core.git --branch REL1_39 mediawiki
(if you add--depth=1
at the end, this would reduce the number of revisions that are cloned but this makes it impossible to checkout newer branches later on)- To load all bundled extensions and skins (not possible in master branch): In the
/mediawiki
folder:git submodule update --init --recursive
(this takes about 7 minutes) This somehow makes all extensions be "HEAD detached at..." (how can I set all extensions to the 1.39 branch?) - In the
/mediawiki
folder: Runcomposer update --no-dev
to load external dependencies.
- If I can't use GIT: Get the latest download link at Download.
wget Link
,unzip File
andmv Folder mediawiki
- If I use GIT (preferred):
- Go to the mediawiki directory in the browser and follow the steps (use the database credentials from step 1).
- Download LocalSettings.php.
- Edit LocalSettings.php: Below the line with
$wgMetaNamespace =
add this line (for security reasons):$wgCookiePrefix = $wgMetaNamespace;
- Upload LocalSettings.php.
Extensions
editHow to install Extensions with GIT:
- Connect to Server via SSH
- Go to the folder
mediawiki/extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/NAME --branch master
You can try to go with the master version first. If a certain branch is needed, replacemaster
withREL1_3x.
ReplaceNAME
with the extension's name, starting with a capital letter.
If you install the VisualEditor extension, make sure to run git submodule update --init
in extensions/VisualEditor
afterwards. Otherwise files under extensions/VisualEditor/lib/ve/src might be missing.
If for some reason an extension is not hosted on Gerrit, but on Github, use git clone https://github.com/miraheze/RottenLinks.git --branch master
Upgrading / Updating
edit- Detailed information: Manual:Upgrading
- Version lifecycle - Information about MW Versions - including info about Long term support (LTS)
- All versions of MediaWiki that were ever releases
- Locking the database during upgrades or technical stuff: Manual:$wgReadOnly
- If you did an update but the version number is still the old one, try running
maintenance/update.php
. This should clear all relevant caches.[1]
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 [3])
Essential changes (to me) in the change log:
- List of essential changes in MediaWiki versions
- Hit counters were removed in MediaWiki 1.25, see here why.
With Git
edit- Updating with Git, see Download from Git
- Everything in this chapter has a prerequisite, that the wiki and its extensions were installed with Git, see #Installing.
- To see which branch the core or a extension is on and which other branches exist:
git branch
Core, minor upgrade
edit(for example from 1.36.3 to 1.36.4):
- Go the the
mediawiki
folder. git pull
This downloads updates for the bundled extensions too, but it does not switch the extensions to their latest versions.- Update your extensions. See below.
- If you get a message like "Please commit or stash your changes first" and you didn't change anything, use
git stash
to ignore the message and usegit pull
again.
Core, major upgrade
edit- Go to the
mediawiki
folder. git checkout REL1_3x
git pull
(maybegit pull --recurse-submodules
is nescessary, maybe evengit submodule update --init --recursive
)- Update your skin too. If you use Vector, go to
skins/Vector
and dogit checkout REL1_3x
too. - Update your extensions. See below.
- Run
composer update --no-dev
- Run
php_cli maintenance/update.php
Extensions and skins
edit(Go tomediawiki/extensions
and dogit pull)
(I think this pulls the new versions but doesn't switch the extensions to the new versions)- You must go into each extension and skin directory and update it with a command like
git pull --recurse-submodules
[2]
If an extension is not in the right branch read on.
How to change branch of extensions:
The following only works if you have not used --depth=1
in the inital checkout:
- Navigate to the extension folder that you want to change
- Use
git checkout REL1_39
to change to the 1.39 branch for example
How to checkout a certain ID within an extension:
This might be helpful if the latest version does not work for some reason.
- Find the version / ID that works. It might be helpful to use
git log
- Use
git checkout ID
See more here.
Without Git
editThis is how to upgrade without Git:
Core, major upgrades
editThis is how I do major upgrades on my wikis:
- Backup all MediaWiki databases and all FTP files that I adapted (for example these files).
- Access the command line by connecting to my server via Putty/SSH.
- Navigate to my website folder (not the
mediawiki
folder but the one that contains themediawiki
folder). - Download the new package via
wget https://releases.wikimedia.org/mediawiki/1.3x/mediawiki-1.3x.y.tar.gz
(URLs of the download packages can be retrieved from Download). - Extract the file via
tar -xvzf mediawiki-1.3x.y.tar.gz
(this will create a new folder namedmediawiki-1.3x.y
) - Copy all "old", adapted FTP files into the new mediawiki folder.
This includes, but is not limited to:- extensions that are not bundled with the tarball
- the
images
folder (for example withcp -r sitename/mediawiki/images/ sitename/mediawiki-1.3x.y/
LocalSettings.php
composer.local.json
- custom skins (or changes you made to default skins)
- In the release notes for the new version, see if any changes need to be made to
LocalSettings.php
. - Rename the old
mediawiki
folder tomediawiki-old
. - Rename the new
mediawiki-1.3x.y
folder tomediawiki
. - Update any extensions if there are updates.
- Run the update script with
php_cli maintenance/update.php --skip-external-dependencies
. - Check my wiki if all works like it should, for example
- Viewing pages
- Editing pages
- Uploading a file
- Visit Special:Version and check that the version shown is correctly and that my extensions are present.
Core, minor upgrades
editThis is how I do minor version upgrades:
- Backup all MediaWiki databases and all FTP files that I adapted (for example these files).
- Access the command line by connecting to my server via Putty/SSH.
- Navigate to my html folder.
- Download the new patch file via
wget https://releases.wikimedia.org/mediawiki/1.xx/mediawiki-1.xx.x.patch.gz
- Extract the file via
gunzip mediawiki-1.xx.x.patch.gz
- Navigate to the
mediawiki
folder of the wiki. - Run
patch -p1 --dry-run -i ../../mediawiki-1.xx.x.patch
to check what will be patched. - If all is fine, run
patch -p1 -i ../../mediawiki-1.xx.x.patch
- Visit Special:Version and check that the version shown is correctly and that my extensions are present.
- Repeat the last 4 steps for every wiki.
Extensions
editThis is how I upgrade my extensions:
- Visit the extension page and get the download link of the new version (I always try to run the master version, even if I'm on the LTS version).
- Access the command line by connecting to my server via Putty/SSH.
- Navigate to my extension folder.
- Run
wget COPIED-URL
- Rename the existing extension folder to
EXTENSION-NAME-old
- Run
tar -xzf GZ-FILE
(this extracts the files into the folderEXTENSION-NAME
. - Visit Special:Version and check that the version number is updated.
- Check functionality that the extension provides.
Running a MediaWiki site
editMediaWiki Support
editHere you can get free support for MediaWiki:
- Project:Support desk
- Mailing lists
- IRC channel #mediawiki: Best time to get answers: 17:30 MEZ (5:30 pm) = 10 pm IST = forenoon in the US[3]
- Facebook group "MediaWiki Developers"
- MediaWiki on Slack
- German forum: http://www.wiki-forum.de/mediawiki-forum-f466.htm
Finding MediaWiki Consultants:
- Professional development and consulting
- http://www.wikimatrix.org/consultants/mediawiki/
- SMW: https://www.semantic-mediawiki.org/wiki/Professional_support
SEO
edit- If you use Sitenotice chances are Google will show the sitenotice text instead of the page content in the SERPs. Use no index for the sitenotice (?).
- http://www.cloudways.com/blog/mediawiki-seo-tips/
- Lots of tips & tricks (German)
- Optional: Set some links to be follow (no nofollow) (German)
- Thread:Project:Support desk/SEO question: Removing "wiki" from domain
- Add Meta Description
- To read:
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
editDefault behavior:
- URLs are case sensitive
- However, the first character of the page name is case-insensitive - Example: https://secret-wiki.de/wiki/vitori_Kristallmatte redirects to https://secret-wiki.de/wiki/Vitori_Kristallmatte (this is also the case on Wikimedia projects)
- https://secret-wiki.de/wiki/Vitori_kristallmatte gives an error - 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
editPossibilities to generate a sitemap:
- Extension:DynamicWikiSitemap (my preferred methode)
- Manual:generateSitemap.php
- Generate Sitemap via shell: http://wiki.laub-home.de/wiki/Mediawiki_Sitemap_erstellen (German)
Ways to set a page to noindex
edit- Use the magic word
__NOINDEX__
- Use the Extension:WikiSEO
Debugging & Hacking
editIf you get an empty page, chances are there is a fatal PHP error: Add this to the second line from the top (right below the <?php) of 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.
For more info see Manual:How to debug. Another proposed way: [4]
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:
- Gerrit/Tutorial, Gerrit/Getting started
- Info for myself: My account on https://wikitech.wikimedia.org is separate from my Unified Account, because wikitech is separate. The accounts have the same login though.
Hosting
edit- Never go for windows hosting for Meadiawiki.[4]
Memory limit:
- "The minimum amount of memory that MediaWiki "needs" is 50 megabyte."[5]
- "The minimal limit should be something like 20 MB, but if you want MediaWiki to work correctly, consider using at least 50 MB."[6]
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).
- chown everything to the apache user/group (recursively). In Ubuntu:
- 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- To keep database size small the contents of objectcache table may be deleted (delete only the contents of this table, no other one!) - see http://www.mediawiki.org/wiki/Manual:Objectcache_table and http://www.mediawiki.org/wiki/Thread:Project:Support_desk/How_to_use_only_small_images_from_commons.wikimedia.org%3F#How_to_use_only_small_images_from_commons.wikimedia.org.3F_16262
Maintenance scripts
edit- Manual:Maintenance scripts
- Helpful after importing data into your wiki (fixes categories for example): Manual:rebuildall.php
- If you see some links with
Special:BadTitle
the script Manual:cleanupTitles.php can help to fix this. - 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[7]
SERVER_NAME=yourdomain.com export SERVER_NAME php update.php
- If
php update.php
doesn't work, tryphp_cli update.php
- one can also run it with
php srv/directory/mediawiki/maintenance/runJobs.php
- SMW recommends parameter
--maxjobs 1000
Moving entire wiki
editSteps 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- see Manual:Cache
- "load.php is cached by the main cache. If you have memcached or redis, use it as the main cache type. Otherwise, leave $wgMainCacheType = CACHE_ANYTHING; so it uses database for caching."[8]
- Caching on SMW: http://semantic-mediawiki.org/wiki/FAQ#Why_doesn.27t_data_I_have_just_added_show_up_in_queries.3F
- Only single page:
- http://www.mwusers.com/forums/showthread.php?15954-Is-it-possible-to-disable-cache-for-a-particular-page
- worked for me (1.19.2): Extension:Winter with {{#nocache}}
- It's important to understand that object caching is something different that page caching!
Object caching:
- If you use
$wgMainCacheType = CACHE_ACCEL;
and you can't login afterwards, try to set$wgSessionCacheType = CACHE_DB;
.[9]
Page caching:
- See Manual:File_cache
- To invalidate all cached html files, just edit LocalSettings.php (adding a space is enough).
- If you edited a template that is used on all pages, logged-in users see the change (coming from the template), but logged-out users are still served the cached page. -> Invalidate all cached files to reflect the changes for everybody.
Extensions
editAll Extensions:
- Category:All_extensions
- Extension Matrix/AllExtensions is no longer up to date
- Good tip: Search for keywords within the namespace "Extension": https://www.mediawiki.org/w/index.php?title=Special%3ASearch&profile=advanced&ns102=1 [10]
Downloading:
- Download extensions and see most popular ones can be done with Special:ExtensionDistributor
Yaron Koren: "However, for most extensions, these files represent a random snapshot that may not actually hold a working set of code."[11] -> it's better to download extensions with Git - "...the fact that an extension's code is contained on the MediaWiki Git repository is to some extent... a positive sign about its maintenance."[12]
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.
- If the version number on Special:Version is not updated although you have the new files in place: Topic:Ubxbytoe9k5jqkug
Useful extensions
edit- 100 most popular MW extensions
- Extensions in use on my site Secret Wiki
- Extension:AddBodyClass: allows to add custom classes to the HTML body tag
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
editExtensions 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- Extensions_FAQ
- Available_hooks
- To insert HTML on edit pages only: Manual:Hooks/EditPage::showEditForm:fields (maybe there's a better hook, but it works with this one)
- If custom hook doesn't work: Check if custom php file is included in LocalSettings.php first ;)
- How to render wikitext in one's extension -
$wgOut->parse( $text );
doesn't seem to work in my "usual" extensions (not special pages)
Ways to add HTML output (in MediaWiki 1.19)
editDon'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, likefunction 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>");
Get the title of a page
edit- in VectorTemplate.php:
$this->getSkin()->getTitle()
- in LocalSettings.php:
$out->getTitle()
(at least this works within a function like thisfunction MyFunction(&$out, &$skin) { ... }
Example: Adding og:image to the Main page of your wiki (and only on the Main page):
$wgHooks['BeforePageDisplay'][] ='MyFunction'; function MyFunction(&$out, &$skin) { $script= ""; if ($out->getTitle() == "Main page" ) { $script .= "<meta property='og:image' content='/your-logo.png'>"; } $out->addHeadItem("My script", $script); return true; };
CSS
edit- All stylesheets MW uses: Manual:Interface/Stylesheets
- CSS class for every category: Snippets/Style_pages_based_on_categories
- To change the way MediaWiki pages print: add CSS on the page MediaWiki:Print.css
- To allow CSS on restricted pages like the login page: Manual:$wgAllowSiteCSSOnRestrictedPages
Tables:
- Zebra (alternating colors) and highlighting: http://de.wikipedia.org/wiki/Hilfe:Tabellen#zebra
- Working zebra CSS:
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;
}
- Remove entries from toolbox: http://www.wiki-forum.de/aus-toolbox-einzelne-eintraege-entfernen-t328359.htm (German)
Design & Skins
edit- Manual:Interface
- Thread:Project:Support desk/How to add wikitext into a skin
- To get the page without skin: add
?action=render
to URL - To make Vector more responsive:
$wgVectorResponsive = true;
Footer:
- To remove the privacy, about and/or disclaimer links entirely, replace the link text in MediaWiki:Privacy, MediaWiki:Aboutsite or MediaWiki:Disclaimers with a single dash
-
. - See Manual:Footer for more info
Mobile skinning:
- Manual:Mobiles, tablets and responsive design
- Extension:MobileFrontend
- Simple_mobile_skin_auto_change
- Use other skin for mobile devices (German)
- How to use mobile theme of Wikipedia (German)
Learn skinning:
- Manual:Skinning/Tutorial
- German skin docu on WikiPedia: w:de:Wikipedia:Technik/Skin
- http://www.earlgreyandbattenburg.co.uk/books/mediawiki-skins-design/
- http://blog.blue-spice.org/2012/10/01/mediawiki-skins-a-visual-feast/
- WMF style guides: https://tools.wmflabs.org/styleguide/
Cool skins
editMy favorites:
- Skin:Chameleon - Discussions: [5], [6], with nice example
- http://www.mediawikibootstrapskin.co.uk
- http://foreground.thingelstad.com
- Puts your content in the foreground
- used as default skin on https://wikiapiary.com
- inherently responsive for mobile thanks to Foundation
- User:Thingles on responsiveness: However, responsiveness on a wiki is such a tricky thing since the editors have a ton of control over it. CSS changes can make it non-responsive. Also, any template that uses tables can break responsiveness. In short, the skin enables it but the wiki must play along.
Other skins:
- The most used MediaWiki skins: https://wikiapiary.com/wiki/Skin:Skins
- https://github.com/mtyeh411/mediawiki-bootstrap
- https://de.onpage.org/wiki/Hauptseite
- http://fr.wikimini.org/wiki/Accueil
- http://energypedia.info - uses Iswiki skin developed by http://idea-sketch.com (my guess)
- http://practicalplants.org/wiki/Practical_Plants
- http://docs.webplatform.org
- http://sunshinereview.org/index.php/Portal:WikiFOIA
- http://www.whoinspired.com/
- http://gomediawiki.com/wiki/Free_wiki_skin (Example: critical-mass-rides.co.cc)
- Skin:Erudite
- Nimbus_skin - Example: http://www.halopedia.org/
- https://sellfy.com/p/VRjA/
- http://rilpartner.se/mediawiki-skins/
- http://paulgu.com/wiki/Mediawiki_Skins - Used to used it myself on http://marketingunited.org
- Even more skins: Category:All_skins
Ideas:
Show content only to logged-in users
editWays 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)
editThe following worked for me - I added this code in my skin PHP file:
global $wgUser;
if (in_array("YourUserGroupName", $wgUser->getEffectiveGroups())) {
dosomething;
}
Images
editThumbnails:
- Change thumbnail size: Manual:$wgThumbLimits
- Issues with thumbnails
- in 1.19.x: Thread:Talk:MediaWiki 1.19/Thumbnails didn't work since Update to 1.19/reply (32)
- other option: [7]
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
editJavaScript:
- JavaScript code should be added within MediaWiki:Common.js
- if you want to load a certain JavaScript file (asynchronously): Add
mw.loader.load('http://example.org/script.js');
to your MediaWiki:Common.js[13]. See also ResourceLoader/Modules#mw.loader.load. - In MediaWiki:Common.js: Leave out
<script type="text/javascript"></script>
. Otherwise you'll get an JavaScript error. - Manual:Interface/JavaScript
- It's not possible to use JavaScript inline elements in Common.js. See [8].
- Add scripts / styles / fonts to the head in
LocalSettings.php
via the hook BeforePageDisplay[14]:
$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.[15]
-> Possibilities:
- Add JavaScript code itself to Common.js (worked for me).
- mw.loader.using would be a good solution for this. But at the moment it doesn't accept URLs and thus external scripts.
- Use one of two possible workarounds given at https://phabricator.wikimedia.org/T27962#3790660
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. This is because the script is loaded before jQuery and mw scripts[16]. Instead, edit Common.js and insert this, adapting the page name and script path:
if (mw.config.get('wgPageName') == 'Your page') {
$.getScript('path.script.js');
}
- Also, 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.
- The JavaScript from Common.js is loaded after the page load event, so document.write cannot be used there.[17]
Search / Replace
editThe Wikimedia Foundation uses CirrusSearch (ElasticSearch). More info:
- Help:CirrusSearch
- http://blog.wikimedia.org/2014/01/06/wikimedia-moving-to-elasticsearch/
- How to search within wikitext: Use
insource:"URL"
(Help:CirrusSearch#insource:) - Some search operations (german)
- With Extension:CirrusSearch it is possible to use CirrusSearch on own wikis.
- Since MediaWiki 1.28, CirrusSearch supports indexing and searching of properties of files - see here
"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:
Replace:
- Extension:ReplaceText works fine - in terms of Regex (regular expressions) only the following special characters are allowed:
( ) . * + ? [ ] |
-^
for example doesn't work - To use other (all) Regex commands, use Extension:MassEditRegex
- Do not alter the database with offline tools like Notepad++, see Topic:Ubxsfo482b58tlop.
- People also recommend to use Pywikibot to do replacements on the wiki.
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 (usernames) are case sensitive. Not allowed characters in usernames by default:
@
and:
(see Manual:$wgInvalidUsernameCharacters). Spaces are allowed. - Change email address of an user: [9]
- Mass delete (spam) users: Possible with Extension:BlockAndNuke in combination with Extension:UserMerge - see this paragraph
Permissions
edit- Important to know:
*
means everyone, it doesn't mean "only anons"! - Thread:Project:Support desk/Bureaucrat can degrade sysop!?
- Manual:User_rights
- Default_rights
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- Per default feeds give only 50 entries. To increase it change $wgFeedLimit.
- Category:Feed variables
- Category:Feed generator extensions
- Discussion on how to use a RSS feed from MediaWiki to use in Social Media: [10]
- Feeds Available from MediaWiki
- By default the Recentchanges feed is only renewed after 60 seconds - see Manual:$wgFeedCacheTimeout
Multilingual Wiki
edit- Manual:Wiki_family
- Discussion about alternatives to a wiki family: [11]
- Extension:Translate
- Opinion from Marc (german): [12]
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:
- "Numbers from 3000 and higher are a good pick for system administrators to define their custom namespaces."[18]
- Manual:Using custom namespaces
- Change ids of custom namespace: One way (didn't test it)
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
editSingle Sign-On
- Use Extension:WPMW
- If WordPress (WP) is not installed in a higher level folder but in the same folder as MediaWiki (MW) use this WordPress plugin to fix cookie problems
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:
- WordPress Address (URL): http://domain.com/wordpress (should be set to this already by the installation)
- Site Address (URL): http://domain.com/
- Copy the index.php from root/wordpress to root/ and change the line
require('./wp-blog-header.php');
torequire('./wordpress/wp-blog-header.php');
(see also [13]) - 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)
Cookies
edit- Overview of cookies that MediaWiki sets
- If you check the "Keep me logged in" box when you log in, the login cookies have a lifetime of half a year (be default). Without the tick, the lifetime is only one month (by default).
Misc
edit- A better diff tool that recognizes if a wikitext block was only moved: http://www.mediawiki.org/wiki/Thread:Project:Support_desk/Better_diff_tool%3F#Better_diff_tool.3F_18763
- Mass rename pages: Manual:MoveBatch.php, [14]
- Mass delete pages: Manual:deleteBatch.php works fine. Extension:Nuke does not see imported pages and is limited to pages that are shown under Recent Changes.
- Resetting the password for a user: Manual:Resetting_passwords#Use_the_changePassword.php_maintenance_script
Timezone issues:
Security:
- Make a mirror of your wiki: http://wiki.laub-home.de/wiki/Mediawiki_Mirror_Skript (German)
References:
- Any list with more than 10 references will get the CSS class
.mw-references-columns
[19]. This can be used to show the references in columns.
How to chose the right editor / form / template
editWhen it comes to editing usual pages (without SMW attributes) as of 2024 I go with the VisualEditor, because it has WYSIWYG and it handles citation very well.
Extension:PageForms was my choice before, even for editing usual pages. It can be used with Extension:VEForAll, but unfortunately VEForAll has no citation option.[20] So now we use PageForms only when a page has a lot of attributes and/or needs autosuggestion in input fields.
In combination with the VisualEditor I use Extension:TemplateData to provide helpful information when using simple templates like a warning boxes with custom text (i.e. a template with one string parameter). But TemplateData lacks flexibility to autosuggest values and/or restrict input. There is a suggestedvalues parameter, but the values within that parameter need to be put in manually. One can't use a SMW query for example. So it can't replace PageForms and SMW templating.
Creating content
edit- Text Editor support
- How to do syntax highlighting in WikiEditor: wikEd
- Half automated editor: https://de.wikipedia.org/wiki/Wikipedia:AutoWikiBrowser
Some special wikitext:
----
= horizontal rule<syntaxhighlight lang="php"> </syntaxhighlight>
= show code in PHP highlighting (requires Extension:SyntaxHighlight GeSHi)<div class="mw-collapsible mw-collapsed">Text that is collapsed</div>
- see Manual:Collapsible elements
Templates
edit- See which pages include a certain template: Navigate to template and hit "What links here" (in the toolbox)
- Use "|" as an screen output in templates: "|", Example
- Use table in template: with Template:!
- String templates: w:Template:String_templates_see_also_text
Parameters
edit- How to use parameters in templates: Template#Parameters
- If you use
=
within your parameter content, you can't use Anonymous parameters - just use1=
before the first parameter content. If you have other parameters put2=
,3=
... before them.xy=
works great too. - When applying ParserFunctions to template parameters, a pipe symbol
|
may be used - see Help:Parser functions in templates and Difference between {{{1}}} and {{{1|}}} - Only output parameter if it's non empty:
{{#if:{{{1|}}}|{{{1}}}|}}
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- Edit watchlist: Special:EditWatchlist, in German Spezial:Beobachtungsliste_bearbeiten
- If a watched page is moved, the old and the new are watched after the move (result of a test by myself).
- If you want to hide edits from other users (so that they don't get a mail notification about it): Check "minor edit" when saving ("Replace all" uses this minor edit too) and make sure the users don't have the checkmark in "E-mail me also for minor edits of pages and files" (also see Thread:Project:Support desk/Hide (bot) edits from other users)
- Script to see who added / edited what: https://github.com/FlominatorTM/wikiblame
How to add this script to your site. Download the files. Add your domain under https://github.com/FlominatorTM/wikiblame/blob/master/wikiblame.php#L73 like this:$server="your-domain.com"
. Upload the files to your server.
Liquid Threads
editUpdate: 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 Help:Extension:ParserFunctions##expr and https://meta.wikimedia.org/wiki/Help:Calculation
- Check whether or not a text/word exits as a wiki page: #ifexist
- #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 |}}
- Add references tag plus heading automatically if a ref tag is entered? Help_talk:Extension:ParserFunctions#How_to_use_tag_function_within_parser_function.3F, Solution: Thread:Project:Support_desk/_How_to_use_within_parser_function?
#time
#timel
is identical to#time
, except that it uses the local time of the wiki (I didn't have to set$wgLocaltimezone
,#timel
gave the right time anyway).- Check if a date is in the past or not:
{{#ifeq:{{#expr:{{#time:U|DATE}}>{{#time:U}}}}|0|In the past|In the future}}
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- This HTML is permitted (allowed): https://meta.wikimedia.org/wiki/Help:HTML_in_wikitext
- Using
<div>
properly: https://meta.wikimedia.org/wiki/Help:HTML_in_wikitext#.3Cdiv.3E - When
$wgRawHtml = true;
, the wiki will allow raw unchecked HTML in<html>...</html>
sections - You can't set group permissions to allow some to use raw HTML and some to not use it.
- Better solution than allowing RawHtml: Extension:Secure HTML
- Allow
<img>
: Manual:$wgAllowImageTag
TOC / Headlines
edit- Making a heading that does not show up in TOC: http://meta.wikimedia.org/wiki/Help:Section#Making_a_heading_that_does_not_show_up_in_ToC - alternative: http://en.wikipedia.org/wiki/Template:Fake_heading
__NOEDITSECTION__
anywhere on the page will remove ALL edit links on an article.- Show numbers in front of headlines: Add
$wgDefaultUserOptions['numberheadings'] = 1;
to LocalSettings.php (see Auto-number headings) - To put
.
after number of h2 headlines in the TOC: http://stackoverflow.com/a/32347680/3194543
Categories
edit- Hide Categories by adding
__HIDDENCAT__
to category page (see Help:Categories#Hidden_categories) - Showing number of pages in subcategories (instead of number of subcats)
- Hiding certain pages in categories is not possible (see here).
- Help:Categories says: "It is a good idea to organize all categories into a hierarchy with a single top level category." See also this support thread.
- Show pages from all categories except one category (german)
- Show all pages (with help of Special:AllPages)
- Thread:Project:Support desk/Random page from certain category?
Ways to print out a list of all available categories:
- Use Extension:CategoryTree
- Use
{{Special:AllPages|namespace=14}}
[21]
Linking
edit- Linking between Wikis: http://meta.wikimedia.org/wiki/Help:Interwiki_linking, Link on german wikipedia: [[w:de:Artikel]]
- Template:Softredirect
- To display a link without the arrow icon, place the external link syntax between
<span class="plainlinks">...</span>
tags. - Linking to user's user page:
[[User:{{CURRENTUSER}}]]
- Manual:Redirect_to_the_user's_user_page
- Avoid auto-linking of URLs:
- Wrap URL in nowiki tags:
<nowiki>http://url.com</nowiki>
- In SMW: use
?property#nowiki
when querying data, see [15] and Topic:T9gishan276abiu0
- Wrap URL in nowiki tags:
- To check for broken links, use Extension:RottenLinks.
- If there are problems with redirects, links, Special:LinkSearch or similar, try Manual:refreshLinks.php
Revisions
edit- If you want to show the date on which an article was last updated:
Last update: {{REVISIONDAY}}.{{REVISIONMONTH1}}.{{REVISIONYEAR}}
- If you want to hide revisions from the public: Use
$wgGroupPermissions['sysop']['deleterevision'] = true;
. See Manual:RevisionDelete.
Misc
edit- MW was released to the public in 2002. MW is supported with over 2,000 extensions. It is available in 300 languages.[22]
- Blog article about User engagement: http://blog.wikimedia.org/2013/02/22/onboarding-results/, Suggest Bot: https://en.wikipedia.org/wiki/User:SuggestBot
- List of Magic Words
Other wiki software:
- Open sourceL DokuWiki, PmWiki, Tiki, TiddlyWiki,
- Confluence (proprietary application)
- CMS that include some limited wiki functionality: for example Traction TeamPage, Microsoft SharePoint
Market share:
- In 2013 MediaWiki had a CMS marketshare of 0,2 %, in 2021 it had 0,1 % [23].
- http://trends.builtwith.com/cms/MediaWiki/Market-Share
References
edit- ↑ https://phabricator.wikimedia.org/T180121#8737030, viewed on 3.4.2023
- ↑ Download from Git#Keeping up to date, viewed on 29.3.2024
- ↑ https://www.facebook.com/groups/2205099323/permalink/10153412499994324/?comment_id=10153413494564324
- ↑ https://www.facebook.com/groups/2205099323/permalink/10153329509004324/
- ↑ Manual:$wgMemoryLimit, viewed on 23.5.2016
- ↑ PHP_configuration#Runtime_configuration_.28php.ini.29, viewed on 23.5.2016
- ↑ https://www.mediawiki.org/wiki/Manual:Wiki_family#Updating_wikifarm_from_the_commandline, viewed on 14.7.2016
- ↑ https://www.mediawiki.org/wiki/Topic:Txr70j0hdpc0lv11, viewed on 25.11.2020
- ↑ https://www.mediawiki.org/w/index.php?title=Topic:Ttnxs3dosx3he584&topic_showPostId=ttoooy8x731aiqzj#flow-post-ttoooy8x731aiqzj, viewed on 22.2.2019
- ↑ Topic:Sv0x5t8jb1qgqqhe
- ↑ https://workingwithmediawiki.com/book/chapter2.html, viewed on 28.4.2021
- ↑ https://workingwithmediawiki.com/book/chapter2.html, viewed on 28.4.2021
- ↑ http://www.wiki-forum.de/javascript-in-head-einbinden-t362082.htm?sid=d493a1c299ca33d4ad09e46fc7a4adbc#4419655, viewed on 25.7.2016
- ↑ https://stackoverflow.com/a/26436873/3194543, viewed on 21.10.2017
- ↑ https://stackoverflow.com/a/43581394/3194543, viewed on 24.11.2017
- ↑ [1], viewed on 11.2.2020
- ↑ [2], viewed on 11.2.2020
- ↑ https://www.mediawiki.org/wiki/Manual:Using_custom_namespaces#Creating_a_custom_namespace, viewed on 13.7.2016
- ↑ Contributors/Projects/Columns_for_references, viewed on 29.7.2020
- ↑ Topic:Vjsmim3tel8qynrd, viewed on 17.5.2024
- ↑ https://www.mediawiki.org/w/index.php?title=Topic:Qyy7labouxcfg3oy&topic_showPostId=w2dac61d4q9u5ezg#flow-post-w2dac61d4q9u5ezg, viewed on 17.5.2024
- ↑ http://www.cloudways.com/blog/mediawiki-seo-tips/
- ↑ http://w3techs.com/technologies/overview/content_management/all, viewed on 21.9.2013 and on 17.11.2021