|
Some users are concerned that the template transclusion feature of the MediaWiki engine may not always be used wisely. Transclusion is a simple idea, but all of its consequences may not be immediately apparent to users with a less technical background. Although templates make many tasks easier, there are risks associated with their use — as there are with any tool. This is a kind of cost we pay for the benefits of templates. Additionally, there is a direct cost in terms of machine resources — as there is with any computer tool. This cost may be represented in simple dollar terms; if the money is not spent, the cost surfaces as a degradation of engine performance. This article is an explanation of these costs and benefits.
How transclusion worksTo transclude any source page (within a single MediaWiki project, such as en:Wikipedia) within another target page, include the following code:
Whenever the target page A with this code is rendered, the engine will include in that place not the code itself, but the entire content of the source page B, SOMEPAGE. For example, you might decide to place a welcome message on every newcomer's Talk Page. Transclusion creates a "live" link between the template-page and the target-page(s) upon which the message should appear. When the template is edited, all the target-pages are edited too. For example, you might decide to create a (template) page with your mailing address and include that template on not only your page, but all your friends' pages, too. When you move your television and couch to another apartment, you will change your address template, and automatically, that new information will appear on all your friends' pages. Costs and benefitsTransclusion is a tool, and like any tool, provides benefits and incurs costs. The exact values of these costs and benefits vary according to wise or foolish design and use, and is the subject of debate. It is not possible to pretend that anyone can give a perfectly neutral statement of these costs and benefits; both are largely subjective and extremely difficult to measure. SocialThere is a social cost of transclusion, the total expectation over time of the risk that a transcluded template page may be vandalized. If a popular template's content is replaced by gibberish, that same gibberish will momentarily appear on every page in which the template is transcluded — just as would any edit. This also adds to the burden borne by the engine — as does any edit. Offsetting this cost is the fact that template vandalism is as easy to revert as to commit. The offending material is removed and the former content restored. There is, again, another imposition on the engine. If a great deal of text, appearing on many pages, is kept in a template and transcluded in all of the targets, then there are some savings in storage, but generally there is little, if any, benefit to the machine granted by transclusion. Humans, however, may find transclusion very useful, and in many ways, some of them quite unexpected. Almost any type of text, markup, HTML or CSS code can be transcluded; if that text or code is used in several places, templates make manual labor much easier. Not only that, but by reducing errors in otherwise repetitive typing, templates help to lower Wikistress and reduce the amount of janitorial work. ComparisonA basic principle of graphic design — of almost any design — is to standardize presentation. For example, if on several pages it is thought to be desirable to present a certain list of items, then all such lists should look alike. Even if the items vary somewhat from page to page, there is often a clear advantage to making them appear similarly. There is no technical reason to do this, as the engine will function just as well if every list is a little bit different from the last. But a standard appearance contributes greatly to a professional impression on human readers. Changes to the mere layout of the lists are easy to implement across all occurrences of the list by simply changing the layout as opposed to changing every list. The same Wikipedia logo and other basic site navigation elements, for example, are all transcluded onto every page in order to create a consistent look and feel across millions of pages. Changes to the logo, navigational, or other language elements of the site can be performed from a central location and take effect on every page at the cost of rendering time for every page. However, this social functionality outweighs the resource costs of maintaining the uniform look. Double transclusionSince almost any page can be transcluded, why can't we transclude one page in another, and then transclude that page in a third? The answer is, we can. Some master templates are designed to be used with other subtemplates. When master template B is transcluded within target page A, the subtemplate C is transcluded, too. Since both links are "live", if the subtemplate is edited, the target page is also changed. This could be carried even further; page C could transclude some page D , and the content on page A would be an instance of triple transclusion. When page D is edited, page C changes, so page B changes, so page A changes — right on down the line. Geometric effect of multiple transclusionCosts and benefits of double transclusion increase geometrically (in a loose sense of the term). Say a template X is transcluded on 5 other templates; and say each of those templates is itself transcluded on 5 target pages. The template X is doubly transcluded onto 25 pages. An edit to X appears on a total of 31 pages: X, the 5 templates, and the 25 targets. There is no limit to the number of targets for a given template, nor to levels of transclusion, so it is possible that X be doubly or triply transcluded hundreds or even thousands of times. Thus double transclusion is extremely powerful and the technique in itself has become an object of dispute. How substitution worksMediaWiki provides the To substitute a page, use this code instead:
(The same syntax applies as in the case of transcluded pages.) When you preview a page containing a substitution, you will still see the code in the edit box; you can change it if you like. But when you save the target page, the engine substitutes, or replaces, the code with whatever is on the source page. If you edit the target again, then you will see that the substitution code is gone; the content of the source page has replaced it directly. The link from the target to the source is not merely broken; it does not exist at all. Now, if the source page changes, the target page will not change. The substituted content is frozen in time, in the form it had at the moment the page was saved. Substitution and transclusion can be used together, and often this is a good idea. Instead of using double transclusion, you might substitute one page in another, then transclude that page in a target page. Or, you might find that a page transcludes another; you choose to substitute the transcluding page in a target, rather than force a double transclusion. On the other hand, double transclusion can be very useful, and may be justified or even demanded in certain contexts. Each case is different, and can only be decided after careful, informed consideration of the technical and social situation. TaggingA very common use of templates is to "tag" a page — to insert on it some snippet of text, often boxed, often seen at the very top or bottom of a page. A tag does not contain content, but metacontent: information about the page itself. For example, {{FAC}} inserts the following tag: There are hundreds, perhaps thousands of tags, each with a different function, many transcluded onto hundreds of pages. Thus tags represent a significant fraction of server resources devoted to transclusion. Many tags include category references, which automatically include pages on which they are transcluded within a category. Article pages are rarely transcluded, so tagging them presents no problems — the same goes for Talk pages, Wikipedia namespace pages, and indeed most pages. When a page is so tagged, the tag appears only in that one place; if it refers to "this page", it is clear what is meant. However, Template namespace pages are intended to be transcluded and substituted, so tagging them — for any reason — is problematic.
There are cases in which tagging a template may be less destructive; however, it is very difficult to isolate them — to ensure that a tag will cause no problems. Therefore: Most tags should not be placed on Template namespace page bodies. If a certain tag seems to apply to a template, there are various options: sometimes the tag can be placed on its associated Talk page or /doc page (if any), or it can be <noinclude>d onto the template. Some tags (such as {{tfd}} are specifically designed to be visibly included on templates. Other kinds of inclusionOther types of markup and engine function also cause content to be included in a rendered page, similar in effect to transclusion or substitution:
See also |
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.
Mercedes Car
This site monitored by SitePinger.net