I've set up a MediaWiki on a wiki farm, and want to have Wikipedia-style templates available, like {{reflist}}, {{merge from|article}}, {{cite book|...}}, etc.

Following DRY principle, it would seem best to transclude them, which is possible using syntax like {{raw:w:reflist}}, and this is recommended by Wikia Help:Shared templates.

This works for simple templates, however, for more complicated ones like reflist, I get Script error: No such module "Check for unknown parameters". I guess the raw transclusion can bring in some template dependencies, but not Lua module dependencies?

Also, the Wikia page says "Parameters cannot be used with shared templates", which would be bad (but I'm not sure is actually true). Also Manual:$wgEnableScaryTranscluding says "It's somewhat inefficient."

Another option is just copying the template code over, which seems to be the recommended way on Template:Reflist/Transwiki guide, but this requires copying many templates and Lua modules, which aren't automatically updated when the upstream template gets bug fixes.

What's the smoothest way to do this? Is there another option I haven't discovered?

  • 1
    Welcome to the hell that is Mediawiki templates. – Rob Kam Sep 1 at 21:36
  • @RobKam Oh, I've been familiar with it for years :D – endolith Sep 1 at 23:02
  • 1
    This also uses Export/Import feature: mediawiki.org/wiki/… – endolith Sep 1 at 23:57

It's a PITA and unfortunately (unlike extensions or media files) there is no repository of canned templates. Templates load other templates which load others in turn, etc. Templates are there to sabotage the efforts of anyone who just wants to edit their own wiki, instead taking them over to the coder side.

By the way Wikia has its own template repository, you might find useful.

This is not the best solution but it does the job:

Go to Wikipedia and copy the name of the template you're after, go to Special:Export and paste the name of the template in the big text box, e.g. Template:Infobox. Check "Include templates" and check "Include only the current revision, not the full history", (or the file will be too big). Click Export to dump a .xml file of the template. Then import this into the destination wiki.

After it has been imported open the template for editing, check the list below the edit box "Pages transcluded onto the current version of this page:". If there are any red links repeat the above steps for these templates as well. You might also need to copy styles in MediaWiki:Common.css page and Javascript in MediaWiki:Common.js before everything works. Finally edit the templates to customize for your wiki.

If it still doesn't work and you have messy pages of braces and if statements, then you need to install the ParserFunctions extension. If there is {{#invoke: }} in template code you'll also need to install the Scribunto extension.

MediaWiki Help:Templates explains the process in more detail.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.