Magic words & parser functions

From Redazione
Jump to navigation Jump to search
m (Admin moved page How it works/Parser functions to How it works/Magic words & parser functions without leaving a redirect)
(proper division between magic words and parser functions)
Line 1: Line 1:
[https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions Parser functions] are a way to empower the wiki text (the specific language through which pages of all wikis are written, thus one can also use Visual editor where available) with some programmatic feature, for instance the ability to add the current date to a page (which will update during subsequent access) or to trigger whatever other function available in the wiki on the server side.
+
[https://www.mediawiki.org/wiki/Help:Magic_words Magic words] and [https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions Parser functions] are a way to empower the wiki text (the specific language through which pages of all wikis are written, thus one can also use Visual editor where available) with some programmatic feature, for instance the ability to add the current date to a page (which will update during subsequent access) or to trigger whatever other function available in the wiki on the server side.  
  
Currently this platform offers the following additional parser functions.
+
The first ones are key-words which will be replaced by a specific value, while parser functions are completely comparable to [[How it works/Templates|templates]] invoked with some parameter, with the difference that the logics behind parser functions is not contained in templates but stands server side.
They are prefixed with the string "ci_" to distinguish them easily from other Mediawiki [https://www.mediawiki.org/wiki/Help:Magic_words magic words] and [https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions parser functions], either standard or provided by other extensions.
 
  
Here is a list of the currently available functions
+
Here is a list of the additional magic words provided by our platform (as usual they are prefixed with the string "CI_" to distinguish them easily from other Mediawiki [https://www.mediawiki.org/wiki/Help:Magic_words magic words] and [https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions parser functions])
  
 
{| class="wikitable"
 
{| class="wikitable"
 
|+
 
|+
!function name
+
!name
 
!what it does
 
!what it does
 
|-
 
|-
|ci_userAffiliatedTo
+
|CI_userAffiliatedTo
 
|shows the organization to which the logged in user is affiliated
 
|shows the organization to which the logged in user is affiliated
 
|-
 
|-
|ci_userRealName
+
|CI_userRealName
 
|shows the real name of logged in user (by contrast to the username)
 
|shows the real name of logged in user (by contrast to the username)
 
|-
 
|-
|ci_isSysop
+
|CI_isSysop
 
|returns 1 if the logged in user is an admin ("sysop")
 
|returns 1 if the logged in user is an admin ("sysop")
 
|-
 
|-
|ci_loggedIn
+
|CI_loggedIn
 
|returns 1 if the page's visitor is logged in
 
|returns 1 if the page's visitor is logged in
 
|-
 
|-
|ci_visitorIsoCode
+
|CI_visitorIsoCode
 
|returns the iso code of country of the visitor
 
|returns the iso code of country of the visitor
 
|-
 
|-
|ci_visitorCountry
+
|CI_visitorCountry
 
|returns the country name of the visitor
 
|returns the country name of the visitor
 +
|}
 +
 +
and parser functions:
 +
{| class="wikitable"
 +
|+
 +
!name
 +
!what it does
 
|-
 
|-
|ci_editors_realnames
+
|CI_editors_realnames
 
|returns the real names from a list of usernames
 
|returns the real names from a list of usernames
 
|-
 
|-
|ci_editors_attribution
+
|CI_editors_attribution
 
|returns the string "edited by [real name], affiliated to [organization name]" from an [https://www.semantic-mediawiki.org/wiki/Help:Inline_queries ask query] returning editors of a page
 
|returns the string "edited by [real name], affiliated to [organization name]" from an [https://www.semantic-mediawiki.org/wiki/Help:Inline_queries ask query] returning editors of a page
 
|-
 
|-
|ci_noparse_isHTML
+
|CI_noparse_isHTML
 
|prevents Mediawiki from html encoding output
 
|prevents Mediawiki from html encoding output
 
|}
 
|}
Line 43: Line 49:
  
 
==Instructions of use==
 
==Instructions of use==
(Note: thus the following are formally parser functions, currently they don't expect arguments and therefore they shall be converted to ''magic words'' in a second time)
+
<br />
 
 
 
===Magic words===
 
===Magic words===
 
{| class="wikitable"
 
{| class="wikitable"
Line 90: Line 95:
 
-->
 
-->
  
===parser functions===
+
===Parser functions===
(Note: because the structured pages path is a core feature of this forked version of Mediawiki, the output currently produced by the following parser functions should returned as default, and conversely they could be used to retrieve the complete page path)
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|+
 
|+
Line 98: Line 102:
 
!parameter
 
!parameter
 
|-
 
|-
|ci_editors_realnames
+
|CI_editors_realnames
 
|comma separated real names
 
|comma separated real names
 
|list
 
|list
 
|-
 
|-
|ci_editors_attribution
+
|CI_editors_attribution
 
|<nowiki>wikicode with links, in the form [[complete path|page name]] followed by a string in the form "created by [editor real name] affiliated to [editor affiliation]</nowiki>
 
|<nowiki>wikicode with links, in the form [[complete path|page name]] followed by a string in the form "created by [editor real name] affiliated to [editor affiliation]</nowiki>
 
|list, delimiter, kind of output (ul or comma separated values)
 
|list, delimiter, kind of output (ul or comma separated values)
Line 110: Line 114:
  
  
'''ci_editors_attribution'''
+
'''CI_editors_attribution'''
  
 
<pre class="language-wiki">
 
<pre class="language-wiki">
Line 138: Line 142:
 
</pre>
 
</pre>
  
therefore the function '''ci_editors_attribution''' will parse the output using the standard Semantic Mediawiki &lt;PROP&gt; and &lt;MANY&gt; delimiters and will retrieve the real name and the user affiliation from the username: then, it will return an unordered list as above.
+
therefore the function '''CI_editors_attribution''' will parse the output using the standard Semantic Mediawiki &lt;PROP&gt; and &lt;MANY&gt; delimiters and will retrieve the real name and the user affiliation from the username: then, it will return an unordered list as above.
  
  
  
'''ci_editors_realnames'''
+
'''CI_editors_realnames'''
  
 
<pre class="language-wiki">
 
<pre class="language-wiki">

Revision as of 07:51, 1 September 2020

Magic words and Parser functions are a way to empower the wiki text (the specific language through which pages of all wikis are written, thus one can also use Visual editor where available) with some programmatic feature, for instance the ability to add the current date to a page (which will update during subsequent access) or to trigger whatever other function available in the wiki on the server side.

The first ones are key-words which will be replaced by a specific value, while parser functions are completely comparable to templates invoked with some parameter, with the difference that the logics behind parser functions is not contained in templates but stands server side.

Here is a list of the additional magic words provided by our platform (as usual they are prefixed with the string "CI_" to distinguish them easily from other Mediawiki magic words and parser functions)

name what it does
CI_userAffiliatedTo shows the organization to which the logged in user is affiliated
CI_userRealName shows the real name of logged in user (by contrast to the username)
CI_isSysop returns 1 if the logged in user is an admin ("sysop")
CI_loggedIn returns 1 if the page's visitor is logged in
CI_visitorIsoCode returns the iso code of country of the visitor
CI_visitorCountry returns the country name of the visitor

and parser functions:

name what it does
CI_editors_realnames returns the real names from a list of usernames
CI_editors_attribution returns the string "edited by [real name], affiliated to [organization name]" from an ask query returning editors of a page
CI_noparse_isHTML prevents Mediawiki from html encoding output



Instructions of use


Magic words

name return value example result
CI_userAffiliatedTo logged in user affiliation {{CI_userAffiliatedTo}}
CI_userRealName logged in user real name {{CI_userRealName}}
CI_isSysop whether the logged in user is an administrator or not {{CI_isSysop}}
CI_loggedIn whether the user is logged in or not {{CI_loggedIn}}
CI_visitorIsoCode country code of user (based on the ip) {{CI_visitorIsoCode}} US
CI_visitorCountry country of user (based on the ip) {{CI_visitorCountry}} United States


Parser functions

function return value parameter
CI_editors_realnames comma separated real names list
CI_editors_attribution wikicode with links, in the form [[complete path|page name]] followed by a string in the form "created by [editor real name] affiliated to [editor affiliation] list, delimiter, kind of output (ul or comma separated values)

Examples

CI_editors_attribution

{{#ci_editors_attribution: {{#ask:
[[Category:Reading suggestions]]
|format=array
|?Page creator
|?Page author
|sep=##
}}|##|ul}}

will create the following list:

to be noted that the output returned by the ask query above will be as follows:

Announcements/European Commission - Supporting the cultural and creative sectors in the ACP countries<PROP>User:Luca.speziale<PROP>User:Admin<MANY>User:Luca.speziale##Announcements/General Secretariat of the Council - Traineeships at the General Secretariat of the Council<PROP>User:Luca.speziale<PROP>User:Admin<MANY>User:Luca.speziale##Announcements/Language school "Praticamente" - Lavoro per un insegnante di inglese in Kazakistan per 3 mesi presso la Scuola di lingua Italiana “Praticamente”<PROP>User:Luca.speziale<PROP>User:Admin<MANY>User:Luca.speziale

therefore the function CI_editors_attribution will parse the output using the standard Semantic Mediawiki <PROP> and <MANY> delimiters and will retrieve the real name and the user affiliation from the username: then, it will return an unordered list as above.


CI_editors_realnames

{{#ci_editors_realnames: {{#ask: 
[[{{PAGENAME}}]] 
|?Page creator
|?Page author
|format=array
|mainlabel=-
|sep=##
}}
}}

will produce the following output:


As above, the output produced by the ask query, will be similar to the following:

User:MediaWiki default<PROP>User:Admin<MANY>User:Luca.speziale<MANY>User:MediaWiki default

and applies as above with the difference that the output produced by the ci_editors_realnames function will be a comma separated list of real names of provided usernames.