Help talk:Extension:ParserFunctions/2021

Any objection to removing section StringFunctions?

According to this discussion at w:WP:VPT and phab:T8455, String functions were never enabled. Any objection if I delete this section? For the benefit of users coming here from various sister projects, we could replace it with a bullet list of links, for example, starting with:

and so on. Mathglot (talk) 22:06, 2 February 2021 (UTC)

Given User:The Earwig's response at WP:VPT, I won't delete this section. However, I may add a caveat near the top for the benefit of visitors from other Wikimedia projects, and a bullet list of links, as I suggested. I wasted a lot of time trying to figure out what was wrong, with nary a hint from this page. Mathglot (talk) 22:17, 2 February 2021 (UTC)
Definitely don't simply remove the documentation of these functions; they are used on third-party wikis. A good solution here would instead be something like Extension:Variables, where a visually-obvious notice gives a summary of the WMF view of the functionality, as well as a quick rundown (or a link to a list) of alternatives. ディノ千?!☎ Dinoguy1000 07:09, 3 February 2021 (UTC)
Since Wikipedia is not the only MediaWiki in the world .. no, you cant't just delete? Gunnar.offel (talk) 15:06, 12 February 2021 (UTC)

#switch doesn't work with #while

i tried to use a #while and deside by #switch how the reply would be.

in meta-code

     count:=3
     i:=0
     {{#while:
        | i < count
        | i++
          {{#switch:
           | 1 = 
           | count = 
           | #default = 
          }}
        }}

So, not work isn't exactly right, it works for the first run, all other runs are empty. i solved it now by several #ifeq - compares. Is it a wanted behavior? Gunnar.offel (talk) 18:19, 12 February 2021 (UTC)

#while is not added by Extension:ParserFunctions; I don't know what extension adds it. Looking at your code, and knowing how while loops operate in general, though, I wonder if you didn't forget a pipe before the #switch:
     count:=3
     i:=0
     {{#while:
       | i < count
       | i++
       | {{#switch:
          | 1 = 
          | count = 
          | #default = 
         }}
       }}
ディノ千?!☎ Dinoguy1000 05:29, 13 February 2021 (UTC)
The code was just to illustrate in which way i wanted do use.
No, the third pipe isn't correct, the #while has just a head and the instructions. i set the increment as first to get sure, that the loop terminates correctly. #while comes with the extension loops. i posted it here, since it works as said with #ifeq-compares.
I just wanted to get more information how it works. i could swear if i divide it in two pages it would works flawless (calling the secound page like a function). To look more in the philosophy may it be, that the #switch is set late in the page generation, so the loop couldn't generate properly? Gunnar.offel (talk) 11:45, 13 February 2021 (UTC)
I don't know any of the specifics of how/when #switch parsing happens, and I don't have any experience at all with the #while parser function (as you might have guessed when I incorrectly suggested you were missing a pipe in it). At this point, all I can offer is to experiment until you find something that works, and maybe file a bug report for constructions that you think should work, but don't currently (you would do this wherever the #while extension's issues are tracked, and if necessary mark your report(s) as belonging to that extension). I can at least say that it's unlikely any changes will be made to #switch or the other Ext:ParserFunctions functions to make them play nicely with #while, unless the cause of the issues is an actual bug in them that needs to be fixed for other reasons (but if you believe the cause is a bug in them, I'd encourage you to file a bug report anyways, especially if you can come up with a demonstration that only uses extensions enabled on WMF wikis). ディノ千?!☎ Dinoguy1000 22:42, 13 February 2021 (UTC)

explode, limit parameter, ... ???

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.


Doc: "{{#explode:string|delimiter|position|limit}}"

OK. Seems simple enough.

Doc: "The limit parameter is available in ParserFunctions only, not the standalone StringFunctions version,"

OK, checked.
So far so good.

Doc: "..., and allows you to limit the number of parts returned, ..."

Perfect.
That's what I'm looking for.

Doc: "..., with all remaining text included in the final part."

??? Come again.
If its "including all remaining text" in the "final result". What's the point of that limiter value?

O well, lets just see how it actually works.

  • explode: "{{#explode:aaa bbb ccc ddd eee fff| |2|2}}"
  • Looking for: "ccc ddd eee"
  • Returns: "" (ie: empty string)

Wtf ???

MediaWiki: 1.31.0
ParserFunctions: 1.6.0 MvGulik (talk) 16:30, 15 February 2021 (UTC)

I interpret the limit parameter to be a count, while the position is an index. So if you say divide it into at most 2 pieces and then ask for the 3rd piece (index 2) then you get an empty string. Try {{#explode:aaa bbb ccc ddd eee fff| |2|3}} instead. Clump (talk) 16:41, 15 February 2021 (UTC)
If you have a wiki with string functions enabled and Extension:Arrays handy, try the following code:
{{ #arraydefine: pos | 0,1,2,3,4,5,6,7 }}
{{ #arraydefine: lim | 0,1,2,3,4,5,6,7 }}
<table class="wikitable">
  <tr>
    <th>Pos &rarr;<br />Lim &darr;</th>
{{ #arrayprint: pos || $pos | <th>$pos</th> }}
  </tr>
{{ #arrayprint: lim || $lim | <nowiki/>
  <tr>
    <th>$lim</th>
{{ #arrayprint: pos || $pos | <td>"{{ #explode: aaa bbb ccc ddd eee fff || $pos | $lim }}"</td> }}
  </tr>
}}
</table>
It results in the following table (provided for those who don't have access to Ext:Arrays):
|-
!Pos
Lim
!0||1||2||3||4||5||6||7
|-
!0
|"aaa"||"bbb"||"ccc"||"ddd"||"eee"||"fff"||""||""
|-
!1
|"aaa bbb ccc ddd eee fff"||""||""||""||""||""||""||""
|-
!2
|"aaa"||"bbb ccc ddd eee fff"||""||""||""||""||""||""
|-
!3
|"aaa"||"bbb"||"ccc ddd eee fff"||""||""||""||""||""
|-
!4
|"aaa"||"bbb"||"ccc"||"ddd eee fff"||""||""||""||""
|-
!5
|"aaa"||"bbb"||"ccc"||"ddd"||"eee fff"||""||""||""
|-
!6
|"aaa"||"bbb"||"ccc"||"ddd"||"eee"||"fff"||""||""
|-
!7
|"aaa"||"bbb"||"ccc"||"ddd"||"eee"||"fff"||""||""
|-
|}
Based on this, I don't really understand what the limit parameter is doing, but it doesn't strike me as particularly useful (and it definitely doesn't behave as I'd expect from documentation that says it "allows you to limit the number of parts returned"). ディノ千?!☎ Dinoguy1000 23:09, 15 February 2021 (UTC)
Thanks (both).
I see it now. (also vaguely remembering having run into this a long time ago)
The limiter part is uses to control the initial splitting of the source string.
(that also means a direct "ccc ddd eee" output in this example case is not possible, ... with one single #explode that is.)
The doc page definitely seems in need of some adjusting on this. Although it is giving some hints towards how it actual works, its not very clear or none-ambiguous on this part in my view.
Definitely going to look into requesting the Extension:Arrays to be added to the wiki I'm running around in. (very nice table btw) MvGulik (talk) 12:46, 16 February 2021 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

#sub doesn't work

The #sub function doesn't work on sites where ParserFunctions is enabled. --  David L  discuter ► 19:02, 23 March 2021 (UTC)

Only #sub? And on what sites? #sub is from the Extension:StringFunctions.
Edit: Oh, it was integrated into Extension:ParserFunctions. Does those sites have it enabled in config ($wgPFEnableStringFunctions; if other string functions works, then they have)? MarMi wiki (talk) 23:45, 23 March 2021 (UTC)
I only tried the #sub function: it seems to not work on https://www.mediawiki.org and https://fr.wikibooks.org where ParserFunctions seems to be enabled according to Special:Version and b:fr:Special:Version.
--  David L  discuter ► 00:28, 24 March 2021 (UTC)
Integrated functions from StringFunctions needs to be enabled in config in order to work, read the extension pages. I'm guessing that after enabling, they should also appear on the parser functions list (at the bottom of the Special:Version).
Edit: They indeed appear on that function list: https://donate.wikimedia.org/wiki/Special:Version, where that extension is enabled by default (Per-wiki settings for Wikimedia wikis from https://meta.wikimedia.org/wiki/Requesting_wiki_configuration_changes#See_also, search for wmgPFEnableStringFunctions).
Since on your wikis there is no "sub" function, then most likely that extension isn't enabled. And judging by https://phabricator.wikimedia.org/T254782, it most likely wont be enabled. MarMi wiki (talk) 01:54, 24 March 2021 (UTC)
The mentioned wikis are both WMF wikis, and StringFunctions will never be enabled on WMF wikis. The recommended alternative is Lua via Scribunto. ディノ千?!☎ Dinoguy1000 04:23, 24 March 2021 (UTC)
Specifically Module:String in this case. * Pppery * it has begun 04:26, 24 March 2021 (UTC)
If the module is not enabled, it should not appear in Special:Version, or at least there should be a column indicating the module status (enabled or disabled).
I found another solution to use in my template, copied from en.wikipedia.org.
Thanks for replies.   David L  discuter ► 09:31, 24 March 2021 (UTC)
ParserFunctions is enabled on these wikis (you'll note that the functions #if and #expr, among others, work just fine); however, the StringFunctions components of the extension (including #sub) are behind a configuration flag, which is not enabled on WMF wikis. ディノ千?!☎ Dinoguy1000 12:39, 24 March 2021 (UTC)

#ifeq question

Hello! {{#ifeq: string 1 | string 2 | value if identical | value if different }} Can you make /value if not identical/ render /string 1/? Jonteemil (talk) 18:34, 2 July 2021 (UTC)

{{#ifeq: string 1 | string 2 | value if identical | string 1 }}? MarMi wiki (talk) 18:58, 2 July 2021 (UTC)
If you mean without repeating yourself, there's no straightforward way without using other extensions. The obvious suggestion is Extension:Scribunto , though this does require you to be able to code in Lua; the one I'm personally much more familiar/comfortable with is Extension:Variables , though it's unfortunately basically unmaintained, and parser changes in future MW versions may break it at some point. ディノ千?!☎ Dinoguy1000 19:18, 2 July 2021 (UTC)

Time, timel not compatible with MediaWiki timestamp (?)

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.

It seems that both #time and #timel do not support MediaWiki's timestamp format. That's strange from my perspective. People may want to do something like:
{{#time: Y m d | {{REVISIONTIMESTAMP}} }}
How do you usually do such a thing? I mean, applying a custom format to a {{REVISIONTIMESTAMP}} (20250314042202). I have a way in mind but it's pretty complicated and unreadable without a template or Lua. Valerio Bozzolan (talk) 01:03, 3 July 2021 (UTC)
This seems to work fine to me. For example, {{REVISIONTIMESTAMP}} here currently returns 20250314042202, and {{#time: Y m d | {{REVISIONTIMESTAMP}} }} results in 2025 03 14. ディノ千?!☎ Dinoguy1000 01:17, 3 July 2021 (UTC)
I absolutely don't know why now it works also for me. Thank you and my apologies. Valerio Bozzolan (talk) 12:18, 5 July 2021 (UTC)
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

#ifexist for a "real" article

Is there any way to test for the article being a "real" one -- i.e. not being a redirect? ~GhostInTheMachine talk to me 10:55, 3 October 2021 (UTC)

I don’t think it’s possible using ParserFunctions. However, if you have Scribunto installed (on Wikimedia projects it’s installed), you can use it, as its mw.title objects’ properties include isRedirect. Tacsipacsi (talk) 11:27, 3 October 2021 (UTC)
If you just need to be able to use redrect logic in a template, you might want to have a look at wikipedia:Template:Ifexist not redirect. Robin Hood  (talk) 12:57, 3 October 2021 (UTC)
That template uses wikipedia:Module:Redirect, which itself uses the isRedirect property. It's a convenient packaging if you're just looking for the functionality and don't want to spend time writing something yourself, but if you aren't able to use Lua modules it won't help you. ディノ千?!☎ Dinoguy1000 00:04, 4 October 2021 (UTC)
Oh, I didn't look closely enough. I saw other checks there and just figured there was some trickery going on. My mistake. Robin Hood  (talk) 07:54, 4 October 2021 (UTC)

use the output of Special:Editcount/User in #expr

Hi all, thanks for having an eye this: I want to use the output of Special:Editcount/User in #expr to calculate something. But of course the output is handled a string, even if I split it into its figures with #sub. So how can I make it being recognized as int? Any idea? Thank you in advance! --~ Plasmarelais (talk) 14:01, 2 November 2021 (UTC)

{{Special:Editcount/Jrooksjr}} output should be interger! At, least on Fandom it is!
I see it is not turned on on MediaWiki though! Jrooksjr (talk) 21:39, 2 November 2021 (UTC)

Amazigh date

Hi all, I'm one of the admins of shi.wikipedia.org. Recently, I want to insert the amazigh date on this project according to the Berber calendar I'm here to ask about adding this calendar in the function #time. Thank you a lot Lhoussine AIT TAYFST (talk) 18:19, 4 November 2021 (UTC)