User:Wayoshi/Code FAQ: Difference between revisions
m (Robot: Automated text replacement (-Color codes +Color codes)) |
|||
(5 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
While I'm not a professional coder by any means, I have an expert grip on WikiSyntax, and I'd like to help newbies & long-time contributors alike with any issues they come across, hence this page. Most of you know [[Help:Editing|basic syntax]], but very few besides me can use ParserFunctions & DPL successfully, which I plan writing about here eventually. | |||
While I'm not a professional coder by any means, I have an expert grip on WikiSyntax, and I'd like to help newbies & long-time contributors alike with any issues they come across, hence this page. Most of you know [[Help:Editing|basic syntax]], but very | |||
You may ask a specific question on the talk page, in chat, my talk page (if something comes up), or basically anywhere, and I'll add it here if I think other people might ask the same question. | You may ask a specific question on the talk page, in chat, my talk page (if something comes up), or basically anywhere, and I'll add it here if I think other people might ask the same question. | ||
Line 8: | Line 6: | ||
---- | ---- | ||
<center> | <center>Color codes · [[Help:Editing|Editing]] · [[Help:Format|Format]] · [[Help:Gallery|Gallery]] · [[Help:Image|Image]] · [[Help:Link|Link]] · [[Help:List|List]] · [[Help:Signature|Signature]] · [[Help:Table|Table]] · [[Help:Template|Template]]</center> | ||
---- | ---- | ||
Line 15: | Line 13: | ||
__TOC__ | __TOC__ | ||
==Parser Functions== | ==Parser Functions== | ||
:'' | :''I'm going to get back to this soon! 23:34, 1 January 2008 (EST)'' | ||
A '''parser function''' is a special template-based construction. Instead of <code><nowiki>{{name}}</nowiki></code>, the construction is <code><nowiki>{{#name:}}</nowiki></code>, with different syntax after the colon depending on each function. They are used for dynamic results in templates. 8 total are installed in a collective extension on this wiki, but we only have use for half of them: | A '''parser function''' is a special template-based construction. Instead of <code><nowiki>{{name}}</nowiki></code>, the construction is <code><nowiki>{{#name:}}</nowiki></code>, with different syntax after the colon depending on each function. They are used for dynamic results in templates. 8 total are installed in a collective extension on this wiki, but we only have use for half of them: | ||
*'''{{#expr}}''' | *'''{{#expr}}''' | ||
Line 30: | Line 28: | ||
Sadly, the additional parser function {{#ec}} for EditCount has been disabled for now, the template {{tem|user-analysis}} provided an excellent example of the possibilities of {{#expr}}, as {{#ec}} always gives out a numeric result. For the time being, {{#expr}} does not have much use. | Sadly, the additional parser function {{#ec}} for EditCount has been disabled for now, the template {{tem|user-analysis}} provided an excellent example of the possibilities of {{#expr}}, as {{#ec}} always gives out a numeric result. For the time being, {{#expr}} does not have much use. | ||
===#if=== | |||
The '''''if''''' function is to be used solely with templates, as it takes a variable of a template as the determinant. The actual "if" part of the function is to test whether the variable of a template is defined or not. Syntax: | |||
<pre>{{#if:{{{variablename|}}} | defined text | undefined text}}</pre> | |||
If the variable is defined on a certain page the template is called, the defined text will be outputed. If the variable is left blank (<code><nowiki> {{something|1=}}</nowiki></code>) or left uncalled entirely, the undefined text will be outputed instead. | |||
More than one variable can be put in, but there's no OR function – all the variables have to be defined to get the defined text. Example of a combination of {{#expr}} and {{#if}} in {{tem|PAIRreview}}: | |||
<pre>{{#if:{{{A-rating}}}{{{D-rating}}}{{{G-rating}}}{{{I-rating}}}{{{F-rating}}}| | |||
{{#expr:{{{A-rating|0}}}+{{{D-rating|0}}}+{{{G-rating|0}}}+{{{I-rating|0}}}+{{{F-rating|0}}}}}|N/A}}</pre> | |||
If all 5 ratings are defined, the ratings are summed for a final rating. If not, the final rating is not displayed. | |||
This parser function is designed to be used in templates, of course, since it takes variable(s) as an argument, as with all other if parser functions, or, any page that is included multiple times elsewhere, such as a [[Help:Signature|user signature]]. | |||
===#ifexist=== | |||
'''''ifexist''''' is a branch of ''if''. It uses the same syntax, except you input an article name and it checks to see if it is in the database or not: | |||
<pre>{{#ifexist: articlename | does exist text | does not exist text}}</pre> | |||
Magic words such as <nowiki>{{PAGENAME}}</nowiki> or <nowiki>{{FULLPAGENAME}}</nowiki> or variables to take article names can be used. This is useful for [[MediaWiki:Newarticletext]], as if the adjoining page of a talk page is not created, a message strongly advising against creating the isolated talk page will be shown instead of the normal text. Isolated talk pages can be found combining this parser function with DPL (explained later). |
Latest revision as of 20:23, December 4, 2016
While I'm not a professional coder by any means, I have an expert grip on WikiSyntax, and I'd like to help newbies & long-time contributors alike with any issues they come across, hence this page. Most of you know basic syntax, but very few besides me can use ParserFunctions & DPL successfully, which I plan writing about here eventually.
You may ask a specific question on the talk page, in chat, my talk page (if something comes up), or basically anywhere, and I'll add it here if I think other people might ask the same question.
Please see these help pages before asking me your question, as these cover the basics:
Parser Functions
- I'm going to get back to this soon! 23:34, 1 January 2008 (EST)
A parser function is a special template-based construction. Instead of {{name}}
, the construction is {{#name:}}
, with different syntax after the colon depending on each function. They are used for dynamic results in templates. 8 total are installed in a collective extension on this wiki, but we only have use for half of them:
- {{#expr}}
- {{#if}}
- {{#ifeq}}
- {{#ifexist}}
- {{#ifexpr}}
- {{#switch}}
- {{#time}}
- {{#rel2abs}}
#expr
This expression function takes mathematical expressions, including basic operations & rounding. While something like {{#expr:(((8+76)/7)*3)/9}}
seems like a waste of time (it comes out to be 4), any variables in a template that are numbers can be fed into this function without error and give varying results.
Sadly, the additional parser function {{#ec}} for EditCount has been disabled for now, the template {{user-analysis}} provided an excellent example of the possibilities of {{#expr}}, as {{#ec}} always gives out a numeric result. For the time being, {{#expr}} does not have much use.
#if
The if function is to be used solely with templates, as it takes a variable of a template as the determinant. The actual "if" part of the function is to test whether the variable of a template is defined or not. Syntax:
{{#if:{{{variablename|}}} | defined text | undefined text}}
If the variable is defined on a certain page the template is called, the defined text will be outputed. If the variable is left blank ( {{something|1=}}
) or left uncalled entirely, the undefined text will be outputed instead.
More than one variable can be put in, but there's no OR function – all the variables have to be defined to get the defined text. Example of a combination of {{#expr}} and {{#if}} in {{PAIRreview}}:
{{#if:{{{A-rating}}}{{{D-rating}}}{{{G-rating}}}{{{I-rating}}}{{{F-rating}}}| {{#expr:{{{A-rating|0}}}+{{{D-rating|0}}}+{{{G-rating|0}}}+{{{I-rating|0}}}+{{{F-rating|0}}}}}|N/A}}
If all 5 ratings are defined, the ratings are summed for a final rating. If not, the final rating is not displayed.
This parser function is designed to be used in templates, of course, since it takes variable(s) as an argument, as with all other if parser functions, or, any page that is included multiple times elsewhere, such as a user signature.
#ifexist
ifexist is a branch of if. It uses the same syntax, except you input an article name and it checks to see if it is in the database or not:
{{#ifexist: articlename | does exist text | does not exist text}}
Magic words such as {{PAGENAME}} or {{FULLPAGENAME}} or variables to take article names can be used. This is useful for MediaWiki:Newarticletext, as if the adjoining page of a talk page is not created, a message strongly advising against creating the isolated talk page will be shown instead of the normal text. Isolated talk pages can be found combining this parser function with DPL (explained later).