# CPFAQ: Making a Wiki Look Like Wikipedia

I’m working on a project this year to build a competitive programming FAQ. This is one in a series of articles describing the research, writing, and tool creation process. To read the whole series, see my CPFAQ category page.

I mentioned last week that I was creating a glossary of competitive programming terms, in the format used by glossaries on Wikipedia. This week, I made the necessary changes to CPWiki to properly render the glossary.

## MediaWiki

Wikipedia runs on the MediaWiki open-source wiki software. A wiki running on the default MediaWiki installation looks a lot like Wikipedia. However, that doesn’t mean the markup for any particular Wikipedia page will render correctly on a vanilla MediaWiki site. For example, Wikipedia glossary pages, like Wikipedia:Glossary, look completely broken on vanilla MediaWiki.

To get my glossary page to look like a Wikipedia glossary page, I had to update four types of components: Extensions, Modules, Templates, and CSS.

## Extensions

MediaWiki extensions allow developers to modify the behavior of the MediaWiki software without changing the base MediaWiki code. MediaWiki administrators can load an extension by adding a wfLoadExtension command to LocalSettings.php, a file in the root of the wiki installation.

I installed three common extensions on CPWiki: Scribunto, TemplateStyles, and ParserFunctions. To activate them, I loaded them as follows in LocalSettings.php:

wfLoadExtension( 'Scribunto' );
\$wgScribuntoDefaultEngine = 'luastandalone';


Scribunto allows MediaWiki authors to use the Lua scripting language in wiki pages.

TemplateStyles provides a way to modify the CSS used to render a page without editing a global MediaWiki stylesheet.

ParserFunctions includes a set of functions that page authors can call, supplementing the functions that come with base MediaWiki.

## Modules and Templates

MediaWiki modules contain Lua functions that page authors can invoke. To use modules, a wiki administrator must load the Scribunto extension, as described above.

Templates allow page authors to write wiki markup once and re-use it on multiple pages. Compact ToC, the Wikipedia glossary component that prompted this week’s investigation, is a template. If I want to put a compact table of contents anywhere on my glossary page, I just insert {{Compact ToC}} at the desired location, and MediaWiki generates a compact ToC.

A MediaWiki edit view, like the one for Wikipedia:Glossary, has a section at the bottom called “Pages transcluded onto the current version of this page.” For Glossary, the list includes many templates and modules. Since they aren’t all included in the default MediaWiki installation, my glossary page didn’t work properly without them, so I had to copy them to CPWiki.

To copy modules and templates between wikis, MediaWiki provides Export and Import functions. From the source wiki’s Special:Export page, the user supplies a list of pages to export, and MediaWiki packages them into a single XML file for download. This file can then be imported on the target wiki’s Special:Import page (which requires elevated permissions).

One issue I encountered: although I could export the whole list into a single XML file, and this file seemed to upload fine, the Import process timed out after 2 minutes. I suspect that it took much longer to install the templates and modules than it did to transfer the file to the server. Rather than try to adjust the timeout setting, I just exported the list into a few separate XML files and imported each one individually.

## CSS

Although the TemplateStyles extension can be used to modify CSS, Wikipedia also runs a modified version of Common.css, the top-level CSS file for the site. Since I want CPWiki to look like Wikipedia, I updated the CPWiki version of that file to match the one that Wikipedia uses.

Once I made all the changes described above, my glossary page rendered correctly, with a compact ToC and other features.

(Image credit: Criptych)