Misplaced Pages

:Avoid using meta-templates - Misplaced Pages

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

This is an old revision of this page, as edited by Netoholic (talk | contribs) at 23:27, 2 February 2006 (This is an active proposal, recently rewritten, being discussed, and being worked on to gain consensus. - exactly what {{proposed}} states). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 23:27, 2 February 2006 by Netoholic (talk | contribs) (This is an active proposal, recently rewritten, being discussed, and being worked on to gain consensus. - exactly what {{proposed}} states)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff) Shortcut
  • ]
The following is a proposed Misplaced Pages policy, guideline, or process. The proposal may still be in development, under discussion, or in the process of gathering consensus for adoption.
This page in a nutshell: Avoid using templates within other templates as the result can be complex, fragile, and increases the server-side processing requirements.

Template messages allow certain standard text to be included on many pages, usually with the idea that in the future, any changes to that text block can be changed in one place. The term "meta-templates", as used in this article, refers to nested templates which are created and used to add functions or formatting to other templates. While on the surface, they can seem extremely useful and convenient, they should be avoided.

Meta-template schemes can be fragile and hard for new editors to understand. They increase the number of database reads per page view and therefore impact back-end server performance; though the developers are not in agreement over whether such server impacts are significant and there is no developer mandate to that effect.

For these reasons, it is better to avoid meta-templates when clearer and more robust alternatives are available. In short, messy unintuitive structures in articles and in templates are undesireable.

Harmful effects

Complexity

Some nested template schemes are so complex that they are prohibitively difficult for the average editor to grasp. This is particulary true in non-technical areas where the subject expert, who knows best what information should be presented in a template, is not able to edit the template due to the use of esoteric coding. As a result, routine maintenance and changes are neglected, improper usage can proliferate, and innovation suffers. The solution, meant to become an easy replacement, becomes more difficult than the function it was meant to improve. Clear article source and clear template source are most preferred, though it is understandable if complex code is moved to the template. If this is the case, steps should be taken to reduce complexity to a minimum.

Template links

When a page is edited, a list of all templates in use on that page is stored in the database. This list can be seen when in edit mode as a list of links at the bottom. Not only are the templates that are directly called listed there, but any higher-level meta-templates as well. This feature was created as a helpful aid for editors, in order that they can easily tell what templates are being used on a page in case the want to edit one of them. Meta-templates clutter this list, making it unclear to editors exactly which link is correct.

Template links created by meta-templates also frequently cause problems for template namespace maintenance. If a Template:A calls Template:B, but then is changed to either remove B or use Template:C, the article-level template links are not updated until each article is edited or "touched". Since the links can't be fully trusted, template maintenance work which relies on that information is made difficult or impossible. Automated bots rely on those links as well, such as when performing Template substitution or migrating fromone template to another.

Vandalism

As with any template which is used on a very high percentage of pages, a nested template is an excellent denial-of-service attack vector, since changing it or any component used in it would flush a substantial percentage of the site caches, which are critical to site performance and normally serve some 75–80% of all hits. Making even one subtle change, like the addition of a space, causes the effect. A sub-sub-sub-template could be vandalised with offensive content. These could be difficult to notice immediately, because the sub-template is not edited often and appears on only one or a few Watchlists, and difficult to track down in a timely manner.

Server impact

The developers have noted that nested templates increase the number of back-end database calls, as each nested template is fetched and evaluated internally. As is typical of websites that use a database and cache scheme, extra database processing is more "costly" in terms of resource availability than the page caching mechanism. How much more costly meta-templates are than templates, and whether this has a noticable impact on server load, is (as of early 2006) a matter of debate. Also, when any template is edited, that change results in the cached version of every page using that template, whether directly or indirectly, to be marked invalidated. Pages using nested templates must be rebuilt, bringing a lot of activity onto the database servers. In some cases, editing meta-templates has caused enough server stress to temporarily lock the database.

Protection

Because of vandalism and the potential server load problems described above, several high-use meta-templates have had to be protected, so that they can only be edited by administrators. If the meta-template is rarely changed, then any daughter templates probably don't change either, so it may make sense to move the formatting into the daughter templates. This was done with stub templates, which now no longer use a meta-template scheme. Remember also: meta:Protected pages considered harmful.

Conditionals

One of the most common reasons meta-templates are created is to add functions that mimic conditional expressions -- selectively hiding or displaying text based on the parameters which have been set. Currently, MediaWiki supports only one conditional mechanism -- the ability to describe a parameter default -- alternate text that is displayed if the parameter is not set. Several alternate methods ("hacks") have been created to extend conditional expressions beyond this, but each has its own limitations which make not avoiding them preferrable:

  • Template:Qif, and related templates -- these perform a wide range of functions, but the mechanism can only be used by resorting to nested templates. The template source code is often difficult to understand. Cannot be used with "subst:".
  • Misplaced Pages:HiddenStructure -- this makes use of CSS to hide text from view. Because this is handled by the browser, the hidden text is still sent to the client. It fails if CSS is disabled or not supported; such as on older versions of text browsers and screen readers.
  • Blank parameter (aka "Weeble") -- this method requires that each template call includes a blank parameter ( {{template|if=|param=data}} ). Requiring this on every page using a template is difficult, and the template source code is often very hard to understand. Cannot be used with "subst:".

Wikimedia developers have expressed in interest in bringing some basic conditionals into the software, but it's unknown how they will be defined.

Alternatives

  1. Design, document, and then implement — To give an example in the case of Misplaced Pages:Sister projects, a proposal was made to use a meta-template. In this area, it is much better to decide on a common look and format, document that standard for easy reference in case new related templates are needed, and then implement it across the few templates being used. When changes are needed, this gives one central place for discussion and revision. After there is consensus for the change, interested editors can quickly apply them. Creating a page which displays each template also helps to locate templates which don't follow the agreed upon format.
  2. Make use of CSS — Some meta-templates serve only to produce a specific visual format — such as size, position, color. If these were identified, CSS classes could be added to the site's global stylesheets. The meta-templates could then be replaced with the CSS classes in relevant pages. This would accomplish the same purpose — maintaining uniform style across the site — without placing a burden on the server. This also allows the visual style to be personally customized.
  3. Use lists, not templates or categories — Some templates and categories are used with the goal of helping editors find articles under a specific topic area of interest. For this use, it is often more valuable to create a list, which can be annotated and prioritized. Many WikiProjects already maintain an area for reporting articles that need work. (Note that categories also heavily load the servers, for similar reasons.) See Misplaced Pages:Categories, lists, and series boxes
  4. Use {{subst: }}Template substitution copies the template's text to any daughter templates(substitution) rather than causing a transclusion, thus eliminating the second template call. Of course, this means that when the meta-template is changed, the daughter templates won't update, and won't be tracked by the What links here feature. This is a good solution for any template that doesn't change often or where the exact text need not be kept up-to-date on every page.
  5. MediaWiki needs developers. Mechanisms that provide desired template functions, yet avoid meta-templates, could be of great benefit to the project. See m:How to become a MediaWiki hacker.

Still want to use them?

The use of meta-templates should be avoided in almost all circumstances. If you are considering using a meta-template, ask these questions.

  1. Is the end product essential to Misplaced Pages, or is it a primarily decorative feature? Meta-templates that are not essential should be avoided.
  2. Is the template likely to be high-profile? High-profile templates cause more server load, and so are less appropriate for meta-templates.
  3. Is the desired effect only achievable through a meta-template, or can a template of basically the same appearance be made without them? If the same effect can be achieved differently, even if it is more difficult, a meta-template should be avoided.
  4. Will later editors understand how this works?

You should not use meta-templates unless you have a really good reason that you have to. If you do create one, be open to other methods which achieve the same end, and be prepared to trade functionality in favor of avoiding the problems with meta-templates.

See also

Category: