MediaWiki
Install
- https://www.mediawiki.org/wiki/Download
- https://www.mediawiki.org/wiki/Version_lifecycle
- https://www.mediawiki.org/wiki/Manual:Installing_MediaWiki
MediaWiki will be installed on Linux (Fedora) in /opt/mediawiki directory with Apache web server, PHP and MariaDB database server. Suppose we have root access to the server. MediaWiki will be used "pretty URL" Short URL page address. Download latest MediaWiki tarball and unpack to /opt directory.
$ tar -xzf mediawiki-*.tar.gz -C /opt/ $ chown -R root:root /opt/mediawiki-*/ $ ln -s /opt/mediawiki-*/ /opt/mediawiki $ wget -nc https://raw.githubusercontent.com/musinsky/config/master/MediaWiki/mediawiki.conf -P /etc/httpd/conf.d/ $ systemctl restart httpd.service
Database creation
You can create your database and user in setup process by running the supplied configuration script (see bellow), but personally prefer create wiki MariaDB database and user manually (or using phpMyAdmin). It will be more general, useful especially in the future (backup, restore or reinstall wiki). Warning: delete .mysql_history file after running these commands (history store the password).
$ mysql -h localhost -u root MariaDB [(none)]> CREATE DATABASE example_wiki; MariaDB [(none)]> CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'sql_wiki_passwd'; # change sql_wiki_passwd to custom password MariaDB [(none)]> GRANT ALL PRIVILEGES ON example_wiki.* TO 'wikiuser'@'localhost' WITH GRANT OPTION; $ rm .mysql_history # history store the password
MediaWiki installation
Open in browser http://localhost/mediawiki/mw-config/index.php and follow the on-screen instructions to complete the process. All settings will be temporally caching in your browser. After MediaWiki installer (config script) has finished running successfully, settings are stored in LocalSettings.php file and example_wiki
MariaDB database.
Welcome to MediaWiki
The environment has been checked. You can install MediaWiki.
Database type | MariaDB, MySQL, or compatible | $wgDBtype = "mysql";
|
---|---|---|
Database host | localhost | $wgDBserver = "localhost";
|
Identify this wiki | ||
Database name | example_wiki | $wgDBname = "example_wiki";
|
Database table prefix | $wgDBprefix = "";
| |
User account for installation | ||
Database username | wikiuser (user was created manually before installation) |
$wgDBuser = "wikiuser";
|
Database password | sql_wiki_passwd (passwd was created manually before installation) |
$wgDBpassword = "sql_wiki_passwd";
|
Database account for web access | |
Use the same account as for installation | ✓ |
---|
Name of wiki | ExampleWiki | $wgSitename = "ExampleWiki";
|
---|---|---|
Project namespace | Same as the wiki name: ExampleWiki | |
Administrator account | ||
Your username | WikiAdmin | example_wiki.user table (MariaDB)
|
Password | wiki_admin_passwd (must be at least 10 characters) |
example_wiki.user table (MariaDB)
|
Email address | (optional) | example_wiki.user table (MariaDB)
|
Share data about this installation with MediaWiki developers |
✓ (optional) | $wgPingback = true;
|
Ask me more questions | ✓ | → Options page |
User rights profile | Authorized editors only | $wgGroupPermissions['*']['createaccount'] = false; $wgGroupPermissions['*']['edit'] = false;
|
---|---|---|
Copyright and license | Creative Commons Attribution-ShareAlike | $wgRightsUrl $wgRightsText $wgRightsIcon
|
Email settings | ||
Enable outbound email | ☐ (uncheck) | $wgEnableEmail = false;
|
Skins | ||
Vector | ✓ (Use this skin as default) | $wgDefaultSkin = "vector"; wfLoadSkin( 'Vector' );
|
Extensions | ||
ExtensionName | ✓ (optional) | wfLoadExtension( 'ExtensionName' );
|
Images and file uploads | ||
Enable file uploads | ✓ | $wgEnableUploads = true;
|
Enable Instant Commons | ✓ (optional) | $wgUseInstantCommons = true;
|
Personalization | ||
Logo (icon) | path/to/ExampleWiki.logo.icon.svg | $wgLogos, icon
|
Wordmark (optional) | path/to/ExampleWiki.logo.wordmark.svg | $wgLogos, wordmark
|
Tagline (optional) | (optional) | $wgLogos, tagline
|
Sidebar logo (optional) | (optional) | $wgLogos, 1x
|
Advanced configuration | ||
Settings for object caching | No caching | $wgMainCacheType = CACHE_NONE;
|
Install
Press on continue and you will begin the installation of MediaWiki. Only now MediaWiki installer store settings in LocalSettings.php file and populate example_wiki
MariaDB database.
Complete
Download generated configuration file LocalSettings.php and move this file to the main wiki directory /opt/mediawiki.
$ mv LocalSettings.php /opt/mediawiki $ chmod 600 /opt/mediawiki/LocalSettings.php # contains $wgDBpassword $ chown apache:apache /opt/mediawiki/LocalSettings.php
Once the wiki is set up, you should remove the mediawiki/mw-config/ directory. You can remove other unnecessary dirs/files (for example mediawiki/tests/ dir), see Fedora mediawiki.spec for "more inspiration".
NOTE You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory
block, as it will have the same effect with better performance.
$ find /opt/mediawiki/ -type f -name .htaccess -exec rm {} \;
Configuration
- https://www.mediawiki.org/wiki/Manual:System_administration
- https://www.mediawiki.org/wiki/Manual:Configuration_settings
The LocalSettings.php file provides basic configuration settings (based on the includes/DefaultSettings.php file) of a MediaWiki installation. Edit generated settings in /opt/mediawiki/LocalSettings.php file.
- General
$wgSitename = "ExampleWiki"; $wgScriptPath = "/mediawiki"; # see also in file /etc/httpd/conf.d/mediawiki.conf $wgArticlePath = "/wiki/$1"; # Short URL, see also Short URL, Short URL on Apache $wgServer = "https://example.site.com"; $wgForceHTTPS = true; # optional
# $wgDefaultSkin = "vector"; # vector 2010 # $wgDefaultSkin = "vector-2022"; # vector 2022 # vector 2010 only $wgLogos = [ 'svg' => "$wgResourceBasePath/images/ExampleWiki.logo.svg" ]; # vector 2022 and 2010 together (mediawiki 1.38+) $wgLogos = [ 'svg' => "$wgResourceBasePath/images/logos/ExampleWiki.logo.svg", # vector 2010 'icon' => "$wgResourceBasePath/images/logos/ExampleWiki.logo.icon.svg", # vector 2022 'wordmark' => [ "src" => "$wgResourceBasePath/images/logos/ExampleWiki.logo.wordmark.svg", # vector 2022 "width" => 135, "height" => 20, ], ]; $wgFavicon = "$wgResourceBasePath/images/logos/ExampleWiki.favicon.png";
$wgLocaltimezone = "Europe/Bratislava"; # optional
- File uploads
- https://www.mediawiki.org/wiki/Manual:Configuring_file_uploads
- https://www.mediawiki.org/wiki/Manual:Image_administration
$ find /opt/mediawiki/images/ -type d -exec chmod 755 {} \; $ find /opt/mediawiki/images/ -type f -exec chmod 644 {} \; $ # chmod -R 755 /opt/mediawiki/images/ $ chown -R apache:apache /opt/mediawiki/images/
Uploaded files will be distributed into several subdirectories of $wgUploadDirectory
(/opt/mediawiki/images/) based on the first two characters of the md5 hash of the filename (e.g. $IP/images/f/f8/foo.jpg). If $wgHashedUploadDirectory
is false (by default is true), all images are uploaded itself (e.g. $IP/images/foo.jpg). Personally prefer (wiki with few tens uploaded images) if all images are stored without several subdirectories. The millions of free (freely licensed) images/files are hosted in Wikimedia Commons. InstantCommons is a feature of MediaWiki to allow the usage of any uploaded media file from the Wikimedia Commons in the local MediaWiki installation.
https://muke.saske.sk/wiki/File:Foo.jpg | wiki page with uploaded file |
https://upload.wikimedia.org/wikipedia/commons/0/06/Foo.jpg | direct link to uploaded file |
https://muke.saske.sk/mediawiki/images/logos/MukeWiki.favicon.png https://muke.saske.sk/mediawiki/README.md |
direct link to any local file in /mediawiki directory (relative to $wgScriptPath) |
$wgEnableUploads = true; $wgHashedUploadDirectory = false; $wgFileExtensions = [ 'png', 'jpg', 'jpeg', 'webp' ]; # override the default filetypes (optional) $wgFileExtensions[] = 'svg'; # add new (just one) filetype $wgSVGNativeRendering = true; # direct SVG display (mediawiki 1.41+) $wgAllowExternalImages = true; # optional $wgUseInstantCommons = true;
MediaWiki supports SVG image rendering automatically be rendered as a PNG file. Direct SVG display is not supported in MediaWiki by default, unless you install NativeSvgHandler extension.
- User rights
- https://www.mediawiki.org/wiki/Manual:User_rights
- https://www.mediawiki.org/wiki/Manual:Preventing_access
$wgGroupPermissions['*']['createaccount'] = false; # restrict account creation (only sysop) $wgGroupPermissions['*']['edit'] = false; # restrict anonymous editing
New users will still be able to be created, but only when logged in to Special:Userlogin as sysop (or direct via Special:CreateAccount). Note that the first letter of a username is capitalized (changes to uppercase). Changing user rights (user groups) over Special:UserRights page (as sysop).
- Debug
$wgShowExceptionDetails = true; $wgDebugToolbar = true; # optional
Customization
- https://www.mediawiki.org/wiki/Manual:Page_customizations
- https://www.mediawiki.org/wiki/Manual:Interface
- https://www.mediawiki.org/wiki/Manual:FAQ
Most look and feel customizations can be done by modifying System messages using the Special:AllMessages page. Messages (snippet of plain text, wikitext, CSS or JavaScript) can be overridden from their default values by editing them on your wiki. Each message has a wiki page in the MediaWiki namespace with its message key as the name of the page. The Interface messages category contains articles on all of the documented interface (system) message available within MediaWiki.
- Footer
To remove the Privacy policy or Disclaimers links at the bottom of each page entirely, replace/set the content of pages MediaWiki:Privacy or MediaWiki:Disclaimers respectively (as sysop) to a single hyphen character (-
).
Link | Default content | New content |
---|---|---|
https://muke.saske.sk/wiki/MediaWiki:Privacy | Privacy policy |
-
|
https://muke.saske.sk/wiki/MediaWiki:Disclaimers | Disclaimers |
-
|
Analogically to customize the About ExampleWiki or Last edited links at the bottom of each page entirely, replace/set the content of pages MediaWiki:Aboutsite or MediaWiki:Lastmodifiedat respectively (as sysop) to customize content.
Link | Default content | New content |
---|---|---|
https://muke.saske.sk/wiki/MediaWiki:Aboutsite | About {{SITENAME}} |
- or customize About ExampleSite.com
|
https://muke.saske.sk/wiki/MediaWiki:Lastmodifiedat | This page was last edited on $1, at $2. |
This page was last edited on $1, at $2 UTC.
|
Customize some Copyright pages over MediaWiki:Copyright or MediaWiki:Copyrightpage (as sysop). Footer containing MediaWiki:Copyrightwarning is displayed under the edit box when editing a page.
Link | Default content | New content |
---|---|---|
https://muke.saske.sk/wiki/MediaWiki:Copyrightwarning | ... released under the $2 (see $1 for details). ... |
... released under the $2. ...
|
- Sidebar
MediaWiki:Sidebar allows a user to modify the navigation bar. The Vector skin place the navigation bar on the top-left along with the search bar and toolbox, but the placement may be different in other skins.
- Stylesheets
- https://www.mediawiki.org/wiki/Manual:Interface/Stylesheets
- MediaWiki and Wikipedia Common.css page or MediaWiki and Wikipedia Vector.css page
MediaWiki:Common.css is a page on your wiki (not a file somewhere in /opt/mediawiki) and is a CSS loaded after the active skin stylesheet. Can be edited (only as interface-admin) as like any other page on your wiki. This stylesheet is loaded with all skins and a similar stylesheet specific to the skin (for example MediaWiki:Vector.css) is appended to it. Analogically MediaWiki:Common.js contains JavaScript that will be loaded for all users on every page.
Maintenance
The maintenance scripts (in the maintenance subdirectory) are used to perform various administrative, import, maintenance, reporting and upgrade tasks. For example, deleteOldRevisions.php file is a maintenance script to delete all old (non current) revisions from the revision table in the database (script deletes page histories).
$ php maintenance/deleteOldRevisions.php # --delete
- Backup
Backup MediaWiki (MariaDB database + images + LocalSettings.php + others) simple script wiki-backup.sh. Execute as root user (needed permissions to read LocalSettings.php file, images and other files).
$ wget https://raw.githubusercontent.com/musinsky/config/master/MediaWiki/wiki-backup.sh
It is also a good idea to create an XML dump for backup or export (in addition to the MariaDB database dump). XML dump contain the content of the wiki (wiki pages with all their revisions) without the site related data (they do not contain user accounts, images, logs, etc). XML dump are independent of the database structure and can be imported into future (and even past) versions of MediaWiki. dumpBackup.php file creates an XML dump for export or backup. importDump.php file is a maintenance script to import XML dump files into the current wiki.
- Restore
- https://www.mediawiki.org/wiki/Manual:Restoring_a_wiki_from_backup
- https://www.mediawiki.org/wiki/Manual:Upgrading
# backup the database and wiki files (see above) # re-create the database, user and permissions (see above) $ mysql -h localhost -u root MariaDB [(none)]> CREATE DATABASE example_wiki; # DROP DATABASE IF EXISTS example_wiki; # if a previous database exists MariaDB [(none)]> CREATE USER 'wikiuser'@'localhost' IDENTIFIED BY 'sql_wiki_passwd'; # change sql_wiki_passwd to custom password MariaDB [(none)]> GRANT ALL PRIVILEGES ON example_wiki.* TO 'wikiuser'@'localhost' WITH GRANT OPTION; # import the database backup $ mysql --user=wikiuser --password example_wiki < example_wiki-dump_YYYY-MM-DD.sql
# copy previous wiki settings file LocalSettings.php and modify if needed (sitename, server, database settings, extensions, etc.) $ chmod 600 LocalSettings.php; chown apache:apache LocalSettings.php # copy previous wiki files (dir images, logo, icon, etc.) $ find images/ -type d -exec chmod 755 {} \; ; find images/ -type f -exec chmod 644 {} \; ; chown -R apache:apache images/
# run the update script (run after each upgrade of MediaWiki) $ php maintenance/run.php update.php # mediawiki 1.40+$ php maintenance/update.php
NOTE Be careful when upgrade MediaWiki with "switch" symbolic links (/opt/mediawiki -> /opt/mediawiki-x.y.z) and Apache server (httpd) with Alias
in your mediawiki.conf.
- Sitemap
- https://www.mediawiki.org/wiki/Manual:Sitemap
- https://www.mediawiki.org/wiki/Manual:GenerateSitemap.php
$ php /opt/mediawiki/maintenance/generateSitemap.php --fspath=/var/www/html/ $ ln -s /var/www/html/sitemap-index-example_wiki.xml /var/www/html/sitemap-index.xml
- robots.txt
Example how prevent spiders from crawling non-article wiki pages with "pretty URL" (short URL) page address. Create file /var/www/html/robots.txt (in the root directory of Apache web server).
User-agent: * Disallow: /mediawiki/ Disallow: /mediawiki/api.php Disallow: /wiki/Special:
Be careful Disallow: /mediawiki
(without /
at the end) you'll block access to the /mediawiki directory and search engines will drop your wiki.
Extensions
- https://www.mediawiki.org/wiki/Manual:Extensions
- Special:Version, MediaWiki and Wikipedia Special:Version page with installed extensions
The downloadable version of MediaWiki comes with a number of bundled extensions and skins in by default. Extensions are usually distributed as modular packages in their own subdirectory extensions/. To install extensions add at the end of the LocalSettings.php file
wfLoadExtension( 'ExtensionName' );
Some extensions changes database and need manually run php maintenance/update.php
.
CategoryTree,
Cite,
Interwiki (optional),
Math or
SimpleMathJax,
MultimediaViewer,
ParserFunctions,
Replace Text,
SyntaxHighlight,
TemplateData (ToDo),
Variables (not recommended by wiki)
WikiEditor, CodeMirror, CodeEditor (requires WikiEditor, optional), VisualEditor (optional)
- Other extensions
Semantic MediaWiki, ExternalContent, GitHub, External Data
Notes
The full list of default interwiki prefixes is available at maintenance/interwiki.list
For the full list of languages supported by Pygments see https://pygments.org/languages/.
Command extensions/SyntaxHighlight_GeSHi/pygments/pygmentize
will execute in the editing process (not for every view).