COVER STORY Mediawiki

Configuring and Managing Mediawiki 1.4 CCOMMUNITYOMMUNITY EFFORTEFFORT

The best way of organizing collaboration on the Web is with a . Mediawiki, the Wiki behind the famous project, sets the standard for web-based collaboration tools.

BY ELISABETH BAUER

iki fans will be familiar with proven its value for over two years in a will be using Mediawiki 1.4beta5. The the scenario: you spot a typo permanent production situation. This final version of 1.4 should have been Won a website and drag the trial by fire has allowed Mediawiki released by the time this magazine mouse around the screen vainly search- developers to quickly discover and reaches the newsstands, so you may be ing for the edit button. Until the incep- remove vulnerabilities, making Media- using a slightly different version. tion of the Wiki principle, it was consid- wiki one of the most stable and well Log on to the console as root, and ered unthinkable for any visitor to be tested Wiki options. change to the ’s root direc- able to edit a Website. But now, projects tory; this is /opt/lampp/htdocs on like the free encyclopedia, Wikipedia Installation XAMPP, or /var/www, on Debian. Once [1], clearly demonstrate the viability of a Mediawiki requires a functional Apache you get to the web server’s root direc- collaborative effort involving thousands web server with the PHP module and a tory, you can type in the following com- of volunteers. Many business and open MySQL . The Mediawiki man- mands: source projects have put to effec- agement scripts need the PHP command tive use in areas such as software docu- line , which Debian users will xzvf /path/to/U mentation, or simply as a means for find in a package of its own, php4-cli. To -1.4beta5.tar.gz organizing documents on an enterprise generate thumbnails of images you will intranet. be using with the Wiki, you might also to unpack the in the If you are interested in setting up your like to install ImageMagick or the PHP current directory. The new directory that own Wiki, you are spoiled for choice. graphical library, GD. Your web server this step creates will later become part of You’ll find over 50 Wiki engines in a will need to support PHP code execu- the URL for your Wiki, so you will want variety of programming languages. tion. to make sure you give the directory as Mediawiki [2], the software that Download the current version of short a name as possible, wiki, for exam- Wikipedia uses, is a Wiki tool that has Mediawiki from [2]. In this article, we ple: mv mediawiki-1.4beta5 wiki.

22 ISSUE 55 JUNE 2005 WWW.LINUX- MAGAZINE.COM Mediawiki COVER STORY

Change to the directory by license for texts and other Advertisment entering cd wiki. documents that was inspired Then type by the GPL. The license allows free copying, modifi- chmod a+w config cation and commercial uti- lization. The Creative Com- to make the web server con- mons licenses allow you figuration directory writable more leeway; for example, temporarily. After completing you can prohibit any com- the installation, don’t forget mercial use and choose a to make the directory read version applicable to your only again. location. Click choose to go to Now, launch the installa- the selection dialog on the tion script in your browser: website, http://localhost/wiki/config/ where you can put together a index.. license that reflects your The script first checks the requirements. Mediawiki installation requirements. If accepts your choice of license you see an error message at and displays a link to the this point, instead of the license in the footer of every dialog shown in Figure 1, you page. will need to go back, then You need to specify a user check and correct your account as your Sysop Apache and PHP settings. account; the sysop will have You will also be able to see if extended privileges for the the script has found either Wiki; the account name is ImageMagick or the PHP GD arbitrary. extension for generating To accelerate Mediawiki, thumbnails. the installer offers to enable Enter a name for your Wiki either Turck MMCache or in Site name:. The Site name Memcached – you will only will appear at several posi- want to enable these options tions in your Wiki as the if you have installed the project name, and Mediawiki cache software. Debian has will create a so-called project packages for both. Turck name space with this title – MMCache is a PHP bytecode but we will be returning to cache that is useful if you this subject later. will be running Mediawiki on The email address is the a single host. The Wikipedia contact address for error server farm uses Memcached, messages. Use the language a distributed caching system selection dialog to select the originally developed for Live- default language for the Wiki. journal, which runs as a Besides the interface lan- daemon. guage, you need to set char- The database settings are acter encoding. Setting us - the final stage. The install English - Unicode allows script creates a MySQL user users to add entries to the and a database. You can use Wiki in foreign character sets the defaults in most cases. If without needing a you want Mediawiki to share workaround via HTML enti- a database with other appli- ties. cations, enter the database On a local network, the name, and then enter a prefix Wiki licensing information is for the table name in Data- not that important, but if you base table prefix, mw_ for are running a public Wiki, example. This will avoid con- you might like to think about flicts if another application the subject. The GNU Free uses tables of the same name Documentation License is a (for example user).

WWW.LINUX- MAGAZINE.COM ISSUE 55 JUNE 2005 23 COVER STORY Mediawiki

Type your MySQL root password in the last field, DB root password. This is not the same as your Linux root pass- word, and some distributions allow you to use a blank password. Now click on Install, and the script will create the database, the MySQL and Wiki users, and the LocalSettings.php configuration file in the config directory. If all of this works as planned, you will see a success message with a link to the Wiki in the last line. Before you can visit your new Wiki, you will need to take a short detour via the console. In the Mediawiki directory, move the newly created local settings from the configuration directory to the main directory by typing

mv config/LocalSettings.php .

Your Wiki is now ready for use. The link Figure 1: Run a PHP script in your browser to install Mediawiki. The script prompts you for the displayed on your screen will take you to critical settings. the main page (see Figure 2). page already exists. The Mediawiki man- with the sysop account created previ- First Steps in the Wiki ual has more information on creating ously, the other settings involve editing Clicking on edit in the toolbar at the top pages [3]. the LocalSettings.php configuration file pops up a text window, which visitors As Mediawiki was developed with the created by the install. The configuration can use to populate the page with con- encyclopedia in mind, it differs from tra- options are located in includes/Default- tent in Wiki syntax (see Table 1). This is ditional Wikis at certain points. For Settings.php. If you want to change any just plain vanilla text with a few special example, Mediawiki introduces the con- of them, copy the values to your local formatting tags. Typing * at the start of a cept of namespaces, fixed prefixes that settings and change them there, as line allows you to create a list, for exam- appear in front of the page title. There is DefaultSettings.php is overwritten by ple, and you can put your text in two, a discussion page for each Wiki page, updates. three, or four sets of equals signs to use and a link in the toolbar at the top takes To add your own log, enter the path to headlines of different sizes: you there. Each user has a personal page the image file in LocalSettings.php: (a link in Wiki syntax [[User:Name]], ==Heading== which allows a user to introduce herself $wgLogo = U or make notes. If someone leaves a mes- "/path/to/your/logo.png"; An empty line gives you a new para- sage on a user’s discussion page, Medi- graph. But the links are the most fasci- awiki informs the user the next time that You can modify any text on the user nating functions. In contrast to classical user accesses a page. The software adds interface directly in the Wiki. http:// Wikis such as Usemodwiki or TWiki, a descriptive page with an image prefix localhost/wiki/index.php/Spezial: which rely on automatic link detection for images, and users can edit the page Allmessages gives you a list of the pages based on CamelCase format, Mediawiki just like any other Wiki page. in the MediaWiki namespace. Each page only supports free text links. Mediawiki Users can create and edit pages in the corresponds to a software message, such converts the text between square brack- Template namespace. {{Title}} allows as Login successful. ets into internal links. Type users to add the content of http:// MediaWiki 1.4 and later allows users localhost/wiki/index.php/Vorlage:Titel to modify the interface settings in their [[Testpage]] to any other page. own language. MediaWiki only imports the default language selection from the and store your changes by clicking on Settings installation phase into the MediaWiki Save page. Mediawiki will now display The standard installation is fine as far as namespace; it references the languages Testpage as a red link – clicking on the it goes, but you will probably prefer to directory for all other files. But you can link will open another editor window, personalize your Wiki – by adding a logo modify messages directly in the Wiki as where you can edit a new page entitled of your own, a welcome text, and a MediaWiki:Message/xx; replace xx with Testpage. To link back to the main page, modified skin, for example. You can the ISO code for the required language. create a link called [[Mainpage]]. This complete part of this configuration MediaWiki messages also allow you to link will be displayed in blue, as the directly in the Wiki, assuming you log in modify the links in the sidebar. The

24 ISSUE 55 JUNE 2005 WWW.LINUX- MAGAZINE.COM Advertisment COVER STORY Mediawiki

Only logged on users are allowed to upload files. To make sure that this works, use the Create account link, top right, to create a user account, or log on with the user account created by the install, WikiSysop. The page bar on the left should now show an upload form. Mediawiki only supports a few file types by default. If you want to extend the list, you need to copy the values from the includes/DefaultSettings.php file to LocalSettings.php and extend that list. The following specifies valid file extensions:

$wgFileExtensions = U array( 'png', 'gif', U 'jpg', 'jpeg', 'ogg' );

Figure 2: Click the link at the bottom of the final installation screen to reach the main page of If you will be running your Wiki on a your new Wiki. local network, behind a firewall, and with trusted users only, you can disable http://localhost/wiki/index.php/Media server is running, for example, www- file type checking by specifying Wiki:Currentevents URL allows you to data for Debian. redirect the Current events link to a page You will definitely want to prevent $wgCheckFileExtensions = U more appropriate to your Wiki. You can PHP execution and the rendering of false; use the MediaWiki:Portal and Medi- HTML files in the upload directory. The aWiki:Portal-url tags to assign a new following lines in the Apache configura- Uploaded files are added to pages in a title and address to your project portal. tion file take care of that: similar way to images: [[Image:exam- To prevent any user changing the inter- ple]] will add an image called face arbitrarily, these features are installed ImageMagick or the PHP GD privileges. php_admin_flag engine off library, you can add a thumbnail to the Instead of creating a skin from scratch, AddType text/plain U page using the following syntax: you can use the MediaWiki namespace .html .htm .shtml .php [[Image:example|thumb|30px|descrip- to modify the appearance of the page. In [[MediaWiki:Monobook.css]] and Table 1: Wiki Syntax [[MediaWiki:Monobook.js]] you can ==Level 1== First level heading modify many elements of the Monobook ===Level 2=== Second level heading standard skin using CSS and Javascript. ====Level 3==== Third level heading The corresponding [[User:Name/Mono- ‘’italic’‘ Italic book.css]] and [[User:Name/Monobook. ‘’‘bold’‘’ Bold js]] pages allow Wiki users to design * Entry Lines in unnumbered lists start with an asterisk (*) their own personalized skins. # Entry Enumerated lists — Horizontal line Images [[Title of new page]] Internal link With the exception of the file upload fea- [[Title|Other Text]] Internal link with alternative text ture, your Wiki installation is now com- http://example.com External link (automatically converts to a clickable link) pletely functional. This is typically dis- http://example.com External link with alternative text abled for security reasons. To allow file [[Image:File.jpg]] Add image to page uploads, remove the comment tags (#) [[Image:File.jpg|thumb]] Add thumbnail in the # $wgDisableUploads = false; {{Name}} Dynamically integrate content on page “Template:Name” line. The web server process needs write {{subst:Name}} Replaced by content on “Template:Name” when storing the page permission for the images directory: the {{:Name}} Dynamically integrate content on page “Name” best way of doing this is to run chown to ~~~ Creates a signature for the logged on user, that is a Wiki link to a per- sonal user page. assign appropriate permissions to the ~~~~ Signature with time and date stamp user account under which the web

26 ISSUE 55 JUNE 2005 WWW.LINUX- MAGAZINE.COM Mediawiki COVER STORY

Advertisment tion]]. Clicking on the world of Mediawiki rights thumbnail takes you to a spe- management, only so-called cial image description page bureaucrats can do this using where the image is described the [[Special:Makesysop]] in full. Version 1.4 or later of page. The account created at Mediawiki supports the installation sets this flag. , which places Users with administrative images in a neat gallery on a accounts can delete pages, page: protect pages against editing by normal users – the link for doing this is in the bar at the Image:Landscape|U top – and block notorious Description trolls on a special page, Image:Sunset.png [[Special:Blockip]]. Entries Image:Yet Another U here are free form; the soft- Image.gif ware will accept numbers with the days, hours, weeks keywords, or even infinite for Mediwiki logs uploaded a lifetime ban. images and files in the By default, Mediawiki only searchable Image-Log allows administrators to (Figure 3). block IP addresses. To block You can add links for other logged on users and IP files, which the browser can’t address ranges, you need to render directly using [[Media: add the following lines File.pdf]] – this tells Medi- awiki to create a download $wgSysopUserBans = U link for the file. true; $wgSysopRangeBans =U Access Control true; Wikis started off life with two radically new ideas: on the to LocalSettings.php. one hand, there was simple By now, spam is not only editing, and on the other, the an issue for email users, it idea that anyone would be has also started to encroach able to modify the pages of a into the Blogosphere – the Wiki – just like that, without world of blogs – and Wikis. If logging on. Many popular you intend to run an open Wikis, such as Wikipedia, the Wiki, you might as well get German parody Kamelopedia used to checking your Wiki [4], or the WikiTravel [5] for spam, in the form of travel guide still uphold these inserted links in this case, goals. and removing the offending These open Wikis are material. backed up by a community of To prevent linkspam, volunteers who check new which is designed to improve entries and changes, quickly the ranking of addresses in removing spam, vandalism, search engines, the develop- and nonsense. Features such ers introduced a $wgNo as version control and moni- FollowLinks option to Medi- toring lists, which allow users awiki 1.4. This option is to monitor changes to enabled for all Wikis by selected articles, make Medi- default. It tells Mediawiki to awiki easier for operators to automatically assign the run open Wikis. rel="nofollow" attribute to If you prefer to avoid clean- external URLs, preventing ing up your own Wiki, you crawlers from evaluating can promote other users to links of this kind. Of course, administrators. In the wacky this also affects legitimate

WWW.LINUX- MAGAZINE.COM ISSUE 55 JUNE 2005 27 COVER STORY Mediawiki

links – to avoid this, you can set $wgNo- have the time to check your Wiki regu- rity settings I just described can be followLinks = false; to disable the larly, or if you will be restricting your applied separately. option. Wiki to a closed user group, you can Another alternative is to use regular limit write and read access and account Extensions expressions to filter spam – Mediawiki generation in Mediawiki. The following Mediawiki now includes a large collec- will refuse to accept entries that match lines in LocalSettings.php allow you to tion of extensions and external utilities the regexp set in LocalSettings.php. restrict write access, read access, and [8]. These extensions and utilities, account generation: which were developed primarily based $wgSpamRegex = U on the requirements of the Wikipedia "/((http:\/\/(www\.|)U $wgWhitelistEdit = true; encyclopedia, include features such as (spammer1.com|U $wgWhitelistRead = U timebars, hieroglyphics, the ability to spammer2.vu)/"; array ("Special:Userlogin", U add mathematical formulae in LaTeX "Mainpage"); syntax, a sheet music extension for Lily- The usefulness of this method is $wgWhitelistAccount = U pond, and many other things. restricted. Administrators need to update array ( 'user' => 0, 'sysop' U If you do not have time to keep up the configuration file after each incident => 1, 'developer' => 1 ); with the changes you and the other and the list of blocked URLs can grow users are making to your Wiki, you very quickly. It makes far more sense to The first line in this section restricts might like to check out the Enotif patch enable the experimental SpamBlacklist access to logged on users; the second by Thomas Gries [9]. The Enotif patch Extension [6], which Wikipedia has line specifies which pages users who are adds configuration options to Medi- been using since December. You can not logged on are allowed to visit – you awiki, allowing for email-based notifica- download the SpamBlacklist from the will at least want to allow anonymous tion of users if pages on their watchlist Sourceforge CVS repository for Medi- visitors to view the login page, but you change. awiki. The list allows administrators to can also add more pages to the list of Most administrators will prefer to manage a blacklist as a Wiki page. To Wiki pages authorized for anonymous avoid time-consuming management avoid spammers removing their own access if you wish. The $wgWhitelist tasks, such as modifying the links for a addresses, you will want to lock the Account array allows you to specify long list of pages or modifying texts. The page to restrict editing to Wiki adminis- users who are allowed to create new PyBot [10]is a Bot framework written in trators. accounts – in this example, Wiki users Python for Mediawiki, which supports All of these security measures are need administrator or developer status the simple creation of bots for special designed for open Wikis. If you don’t to create new accounts. The three secu- tasks. ■

INFO [1] Wikipedia encyclopedia: http://en.wikipedia.org [2] Mediawiki: http://mediawiki.org [3] Mediawiki manual: http://en.wikipedia.org/wiki/ Wikipedia:Manual_of_Style [4] Wikipedia parody, Kamelopedia (in German): http://kamelopedia.de [5] Wikitravel travel guide: http://wikitravel.org [6] Spam blacklist: http://cvs.sourceforge. net/viewcvs.py/wikipedia/extensions/ SpamBlacklist/ and http://meta. wikimedia.org/Spam_blacklist [7] Stylesheets: http://meta.wikimedia. org/Gallery_of_user_styles [8] Mediawiki extensions and tools: http://meta.wikimedia.org/ Category:AMediawiki_Extensions and http://meta.wikimedia.org/ Category:MediaWiki_tools [9] Enotif: http://meta.wikimedia.org/ Email_notification_(documentation) [10] Pybot: http://sourceforge.net/ projects/pywikipediabot Figure 3: Mediawiki displaying images and files in a gallery.

28 ISSUE 55 JUNE 2005 WWW.LINUX- MAGAZINE.COM