Personal tools

Skinny

From OrganicDesign Wiki

Jump to: navigation, search
NOTE: this article is mainly obsolete, since it was made without a full understanding of the existing templates. The existing template mechanism already handles named parameters using tripple-brace tokens, see Help:Advanced templates


So far we have wikitext skin which allows all the aspects of the skin which wraps the main content to be defined within the wiki using normal wikitext markup. To achieve this a number of new MediaWiki variables were required to allow for the various special links like "Template:LOGIN".

1 Templates & parameters

The next step in skinning is to add a more sophisticated templating mechanism than just transclusion or embedding. MediaWiki already has a convension for specifying content that includes fields which will be replaced by dynamic information at the time it is used. This convension is to use $1, $2, $3 etc to denote the dynamically replaceable elements, and the context which uses the template should know how many their are and what to replace them with. All the MediaWiki system messages are done like this, so look at them as an example.

The other aspect of implementing this templating mechanism is to extend the wikitext parsing to offer a syntax for including a template and specifying the parameters to replace the $1, $2... tokens with. More recent versions of MediaWiki come with an established convension for passing parameters in this way called parser functions which takes the following form:

{{#function-name:parameter1|parameter2|parameter3...}}

So we could simply extend the current MediaWiki template transclusion method to check if there's any pipe-separated parameters in the braces after the template name, and if so replace the corresponding tokens in the template content before transclusion.

Named parameters

Often it's more convenient to use named parameters (like HTML attributes) rather than just a list of values. MediaWiki does this by allowing each of the pipe-separated parameters to take the form name=value. This allows the parameters be optional and to be specified in arbitrary order.

Obviously the tokens of numeric form aren't sufficient and would have to take the name of their corresponding named-parameter, eg $NAME. MediaWiki has also started using named parameters in their system-messages, and use the uppercase convension which I've followed. Combinations may as well be supported too, because any unnamed would automatically be assigned to the next unused numeric token name.

2 Installation

First a new hook needs to be added into the parser.php file in your /wiki/includes directory. It goes in the function called braceSubstitution in the section starting with the comment Load from database, the relevent block of code and patch is shown below:

+skinny-parser-patch.php

Next the following code must be added to your LocalSettings.php file or article to add the template token replacement functionality to the new parser hook.

+skinny.php

The GNU Project Debian Linux Ubuntu Linux Wikipedia online encycopedia MediaWiki