Complex Templates
A Guide to Using MediaWiki in a Hosted Environment
An instructional website by the developer of mh370wiki.net - a MediaWiki site about Malaysia Airlines Flight MH370.
An example of a complex template is provided on the page Templates.
The example below includes a parser function ifexpr.
<onlyinclude>
<!-- superscript - destination link - RefID is the visible text - end superscript -->
<span class="suptxt">[[{{{Link|-}}}|{{{RefID|-}}}]]</span>
<!-- Content not visible on the source page and visible ONLY when transcluded onto a different page. -->
<includeonly>
{{#ifexpr:{{NAMESPACENUMBER}}=0
OR {{NAMESPACENUMBER}}=nnv
OR {{NAMESPACENUMBER}}=nnx
OR {{NAMESPACENUMBER}}=nny
OR {{NAMESPACENUMBER}}=nnz | [[Category:{{{RefID}}}]] | }}
</includeonly>
</onlyinclude>
Explanation
This template is part of the system for references on the mh370wiki.net website. Each reference item is allocated a unique Reference Identifier, for example MAS-MS3-001, stored in the RefID: namespace.
The Reference Identifier is displayed in superscript text using a custom style suptxt defined in Common.css.
The Reference Identifier contains a link to the actual reference, the page name and an anchor. References are in sub-pages of mh370wiki.net/References.
Whenever an item is referenced, the page or article is added to a category named the same as the Reference Identifier. Using the CategoryTree extension a list of all instances of that reference item can be displayed.
However, the content displayed may be transcluded from a 'hidden' namespace. If the Reference Identifier is added to a source page and then transcluded, the source page would be added to the associated category page, in addition to the visible page. That is an unwanted consequence. So the expression ifexpr adds the page to the category ONLY if the page is in one of the listed namespaces.
Namespaces are numbered. The Main: namespace is 0. Namespace numbers -2 to 15 are reserved and allocated by MediaWiki.
The namespaces represented by numbers nnv through to nnz are numbers for the publicly accessible namespace Communications:, MH370News:, Passenger:, and MH17:
Additional templates ensure consistency for each of the category pages and the layout for each reference item on References/... pages.
Links
- Help:Extension:ParserFunctions
- https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions
- Extension:ParserFunctions
- https://www.mediawiki.org/wiki/Extension:ParserFunctions
- The ParserFunctions extension is included with all recent versions of MediaWiki. To use this extension, add the appropriate code to LocalSettings.php.
- Help:Templates
- https://www.mediawiki.org/wiki/Help:Templates
- Manual:Namespace constants
- https://www.mediawiki.org/wiki/Manual:Namespace_constants
Articles which relate to MediaWiki Templates
Articles which relate to MediaWiki Templates are included in Category:Templates.
The CategoryTree Extension enables a listing of relevant sub-categories and pages:-