home | tech | misc | code | bookmarks (broken) | contact | README


Mediawiki notes

Installing MediaWiki with the PostgreSQL database in NetBSD

Install the following packages from pkgsrc. Don't forget the dependencies.

  • postgresql81
  • postgresql81-tsearch2
  • apache2
  • php5
  • phppgsql

Take attention to the messages that you receive among normal output of pkgsrc. There are very important information like how to make apache work with php and to bind postgresql to php.

After installing and started (don't forget to copy the start scripts of apache and PostgreSQL (pgsql) from p../../share/examples/rc.d to /etc/rc.d and add apache=YES and pgsql=YES to /etc/rc.conf).

Change the DocumentRoot option in the Apache configuration file (pkg/etc/httpd/httpd.conf) to the directory where you want to install mediawiki and the rest of the htdocs. Also, add the index.php element to the list of the option DirectoryIndex, like in the following example:

DirectoryIndex index.html index.html.var index.php

Download and unpack mediawiki. Move it to your htdocs path and open the main page in a browser. You are now in the installer of mediawiki where you have to set the options of it properly. When you click at the submit button at the bottom it will create the database, the mediawiki tables but will fail asking for tsearch2 and plpgsql, so it is necessary to set them manually:

cd to the directory where tsearch2.sql can be found, normally p../../share/postgresql/contrib

Login to the database of the wiki as super user:

$ psql -U pgsql <databasename>

Run the script in your database:

# \i tsearch2.sql

Logout psql. Call the createlang command to install plpgsql to the wiki database:

$ createlang -U pgsql plpgsql <databasename>

Your wiki should be working nice now.

To set up the phppgadmin, just copy the folder p../../share/phppgadmin to the directories where the rest of the htdocs are locatted. You will not be able to login as the superuser if you don't turn off a security flag in phppgsql configuration file (which is not recommended). So it is better to add users with the CREATE ROLE command and make modifications in the database as one of them. So:

$ psql -U pgsql <databasename>
# CREATE ROLE <rolename> PASSWORD '<password>' LOGIN CREATEDB SUPERUSER;

From PASSWORD to the last parameter all of them are optional. The LOGIN parameter can not be avoided because it grants login capacities to the role, from either psql or a web interface like phppgsql. The CREATEDB parameter enables the role to create databases and the SUPERUSER parameter enables the role to CREATE, DROP and ALTER roles. The CREATEDB and the SUPERUSER parameters should be avoided and use carefully.

After CREATEing the necessary roles you should be able login use phppgadmin fine.

Using a local readonly user along LDAP authentication for other users

Mediawiki up to 1.25 didn't have the possibility of multiple authentication. One authentication method was set with the $wgAuth variable and was impossible to mix different types of authentication without extension features or admin workarounds. This has changed since 1.26, which uses AuthManager.

So, I had to setup a Mediawiki server that users logged in using LDAP but I had to setup a local user with read only access. First, I changed $wgAuth in LocalSettings.php:

$wgAuth = new LdapAuthenticationPlugin();
/*
 * Here below, all the LDAP configuration (server, domain, port, search
 * attributes, etc.) is setup with $wgLDAP* variables.
 */

But I still needed to turn on a feature to allow local users to login along with authentication for local users. This is done setting the $wgLDAPUseLocal variable:

$wgLDAPUseLocal = true;

On the login page, two domains will show up. The LDAP domain and the "local" domain. You now shall be able to login with local users.

Note

$wgLDAPUseLocal is, though, a non-recommended feature. See this discussion about $wgLDAPUseLocal for more information.

Creating a user with readonly permissions

I had a bunch of users with read-write access to the wiki but I had to create a single user with readonly access. Unfortunately, I just found an awkward way to do it (if you know a better way or find anything wrong in this guide, please, let me know).

User rights must be done with groups. They are set in $wgGroupPermissions variable, described in details in the Mediawiki manual about user rights page. There are two important groups, * and user. The former holds all users, including anonymous users, the later represents all registered users.

Suppose we create a new group called guest. Creating a new group and setting $wgGroupPermissions['guest']['edit'] = false; is not enough to make the users it holds readonly, because it also inherits properties from the group user. So we need to make all users readonly, create besides the guest group, also the writer group and have an "autopromote" rule to make any user not in guest group be in the writer group.

In summary, here is where we ended up, in LocalSettings.php:

$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['read'] = false;

$wgGroupPermissions['user']['edit'] = false;

$wgGroupPermissions['guest'] = $wgGroupPermissions['user'];
$wgGroupPermissions['guest']['edit'] = false;

$wgGroupPermissions['writer'] = $wgGroupPermissions['user'];
$wgGroupPermissions['writer']['edit'] = true;

# Make every user NOT belonging to groupt 'guest', be promoted to group
# 'writer'
$wgAutopromote = array (
        'writer' => array ('!', array(APCOND_INGROUPS, 'guest'))
);

Troubleshooting

Problems with Mediawiki 1.12.0

After installing Apache, PHP and MySQL, MediaWiki 1.12.0 was installed. Following the installing documentation, everything went fine: the on-screen wizard worked fine and created the database and also the LocalSettings.php file.

But, MediaWiki's main page didn't appear. After searching, I found this page, from a guy that had the same problem of mine. So, I put at php.ini configuration file:

log_errors = On
error_log = /tmp/php.log

And after restarting Apache and trying to running the page again, I analyzed the log file in /tmp/php.log:

[27-Jun-2008 11:31:50] PHP Fatal error:  Class 'DOMDocument' not found in
/disk/files/www/wiki/includes/Preprocessor_DOM.php on line 566

It seems it there is a bug in the 1.12.0 version of MediaWiki that makes this error (maybe only in a specific environment?).

I just installed a newer version (1.11.2) and everything went fine.

Eliminating index.php from URL

Googling, I found this page which led me to short url page in mediawiki documentation. In the file LocalSettings.php:

$wgScriptPath = "/wiki";
$wgArticlePath = "/w/$1";
$wgUsePathInfo = true;

The $wgScriptPath variable holds the real directory where Mediawiki scripts are stored. $wgArticlePath is the "virtual" directory. Both need to be different.

A line in httpd.conf is necessary too:

Alias /w "<path_to_htdocs>/wiki/index.php"

Where <path_to_htdocs> is what it says.

Increasing maximum file upload size

Just follow the following steps: (Like in the page other mediawiki settings).

In php.ini, change the post_max_size and upload_max_filesize variables to the maximum size you want:

post_max_size = 16M
upload_max_size = 16M

In the mediawiki software, open the SpecialImport.php and alter the MAX_FILE_SIZE hidden input to the value you want, in bytes:

<input type='hidden' name='MAX_FILE_SIZE' value='16000000' />

Restart apache (which is necessary, since you changed php.ini). It might be working fine, now.

Error creating thumbnail when trying to show SVG

MediaWiki accepts showing SVG images in pages by converting them to PNG. The procedure is in MediaWiki Manual: Image Administration - SVG.

Basically, the administration just have to include in the LocalSettings.php file:

$wgFileExtensions[] = 'svg';
$wgAllowTitlesInSVG = true;
$wgSVGConverter = 'rsvg'

Where the $wgSVGConverter may vary from system to system, depending on what conversion tool you have. It may be other, like ImageMagick. I use rsvg because that was available on the system.

After configuring these settings, I just got an error inline the page:

Error creating thumbnail

And a blank place where the picture should remain.

The quest starts here. Although I was cheated to other error messages that lead me to wrong solutions not worth to put here (a quick search for "rsvg not working in mediawiki" will show you common problems) I realized that there was some errors in Apache's error_log file (not the site's error log, which is a different file in this setup). Let's cat(1) it:

: command not foundos/includes/limit.sh: line 8:
: command not foundos/includes/limit.sh: line 15:
: command not foundos/includes/limit.sh: line 18:
'...includes/limit.sh: line 62: syntax error near unexpected token `{
'...includes/limit.sh: line 62: `cleanup() {

I placed the script under scrutiny and did not find anything strange. After some searching, I found this page, that shows the bash script ended with CRLF lines and it confused the interpreter. In fact, these files were uploaded from a Windows box!

If we open the same file with less(1) we see the ^M characters:

...includes/limit.sh: line 8: ^M: command not found
...includes/limit.sh: line 15: ^M: command not found
...includes/limit.sh: line 18: ^M: command not found
...includes/limit.sh: line 62: syntax error near unexpected token `{^M'
...includes/limit.sh: line 62: `cleanup() {^M'

After opening it in vim and changing the fileformat, everything worked just file :-).

(Here your will find a simple but nice explanation on why MediaWiki doesn't use inline SVG.)

Error creating thumbnail: Unable to create temporary thumbnail file

It actually depends of what you were trying to do. Mediawiki uses symbolic links when creating images from SVG files, so you need to make sure if any symlink() restriction isn't enabled. In my case, I had to change the following configuration in suhosin.ini file:

suhosin.executor.allow_symlink = On

For more information about Suhosin PHP extension, see this.