Wikipedia:Substitution: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
List: -deleted
 
(One intermediate revision by one other user not shown)
Line 7:
'''Substitution''' is a different way of handling [[WP:Templates|templates]] than normally done on Wikipedia. Usually, templates are [[WP:Transclusion|transcluded]], which means that if the template changes, every page that uses it will update to comply with the change-in-question. This is the procedure used for most templates. However, some templates are instead substituted. This means that if the template changes, the page that uses it will not, and will continue to show the old version of the template. Some templates should always be substituted, while most should always be transcluded.
 
To substitute, add <code>subst:</code> after the opening braces, as in <code><nowiki>{{((}}subst:page name{{))}}</nowiki></code>. For example: ''substitution'' <code><nowiki>{{((}}subst:Medicine{{))}}</nowiki></code> in contrast to ''transclusion'' <code><nowiki>{{((}}Medicine{{))}}</nowiki></code>. The contents of [[Template:Medicine]] will be expanded (for any templates) and stored at each point where "<nowiki>{{((}}subst:Medicine{{))}}</nowiki>" is placed in a page. Note that ref tags refuse to run "subst:" unless temporarily renamed as "<code>&lt;xref name=xx></code>" or similar (see the bug report at {{phab|T4700}}).
 
This page also lists templates that should either always or never be substituted except in the Wikipedia namespace. Automated tools (a.k.a. [[WP:Bots|bots]]) that do such replacements will <em>never</em> be used on the original template. If you are going to use a bot to substitute templates, please read through [[Wikipedia talk:Substitution|the talk page]] first, as many are under dispute or change status over time, and substitution is permanent.
 
== About subst: ==
<!-- The colon (:) is part of the keyword, so please leave it in the header. Thanks! -->
 
=== Definition ===
The '''<code>subst:</code>''' keyword (short for "substitution") is used inside [[WP:Template messages|template code]], placed as a prefix before the name of the template but within the curly braces (<code><nowiki>{{((}}{{))}}</nowiki></code>). It changes the way the MediaWiki software expands the template.
 
Ordinarily, a template will be expanded "on the fly"; that is, the template code on a page calls a separate page every time it is rendered. Although most page views are served from the cache, pages need to be rendered for previews and rendered again when the page changes. When someone is editing a page with a normal template call, they see the template call.
 
Placing "subst:" inside the curly braces tells the software to <em>permanently</em> replace the template with the text of the template (i.e., the text that is on the template's article page <em>when the template is added to the page</em>). Therefore, <nowiki>{{((}}template{{))}}</nowiki> becomes <nowiki>{{((}}subst:template{{))}}</nowiki>, until you save the page. The next editor sees not the template call, but instead the text of the template when you saved; it does not change even if the original template is edited.
 
=== Usage ===
You can substitute a template tag by adding "subst:" to it. For example, use <nowiki>{{(({{))}}</nowiki>subst:test5}} instead of <nowiki>{{(({{))}}</nowiki>test5}}.
 
When this is a major component of an edit, it is strongly suggested that the template be mentioned in the [[Help:Edit summary|edit summary]] (for instance, put "<nowiki>{{((}}subst:test{{))}}</nowiki>", "subst:test" or "test1 applied" in your edit summary) so other editors can easily see what you have done.
 
{{Anchor|Hidden comment}}Additionally, when creating or editing templates that are commonly substituted, adding a hidden comment to the template page helps article editors to see how templates are being used (e.g. <code>&lt;!-- Substituted from [[Template:Documentation]] --></code>). Use {{tls|html comment}} if you want to write HTML comments that contain wikitext expansions.
 
=== Benefits ===
* If there is a template you would like to modify for a single occasion, but you do not want to modify the template for all the pages that use it, and you do not want to make a new template, you can substitute the template and then with a second edit, make the modifications. For example, a template might be used with all the states of the United States and with the District of Columbia. The template might be worded correctly for the states, but not for DC. To fix the wording, you can substitute the template and then fix the wording.
* Substituting frequently used, but unprotected templates, limits the damage that can be caused by people [[WP:Vandalism|vandalizing]] the template. See [[WP:high-risk templates|high-risk templates]].
Line 34:
* Substitution allows for recursive evaluation through macro templates.
 
=== Neutral ===
* Substituting ''en masse'' <strong>may</strong> ultimately speed up the site, but this is not a reason to prefer substitution over transclusion. [[WP:Don't worry about performance|Don't worry about performance]] of Wikipedia's servers.
* Templates are often modified or deleted. If a template is [[WP:Glossary#Boilerplate text|boilerplate text]], consider whether you want it to vary as the template is modified. If your answer is "no", substitution is warranted. An example of this is the {{tls|welcome}} template. The archives of a user's talk page should show the actual welcome message they received, not the current welcome message.
 
=== Drawbacks ===
* Once a template is substituted, the result is no longer linked to the template, making it hard to find all pages displaying that text (though categories can sometimes relieve this). The problem can easily be worked around by including a link to the template in the template's code.
* A substituted template will not be updated when errors in the master template are corrected.
Line 50:
* Some meta-templates, such as {{tn|!}} and {{tl|((}}, do not work if they are substituted.
 
== Templates that should <em>always</em> be substituted ==
This is a list of templates that should always be substituted, organized by [[WP:Namespace|namespace]]. Each list is ordered alphabetically with grouped series. '''This is not a comprehensive list'''; other less-used templates may also need to be substituted, see the template's documentation for details.
 
=== Article namespace ===
* {{tl|No more links}}, substituting this inserts a commentary only visible in edit mode, with a short explanation to discourage spamming links.
 
=== Article talk ===
* {{tl|tmfrom}}, {{tl|tmto}}
 
=== User talk namespace ===
All of the templates listed in [[:Category:User warning templates]] and [[:Category:Welcome templates]] should be substituted. This does not apply to templates on the user page.
 
=== File namespace ===
{{empty section}}
 
=== Misc. templates ===
* User signature templates, if transcluded, cause undue server strain as changes to a minor user template must then be widely propagated. If used, user signature templates should be substituted. (It should be noted, however, that [[WP:SIG#NT|user signature templates are discouraged]].)
 
=== Uncategorized suggestions ===
{{empty section}}
 
== Templates that <em>must</em> be substituted ==
{{Anchor|Must}}{{shortcut|WP:SUBSTMUST}}
These templates have a purpose and/or syntax that require them to be substituted.
Line 89:
* {{tl|OnProd}}, which inserts today's-date-dependent name of the category page to which the article was added when nominated for deletion.
 
== Templates that should <em>not</em> be substituted ==
{{Anchor|Not}}{{shortcut|WP:SUBSTNOT}}
Technically, templates should not be substituted that:
Line 96:
<li>contain external links as the formatting of the URL to perform queries or look-ups may change
</ol>
This is because these constructs are not replaced in the generated wiki-code (single level substituting of case (A) leaves the <code>#if</code> or <code>#switch</code> constructs verbatim at the subst location and (B) leaves constructs like <code><nowiki>{{((}}{1|default value}{{))}}</nowiki></code>).<br />
If specific [[WP:CON|consensus]] is to eliminate a particular call of such a template, [[Special:ExpandTemplates]] can be used to expand that call to plain wiki-syntax.
 
=== List ===
This is a list of templates that should not be substituted. This is because they contain formatting standard code, complex code, or code that breaks if substituted.
* Various citation/reference templates which contain very complex conditional code (see: [[WP:CITET]]).
* {{tl|Curlie}}, URL queries external web directories (former DMOZ).
* [[:Category:Infobox templates|Infobox templates]], various ones for the sake of bot-identification and consistency.
* {{tl|Javadoc:EE}}, {{tl|Javadoc:SE}}, {{tl|Javadoc:SE-guide}}, conditional templates whose purpose is to update the links when the master template is updated.
Line 119 ⟶ 118:
Note also that some things may appear to be templates but are actually [[Help:Magic words|magic words]], such as {{tlf|!}} and {{tlf|noexternallanglinks}}. Substituting them either will output nothing, or will substitute a template that [[variable shadowing|shadows]] them (like the deprecated [[Template:!]]).
 
=== Wrong title templates ===
These templates, used in the main-space, add a comment about why an article is misnamed. They may be removed as the MediaWiki titling facilities improve, and the wording/layout may change.
* {{tl|correct title}}
* {{tl|lowercase}}
 
=== Deletion-related ===
Most templates related to renaming or deleting pages are used temporarily, and thus do not need to be substituted (it just makes more work to delete them).
* {{tl|catfd}}
Line 149 ⟶ 148:
* {{tl|archive top}} {{tl|archive bottom}}, {{tl|discussion top}} {{tl|discussion bottom}}
 
== See also ==
{{Wikipedia glossary}}
* [[Help:Substitution]]