CSUF LogoCSUF Site Navigation
optics.csufresno.edu

F12 Apache/MySQL/PHP Services & Applications MediaWiki

Department of Electrical and Computer Engineering
Associate Professor Gregory R. Kriehn
Forums
Wiki
F12 MediaWiki

"MediaWiki is a free software wiki package originally written for Wikipedia. It is now used by several other projects of the non-profit Wikimedia Foundation and by many other wikis." I use it for one of my classes, simply because I am trying to introduce new technology that students are familiar with into the classroom. In general, a wiki can be edited by anyone — however, in my case, I only want the wiki to be edited by my students. To circumvent this problem, many Wiki's are setup so that you can only edit a page if you have logged in. Even so, this still does not preclude an unknown person from registering, logging in, and editing the pages. As a result, I setup my Wiki to include security contexts and groups, meaning that if a user does not have the proper permissions to edit the page, the page cannot be edited. Period.

Installation of MediaWiki requires first heading getting Apache, PHP, and MySQL running. I also find it useful to have phpMyAdmin installed as well. See the appropriate pages if you need help. I also strongly recommend reading over the Installation Guide on MediaWiki's web site.

Before we install MediaWiki, we also need to install php-pecl-apc and php-devel, which can be used to increase the performance of PHP scripts by caching them in their compiled state.  Install it using yum:

~> sudo yum install php-pecl-apc php-devel
Press 'y' when prompted to install the program and any dependencies.  Then restart httpd:
~> sudo service httpd restart
You should see the daemon successfully stop and restart:
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Assuming that you have the appropriate software installed and configured, head over to their website:

http://www.mediawiki.org/wiki/MediaWiki

Click on the scroll down to Current versions, followed by Download, and click on the download for the current version of MediaWiki (mediawiki-1.15.1.tar.gz at the time of this writing). Once the file downloads,
copy the source tarball to the /var/www/html directory:
~> sudo cp ~/Downloads/mediawiki-*.tar.gz /var/www/html/.
Change into the /var/www/html directory:
~> cd /var/www/html
and decompress the source:
~> sudo tar vfzx mediawiki-*.tar.gz
Once the package has been decompressed, delete the source file, and move the mediawiki-* directory to mediawiki.
~> sudo rm mediawiki-*.tar.gz
~> sudo mv mediawiki-* mediawiki
Before changing into the directory, we need to set the security context and change the ownership:
~> sudo chown -R apache.apache mediawiki
In this case, we want Apache to have control over the directory so that we can upload files to the Wiki. Then change into the directory and make the config directory writable by all:
~> cd mediawiki
~> sudo chmod go+w config
Next, open up Firefox and go to:
http://[host].[domain].[name]/mediawiki/
Click on the set up the wiki link. If everything is setup properly, you should see a green bullet point that says "Environment checked.  You can install MediaWiki". Scroll down to Wiki name and type the Wiki name for your site. My Wiki name is "Professor Kriehn". Verify the contact e-mail address, the language, and click on the appropriate copyright license that you want to use. Choose an Admin username (in this case, I have changed "WikiSysop" to another username), and type in the Password for your Admin user. Since php-pecl-apc should be installed, click on APC under Shared memory caching. After this, click on the appropriate e-mail authentication options.

Under Database config, click on the MySQL button. The Database host is "localhost", and choose and appropriate Database name (in this case, I have changed it to "mediawiki"). Pick an appropriate DB username ("mediawiki" is fine), and choose a DB password. Since we have not created the database ahead of time, click on the User superuser account option, and type in the superuser password. Finally, type "mw_" for the Database table prefix. Then click Install MediaWiki.

After MediaWiki installs, you should see another green bullet point that says "Installation successful!" We now need to move the config/LocalSettings.php file to the parent directory:

~> sudo mv config/LocalSettings.php .
While we are at it, we might as well make a backup of the LocalSettings.php file (we are going to be editing it extensively):
~> sudo cp LocalSettings.php LocalSettings.php.bak
Finally, correct the write permissions on the config directory:
~> sudo chmod go-w config
With this done, look again at the last line, indicating that installation was successful. Notice that when the LocalSettings.php file is moved from the config directory, you can click on the "this link" to go to your Wiki. Do so now.

Customizing the Wiki

Next, open up the LocalSettings.php file in a text editor. We are going to customize things like the logo up in the top left corner of the Wiki, create a re-direct for the Wiki so that it no longer displays "index.php" in the web address, along with a number of other changes. If you want to understand what each of the configuration options does, go to:

http://www.mediawiki.org/wiki/Help:Configuration_settings

and read about the different Configuration settings.

The first thing we will configure is allow for users to upload files to the Wiki. Perform a search for $wgEnableUploads. Change the setting from "false" to "true" so that the line reads:

$wgEnableUploads       = true;
Scroll down a few lines, to the $wgImageMagickConvertCommand option. Under it, add the following lines:
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'txt', 'doc', 'pdf', 'xls');
$wgMimeDetectorCommand = "file -bi";
The first line restricts what kinds of files are allowed to be uploaded to the Wiki, and the second line performs MIME detection so that the Wiki knows how to handle various file types. If you want to allow other extensions, add them in the $wgFileExtenstions setting.

Scroll down a few lines and uncomment the $wgHashedUploadDirectory option to upload figures under safe mode:

$wgHashedUploadDirectory = false;
We will have to create the images/archive, images/thumb, and images/temp directories. In another terminal window type:
~> cd /var/www/html/mediawiki/images
~> sudo mkdir archive
~> sudo mkdir thumb
~> sudo mkdir temp
~> sudo chown apache.apache *
Next, scroll down to the very bottom of the LocalSettings.php file. Add the following:
# User Defined Settings
The first setting that we are going to define is the location of the logo in the upper left corner of the screen. Add the following lines:
# Set default skin directory and logo path
$wgStylePath        = "$wgScriptPath/skins";
$wgStyleDirectory   = "$IP/skins";
$wgLogo             = "$wgStylePath/common/images/[figure].[ext]";
Notice that the Wiki is going to look for the logo in /var/www/html/mediawiki/skins/common/images/. Copy the figure that you want to use there.
~> sudo cp <image location> /var/www/html/mediawiki/skins/common/images/.
Let's also fix the timezone:
#Set Default Timezone
$wgLocaltimezone = "America/Los_Angeles";

#Calculate the timezone offset with UTC
$oldtz = getenv("TZ");
putenv("TZ=$wgLocaltimezone");
$wgLocalTZoffset = date("Z") / 60 + date("I") * 60;
putenv("TZ=$oldtz");
Assuming that you do not live in the Pacific Time Zone, you can check for the proper value of $wgLocaltimezone at the Time Zone Descriptions link.

To restrict new user creation and anonymous editing, add:

# Restrict new user creation
$wgGroupPermissions['*']['createaccount'] = false;

# Restrict anonymous editing
$wgGroupPermissions['*']['edit'] = false;
Next, we are going to create a redirect from mediawiki to wiki, so that we can use short URLs and remove "index.php" from the web address. The first step in this process involves using the $wgArticlePath option. Add the following lines:
# Redirect path
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
Save and exit. This forces MediaWiki to look in the /var/www/html/wiki directory for the article files, even though it does not exist. But this can be done by merely creating an alias from the nonexistent /wiki directory to the /mediawiki directory, which can be done through .htaccess.

Open the /var/www/html/.htaccess file. Add the following:

# Mediawiki Rewrite Rules
# Rewrite /mediawiki to /wiki
RewriteRule ^wiki/(.*)$ /mediawiki/index.php?title=$1 [PT,L,QSA]
RewriteRule ^wiki/*$ /mediawiki/index.php [L,QSA]
# Rewrite /mediawiki to /
#RewriteRule ^/*$ /mediawiki/index.php [L,QSA]
Only uncomment the last line if you want to redirect your base web page to the Wiki. Save and exit. We have now created a redirect that points back to the mediawiki directory, including the index.php file. If you go to http://[host].[domain].[name]/mediawiki/, instead of seeing the following address:
http://[host].[domain].[name]/mediawiki/index.php/Main_Page
you will now see
http://[host].[domain].[name]/wiki/Main_Page
Much nicer.

Integrating phpBB's User Table with MediaWiki

If you are going to use phpBB for a forum board, there is a nice little extension that integrates phpBB's user table with MediaWiki, and subsequently disallows the creation of new accounts in MediaWiki as well. A user then must use his phpBB username and password to login to edit the wiki. I find it to be extremely useful.

The instructions can be found at:

http://www.mediawiki.org/wiki/Extension:PHPBB/Users_Integration

Upgrading MediaWiki

To upgrade MediaWiki, move the mediawiki directory to mediawiki-bak:
~> sudo mv /var/www/html/mediawiki /var/www/html/mediawiki-bak
Install the new version of MediaWiki. The installation script should automatically preserve tables in the database, and make changes to the tables wherever necessary. When you are done, copy over the images and extensions directories, and other modifications:
~> sudo cp -r /var/www/html/mediawiki-bak/images /var/www/html/mediawiki/.
~> sudo cp -r /var/www/html/mediawiki-bak/extensions /var/www/html/mediawiki/.
Make the appropriate changes to the LocalSettings.php file. You can now delete the old version of MediaWiki:
~> sudo rm -r /var/www/html/mediawiki-bak
The upgrade should now be complete.