SYSADMIN Mediawiki

Installing and Maintaining Mediawiki Collective Authoring The free encyclopedia uses the Mediawiki engine to collect an enormous knowledge database. If you want to launch your own , this PHP-based software is a good choice that provides rich functional- ity and plenty of power.

BY ERIK MÖLLER

iki means quick in Hawaiian each wiki page in the browser. Square an asterisk at the start of a line creates a – and the Web-based wiki brackets are all you need to make a text list; text surrounded by equals signs Wtechnology has established string into a link. If the page already turns into a heading. itself extremely quickly. Ward Cunning- exists, the link is created; if not, the user There are more than 100 wiki engines ham had the idea back in 1995, when he is provided access to an edit box where [1] at present. Mediawiki [2] is a popular was looking for a method to collect he can create a new page with the pro- example. It provides the underlying tech- examples of common programming tasks vided heading (see Figure 1). nology for the Copyleft encyclopedia, amongst a group of developers. The sim- An easily understandable syntax Wikipedia, the role model for most other ple idea was to allow modifications of makes light work of formatting. Typing (see A Journey to the World of Wikis). In its first year, Wikipedia used A Journey to the World of Wikis the usemod wiki [3], which is written in Although it was specially developed for released under a free license.The Wikibooks Perl. But the task proved too challenging Wikipedia,Mediawiki is not restricted to project at http://www.wikibooks.org is unre- for usemod, which threatened to col- encyclopedias. Besides Wikipedia, the lated to the Wikipedia as regards content, lapse under the load of thousands of Wikipedia Community launched the and provides free teaching material for arbi- articles and visitors. Wiktionary http://www.wiktionary.org in trary subjects.The project could develop into This led the wikipedians to develop December 2002.This dictionary supplies a central archive for lecture scripts for univer- the Mediawiki engine in PHP, using a an English definition and a translation into sity teaching. MySQL back-end. PHP skills are useful, a number of languages for each word.The Propaganda Encyclopedia if you need to set up and modify a wiki model is ideal for this kind of task as it A list of Mediawikis is available at Wikipedia wiki. But even if you don’t speak PHP, allows users from all over the world to [10]. Some noteworthy examples are the pro- Mediawiki should still allow you to set supply translations. paganda encyclopedia,Disinfopedia http:// up a wiki that performs well, and is easy Quotes and Schoolbooks www.disinfopedia.org.Mediawiki co-author to use. Wikiquote http://www.wikiquote.org is a cat- Evan Prodromou runs a travel guide wiki egorized collection of quotes;Wikisource called Wikitravel at http://www.wikitravel. Stable or Experimental http://www.wikisource.org adds original org,and the author’s open source documen- Mediawiki is available in two flavors. source material to supplement Wikipedia. tation knowledge base,Openfacts,is The stable version is available as a The material is either public domain or available at:http://openfacts.berlios.de/ download from the homepage at [2]. The

54 May 2004 www.linux-magazine.com Mediawiki SYSADMIN

tions, whereas the SQL user $wgDBsql user has read access only. This account is used for a special page that enables sysops to perform SQL queries, for exam- ple, to locate and welcome recently registered users. The wiki operator should also add the $wgDBadminuser MySQL admin user’s account and pass- word to the AdminSettings.php file. This account has write access and is used by scripts for installation and maintenance tasks. To install the wiki, make sure you are root, and enter php install.php. Some distributions call the command inter- preter php4 rather than php. Among other things, the script prompts you for the MySQL root password, and creates the database, tables, and the MySQL users. Finally, it offers to create two wiki user accounts, a sysop and a developer. Figure 1:The Mediawiki edit window has a Javascript toolbar to help wiki newbies with formatting This is recommended. Without this tasks. Double square brackets indicate a link to another page. option, you will need to assign the access privileges manually at a later developer version should run, but it does Choice of Languages stage. contain experimental functions. You can Wikipedia supports over 50 languages. To configure your Web server, add download it with CVS: It is one of the most widely translated phtml as the PHP extension to wikis. This allows you to create a wiki httpd.conf: cvs -d:pserver:[email protected] in , Chinese, Japanese, Hebrew, sourceforge.net:/cvsroot/U Hindi, Russian or Vietnamese, inclu- AddType application/x-httpd-phpU wikipedia login ding Unicode support. To use these .php .phtml cvs -z3 -d:pserver:anonymous@U languages, the wiki operator simply cvs.sourceforge.net:/cvsroot/U needs to set the $wgInputEncoding In the upload directory created by the wikipedia co phase3 and $wgOutputEncoding variables to installation (where Mediawiki stores UTF-8. uploaded files) PHP execution or HTML The “phase3” directory contains the soft- The installation script creates three rendering should be prohibited: ware, which you can update at any time MySQL users and assigns them database by entering cvs update. Mediawiki privileges. Mediawiki uses the $wgDB and PHP 4.3.2 including the command interpreter. It is compatible with PHP 5. If you want the software to reduce images automatically, you can opt for the Image- magick toolkit, or add the gd library from the current PHP versions. Image- magick supports far more file formats than gd. The install.php script in the program root directory starts the install. Before installing, you will need to perform a few configuration steps. The admin should copy the sample configurations, Local Settings.sample and AdminSettings. sample, to LocalSettings.php and Admin Settings.php. Table 1 shows the Local Settings.php variables that need to be Figure 2: A typical Wikipedia article shows that wikis don’t need to be ugly.The table of contents is configured. automatically generated from the headings.

www.linux-magazine.com May 2004 55 SYSADMIN Mediawiki

AllowOverride None AddType text/plain .html U .htm .shtml php_admin_flag engine off

You need to enable a few global variables for the script directory. php_ value register_globals 1 in the directory statement of your Apache configuration will take care of this. As an alternative, you could modify the php.ini file, which will typically reside in /etc or /etc/php4. Hardening The install script copies all the PHP files to the Web server directory. The more scripts with external access you have there, the greater the risk that an attacker might gain access to internal Figure 3:The diff view highlights the differences between two revisions, showing modifications and functions. This is particularly true of reg- deletions. Sysops can point and click to reinstate previous versions. ister_globals, as URL parameters allow you to set internal script variables. You will need a minimal collection of User Privileges Only really essential files should be settings in LocalSettings.php; leave out Most wikis allow anonymous users to stored in the Web server directory, that the SQL user, and ignore AdminSet- edit their pages. This poses the question is, anything ending with .phtml, images tings.php. Of course, you must have a as to how the wiki operator will handle and stylesheets. Best practice is to move main database user. Copy any .php and undesirable content or even defacement. any files ending in .php to a separate .phtml files from includes and languages, Mediawiki has a few defense mecha- directory outside the document root after and the stylesheets and images directo- nisms. You can restrict reading or editing installing. After moving the files, now ries, to the Web server’s main directory. content to specific user groups. The replace the links to ./LocalSettings.php in You can then run the wiki.phtml file $wgWhitelistEdit and $wgWhitelistRead the phtml files with links to LocalSet- with the path chosen in the previous flags in LocalSettings.php help you do so. tings.php, and add the new path to the step to access the main page of the The $wgWhitelistAccount array defines include_path in the php.ini file. newly installed Mediawiki in your the groups allowed read or write access: Note that in the current unstable ver- browser. Take a look around and try out sion, which may be stable by the time the software’s features (see the Medi- $wgWhitelistAccount=array(U you read this, the .phtml files are depre- awiki 101 box). If the Web server does "user" => 0, "sysop" => 1, U cated – in this case, copy index.php and not recognize phtml, rename the "developer" => 1) redirect.php to the web server directory, index.php file. In this case you will also and copy all other .php files to a safe need to edit the $wgScript and $wgRedi- This setting restricts modifications to directory from which they can be rectScript variables. DefaultSettings.php sysops and developers. The following included. provides a sample. will add a new user type called editor:

Manual Install Table 1: Basic Configuration If you do not have root access to the Variable Local environment server, or if the install script fails, you $IP Local path on the server where you are copying the wiki,for example can install Mediawiki manually. The first /var/www/wiki step is to create a database. You should $wgServer Server address element before the first slash,for example be aware that name conflicts with exist- http://www.mywiki.com ing tables can occur if you use an $wgScriptPath Subdirectory with PHP files,for example wiki;leave this blank (“”””) if the files are existing database – Mediawiki does not in the main directory use a prefix. $wgEmergencyContact Email address of the administrator to be displayed in case of problems Import the tables from tables.sql and $wgDBserver Name of the MySQL database indexes.sql in the maintenance directory: $wgDBuser and $wgDBpassword MySQL user for normal database access $wgDBsqluser and $wgDBsqlpassword MySQL user for SQL queries via Web interface; only has read access mysql -u root -p databasename U $wgLanguageCode Two letter code for language to use,for example en for English < filename,sql

56 May 2004 www.linux-magazine.com Mediawiki SYSADMIN

$wgWhitelistAccount=array(U rated issue. Social issues are more diffi- article about FAQs, and an official "editor" => 1, "user" => 0, U cult. What kind of pages and what kind Wikipedia FAQ. To separate the two sen- "sysop" => 1, "developer" => 1) of behavior will the wiki allow? Opera- sibly, Mediawiki introduced so-called tors definitely need to put some thought namespaces, which are defined in the Having created the user type, the opera- into policies. Language.php or the local translation. By tor can go on to assign read or write Wiki operators should define the default, these are the main namespace, privileges by setting the value of a user’s default options, the $wgDefaultUserOp- multiple discussion namespaces, a name- user_rights database field to editor. tionsEn array in the Language.php file or space for images, one for user pages, a Mediawiki does not have a generic its localized variant, carefully. Options special namespace, and the very special privilege management tool at time of such as quickbar (0 = no navigation bar, Mediawiki namespace. Articles outside writing. This means formulating an SQL 1 = navigation bar left, 2 = right) are the main namespace will always have a query to make a user a sysop, developer important. editondblclick will open the prefix. [[Discussion:Mainpage]] points to or editor, for example: editing window when a page is double- the discussion page that belongs to the clicked. showtoc generates a table of main page, [[User:Troll]] is the personal USE Databasename; contents for pages with more than three page belonging to the user Troll. UPDATE SET user_rights='sysop' U headings, and showtoolbar enables the If you do not intend to run a gigantic WHERE user_name='username'; Javascript toolbox in the edit window wiki, you can save yourself the trouble of (see Figure 1). the meta namespace. By default, this The developer version now has a bureau- The editsection option displays an Edit namespace assumes the value of the crat user type. Bureaucrats use a special link next to each heading. This allows variable $wgSitename in DefaultSet- page to designate other users as sysops. direct editing of specific sections, and is tings.php. The Wikipedia FAQ is stored To do so, the user needs sysop and particularly convenient for longer pages, below [[Wikipedia:FAQ]]. This resolves bureaucrat privileges. as it removes the need to navigate the the conflict referred to previously, but A change history allows you to moni- Edit window. On the downside, links of makes things difficult for smaller sites. If tor recent developments in your wiki. this type can spoil your layout. If you namespaces 4 and 5 are deleted from the Mediawiki provides a diff feature that enable the editsectiononrightclick option, $wgNamespaceNamesDe array in the highlights the difference between two right-clicking a heading has the same LanguageDe.php file, for example, they revisions (see Figure 3). The change his- effect. This caused Konqueror to crash are also removed from the user interface. tory records the modifications to a page occasionally in our labs. One feature that Mediawiki retained right back to the original version. The after migrating from usemod is the sub- version history allows you to reload pre- Namespaces page. For example, an article called vious versions, and save them again, if Wikipedia quickly faced the issue of sep- Linux could have a sub-page called required. Finally, users have a User arating information about the wiki, Linux/Kernel Tips The Kernel Tips page contributions function that allows them policies, or discussions from encyclope- would automatically have a link back to to view all the content created by a dia articles. For example, there is an Linux. Sub-pages can be enabled indi- specific user. Sysops vidually for a namespace can undo entries from by setting the $wg this list, allowing them NamepacesWithSubpages to repair defacements variable. within a few seconds. The MediaWiki name- If a dispute over the space, which is enabled content of a page via $wgUseDatabaseMes- arises, the sysop can sages, allows users to temporarily protect the edit all the text elements page. Admins can ban of the software within persistent trouble-mak- the wiki, thus aiding ers by blocking their translations. The names IP addresses. Unfortu- of the text variables are nately, unregistered stored in Language.php. users with dialup con- nections constantly Shortcuts for Text change their IPs. Blocks For this reason, an IP The content of any pages block will only last for created in this name- 24 hours by default space can be embedded ($wgIPBlockExpiration at any location within option). On the whole, Figure 4: Viewing recent changes to the wiki in the CologneBlue skin.The Recent Changes the wiki. For example, to defacement is an over- link leads directly to the diff view for the current change. provide a default wel-

www.linux-magazine.com May 2004 57 SYSADMIN Mediawiki

come text, create a page called Medi- aWiki:greeting. {{msg:greeting}} will display the content of the page on other pages. Any changes to the Mediawiki page are immediately applied to any other pages that use {{msg}} to access it. The {{subst:greeting}} command adds the text at the current location but without the automatic update feature. Note that pages in the Mediawiki namespace are not allowed to have non- standard characters or spaces in their headings. As each program text is retrieved from the database, you should use this feature only in combination with memcached (described later). Operating a Wiki Running Mediawiki over a longer period of time is actually far less stressful than getting the installation right. In a perfect Figure 5:The Wikitex interface allows Mediawiki to display sheet music, chemical and mathematical world, the wiki operator would only formulae or even chess games. Clicking on the notes will automatically generate a midi file. need to assign sysop and developer privi- leges. mysqldump or phpMyAdmin are the install directory as your next step, to Settings.php. Ensure you copy modified recommended for backing up the data- avoid queries such as What links here, options to LocalSettings.php to avoid base. When importing large datasets, and other requests failing. overwriting them during an update. such as the Wikipedia articles at [5], run Mediawiki has a number of tuning Mediawiki has the $wgMiserMode the maintenance/rebuildall.php script in options – there are examples in Default- option for larger wikis. Enabling the

Mediawiki 101 The main navigational element in Mediawiki for the current page. A page called Linux clicking on its timestamp,edit the page you is the sidebar on the left of the screen (see would have a discussion called are viewing,and store the page.The Current Figure 1). Recent changes is one of the most Discussion:Linux for example. A link called revision link is also quite useful,and shows important links for regular wiki visitors. It Post a comment is available in the side bar the differences between an arbitrary revision shows the pages the wiki contributors are for this page type.You can follow the link to and the current one. currently working on (see Figure 4). open an empty editing window and add Upload allows you to upload arbitrary files. Registered users can click on the Watch this your comment . After clicking on Save Page Uploads are recorded in the logbook,and can page link to add a page to their watchlist. your comment is added to the end of the be embedded using the [[Image:file.jpg]] or The list shows the changes made to the page. [[Media:file.zip]] syntax. Mediawiki displays pages in your watchlist over the past week. A Page and its History image links on the fly; by contrast,media This allows contributors to monitor pages To add a new page,simply create a link on an links point to the file. where they have provided content. Move existing page,for example [[My new page]], Recognizing Relations page allows you to rename a page.The previ- and then follow the red link.The Page history One reason for the move to a database cen- ous title still remains valid; users following link takes you to a page with the previous tric solution was the Wikipedians links to the page will be referred to the new versions of the current page (see Figure 4). requirement for advanced searching. For link. This view can also be used to reinstate previ- example, Mediawiki uses special pages to The Discussion link points to the discussion ous versions.To do so,select a version by display new or orphaned pages, that is pages that are not referred to by any links. Addi- tional functions list articles alphabetically or by length. The special page for Most wanted articles shows an overview of the most commonly used keywords that did not return a page. The What links here link shows a list of the links to the page. Related changes allows you to view changes to the articles that a page links to,and thus monitor specific topics. The official Mediawiki Manual at [4] pro- Figure 6:The history allows the sysop to monitor the development of a Wikipedia article. vides more detail.

58 May 2004 www.linux-magazine.com Mediawiki SYSADMIN

option will disable time-consuming running memcached on a system with pleased to lend a helping hand. If you run queries such as a list of the longest arti- multiple local users. Without a firewall, a Mediawiki, you should sign up for the cles. It definitely makes sense to enable or the -l parameter, external users can -l [9] mailing list, or join the the page cache option, $wgUseFileCache. access the server and capture passwords. #mediawiki IRC channel on irc.freenode. This will serve up static HTML pages to You can now enable the $wgCompress- net. ■ anonymous users and thus provide a Revisions, $wgUseMemCached, $wg considerable performance boost. SessionsInMemcached, and $wgLink INFO If you are prepared to put some time CacheMemcached options. $wgCompress and effort into tuning your wiki, you Revisions uses gzip to compress older [1] Master list of wiki engines: http://c2.com/cgi/wiki?WikiEngines might like to try memcached [6] and page revisions, and thus saves a lot of zlib. Memcached reduces database space on the server. [2] Mediawiki:http://www.mediawiki.org access by caching user data and link [3] Usemod Wiki:http://www.usemod.com information. Zlib compresses older page In the Pipeline: Wikitex [4] Mediawiki manual: revisions. This assumes that you com- It is not in the official version yet, but http://meta.wikipedia.org/wiki/ MediaWiki_User%27s_Guide piled PHP with the --enable-sockets and check out [7] for a first glance at the Wiki- [5] SQL Dumps of Wikipedia: --with -zlib options. Type tex interface written by Peter Danenberg. http://download.wikimedia.org on a PHP test page to find out. This will allow Mediawiki to make use of [6] Memcached: numerous back-ends in future. For exam- http://www.danga.com/memcached Memcached ple, GNU Lilypond [8], which translates a [7] Wikitex trial:http://wikisophia.org The daemon should run in the back- simple syntax into neatly formatted sheet [8] Lilypond:http://lilypond.org/web ground with the options -d -l 127.0.0.1 -p music layouts, various Latex macros that [9] Project mailing list:http://mail.wikipedia. 11000 -m 64 enabled. This assigns 64 generate mathematical and chemical for- org/mailman/listinfo/mediawiki-l MBytes of RAM as cache memory for mulae, or chessboard images to illustrate [10]Projects that use Mediawiki: local applications. Memcached does not game plans (see Figure 5). New users http://en.wikipedia.org/wiki/Wikipedia: provide an authentication feature. Local may find the mass of features confusing Sites_using_MediaWiki users have unrestricted access. Avoid at first. The Mediawiki community is

High Performance 64-bit Linux Clusters

At DNUK we can build a complete Linux computational cluster for you. When you purchase a group of rackmount servers from us we will build, configure and test your cluster for you at no extra charge. Choose from 32-bit Intel Xeon or 64-bit AMD Opteron nodes and a variety of open source libraries including MPICH, LAM/MPI and PVM. A range of hardware interconnects including Gigabit, Dolphin SCI and Myricom Myrinet are available. Visit www.dnuk.com and find out why corporate customers, small and medium businesses and most UK universities choose us for their IT requirements.

For more details on the clustering solutions we can build, please visit: https://secure.dnuk.com/store/clustering.php

www.dnuk.com [email protected] 0161 337 8555