Magic words & parser functions

From Redazione
Jump to navigation Jump to search
Line 3: Line 3:
 
Currently this platform offers the additional parser functions.
 
Currently this platform offers the additional parser functions.
 
They are prefixed with the prefix "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], both standard or provided by other extensions.
 
They are prefixed with the prefix "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], both standard or provided by other extensions.
 +
 +
<br />
 +
{| class="wikitable"
 +
|+
 +
!function 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
 +
|-
 +
|ci_HidePathFromPageList
 +
|
 +
|-
 +
|ci_editors_realnames
 +
|
 +
|-
 +
|ci_pageTitlesAttribution
 +
|
 +
|}
 +
 +
 +
 +
<br />
  
 
==Basic functions==
 
==Basic functions==

Revision as of 06:28, 19 July 2020

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 additional parser functions. They are prefixed with the prefix "ci_" to distinguish them easily from other mediawiki magic words and parser functions, both standard or provided by other extensions.


function 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
ci_HidePathFromPageList
ci_editors_realnames
ci_pageTitlesAttribution



Basic functions

(to be converted to magic words in a second time)

function 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


Complex functions

function return value parameter
ci_HidePathFromPageList wikicode with links, in the form [[complete path|page name]] list, delimiter, kind of output (ul or comma separated values)
ci_editors_realnames comma separated real names list
ci_pageTitlesAttribution 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)


ci_HidePathFromPageList

example:

{{#ci_HidePathFromPageList: path/1/2/a#path/1/2/b#path/1/2/c|#|ul}}

will create the following rendered list:

(that is the path of the pages a, b and c will be removed from the list, thus preserving the link paths).

Of course the same function can be used in combination with a semantic query ("ask" function, from Semantic Mediawiki extension), as follows:

{{#ci_HidePathFromPageList: {{#ask:
|[[~Centro italiano Barcellona*]]
[[Category:Language_courses]]
|format=array
|sep=##
}}|##|ul}}

The ask query will return a list of pages (with paths) separated by '##' and the parser function 'ci_HidePathFromPageList' will take that list, will split it using '##' as delimiter (2nd argument) and will return a 'ul' (unordered list), for instance as follows:


ci_pageTitlesAttribution

example:

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

will create the following list:

to notice 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_pageTitlesAttribution 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 the output likewise the ci_HidePathFromPageList function.


ci_editors_realnames

example:

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