New Lua templates bring faster, more flexible pages to your wiki

Starting Wednesday, March 13th, you’ll be able to make wiki pages even more useful, no matter what language you speak: we’re adding Lua as a templating language. This will make it easier for you to create and change infoboxes, tables, and other useful MediaWiki templates. We’ve already started to deploy Scribunto (the MediaWiki extension that enables this); it’s on several of the sites, including English Wikipedia, right now.

You’ll find this useful for performing more complex tasks for which templates are too complex or slow common examples include numeric computations, string manipulation and parsing, and decision trees. Even if you don’t write templates, you’ll enjoy seeing pages load faster and with more interesting ways to present information.

Background

The text of English Wikipedia’s string length measurement template, simplified.

MediaWiki developers introduced templates and parser functions years ago to allow end-users of MediaWiki to replicate content easily and build tools using basic logic. Along the way, we found that we were turning wikitext into a limited programming language. Complex templates have caused performance issues and bottlenecks, and it’s difficult for users to write and understand templates. Therefore, the Lua scripting project aims to make it possible for MediaWiki end-users to use a proper scripting language that will be more powerful and efficient than ad-hoc, parser functions-based logic. The example of Lua’s use in World of Warcraft is promising; even novices with no programming experience have been able to make large changes to their graphical experiences by quickly learning some Lua.

Lua on your wiki

As of March 13th, you’ll be able to use Lua on your home wiki (if it’s not already enabled). Lua code can be embedded into wiki templates by employing the {{#invoke:}} parser function provided by the Scribunto MediaWiki extension. The Lua source code is stored in pages called modules (e.g., Module:Bananas). These individual modules are then invoked on template pages. The example: Template:Lua hello world uses the code {{#invoke:Bananas|hello}} to print the text “Hello, world!”. So, if you start seeing edits in the Module namespace, that’s what’s going on.

Getting started

The strlen template as converted to Lua.

Check out the basic “hello, world!” instructions, then look at Brad Jorsch’s short presentation for a basic example of how to convert a wikitext template into a Lua module. After that, try Tim Starling’s tutorial.

To help you preview and test a converted template, try Special:TemplateSandbox on your wiki. With it, you can preview a page using sandboxed versions of templates and modules, allowing for easy testing before you make the sandbox code live.

Where to start? If you use pywikipedia, try parsercountfunction.py by Bináris, which helps you find wikitext templates that currently parse slowly and thus would be worth converting to Lua. Try fulfilling open requests for conversion on English Wikipedia, possibly using Anomie’s Greasemonkey script to help you see the performance gains. On English Wikipedia, some of the templates have already been converted  feel free to reuse them on your wiki.

The Lua hub on mediawiki.org has more information; please add to it. And enjoy your faster, more flexible templates!

Sumana Harihareswara, Engineering Community Manager

8 Show

8 Comments on New Lua templates bring faster, more flexible pages to your wiki

Sumana Harihareswara 2 years

Thanks for the question, Michawiki. I’m asking the localisation/internationalisation team to look into it.

Sumana Harihareswara 2 years

DixonD, that’s a good question.

In the March 2013 meeting reviewing the work of WMF’s MediaWiki core team, we went over what that team is planning on doing in the next quarter, including improvements to search, category collation, and various continuing activities. “The idea of a central wiki for code, such as Lua and Gadgets code, is very appealing. However, we decided not to do this work prior to deploying Lua, but plan to revisit this idea next quarter.”

For now, it would be great if there were a social custom of copying your local wiki’s Lua modules to Commons, to make it easier to share them with others. But I don’t think there will be a central code repository within the next few months; sorry.

Seb35 2 years

Traduction en français sur http://blog-fr.seb35.lautre.net/?p=201

bennylin 2 years

Love it! Kudos Sumana!

Michawiki 2 years

What’s with the translation of the Module talk age namespace?

Kozuch 2 years

You can help to localize the new “Module:” namespace here: http://meta.wikimedia.org/wiki/Lua_deployments/Localization_of_Module

Also, templates using Lua on English Wikipedia can also be seen at: http://en.wikipedia.org/wiki/Category:Lua-based_templates

Sam Klein 2 years

Wikipedia:Lua requests is an inspiring page – an amazing cross-section of wikiwork. Thanks for this update and HUZZAH for the upcoming release!

DixonD 2 years

Hi! Is it possible to make Lua modules shared somehow on Commons? Copying and maintaining some common routines like string functions is going to be a bit painful.

Leave a Reply

Your email address will not be published. Required fields are marked *