Help:Page existence

From BDPWiki

Jump to: navigation, search

{{H:h {{#if: Help|Help|Help}}||enname=}}

Contents

Wikitext methods to determine whether a page exists:

methodwhat links here [1]transclusion [1]limitationusageinterwiki link[1]pagename with anchor
#ifexistyesno[1]not more than now 500 on a page[1]branching"does not exist"checks page existence correctly, but not the existence of the anchor
[[{{#if:|template}}:{{#if:|exists|template}}:{{#if:|foo|exists}}]]}} ( {{#if:1|[[{{#if:|template}}:{{#if:|exists|template}} talk:{{#if:|foo|exists}}|talk]]}} {{#if:1|[{{fullurl:{{#if:|template}}:{{#if:|exists|template}}:{{#if:|foo|exists}}|action=edit}} edit]}} {{#if:|[{{fullurl:{{#if:|template}}:{{#if:|exists|template}}:{{#if:|foo|exists}}|action=watch}} watch]}} {{#if:|{{#ifeq:{{#if:|exists|template}}|user|[[{{#if:|template}}:Special:Contributions/{{#titleparts:{{#if:|foo|exists}}|1}}|contribs]]}}}} {{#if:1|[{{fullurl:{{#if:|template}}:{{#if:|exists|template}}:{{#if:|foo|exists}}|action=history}} history]}} {{#if:1|[{{fullurl:{{#if:|template}}:Special:Whatlinkshere/{{#if:|exists|template}}:{{#if:|foo|exists}}|limit=1000}} links]}} {{#if:|[{{fullurl:{{#if:|template}}:Special:Log|page=%7B%7B%23if%3A%7Cexists%7Ctemplate%7D%7D%3A%7B%7B%23if%3A%7Cfoo%7Cexists%7D%7D}} logs]}} {{#if:|[[{{#if:|template}}:Special:Prefixindex/{{#if:|exists|template}}:{{#if:|foo|exists}}|localspace]]}} {{#if:|[{{fullurl:{{#if:|template}}:{{#if:|exists|template}}:{{#if:|foo|exists}}|action=delete}} delete]}} {{#if:|{{#ifeq:{{#if:|exists|template}}|user|[[{{#if:|template}}:Special:Blockip/{{#titleparts:{{#if:|foo|exists}}|1}}|block]]}}}} ), where care is taken that the comparison is insensitive to the applicable conversionsyesyes branching"exists""exists"
linking: class="new" means non-existenceyesnononeseeing the page link in a style depending on existenceclass="extiw"checks page existence correctly, but not the existence of the anchor
Special:Allpagesnonononeseeing the page listed or notnot listedn.a.
Special:PrefixIndexnonononeseeing the page listed or notnot listedn.a.

Examples:

  • {{p{{#ifeq:eq|eq|1|2}}|{{p{{#ifeq:+|-|1|2}}|{&#{{#if:|123;[[Template:#ifexist:existence a|#ifexist:existence a]]|123;#ifexist:existence a}}|1|0|{{{4}}}}} gives {{#ifexist:existence a|1|0|{{{4}}}}} [1]|{{p{{#ifeq:eq|eq|1|2}}|{{p{{#ifeq:0|0|1|2}}|"{&#{{#if:|123;[[Template:#ifexist:existence a|#ifexist:existence a]]|123;#ifexist:existence a}}|1|0}}" gives "{{#ifexist:existence a|1|0}}" [2]|{{p{{#ifeq:eq|eq|1|2}}|{{p{{#ifeq:1|1|1|2}}|"{{{{#if:|{{#ifeq:{{Template:#ifexist:existence a}}|{{#ifexist:existence a}}|[[Template:#ifexist:existence a|#ifexist:existence a]]|#ifexist:existence a}}|#ifexist:existence a}}|{{#switch:p{{#switch:p1q|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=
}}{{#switch:{{#switch:p1q|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|{={|&p=||}=}|&e==|&nl=
|&*=*|&#=#|&:=:}}{{ {{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|{|&p|}|&e|&s|&nl|&*|&#|&:|*|**|***|#|##|###|:|::|:::|;=void|1x}}|{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}}}{{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|*=*|**=**|***=***|#=#|##=##|###=###|:=:|::=::|:::=:::|;=;}}{{ {{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&s=1x|void}}| }}{{#ifeq:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&|amp;}}}}"
gives "{{#ifexist:existence a|1}}" [http://sdnhq.undp.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7B%23ifexist%3Aexistence+a%7c{{#switch:p{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=%0d}}{{#switch:{{#switch:p1q|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&p=%7c|&e=%3d|&s=+|&nl=%0d|&*=%2a|&#=%23|&:=%3a|%7B%7B%23switch%3Ap1q%7Cp+q%3D%26s%7Cp%0Aq%3D%26nl%7Cp%2Aq%3D%26%2A%7Cp%23q%3D%26%23%7Cp%3Aq%3D%26%3A%7C1%7D%7D}}%7D%7D%22]|"{{{{#if:|{{#ifeq:{{Template:#ifexist:existence a}}|{{#ifexist:existence a}}|[[Template:#ifexist:existence a|#ifexist:existence a]]|#ifexist:existence a}}|#ifexist:existence a}}}}" gives "{{#ifexist:existence a}}" {{#ifeq:gives||||||}} [3]}}|{{p{{#ifeq:1|1|2}}|1|"{{{{#if:|{{#ifeq:{{Template:#ifexist:existence a}}|{{#ifexist:existence a}}|[[Template:#ifexist:existence a|#ifexist:existence a]]|#ifexist:existence a}}|#ifexist:existence a}}|{{#switch:p{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=
}}{{#switch:{{#switch:p1q|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|{={|&p=||}=}|&e==|&nl=
|&*=*|&#=#|&:=:}}{{ {{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|{|&p|}|&e|&s|&nl|&*|&#|&:|*|**|***|#|##|###|:|::|:::|;=void|1x}}|{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}}}{{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|*=*|**=**|***=***|#=#|##=##|###=###|:=:|::=::|:::=:::|;=;}}{{ {{#switch:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&s=1x|void}}| }}{{#ifeq:{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&|amp;}}}}"
gives "{{#ifexist:existence a|1}}" [http://sdnhq.undp.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7B%23ifexist%3Aexistence+a%7c{{#switch:p{{#switch:p1q|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=%0d}}{{#switch:{{#switch:p1q|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|1}}|&p=%7c|&e=%3d|&s=+|&nl=%0d|&*=%2a|&#=%23|&:=%3a|%7B%7B%23switch%3Ap1q%7Cp+q%3D%26s%7Cp%0Aq%3D%26nl%7Cp%2Aq%3D%26%2A%7Cp%23q%3D%26%23%7Cp%3Aq%3D%26%3A%7C1%7D%7D}}%7D%7D%22]}}}}}}|{{p{{#ifeq:0|1|2}}|0|"{&#{{#if:|123;[[Template:#ifexist:existence a|#ifexist:existence a]]|123;#ifexist:existence a}}|1|0}}" gives "{{#ifexist:existence a|1|0}}" [4]}}}}}}|{{p{{#ifeq:+|1|2}}|-|{&#{{#if:|123;[[Template:#ifexist:existence a|#ifexist:existence a]]|123;#ifexist:existence a}}|1|0|{{{4}}}}} gives {{#ifexist:existence a|1|0|{{{4}}}}} [5]}}}}

q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=
}}{{#switch:{{#switch:pexistence bq|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|{={|&p=||}=}|&e==|&nl=
|&*=*|&#=#|&:=:}}{{ {{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|{|&p|}|&e|&s|&nl|&*|&#|&:|*|**|***|#|##|###|:|::|:::|;=void|1x}}|{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}}}{{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|*=*|**=**|***=***|#=#|##=##|###=###|:=:|::=::|:::=:::|;=;}}{{ {{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&s=1x|void}}| }}{{#ifeq:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&|amp;}}}}"
gives "Template:Exists" [http://sdnhq.undp.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7Bexists%7c{{#switch:p{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=%0d}}{{#switch:{{#switch:pexistence bq|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&p=%7c|&e=%3d|&s=+|&nl=%0d|&*=%2a|&#=%23|&:=%3a|%7B%7B%23switch%3Apexistence+bq%7Cp+q%3D%26s%7Cp%0Aq%3D%26nl%7Cp%2Aq%3D%26%2A%7Cp%23q%3D%26%23%7Cp%3Aq%3D%26%3A%7Cexistence+b%7D%7D}}%7D%7D%22]|"{{{{#if:|{{#ifeq:Template:Exists|Template:Exists|exists|exists}}|exists}}}}" gives "Template:Exists" {{#ifeq:gives||||||}} [8]}}|{{p{{#ifeq:existence b|1|2}}|existence b|"{{{{#if:|{{#ifeq:Template:Exists|Template:Exists|exists|exists}}|exists}}|{{#switch:p{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=
}}{{#switch:{{#switch:pexistence bq|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|{={|&p=||}=}|&e==|&nl=
|&*=*|&#=#|&:=:}}{{ {{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|{|&p|}|&e|&s|&nl|&*|&#|&:|*|**|***|#|##|###|:|::|:::|;=void|1x}}|{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}}}{{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|*=*|**=**|***=***|#=#|##=##|###=###|:=:|::=::|:::=:::|;=;}}{{ {{#switch:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&s=1x|void}}| }}{{#ifeq:{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&|amp;}}}}"
gives "Template:Exists" [http://sdnhq.undp.org/w/index.php?title=Special:ExpandTemplates&input=%22%7B%7Bexists%7c{{#switch:p{{#switch:pexistence bq|p q=&s|p q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}q|p

  • q|p
    • q|p
      • q|p
  1. q|p
    1. q|p
      1. q|p
q|p
q|p
q=%0d}}{{#switch:{{#switch:pexistence bq|p q=&s|p

q=&nl|p*q=&*|p#q=&#|p:q=&:|existence b}}|&p=%7c|&e=%3d|&s=+|&nl=%0d|&*=%2a|&#=%23|&:=%3a|%7B%7B%23switch%3Apexistence+bq%7Cp+q%3D%26s%7Cp%0Aq%3D%26nl%7Cp%2Aq%3D%26%2A%7Cp%23q%3D%26%23%7Cp%3Aq%3D%26%3A%7Cexistence+b%7D%7D}}%7D%7D%22]}}}}}}|{{p{{#ifeq:1|1|2}}|1|"{&#{{#if:|123;exists|123;exists}}|existence b|1}}" gives "Template:Exists" [9]}}}}}}|{{p{{#ifeq:0|1|2}}|0|{&#{{#if:|123;exists|123;exists}}|existence b|1|0}} gives Template:Exists [10]}}}}

{{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.

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.

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.

Notes


See also

{{H:f {{#if: Help|Help|Help}}|enname=}}

Views
Personal tools