Help talk:Extension:ParserFunctions/2013

From MediaWiki.org
Jump to navigation Jump to search

How to use tag function within parser function?[edit]

I'm trying to build an if-clause that automatically inserts

== References == <references />

into the article if there are some <ref>s entered in the wikitext. If there's no <ref> no heading and no references/ should be inserted.

I tried different things but none of them work - that means I always get "Heading and stuff" even if there's no ref tag entered in the article:

{{#if: <references /> | Heading and stuff | }}
{{#if: {{#tag:references|}} | Heading and stuff | }}

The docu says "Content inside parser tags (such as nowiki) is temporarily replaced by a unique code" and shows that tags won't work.
Is there a workaround to let <references /> be parsed inside the #if?
--Stefahn (talk) 17:38, 9 November 2012 (UTC)

Just for the record: Found a solution/workaround now :) Stefahn (talk) 17:59, 3 April 2013 (UTC)

Expression error: Unexpected < operator.[edit]

I'm trying to add Extension:DPL Page Name S/N Maker (using SemanticForms) (which is really just a complex template combining multiple other extensions) to a corporate wiki, but for any result higher than "00001" it keeps kicking out the error message Expression error: Unexpected < operator. This error isn't covered on the help page here, but based on the documentation I assumed that it must be a stray < character or possibly a tag inside a function where tags aren't allowed. However, even when I remove all instances of the < character from the template (by eliminating the comments, the <strong> tags, and the <noinclude> tags), the error message persists.

Here is the text of the template:

[removed]

Any idea what the problem is and/or how I can correct it? Thanks! ~ Michael Chidester (Contact) 15:07, 22 March 2013 (UTC)

Solution[edit]

Ultimately I determined that this was a DPL conflict, possibly due to the {{expr:}} function refusing to parse the standard output format of DPL. To help anyone having this problem in the future, here is my modified code, changing out the deprecated string functions for their replacements and modifying the DPL output to produce a regular string rather than a link:

{{#if: {{{form|}}}
  |  {{#ifexist: Form:{{{form|}}} 
       |
       | <strong class="error">Warning! The form "{{{form|}}}" may not be a valid form name!</strong>
     }}
  |
}}<!---
-->{{#if: {{{form|}}}
     | {{#ifeq: {{lc:{{NS:{{{namespace|}}} }} }} 
         | {{lc:{{{namespace|}}} }}
         | 
         | <strong class="error">Warning! "{{{namespace}}}" may not be a valid namespace name!</strong>
       }}
     |
   }}<!---
-->The next document number is '''<!--
-->{{#if: {{{namespace|}}} | {{{namespace|}}}: }}{{{prefix|}}}<!--
   -->{{padleft:<!----------- (X+1)                         =>  0000(X+1) 
      -->{{#expr:<!---------- 0000X+1                       =>  (X+1)
         -->{{replace|<!----- "Namespace:prefix0000X"       =>  "0000X" 
            -->{{replace|<!-- "*[[Namespace:prefix0000X]]"  =>  "Namespace:prefix0000X"
               -->{{#dpl:<!-- return pages named "*[[Namespace:prefix0000X]]"
                  -->titleregexp =^{{{prefix|}}}[0-9]{{{{pad|5}}}}$<!--
                  -->| namespace = {{{namespace|}}}<!--
                  -->| order = descending<!--
                  -->| mode = userformat<!--
                  -->| format = ,%PAGE%<!--
                  -->| noresultsheader = {{padleft:0|{{{pad|5}}}|0}}<!--
                  -->| count = 1
                  }}
               |/^([^{{!}}]+\{{!}}){1}([^\]]+).*/  
               |\2
               }}
            | {{#if: {{{namespace|}}} | {{{namespace|}}}:}}{{{prefix|}}}
            |
            }}
         +1
         }}
     | {{{pad|5}}}
     | 0
     }}'''
----
{{#if: {{{form|}}}
  | {{#forminput: {{{form|}}}
      | {{{width|20}}}
      | {{{prefix|}}}<!--
      -->{{padleft:<!----------- (X+1)                         =>  0000(X+1) 
         -->{{#expr:<!---------- 0000X+1                       =>  (X+1)
            -->{{replace|<!----- "Namespace:prefix0000X"       =>  "0000X" 
               -->{{replace|<!-- "*[[Namespace:prefix0000X]]"  =>  "Namespace:prefix0000X"
                  -->{{#dpl:<!-- return pages named "*[[Namespace:prefix0000X]]"
                     -->titleregexp =^{{{prefix|}}}[0-9]{{{{pad|5}}}}$<!--
                     -->| namespace = {{{namespace|}}}<!--
                     -->| order = descending<!--
                     -->| mode = userformat<!--
                     -->| format = ,%PAGE%<!--
                     -->| noresultsheader = {{padleft:0|{{{pad|5}}}|0}}<!--
                     -->| count = 1
                     }}
                  |/^([^{{!}}]+\{{!}}){1}([^\]]+).*/  
                  |\2
                  }}
               |{{#if: {{{namespace|}}} | {{{namespace|}}}:}}{{{prefix|}}}
               |
               }}
            +1
            }}
        | {{{pad|5}}}
        | 0
        }}
     | {{{buttonlabel|Add}}}
     | {{#if: {{{namespace|}}} | namespace = {{{namespace|}}} }}  
     }}
  | <includeonly><strong class="error">Warning! You haven't specified a SemanticForm for page creation! Please specify a SemanticForm name.</strong></includeonly>
}}<noinclude>
{{documentation}}
</noinclude>

Cheers. ~ Michael Chidester (Contact) 15:40, 26 March 2013 (UTC)

handling of incomplete dates[edit]

"Full or partial absolute dates can be specified; the function will "fill in" parts of the date that are not specified using the current values:"

I think this is not acceptable behaviour, unless it can be switched on or off. I am parsing incomeplete dates, and if you have a historical Person in a wiki with a birth date "May 1875" than the #time function should return nothing for a day and not the current day!! — Preceding unsigned comment added by Krabina (talkcontribs) 07:05, September 19, 2013

  • You have full control over how you format the output of the #time function. If you only want month, year, then {{#time:F Y|{{{month|}}} {{{year|}}}}} produces May 1875 when you pass |month=may |year=1875. If you want to make it more complicated, then try playing with:
{{#time:{{#if:{{{day|}}}|d}} {{#if:{{{month|}}}|F}} {{#if:{{{year|}}}|Y}}|{{{month|1}}}/{{{day|1}}}/{{{year|100}}}}}
  • |day= |month= |year=
  • |day=5 |month= |year=
  • 05
  • |day=5 |month=5 |year=
  • 05 May
  • |day=5 |month= |year=1875
  • 05 1875
  • |day=5 |month=5 |year=1875
  • 05 May 1875
  • |day= |month=5 |year=1875
  • May 1875
  • |day= |month= |year=1875
  • 1875
  • |day= |month=5 |year=
  • May
You can also change the layout so that it looks like any of these:
  • May 5, 1875
  • 5/05/1875
  • 1875, 5 05
If you want to make it really complex:
{{#time:{{#if:{{{year|}}}|{{#if:{{{month|}}}|{{#if:{{{day|}}}|F j, Y|F Y}}|Y}}|{{#if:{{{month|}}}|F|"<small>(Date unknown)</small>"}}}}|{{{month|1}}}/{{{day|1}}}/{{{year|100}}}}}
  • |day= |month= |year=
  • (Date unknown)
  • |day=5 |month= |year=
  • (Date unknown)
  • |day= |month=5 |year=
  • May
  • |day= |month= |year=1875
  • 1875
  • |day=5 |month=5 |year=
  • May 5
  • |day=5 |month= |year=1875
  • 1875
  • |day= |month=5 |year=1875
  • May 1875
  • |day=5 |month=5 |year=1875
  • May 5, 1875
I hope this satisfies your need... Technical 13 (talk) 14:12, 19 September 2013 (UTC)
Thank you for these great examples, but it's not quite what I need. I have dates and some of them are incomplete. Say "24 April 1875" or "Mai 1920". If I use {{#time:j|24 April 1875}} I get "24" which is fine, but with {{#time:j|April 1986}} I recieve "1". But it rather should return an error, because if there is no day present I don't want to get a day... --Krabina (talk) 06:39, 24 September 2013 (UTC)
The problem is that {{#time:j|April 2013}} returns the same result as {{#time:j|1 April}}. Both are 1 but in case of April 2013 it is an assumption. Depending what users are doing with the result things could take a wrong turn on there wiki's. The desired result should be something that can not be a day, like 0 so users can "catch" it. Regards, --Jongfeli (talk) 10:00, 24 September 2013 (UTC)