[go: up one dir, main page]

Jump to content

Help talk:Parser function

Add topic
From Meta, a Wikimedia project coordination wiki
Latest comment: 12 years ago by Skierpage in topic "Use of result" section is unintelligible

Merge proposal

[edit]

In spite of the names of the pages, I see no reason to merge Help:Parser function and ParserFunctions. The former is about the concept and about the parser functions in MediaWiki itself, the second about a specific extension.--Patrick 11:56, 22 January 2007 (UTC)Reply

I removed the merge tags, such a proposal can be discussed here.--Patrick 10:43, 23 January 2007 (UTC)Reply

Caution

[edit]

About the UC function, it currently says:

  • {{uc:ä β ß}} gives Ä Β SS, expected: Ä Β SS.

This expectation is incorrect. (a) what to expect from uppercasing "ß" depends on time in history and language and context in print, so "ß" (lower case) and "ß" (upper case but not in Unicode), "ſz" "ſs" "Sz", "Ss", "S", "SZ", "SS" are all correct, it simply depends; (b) uppercasing a single character to a bigraph which is represented by 2 distinct characters, however, is highly problematic in some circumstances. E.g. where we have "Ußßlogge" as a localization string, we should not uppercase it as "USSSSLOGGE" but "USSLOGGE", better "UßßLOGGE" (with the (historic) uppercase "ß" which is not in Unicode) - the same uppercasing when done by web browsers with the appropriate CSS, depending on browser make and their bugs, will yield: "UßßLOGGE", "U??LOGGE", "ULOGGE", "U__LOGGE", USSSSLOG" (note the truncation of the string in the last exsample) Another problem region was with UCFIRST, which may transform "ßööver" to "SSööver" instead of "Ssööver" or "ßÖÖVER" to "SsÖÖVER" instead of "SSÖÖVER" etc.

I think, this may not be the right place to discuss the issue. If you know where this should go better, please be so kind and forward it. --Purodha Blissenbach 14:10, 18 February 2007 (UTC)Reply

Complicated if parser function statement

[edit]

I want a template to accept a single parameter but change the output relative to what that perimeter is (unnamed and named). This code works correctly if I give it an unnamed parameter (where it links to Wikipedia with it) and if I specify "wikt=whatever" (where it links to Wiktionary:whatever) but if I don't specify a parameter it defaults to Wiktionary instead of Wikipedia (which I don't want). Also, I'd like the "wikt" parameter to default to {{PAGENAME}} without having to specify a name ("wikt=name"). Did you get all that? Now, is it possible and, if so, how do I do it? ;)

{{#if:{{{1|}}}|
	[[Wikipedia: {{#if:{{{1|}}}|{{{1}}}|{{PAGENAME}}}}]]|
	{{#if:{{{|wikt}}}|
		[[Wiktionary: {{#if:{{{1|}}}|{{{1}}}|{{PAGENAME}}}}]]
	}}
}}

-Eep² 03:14, 8 August 2007 (UTC)Reply

You mean like Template:T link?--Patrick (talk) 06:09, 8 August 2007 (UTC)Reply
Well, let's see: {{t link}} -> Wikipedia: Parser function (yes), {{t link|test}} -> Wikipedia: test (yes, but can it also support {{{1}}}| to not show the "Wikipedia:" part?), {{t link|wikt=test}} -> Wiktionary: test (yes, but can it also support an option like {{{1}}}| to not show the "Wiktionary:" part?). Almost... -Eep² 18:33, 8 August 2007 (UTC)Reply
Done.--Patrick (talk) 19:34, 8 August 2007 (UTC)Reply
Let's see: {{t link|test|}} -> test and {{t link|wikt=test|}} -> test work but then the above ways without the {{{1}}}| and wikt={{{1}}}| no longer work. :/ -Eep² 20:49, 8 August 2007 (UTC)Reply
What is wrong?
Patrick (talk) 21:48, 8 August 2007 (UTC)Reply
I want the "Wikipedia:" and "Wiktionary:" text in the link for the above declarations (as it was before you changed the template in an attempt to make the {{{1}}}| code work) but not for these (check the page source to see the difference):
  • {{t link|test|}} -> test
  • {{t link|wikt=test|}} -> test
-Eep² 04:15, 9 August 2007 (UTC)Reply
I do not see the logic of putting the prefix before PAGENAME but not before {{{1}}} (done), but since the example template specifies the format for each of the 4 cases separately, it is trivial to adjust each as desired.--Patrick (talk) 07:20, 9 August 2007 (UTC)Reply
  1. {{t link|wikt=test}} should be Wiktionary: test but instead is Wiktionary: test
  2. {{t link|wikt=test|}} should be test and is: test
  3. {{t link|test|}} should be test and is: test
More complicated examples (which I don't need):
Ah well. But if you could make #1 work above, thanks. -Eep² 10:11, 9 August 2007 (UTC)Reply
You started with a question about using a single named or unnamed parameter, and a default {{PAGENAME}}, but these examples are different, with up to 3 parameters, without {{PAGENAME}}, and with an unused parameter value "test". It is all not very clear.--Patrick (talk) 13:10, 9 August 2007 (UTC)Reply
Disregard the last 4 examples (which I said I don't need); they're just for illustrative purposes. I would like example #1 (but numbered list, not the bullets) from above to work as I indicated though, however. -Eep² 04:03, 10 August 2007 (UTC)Reply
Done.--Patrick (talk) 15:09, 10 August 2007 (UTC)Reply
Thanks...but now the first example no longer works:
Should be: [[Wikipedia: {{PAGENAME}}]] -> Wikipedia: Parser function
-Eep² 16:15, 10 August 2007 (UTC)Reply
It was not in your list of three. Done.--Patrick (talk) 13:14, 11 August 2007 (UTC)Reply
Not that list, no, because it was in the initial description and stopped working before the last update. Anyway, it all works now; thanks! I tried indenting the template code to make it easier to read but I'm not sure if I got all the branching right. Can you check it? I may have to edit this code and the easier it is to read, the better. -Eep² 02:43, 13 August 2007 (UTC)Reply
Looking at Template talk:T link it seems OK.--Patrick (talk) 03:29, 13 August 2007 (UTC)Reply
Well, the talk page doesn't have the template code in it, which is what I indented... -Eep² 05:16, 13 August 2007 (UTC)Reply
I mean that the indentation has not introduced errors in the results.--Patrick (talk) 11:32, 13 August 2007 (UTC)Reply

Lowercase this page name

[edit]

Add an example of a common task: lowercase this page name: {{lc:{{PAGENAME}}}}:

It's a great parser function.

Not

It's a great Parser function.

Jidanni 22:48, 24 December 2007 (UTC)Reply

Table with conditional rows

[edit]

I'm trying to make a template on a friends mediawiki install but i can't quiet get it to work right. this is the code i have at the moment http://pastebin.ca/874424, but when i use it it repeats the section name twice (eg: Name Name TestName). Peachey88 (Contribs) (Wikipedia: User) (Wikipedia: Talk) 08:25, 27 January 2008 (UTC)Reply

"Name TestName" is conditionally put, in HTML, including "new row" code, so you don't need the same also in wiki-table-code.--Patrick (talk) 12:44, 27 January 2008 (UTC)Reply

NS:0 gives nothing, but what would chop things?

[edit]

Recently I was editing a template which creates categories from a base name.

For example, let's say that there is a category called Rocks. All of the subcategories start with Rocks by.

I create a template with {{#if:{{{rockcat}}}|[[:Category:Rocks by {{{rockcat}}}]]}}.

When creating an example use of the tamplate using rockcat, I want to back peddle on the category name to remove (space)by(space) to just use the category Rocks.

Can that be done in wikicode? - LA @ 12:13, 4 March 2008 (UTC)Reply

Not now on Wikimedia wikis, but there are plans for installing mw:Extension:StringFunctions, see bugzilla:6455.--Patrick (talk) 12:58, 4 March 2008 (UTC)Reply

wanted: TRIM function to remove whitespace from start and end

[edit]

The TRIM function should "remove newlines and spaces from the start and end" like LC and UC do, but without the case change. I can use anchorencode for my application, but I don't really need the added functionality. The purpose is just to be able to do {{#TRIM:{{processing}}}}.jpg, when processing (for example, explode) can end up with whitespace at the end or beginning. --84.128.185.208 09:31, 4 June 2008 (UTC)Reply

Actually, a template with {{#if:true|{{{1}}} }} works well as trim. --84.128.185.208 16:13, 4 June 2008 (UTC)Reply
... unless there is a = in the input. Use {{trim|1= some strings }} if you can't be sure of this. See my docs for an example. --84.128.185.201 10:12, 6 June 2008 (UTC)Reply
A named parameter is trimmed anyway, so then you can also simply take Template:1x.--Patrick (talk) 00:21, 7 June 2008 (UTC)Reply
{{padleft:{{{1}}}}} also used to work for this. --63.239.69.1 23:15, 9 February 2009 (UTC)Reply

Variable declaration

[edit]

I realise that this may be a bit too much like a programming language but is there any way to make a variable declaration? It would help avoid lots of useless repetition? Blue-Haired Lawyer 11:14, 13 August 2008 (UTC)Reply

There is the extension mw:Extension:VariablesExtension.--Patrick (talk) 15:19, 13 August 2008 (UTC)Reply
Thanks I hadn't spotted this. Doesn't look like there's any chance of having this on English Wikipedia anything soon though. Blue-Haired Lawyer 12:07, 14 August 2008 (UTC)Reply

How do I program in parser functions so my templates can function?

[edit]

How do I program in parser functions?

URLENCODE and Square Brackets

[edit]

Wikipedia discussion re using "illegal" URI characters (especially square brackets) suggests using the URLENCODE parser function. I too am trying to embed square brackets in a URL. I am trying to cite to a Google Scholar footnote, but Google Scholar uses square brackets to link to a footnote subpage. For example, the particular URL I am trying to reference is:

http://scholar.google.com/scholar_case?case=1552575106454200922&q=235+B.R.+527&hl=en&as_sdt=2,44#[7]

When I try to directly embed square brackets in the URL, the resulting reference does not present properly. The UTF-8 representations for the square brackets are 005B and 005D respectively. I unsuccessfully tried implementing urlencode, using the different parameters set forth in examples. That is, in lieu of "[7]", I tried {{urlencode:[ 7 ]}} and {{urlencode:[7]}} without parameters and with the WIKI and PATH parameters. I also tried directly embedding percent-encoding arbitrary data, %5B7%5D, but that did not work either. The Parser function help page does not explicitly discuss square brackets. Can this function be used to embed square brackets in an URL? --Rpclod 15:55, 29 January 2011 (UTC) | wp talk pageReply

"Use of result" section is unintelligible

[edit]
"Use of result
The result, like that of a variable or template, and like a template parameter value, can be used in the following ways:"

?!?! I can't rewrite this because I don't know what it's trying to say

Avoid passive voice, split it up into two sentences (the concept "result" and then how "You can use"), replace "that of" with explicit phrase, motivate each example, and show its result immediately after. Thanks for all you do. -- skierpage (talk) 20:42, 21 September 2012 (UTC)Reply