Help:Page existence

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search
MediaWiki Handbook: Contents, Readers, Editors, Moderators, System admins, Researchers +/-

Wikitext methods to determine whether a page exists:

method what links here [1] transclusion [2] limitation usage interwiki link[3] pagename with anchor
#ifexist yes no[4] not more than now 500 on a page[5] branching "does not exist" checks page existence correctly, but not the existence of the anchor
#ifeq applied to the transclusion and the link: equality means non-existence; this is applied in Template:Exists, where care is taken that the comparison is insensitive to the applicable conversions yes yes branching "exists" "exists"
linking: class="new" means non-existence yes no none seeing the page link in a style depending on existence class="extiw" checks page existence correctly, but not the existence of the anchor
Special:Allpages no no none seeing the page listed or not not listed n.a.
Special:PrefixIndex no no none seeing the page listed or not not listed n.a.

Examples:

{{Special:PrefixIndex/exist}} gives:

Existential Wikimedians

Another method is, of course, going to the web address concerned and seeing the content or a message that the page does not exist.

Branching applications[edit]

A typical application of existence detection is:

  • producing the content of a page if it exists, otherwise some default

with the important special case:

  • producing the content of a page if it exists, otherwise nothing

If the set of possible pages is limited then an alternative is creating them all, with the extra pages containing the default value(s), and unconditionally transcluding the pages.

CSS class[edit]

If existence is checked in order to hide red links, an alternative for {{#ifexist:foo|[[foo]]}} and {{exists|foo|[[foo]]}} is <span class="hidden-redlink">[[foo]]</span>, giving "foo", where we have the CSS specification

.hidden-redlink a.new { display: none; }

(which on Meta has been added to Mediawiki:Common.css).

Conversely an emphasized style could be used for red links, or only red links could be displayed.

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 page counts the choice of parameters can make a difference in the case that the page exists. This can be taken into account when checking a possible member of a family of templates, such as those like w:Template:Data China. If we use 1=void the include size is small, but the preprocessor node count is somewhat large, while if we use for parameter 1 the name of a non-existing template the include size is larger, but the preprocessor node count is smaller; for the latter method preferably a salted template name (list) is used. If we do not define parameter 1 it depends on whether the template takes w:Template:Show data as default (like on the template page itself) or not. If it does, the counts are high.

Notes[edit]

  1. applying "what links here" on a probed page shows the page on which this method is applied
  2. the probed page is counted as transcluded onto the page on which this method is applied; this shows up in the edit page of the latter, and on "what links here" on the probed page
  3. applies with a correct prefix, regardless of existence of the linked page
  4. If a page is conditionally transcluded, namely only if it exists, then if the then-part of the #ifexist is this transclusion, it counts as a transclusion anyway, even if the page does not exist. However, if the then-part of the #ifexist is the name of the page to be transcluded, and the else-part is e.g. the page "dummy", and we have outer double braces to transclude the page with this conditional name, then only real transclusions are listed.
  5. On Wikimedia wikis there is a maximum for the number of distinct pages for which #ifexist is called on a page. A call of #ifexist after a transclusion of the same page does not require an extra database query and is therefore not counted. A call beyond the maximum returns "false". The html-source of each page shows the counted number of calls, as well as the maximum. The maximum is currently 500, and it has been announced that this will be lowered to 100. [1] [2] w:wikipedia:Template limits.

See also[edit]


Links to other help pages[edit]

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Reading
Go · Search · Stop words · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences · User style
Editing
Starting a new page · Advanced editing · Editing FAQ · Edit toolbar · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
Links · URL · Piped links · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · List · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Testing · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Variable · System message · Substitution · Array · Calculation · Embed page
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Languages: English  · Afrikaans · العربية · български · বাংলা · Deutsch · español · euskara · فارسی · suomi · français · עברית · magyar · Bahasa Indonesia · 日本語 · қазақша · latviešu · മലയാളം · Bân-lâm-gú · Nederlands · polski · پښتو · română · русский · slovenščina · српски / srpski · ไทย · Türkçe · Volapük