Изменения

Перейти к: навигация, поиск

Справка:Функции парсера

99 байтов добавлено, 19:53, 28 января 2010
м
Нет описания правки
The {{mediawiki|Extension:ParserFunctions|ParserFunctions}} extension provides ten additional parser functions to supplement the "[[Help:Magic words#Parser functions|magic words]]", which are already present in MediaWiki. All the parser functions provided by this extension take the form:
:<tt><nowiki>{{</nowiki> '''#functionname''': ''argument 1'' | ''argument 2'' | ''argument 3'' ... <nowiki>}}</nowiki></tt>
{{warning|Some expressions may invoke floating-point errors when used with very large or very small numbers:<br />
<tt><nowiki>{{#expr: 20060618093259 mod 10000}}</nowiki></tt> &rarr; '''{{#expr: 20060618093259 mod 10000}}''' in most cases, but may occasionally give '''-6357'''. This varies with the specification and configuration of the server running the wiki. See {{[https://bugzilla|.wikimedia.org/show_bug.cgi?id=6356}}bug 6356].
}}
:<tt><nowiki>{{#if: foo | | no}}</nowiki></tt> &rarr; ''' {{#if: foo | | no}}'''
See [[mediawikiwiki:Help:Parser functions in templates]] for more examples of this parser function.
==#ifeq==
:<tt><nowiki>{{#ifexist:</nowiki> XXX{{FULLPAGENAME}}XXX | exists | doesn't exist <nowiki>}}</nowiki></tt> &rarr; '''{{#ifexist: XXX{{FULLPAGENAME}}XXX | exists | doesn't exist }}'''
The function evaluates to true for [[mediawikiwiki:Help:System messages|system messages]] that have been customised, and for [[Help:Special pages|special pages]] that are defined by the software.
:<tt><nowiki>{{#ifexist:</nowiki> {{#special:Watchlist}} | exists | doesn't exist <nowiki>}}</nowiki></tt> &rarr; '''{{#ifexist: Special:Watchlist | exists | doesn't exist }}'''
:<tt><nowiki>{{#ifexist: MediaWiki:Copyright | exists | doesn't exist }}</nowiki></tt> &rarr; {{#ifexist: MediaWiki:Copyright | '''exists''' (because [[{{ns:8}}:Copyright]] has been customised) | '''doesn't exist''' (because [[{{ns:8}}:Copyright]] has not been customised) }}
<tt>#ifexist:</tt> is considered an "expensive parser function", only a limited number of which can be included on any one page (including functions inside transcluded templates). When this limit is exceeded, the page is categorised into [[:CategoryКатегория:{{MediaWiki:expensive-parserfunction-category}}]], and any further <tt>#ifexist:</tt> functions automatically return false, whether the target page exists or not.
{{admin tip|Configure the maximum number of allowed expensive parser functions using the {{mediawiki|Manual:$wgExpensiveParserFunctionLimit|$wgExpensiveParserFunctionLimit}} variable.}}
:<tt><nowiki>{{subst:#ifexist:</nowiki> {{FULLPAGENAME}} <nowiki>| [[</nowiki>{{FULLPAGENAME}}<nowiki>]] | </nowiki>{{FULLPAGENAME}}<nowiki> }}</nowiki></tt> &rarr; the code '''<tt><nowiki>[[</nowiki>{{FULLPAGENAME}}<nowiki>]]</nowiki></tt>''' will be inserted in the wikitext since the page {{FULLPAGENAME}} exists.
{{warning|The results of substituted parser functions are undefined if the expressions contain ''un''substituted volatile code such as [[Help:Magic words#Variables|variables]] or other parser functions. For consistent results, all the volatile code in the expression to be evaluated must be substituted. See [[w:Help:Substitution|Help:Substitution]].}}
===Tables ===
Parser functions will mangle [[mediawikiwiki:Help:Tables|wikitable]] syntax, treating all the raw pipe characters as parameter divisors. To avoid this, most wikis create the template [[{{ns:10}}:!]] with its contents only a raw pipe character. This 'hides' the pipe from the MediaWiki parser, ensuring that it is not considered until after all the templates and variables on a page have been expanded. Alternatively, raw HTML table syntax can be used, although this is less intuitive and more error-prone.
{{admin tip|You can improve the reliability of HTML table code (and other raw HTML input) by using HTML tidy. See {{mediawiki|Manual:Build Tidy from source|Installing Tidy}} and {{mediawiki|Manual:$wgUseTidy|$wgUseTidy}}.}}
{{admin tip|You can also use the {{mediawiki|Extension:Pipe Escape|Pipe Escape}} extension to improve the handling of pipe characters.}}
==See also==
*[[Help:Parser functions in templates]]
*{{Mediawiki|meta:Help:Newlines and spaces|Help:Newlines and spaces}}
*{{Mediawiki|Help:Magic words}}
* [[Extension:StringFunctions]]
* [[Categorymediawikiwiki:Help:Parser functions in templates]]* {{Mediawiki|meta:Help:Newlines and spaces|Help:Newlines and spaces}}* {{Mediawiki|Help:Magic words}}* [[mediawikiwiki:Extension help:StringFunctions]] [[Категория:Справка|ParserFunctionsФ]]

Навигация