Help:Page existence

From Qi-Hardware
Jump to: navigation, search

Template:H:h

Contents

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:Tim, 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:



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

[edit] Branching applications

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.

[edit] CSS class

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.

[edit] Notes


[edit] See also

Template:H:f

Personal tools
Namespaces
Variants
Actions
Navigation
interactive
Toolbox