MediaWiki: Difference between revisions

From WickyWiki
mNo edit summary
 
(42 intermediate revisions by 2 users not shown)
Line 3: Line 3:
[[Category:201110]]
[[Category:201110]]


== Installation and configuration ==
= Installation and configuration =


=== MySQL database server and PHP Ubuntu ===
== MySQL database server and PHP Ubuntu ==


For more info: [[MySQL]]
For more info: [[MySQL]]


<syntaxhighlight lang=bash>
<source lang=bash>
sudo apt-get install apache2 mysql-server php5 php5-mysql
sudo apt install imagemagick php-fpm php-intl php-xml php-curl php-gd php-mbstring php-mysql php-apcu php-zip
</syntaxhighlight>
</source>


Create wiki database:
Create wiki database:


<syntaxhighlight lang=bash>
<source lang=bash>
sudo mysql -u root mysql -p
sudo mysql -u root mysql -p
</syntaxhighlight>
</source>


SQL:
SQL:


<syntaxhighlight lang=sql>
<source lang=sql>
create database wikidb;
create database wikidb;
grant index, create, select, insert, update, delete, alter, lock tables on wikidb.* to 'wikidbadmin'@'localhost' identified by '**pwd**';
grant index, create, select, insert, update, delete, alter, lock tables on wikidb.* to 'wikidbadmin'@'127.0.0.1' identified by '**pwd**';
\q
\q
</syntaxhighlight>
</source>


Make sure the settings for your database in LocalSettings.php are correct, then go to the configuration web page, here you can create or upgrade the database:
Make sure the settings for your database in LocalSettings.php are correct, then go to the configuration web page, here you can create or upgrade the database:
Line 31: Line 31:
* http://localhost/mediawiki/mw-config/index.php
* http://localhost/mediawiki/mw-config/index.php


=== MediaWiki website files ===
== MediaWiki website files ==


Download the code and copy to /var/www/mediawiki
Download the code and copy to /var/www/mediawiki
Line 38: Line 38:
Edit LocalSettings.php to add extensions and to customize.
Edit LocalSettings.php to add extensions and to customize.


=== Configuration LocalSettings.php ===
== Configuration LocalSettings.php ==
 
Note:
* Generate a new LocalSettings.php during installation and use this example to make your changes.
* Include your LocalSettings.php in your backup to make your upgrades easier
 
Some extensions to tweak:
* WikiEditor - a bit more help while editing
* Highlightjs_Integration - easier reading of code. [[MediaWiki#Performance|Also look at "Performance"]]
* LockDown - allow only registered users to view certain pages and view history
* EditSubpages - Allow anonymous talk - everyone is allowed to start a discussion
* ConfirmEdit - anonymous users need to answer a simple question


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 44: Line 55:
</syntaxhighlight>
</syntaxhighlight>


<blockquote>
== System permissions for uploads ==
<syntaxhighlight lang=php>
 
# Image uploads, make sure the 'images' directory is writable
$wgEnableUploads  = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";
 
# Skin
$wgDefaultSkin = "vector";
$wgFavicon = "$wgScriptPath/images/favicon.ico";
 
# Extensions/WikiEditor
require_once("$IP/extensions/WikiEditor/WikiEditor.php");
$wgDefaultUserOptions['usebetatoolbar'] = 1;
# Displays the Preview and Changes tabs
$wgDefaultUserOptions['wikieditor-preview'] = 1;
# Displays the Publish and Cancel buttons on the top right side
$wgDefaultUserOptions['wikieditor-publish'] = 1;
 
# Reading by anonymous users
$wgGroupPermissions['*']['read'] = true;
 
# Always allow reading access to the login page
$wgWhitelistRead = array ("Special:Userlogin", "MediaWiki:Common.css", "MediaWiki:Common.js"
, "MediaWiki:Monobook.css", "MediaWiki:Monobook.js", "-");
 
# Anonymous editing
$wgGroupPermissions['*']['edit'] = false;
 
# Prevent new user registrations except by sysops (false)
$wgGroupPermissions['*']['createaccount'] = false;
 
require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");
$wgSyntaxHighlightDefaultLang = "bash";
 
#Debugging
$wgShowExceptionDetails = true;
#error_reporting( -1 );
#ini_set( 'display_errors', 1 );
#$wgDebugLogFile = "/tmp/mediawiki_debug.log";
 
</syntaxhighlight>
</blockquote>
 
=== System permissions for uploads ===


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 96: Line 62:
</syntaxhighlight>
</syntaxhighlight>


===Change user password using commandline===
==Change user password using commandline==


Set the password for username 'user1' to '**pwd**'.  
Set the password for username 'user1' to '**pwd**'.  
Line 105: Line 71:
</syntaxhighlight>
</syntaxhighlight>


=== [[Apache2 webserver]] configuration ===
== [[Apache2 webserver]] configuration ==


If you login using http your password will be send over the net in 'clear text'. To force login via https the RewriteRule is added, however, you will also need to configure the SSL part of your website. Read [[Create certificates for Apache2]]. See also [[Apache2 configuration for SOGo and MediaWiki]].
If you login using http your password will be send over the net in 'clear text'. To force login via https the RewriteRule is added, however, you will also need to configure the SSL part of your website. Read [[Create certificates for Apache2]]. See also [[Apache2 configuration for SOGo and MediaWiki]].


=== PHP configuration ===
== Nginx conf webserver configuration ==
 
See:
* https://www.nginx.com/resources/wiki/start/topics/recipes/mediawiki/
 
== PHP configuration ==


With wikimedia, when you import or export all pages or when you upload images and files, this will take more space and time that normally is allowed by PHP. Change these settings:
With wikimedia, when you import or export all pages or when you upload images and files, this will take more space and time that normally is allowed by PHP. Change these settings:


<syntaxhighlight lang=bash>
<source lang=bash>
 
sudo gedit `locate php.ini | head -n 1``
 
#where is php.ini
php -r \@phpinfo\(\)\; | grep 'php.ini' -m 1


sudo gedit `locate php.ini | head -n 1`
</source>
</syntaxhighlight>


<blockquote>
<blockquote>
<syntaxhighlight lang=bash>
<source lang=bash>
...
...
upload_max_filesize = 5M
upload_max_filesize = 5M
Line 128: Line 103:
...
...
max_input_time = 180 ; 3min
max_input_time = 180 ; 3min
</syntaxhighlight>
...
#logon session time (garbage collection)
session.gc_maxlifetime=3600 ; 60 min
...
#nginx webserver requirement
cgi.fix_pathinfo = 0
...
date.timezone = Europe/Amsterdam
</source>
</blockquote>
</blockquote>


Restart Apache2 to apply the settings:
Restart Apache2 to apply the settings:
<source lang=bash>
sudo service apache2 restart
</source>
= Backup =
The most important part to backup is the database, see [[MySQL#Backup]] for more information.
The second part is the files that where uploaded, these are typically located in:
/var/www/mediawiki/images/
We could backup this folder but then you will also have thumbnails and other temporary files. Instead we will use the following command to list the mediafiles we want to backup:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo service apache2 restart
cd /var/www/mediawiki/
php maintenance/dumpUploads.php | sed 's~images/~./images/~' | zip ~/Mediafiles.zip -@
</syntaxhighlight>
 
To add these to a zip file for example:
 
<syntaxhighlight lang=bash>
cd /var/www/mediawiki/
php maintenance/dumpUploads.php | sed 's~images/~./images/~' | zip ~/MediaWikiImages.zip -@
</syntaxhighlight>
</syntaxhighlight>


== Categories ==
= Categories =


Use categories to group your pages by including one or more Category tags:
Use categories to group your pages by including one or more Category tags:
Line 147: Line 152:
[[Special:Categories]]
[[Special:Categories]]


== Tips ==
= Tips =


=== Keywords ===
== Keywords ==


You can make the search tool more efficient <!-- effective --> if you add synonyms and keywords to a page. You might want to keep these hidden <!-- hide, invisible --> from the reader to keep the text readable <!-- neat -->. Insert like this:
You can make the search tool more efficient <!-- effective --> if you add synonyms and keywords to a page. You might want to keep these hidden <!-- hide, invisible --> from the reader to keep the text readable <!-- neat -->. Insert like this:
Line 157: Line 162:
</nowiki>
</nowiki>


=== Hotkeys ===
== Special Import / Export pages ==


The tooltips will show you the letter of the shortcut between brackets. You need to press SHIFT+ALT+<letter> to use it.
=== Import (as Admin) ===
 
Shortcuts:
*SHIFT+ALT+Z main page
*SHIFT+ALT+E start edit (if allowed)
** you can also right click on the section or click the [edit] link
*SHIFT+ALT+P preview
*SHIFT+ALT+S save
*SHIFT+ALT+C cancel
 
=== Special Import / Export pages ===
 
==== Import (as Admin) ====


[[:Special:Import]]
[[:Special:Import]]


==== Export pages  ====
=== Export pages  ===


[[:Special:Export]]
[[:Special:Export]]


==== Export full contents  ====
=== Export full contents  ===


Uploaded files (like images) are not included an need to be copied and linked separately.
Uploaded files (like images) are not included an need to be copied and linked separately.
Line 188: Line 181:
</syntaxhighlight>
</syntaxhighlight>


== VisualEditor ==
== Change where "Main Page" in the menu links to ==
 
By default "Main Page" in the menu links to '[[Main Page]]' but you can replace this with with your own page.
 
Change where "Main Page" in the menu links to:
# Go to [[MediaWiki:Mainpage]] <nowiki>( http://www.yourdomain.com/mediawiki/index.php/MediaWiki:Mainpage )</nowiki>
# Edit the page so it is the name of the page you want and save it
# Now click "Main Page" in the menu and create it
 
Note: you need to be Administrator to be allowed to do this.
 
== Pages to configure MediaWiki ==
 
* [[Mediawiki:Sidebar]]
* [[MediaWiki:Common.css]]
* [[MediaWiki:Mobile.css]]
* [[MediaWiki:Lastmodifiedat]] NB: $1=date, $2=time)
 
More info:
* https://how-to.fandom.com/wiki/How_to_customize_MediaWiki
 
You might want to hide when you have been editing pages. We want to show the date but hide the time.
 
== Require login for certain pages with Extension:Lockdown ==
 
<!-- privacy -->
 
Enable this extension and configure LocalSettings.php to hide pages you only want to logged-in users to see.
 
* https://www.mediawiki.org/wiki/Extension:Lockdown
 
For example, these pages show user/date/time information of edits.
 
<source lang=php>
$wgSpecialPageLockdown['ComparePages']        = [ 'user' ];
$wgSpecialPageLockdown['Redirect']            = [ 'user' ];
$wgSpecialPageLockdown['PermanentLink']      = [ 'user' ];
$wgSpecialPageLockdown['PageInfo']            = [ 'user' ];
$wgSpecialPageLockdown['ApiSandbox']          = [ 'user' ];
$wgSpecialPageLockdown['Contributions']      = [ 'user' ];
$wgSpecialPageLockdown['Recentchanges']      = [ 'user' ];
$wgSpecialPageLockdown['Recentchangeslinked'] = [ 'user' ];
$wgSpecialPageLockdown['Ancientpages']        = [ 'user' ];
$wgSpecialPageLockdown['Newimages']          = [ 'user' ];
$wgSpecialPageLockdown['Log']                = [ 'user' ];
$wgSpecialPageLockdown['Diff']                = [ 'user' ];
$wgSpecialPageLockdown['Export']              = [ 'user' ];
$wgSpecialPageLockdown['Newpages']            = [ 'user' ];
$wgActionLockdown['info'] = [ 'user' ];
$wgActionLockdown['history'] = [ 'user' ];
$wgActionLockdown['historysubmit'] = [ 'user' ];
</source>
 
== Hide 'last modified' time from the pages ==
 
Allowing 'Search' to be used you might want to hide the 'last changed' time from the search results. Unfortunately this is not a standard function but we can get what we want if we modify a .php file.
 
<source lang=bash>
sudo nano -l +66 /var/www/mediawiki/includes/search/searchwidgets/FullSearchResultWidget.php
</source>
 
<blockquote>
<source lang=php>
$date = $this->specialPage->getLanguage()->userTimeAndDate(
</source>
</blockquote>
 
Replace with:
 
<blockquote>
<source lang=php>
$date = $this->specialPage->getLanguage()->userDate(
</source>
</blockquote>
 
Note: these are both functions defined in 'languages/Language.php'.
 
== Performance ==
 
MediaWiki on RapberryPi would be quite slow with some pages and especially while saving edits. This seems to be caused by the syntax highlighting extension (GeSHi). Although I can't explain why it has such high impact, the performance improved greatly with switching to client-side highlighting (HighlightJS). See below information:
 
* [https://www.mediawiki.org/wiki/Extension:Highlightjs_Integration Highlightjs Integration]
* https://highlightjs.org/download/
 
= VisualEditor =


VisualEditor is a WYSIWYG editor that generates readable Wiki text. Due to limitations I prefer to use WikiEdit.  
VisualEditor is a WYSIWYG editor that generates readable Wiki text. Due to limitations I prefer to use WikiEdit.  


Limitations:
Note: Parsoid is no longer a separate service and included in the extension, the extension is also included in the Mediawiki download.
* Can not edit syntax parts and many other type of blocks, for this you still need to edit the wiki text.
 
* Depends on Parsoid which runs as an independed server and is a pain to configure
== Limitations ==
* You may not be able to edit syntax parts or other type of blocks, for this you still need to edit the wiki text.
* The generated wiki-text might be difficult to read and edit as wiki-text


Info:
Info:
Line 251: Line 330:
</syntaxhighlight>
</syntaxhighlight>


== See also ==
= See also =


Go to [[Apache2 webserver]] to read about installing and configuring Apache2 webserver.
Go to [[Apache2 webserver]] to read about installing and configuring Apache2 webserver.
Line 257: Line 336:
Accidentally committed information that really needs to be removed? Go to: [[Permanently remove a MediaWiki revision using SQL]].
Accidentally committed information that really needs to be removed? Go to: [[Permanently remove a MediaWiki revision using SQL]].


=== MediaWiki.org help pages ===
== MediaWiki.org help pages ==
* http://www.mediawiki.org/wiki/Manual:Configuration_settings
* http://www.mediawiki.org/wiki/Manual:Configuration_settings
* http://www.mediawiki.org/wiki/Help:Formatting
* http://www.mediawiki.org/wiki/Help:Formatting
Line 264: Line 343:
* http://www.mediawiki.org/wiki/Manual:Configuration_settings#Database_settings
* http://www.mediawiki.org/wiki/Manual:Configuration_settings#Database_settings


=== Other sources ===
== Other sources ==
* https://help.ubuntu.com/community/MediaWiki
* https://help.ubuntu.com/community/MediaWiki
* http://ubuntuguide.org/wiki/MediaWiki_tips
* http://ubuntuguide.org/wiki/MediaWiki_tips
== Mediawiki upgrade ==
* Example [[Mediawiki upgrade to 1.37.1]]

Latest revision as of 21:53, 18 March 2022


Installation and configuration

MySQL database server and PHP Ubuntu

For more info: MySQL

sudo apt install imagemagick php-fpm php-intl php-xml php-curl php-gd php-mbstring php-mysql php-apcu php-zip

Create wiki database:

sudo mysql -u root mysql -p

SQL:

create database wikidb;
grant index, create, select, insert, update, delete, alter, lock tables on wikidb.* to 'wikidbadmin'@'127.0.0.1' identified by '**pwd**';
\q

Make sure the settings for your database in LocalSettings.php are correct, then go to the configuration web page, here you can create or upgrade the database:

MediaWiki website files

Download the code and copy to /var/www/mediawiki

Edit LocalSettings.php to add extensions and to customize.

Configuration LocalSettings.php

Note:

  • Generate a new LocalSettings.php during installation and use this example to make your changes.
  • Include your LocalSettings.php in your backup to make your upgrades easier

Some extensions to tweak:

  • WikiEditor - a bit more help while editing
  • Highlightjs_Integration - easier reading of code. Also look at "Performance"
  • LockDown - allow only registered users to view certain pages and view history
  • EditSubpages - Allow anonymous talk - everyone is allowed to start a discussion
  • ConfirmEdit - anonymous users need to answer a simple question
sudo gedit /var/www/mediawiki/LocalSettings.php

System permissions for uploads

sudo chown -R www-data:www-data /var/www/mediawiki/images/
sudo chmod -R 755 /var/www/mediawiki/images/

Change user password using commandline

Set the password for username 'user1' to '**pwd**'.

cd /var/www/mediawiki
php maintenance/changePassword.php --user=user1 --password=**pwd**

Apache2 webserver configuration

If you login using http your password will be send over the net in 'clear text'. To force login via https the RewriteRule is added, however, you will also need to configure the SSL part of your website. Read Create certificates for Apache2. See also Apache2 configuration for SOGo and MediaWiki.

Nginx conf webserver configuration

See:

PHP configuration

With wikimedia, when you import or export all pages or when you upload images and files, this will take more space and time that normally is allowed by PHP. Change these settings:


sudo gedit `locate php.ini | head -n 1``

#where is php.ini
php -r \@phpinfo\(\)\; | grep 'php.ini' -m 1
	...
	upload_max_filesize = 5M
	...
	post_max_size = 5M
	...
	max_execution_time = 180 ; 3min
	...
	max_input_time = 180 ; 3min
	...
	#logon session time (garbage collection)
	session.gc_maxlifetime=3600 ; 60 min
	...
	#nginx webserver requirement
	cgi.fix_pathinfo = 0	
	...
	date.timezone = Europe/Amsterdam

Restart Apache2 to apply the settings:

sudo service apache2 restart

Backup

The most important part to backup is the database, see MySQL#Backup for more information.

The second part is the files that where uploaded, these are typically located in:

/var/www/mediawiki/images/

We could backup this folder but then you will also have thumbnails and other temporary files. Instead we will use the following command to list the mediafiles we want to backup:

cd /var/www/mediawiki/
php maintenance/dumpUploads.php | sed 's~images/~./images/~' | zip ~/Mediafiles.zip -@

To add these to a zip file for example:

cd /var/www/mediawiki/
php maintenance/dumpUploads.php | sed 's~images/~./images/~' | zip ~/MediaWikiImages.zip -@

Categories

Use categories to group your pages by including one or more Category tags:

 [[Category:Name]]

Try to distribute your pages evenly over categories, first look here if any of the available categories can be used:

Special:Categories

Tips

Keywords

You can make the search tool more efficient if you add synonyms and keywords to a page. You might want to keep these hidden from the reader to keep the text readable . Insert like this:

<!-- hidden text -->

Special Import / Export pages

Import (as Admin)

Special:Import

Export pages

Special:Export

Export full contents

Uploaded files (like images) are not included an need to be copied and linked separately.

cd /var/www/mediawiki/
sudo php maintenance/dumpBackup.php --full --uploads > ../wiki_dump.xml

Change where "Main Page" in the menu links to

By default "Main Page" in the menu links to 'Main Page' but you can replace this with with your own page.

Change where "Main Page" in the menu links to:

  1. Go to MediaWiki:Mainpage ( http://www.yourdomain.com/mediawiki/index.php/MediaWiki:Mainpage )
  2. Edit the page so it is the name of the page you want and save it
  3. Now click "Main Page" in the menu and create it

Note: you need to be Administrator to be allowed to do this.

Pages to configure MediaWiki

More info:

You might want to hide when you have been editing pages. We want to show the date but hide the time.

Require login for certain pages with Extension:Lockdown

Enable this extension and configure LocalSettings.php to hide pages you only want to logged-in users to see.

For example, these pages show user/date/time information of edits.

$wgSpecialPageLockdown['ComparePages']        = [ 'user' ];
$wgSpecialPageLockdown['Redirect']            = [ 'user' ];
$wgSpecialPageLockdown['PermanentLink']       = [ 'user' ];
$wgSpecialPageLockdown['PageInfo']            = [ 'user' ];
$wgSpecialPageLockdown['ApiSandbox']          = [ 'user' ];
$wgSpecialPageLockdown['Contributions']       = [ 'user' ];
$wgSpecialPageLockdown['Recentchanges']       = [ 'user' ];
$wgSpecialPageLockdown['Recentchangeslinked'] = [ 'user' ];
$wgSpecialPageLockdown['Ancientpages']        = [ 'user' ];
$wgSpecialPageLockdown['Newimages']           = [ 'user' ];
$wgSpecialPageLockdown['Log']                 = [ 'user' ];
$wgSpecialPageLockdown['Diff']                = [ 'user' ];
$wgSpecialPageLockdown['Export']              = [ 'user' ];
$wgSpecialPageLockdown['Newpages']            = [ 'user' ];
$wgActionLockdown['info'] = [ 'user' ];
$wgActionLockdown['history'] = [ 'user' ];
$wgActionLockdown['historysubmit'] = [ 'user' ];

Hide 'last modified' time from the pages

Allowing 'Search' to be used you might want to hide the 'last changed' time from the search results. Unfortunately this is not a standard function but we can get what we want if we modify a .php file.

sudo nano -l +66 /var/www/mediawiki/includes/search/searchwidgets/FullSearchResultWidget.php
$date = $this->specialPage->getLanguage()->userTimeAndDate(

Replace with:

$date = $this->specialPage->getLanguage()->userDate(

Note: these are both functions defined in 'languages/Language.php'.

Performance

MediaWiki on RapberryPi would be quite slow with some pages and especially while saving edits. This seems to be caused by the syntax highlighting extension (GeSHi). Although I can't explain why it has such high impact, the performance improved greatly with switching to client-side highlighting (HighlightJS). See below information:

VisualEditor

VisualEditor is a WYSIWYG editor that generates readable Wiki text. Due to limitations I prefer to use WikiEdit.

Note: Parsoid is no longer a separate service and included in the extension, the extension is also included in the Mediawiki download.

Limitations

  • You may not be able to edit syntax parts or other type of blocks, for this you still need to edit the wiki text.
  • The generated wiki-text might be difficult to read and edit as wiki-text

Info:

At the time I needed to checkout beta version 'MediaWiki 1.22wmf8':

git clone https://gerrit.wikimedia.org/r/p/mediawiki/core.git
cd core
git branch -r | sort -V
git checkout origin/wmf/1.22wmf9
cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/VisualEditor.git
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Parsoid.git
node.js

Download 'node-v0.8.22.tar.gz' (the core files) and 'node-v0.8.22-linux-x64.tar.gz' (the 64 bit specific files) from http://nodejs.org/dist/v0.8.22/ extract these in this order in one folder.

It needed to be exactly this version, newer and older did not work yet.

Go into the folder and build and install this version of node:

./configure --prefix=/opt/nodejs
make -j 3
make install

Install Parsoid using npm. Note: you can uninstall by deleting /opt/nodejs:

sudo -i
cd Parsoid/js
export PATH=$PATH:/opt/nodejs/bin
npm install

Start server:

export PATH=$PATH:/opt/nodejs/bin
cd /var/www/mediawiki/extensions/Parsoid/js
node api/server.js

Go to:

If you want to modify this service you can edit this file:

sudo gedit /var/www/mediawiki/extensions/Parsoid/js/api/ParserService.js

See also

Go to Apache2 webserver to read about installing and configuring Apache2 webserver.

Accidentally committed information that really needs to be removed? Go to: Permanently remove a MediaWiki revision using SQL.

MediaWiki.org help pages

Other sources

Mediawiki upgrade