Red-Green-Code

Deliberate practice techniques for software developers

  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter

CPFAQ: Making a Wiki Look Like Wikipedia

By Duncan Smith Oct 17 0

Lua

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';
wfLoadExtension( 'TemplateStyles' );
wfLoadExtension( 'ParserFunctions' );

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)

Categories: CPFAQ

Prev
Next

Stay in the Know

I'm trying out the latest learning techniques on software development concepts, and writing about what works best. Sound interesting? Subscribe to my free newsletter to keep up to date. Learn More
Unsubscribing is easy, and I'll keep your email address private.

Getting Started

Are you new here? Check out my review posts for a tour of the archives:

  • 2023 in Review: 50 LeetCode Tips
  • 2022 in Review: Content Bots
  • 2021 in Review: Thoughts on Solving Programming Puzzles
  • Lessons from the 2020 LeetCode Monthly Challenges
  • 2019 in Review
  • Competitive Programming Frequently Asked Questions: 2018 In Review
  • What I Learned Working On Time Tortoise in 2017
  • 2016 in Review
  • 2015 in Review
  • 2015 Summer Review

Archives

Recent Posts

  • Do Coding Bots Mean the End of Coding Interviews? December 31, 2024
  • Another Project for 2024 May 8, 2024
  • Dynamic Programming Wrap-Up May 1, 2024
  • LeetCode 91: Decode Ways April 24, 2024
  • LeetCode 70: Climbing Stairs April 17, 2024
  • LeetCode 221: Maximal Square April 10, 2024
  • Using Dynamic Programming for Maximum Product Subarray April 3, 2024
  • LeetCode 62: Unique Paths March 27, 2024
  • LeetCode 416: Partition Equal Subset Sum March 20, 2024
  • LeetCode 1143: Longest Common Subsequence March 13, 2024
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2025 Duncan Smith