Template:Exist

From Dolphin Emulator Wiki
Jump to: navigation, search
[edit] [purge] Template documentation

This template tests 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. (However, in the case of frivolous use of #ifexist which was the reason for the limit, do not replace this use with frivolous use of this template!) Additionally, this template avoids a bug with the #ifexist parser function that causes pages it tests to appear in the wiki's Wanted Pages list.

The full syntax for using it is:

{{exist | page | result if page exists | result if page does not exist }}

The then and else parts are optional, with the empty string as default.

Examples

Page Exists: {{exist|User:kolano|Exists|Doesn't exist}}

Page Exists: Exists

Page Exists: {{exist|gagufiagiusf|Exists|Doesn't exist}}

Page Doesn't Exist: Doesn't exist

Internal technical details

The method is based on transclusion of the possibly existing page. If the 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.

Drawbacks

  • Because this template works off of transclusion, it invisibly includes the entire wikitext of any page being checked. This makes it an expensive template, possibly slower than #ifexist.
  • Also because of transclusion, in certain situations this template can trigger MediaWiki's recursive loop warnings. This is harmless to page output, however it clutters the category with false positives, which can make it difficult to find legitimate warnings.

See also