Help:Page existence
From The Scuba Wiki
MediaWiki Handbook: Contents, Readers, Editors, Moderators, System admins +/- |
Contents |
Wikitext methods to determine whether a page exists:
method | what links here <ref>applying "what links here" on a probed page shows the page on which this method is applied</ref> | transclusion <ref>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</ref> | limitation | usage | interwiki link<ref>applies with a correct prefix, regardless of existence of the linked page</ref> | pagename with anchor |
---|---|---|---|---|---|---|
#ifexist | yes | no<ref>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.</ref> | not more than now 500 on a page<ref>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.
</ref>||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 ( talk edit history links ), 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:
"{{#ifexist:existence a|1|0}}"
gives "0" [3]"{{exists|existence b|1|0}}"
gives "0" [4]- existence c
- Special:Allpages/existence
- Special:PrefixIndex/exist
{{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
<references />
See also
- w:Wikipedia:Village pump (technical)/Archive 9#Inconsistent limitations?
- w:Wikipedia:Village pump (technical)/Archive 9##ifexist limit
- w:Wikipedia:Village pump (technical)/Archive 33##ifexist limit
- w:Wikipedia:Template limits#Expensive parser function calls.
- w:Category:Pages with too many expensive parser function calls
Links to other help pages
- Help contents
- Meta | Wikinews | Wikipedia | Wikiquote | Wiktionary | commons: | mw: | b: | s: | mw:Manual | google
- Versions of this help page (for other languages see below)
- Meta | Wikinews | Wikipedia | Wikiquote | Wiktionary
- What links here on Meta or from Meta | Wikipedia | MediaWiki
- Reading
- Go | Search | Stop words | URL | Namespace | Page name | Section
- Backlinks | Link | Piped link | Interwiki link | Redirect | Category | Image page
- Logging in and preferences
- Logging in | Preferences | User style
- Editing
- Advanced editing | Editing FAQ | Edit toolbar | Export | Import | Shortcuts
- Tracking changes
- Recent changes (enhanced) | Related changes | Watching pages | Diff
- Page history | Edit summary | User contributions | Minor edit | Patrolled edit
- Style & formatting
- Wikitext examples | Reference card | HTML in wikitext | List | Table | Sorting | Colors
- Special input and output
- Inputbox | Special characters | Displaying a formula | Images (uploads) | EasyTimeline
- Advanced functioning
- Template | Advanced templates | Parser function | ParserFunctions | Parameter default
- Variable | Magic word | System message | Substitution | Array | Calculation
- Page management
- Starting a new page | Renaming (moving) a page | Protecting pages | Deleting a page
- Special pages
- Talk page | Testing | Sandbox | CentralNotice