Manual:Checking for page existence/ifeq method
The {{#ifeq:}}
function can be used to test whether a given page exists. It can be useful in view of the maximum number of #ifexist calls that can be used on a page.
If a page does not exist the code for page transclusion produces a (red) link. Even if this result is used for comparison only, and not for final output, the page counts as being transcluded. Therefore the page appears as red link in the list of transcluded pages.
If the page to be transcluded does not exist, then link brackets are put around the full pagename, with the following conversions (visible with Special:ExpandTemplates):
- a colon is put in front if it is not there yet
- the namespace name (if applicable) and the pagename are capitalized (on most wikis)
- underscores are replaced by spaces
Thus {{help:qq w_x}}
and {{:help:qq w_x}}
both give [[:Help:Qq w x]]
.
For the link there is not such an automatic conversion. Therefore the template prefixes a colon to the parameter for the full pagename (it should not already start with a colon) and applies lc and anchorencode (to convert spaces to underscores) on both sides before comparison:
{{anchorencode:{{lc:[[:help:qq w_x]]}}}}
gives help:qq_w_x{{anchorencode:{{lc:{{help:qq w_x}}}}}}
gives help:qq_w_x
Thus a false-positive for a non-existing page is avoided. A false-negative for an existing page is possible, but typically only for specially constructed examples.
Efficiency
[edit]When checking existence of a page through transclusion, any parameters can be used in the call, as long as the result does not happen to be equal to the link to the page. However, for the template limits the choice of parameters can make a difference in the case that the page exists. You should pass a parameter than minimizes the relative template limits.
For example, if a template does nothing but call another template whose name is given as a parameter, like w:Template:Country data China, passing 1=void
makes the post-expand include size smaller but the preprocessor node count larger, while using the name of a non-existing template makes the post-expand include size is larger, but the preprocessor node count smaller, and generates an entry in Special:WantedTemplates. Both of these are much more efficient than not defining parameter 1, resulting in it defaulting to a template that performs useful calculations like w:Template:Country showdata.