Help talk:Extension:ParserFunctions/2020

English ordinals in

It seems to me, that the English ordinal suffixes in date formats in {{#time:}} are not supported: {{#time:jS F Y|January 20, 2000}} gives 20S January 2000 rather than 20th January 2000. Alexander Mashin talk 06:45, 17 July 2020 (UTC)

I don't see a support for them as well. It's probably worth making a feature request as other languages may also benefit from this. A workaround can be a template like:
{{{1}}}{{#switch: {{#expr: {{{1}}} mod 100 }}
 | 11 | 12 | 13 = th
 | #default = {{#switch: {{#expr: {{{1}}} mod 10 }}
  | 1 = st | 2 = nd | 3 = rd
  | #default = th
 }}
}}
Matěj Suchánek (talk) 10:54, 17 July 2020 (UTC)

How to update parsed datas?

I installed the Comments and VoteNY extension, retrieving number of comments and votes from a page on another page.

But it doesn't seem to update when comments or votes are added with this

{{NUMBEROFVOTESPAGE:page name}}

{{NUMBEROFCOMMENTSPAGE:page name}}

I tried to put $wgParserCacheType = CACHE_NONE;

but it doesn't seem to change much. The number of votes and comments stay.

Any idea? Dnsbl1 (talk) 23:26, 25 July 2020 (UTC)

Completely disabling caching is generally a bad idea. Do the numbers update if you force the page's cache to be cleared (e.g. by editing the page, or by using action=purge)? If so, then you should add a link to purge the page near where the numbers are displayed, with text like "update these counts" (the code [{{fullurl:{{FULLPAGENAME}}|action=purge}} update these counts] can be used as a base for this). ディノ千?!☎ Dinoguy1000 01:02, 26 July 2020 (UTC)
I switched to using cache cause the extensions use it to retrieve datas.
I tried after a few hours, ?action=purge update the page correctly and the correct number of comments are displayed, thanks for the idea of adding a link on the page. Dnsbl1 (talk) 06:46, 26 July 2020 (UTC)

How to output html in an #if function?

Is there any way to output HTML in the yes / no sections of an {{#if| parser function? In my case I can't use {{tag| because I need to put a closing span tag </span> followed by an opening span tag <span> (with a specific class). Writing the HTML directly doesn't work, and writing as html entities doesn't work...

>> Update: I didn't realize that {{tag| allows you to specify the type parameter, to determine whether it's an opening tag, or closing tag, or self-closing tag, or opening and closing tag.

>> Update 2: I am quite mixed up. I see that {{tag| is a way of outputting a tag for documentation purposes, so that the tag won't be interpreted literally. How do I actually output a real tag that will be interpreted?

>> Update 3: I finally accomplished what I needed by extending a lua module. The specific case was Template:Quote which I imported into my wiki, I wanted to wrap the author in a <span> with a specific class. I saw that the value for author was being output from within a {{Comma separated list}} template which was directly calling Module:Separated entries. So I added a new parameter "span" to the {{Quote}} template which can be set to true, in which case the lua module separated entries will wrap each element of the list with a span tag. I saw that in lua I can either output an html string directly '<span>' .. doListStuff .. '</span>' or use mw.text.tag('span', {}, CONTENTS). In any case I did succeed, however it seems to me that it is much easier to output html from a lua module than it is from within Template transclusions or template parser functions. Lwangaman (talk) 20:24, 9 September 2020 (UTC)

It would help to know what you're actually trying to do here. It may be that, whatever you're trying to achieve, you haven't thought of the best way to go about it yet. ディノ千?!☎ Dinoguy1000 00:48, 10 September 2020 (UTC)

Leap seconds

Although not stated explicitly, I presume that when calculating at a second level of precision the difference between two dates where a leap second has occurred between them, the leap affects the final count. I was wondering if there is a switch to disregard this and calculate as if the leap second had not happened. This would be handy for math relating to the GPS time system (for instance), which does not observe leap seconds. Arlo Barnes (talk) 07:32, 26 September 2020 (UTC)

would like to use #ifexpr: with #len: and #var:

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I would like to use a expression to check a length.

{{#ifexpr:{{#len:{{#var:refs|}} }} > 10 | [..]

That provides no exeption, as far as good, but the

{{#len:{{#var:refs|}} }}

provides always 0 so the check doesn't work. Any Idea how to solve the issue or change the behavior? Gunnar.offel (talk) 11:33, 22 October 2020 (UTC)

Old topics like:
https://www.mediawiki.org/wiki/Help_talk:Extension:ParserFunctions/2014-2020#Ifeq_always_returns_false_when_using_a_variable
shows that it seems an old topic, any solutions? Gunnar.offel (talk) 11:51, 22 October 2020 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Explode PAGENAME

I've done a lot, but I can't seem to figure out why can't we just use


{{#explode:{{PAGENAME}}|:}}


It just doesn't work. On the other hand, writing the actual words (not substituting them):


{{#explode:Extension:ParserFunctions|:}}


will work. Why is that and what can be done? 31.147.156.166 (talk) 21:41, 6 December 2020 (UTC)

{{PAGENAME}} only returns the name of the current page, without the namespace. For example, (on this wiki) for the page Extension:ParserFunctions, it returns ParserFunctions. Therefore, {{ #explode: {{PAGENAME}} | : }} will only return something different from {{PAGENAME}} if the page name itself contains a colon. If you want to get the namespace of a page, you should instead use {{NAMESPACE}}: for Extension:ParserFunctions (again, on this wiki), it returns Extension. Alternatively, you could use {{FULLPAGENAME}}, which will return the namespace and page name together, but there's no point in doing that just to #explode it to get the namespace. ディノ千?!☎ Dinoguy1000 21:58, 6 December 2020 (UTC)
I was thinking without the namespace. It's more about removing extra characters from the title, like getting "car" from "John's car" if the page is named "John's car". 31.147.156.166 (talk) 20:48, 7 December 2020 (UTC)
For that specific case, you can just do {{ #explode: {{PAGENAME}} || 1 }}: #explode will operate on spaces if you omit or leave blank the second parameter.
If this still doesn't help for what you're trying to do, please post an actual use case from your wiki and I'll see if I can give you better/more tailored advice. ディノ千?!☎ Dinoguy1000 21:35, 7 December 2020 (UTC)
Don't forget that {{NAMESPACE}}, {{FULLPAGENAME}} and {{PAGENAME}} can take an optional parameter after a colon and before the closing braces. This simplifies a lot the design of templates without having to perform lot of tests:
  • You can use {{PAGENAME:{{{1|}}}}} to strip the leading whitespaces and colon and the namespace prefix from the value of {{{1|}}}. It will also strip the trailing whitespaces, and other whitespaces and underscores are normalized and compressed to their default meaningful presentation form (the form displayed in the rendered page titles, and in links to members of categories).
  • Or {{FULLPAGENAME:{{{1|}}}}} to just strip the leading whitespaces and colon (the namespace prefix will be kept). It will also strip the trailing whitespaces.
    A valid pagename (without the namespace or any interwiki/language prefix) may still contain a colon, if what is before that colon it is not recognized as a valid namespace or wiki prefix. Using {{#explode:}} will not make this difference and may strip too much in that case...
  • As well, {{NAMESPACE:{{{1|}}}}} will strip the leading colon and the pagename (containing interwiki prefixes followed by a possible remote namespace), keeping only a leading namespace recognized on the local wiki (with its trailing colon if that namespace is not the empty string for the default namespace).
    The form of the namespace (when it is not empty) present in the value returned by {{NAMESPACE:}} or {{FULLPAGENAME:}} is canonicalized to its default letter case (with a single capital initial), and recognized aliases are converted to the canonical name (e.g. the Image: alias will be converted to the canonical File: namespace).
    This allows comparing namespaces directly, e.g. in test labels of {{#switch:...}} or with {{#ifeq:...}}, without having to convert them to a unique letter case form (with {{UCFIRST:{{LC:...}}}}, or {{UC:...}}).
    This canonical form of any namespace may be localized in the default language of the local wiki. If you intend to write code that would work the same in different wikis, e.g. between English Wikipedia (which uses "Template:") and French Wikipedia (which uses "Modèle:" and recognizes "Template:" only as an alias), you may want to compare with namespace names returned by namespace numbers (using {{NS:number}}, where {{NS:0}} is the empty string for the main namespace of the wiki) instead of comparing them with explicit canonical namespace names (the namespace number for the "Template:" namespace in English is the same as the namespace number for the "Modèle:" namespace in French).
  • None of these three functions will touch/remove/canonicalize the namespaces and pagenames if they occur after any "interwiki:" prefix recognized by the local wiki. The links to external wikis will still work, but will be resolved and canonicalized externally by the target wiki itself when visiting them (as well the target wiki will resolve itself any resulting page redirect); such remote resolution may change over time (extremely rarely, hopefully, generally only during the early development phases of a starting wiki, when the localization to its default language is not finalized; but redirects on the target wiki may occur and change quite frequently). As well no test of existence of the target page on the target wiki is done when using any interwiki prefix, it is assumed to exist for the local wiki, which just validates its locally known interwiki prefix. Verdy p (talk) 19:40, 10 April 2024 (UTC)

Substitute #time

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Is it possible to substitute #time? Because it does not work when "subst:" is used. Thanks Terasail 21:44, 7 December 2020 (UTC)

For example: {{subst:#time:Y-m-d|now}} produces: 2020-12-08. —⁠andrybak (talk) 00:15, 8 December 2020 (UTC)
Ah thanks, I was't using "now" and that was not allowing it to be subst. Terasail 13:25, 9 December 2020 (UTC)
It should work without now as well: {{subst:#time:Y-m-d}} produces 2020-12-11. Tacsipacsi (talk) 18:31, 11 December 2020 (UTC)
Yeah I was using {{CURRENTMONTHNAME}} instead of "now" and it just gives an error message when you use subst: Terasail 21:21, 11 December 2020 (UTC)
It doesn’t make sense to subst: a parser function while keeping its input varying—what wikicode would you expect to get? If you subst: the input as well ({{subst:#time:Y-m-d|{{subst:CURRENTMONTHNAME}}}}), it works: 2020-12-11. Tacsipacsi (talk) 21:28, 11 December 2020 (UTC)
Yeah well I just wasn't thinking much about what I was doing when I first asked the question... I should have been a bit less lazy and thought more about what I was trying to do but it is what it is. Terasail 21:34, 11 December 2020 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.