Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some MediaWiki help - evaluation in a template
Need some MediaWiki help - evaluation in a template
#1
Question 
G'day! I can't figure out where on the MediaWiki site to ask for help with coding an evaluation in a template, so I'll start by asking here:

First question: Can I evaluate the value of one field based on the contents of a different field?

Second question: Can I use wildcards in an evaluation? If yes, what is the syntax of the wildcards?

The specific case:

I've imported the Wikipedia template "Infobox" to the freebie wiki and have written a template that uses it. Right now, my code for the "image" parameter in the calling template is an if/else check that displays the image if a parameter exists or adds a category if the parameter is blank:
|image = {{#if:{{{image|}}} |[[File:{{{image|}}}|250px]] |[[Category:Page Needing Image]]}}

I now have a request for a third case check in that line:
  1. if no value is passed to "image", display nothing and add the category "Page Needing Image" to the page, exactly as above;
  2. elseif a value is passed to "image" and a value that contains a call to a template named "unavailable" is passed to "data1", display the file with a gray background;
  3. else, display the file with the default background, exactly as above.

The value passed to "data1" will contain some but not all of a URL, one or two template calls, or a comment, with no way to know what order they'll be in.

I'm assuming that it's safe to nest "if" statements to create an if/elseif/else check. It's the "elseif" part of this that I'm having trouble with.

Any help with coding this evaluation would be appreciated...
--
Rob Kelk

Sticks and stones can break your bones,
But words can break your heart.
- unknown
Reply
RE: Need some MediaWiki help - evaluation in a template
#2
Huh, let's see.  Elsif is really just syntatic sugar for another if/else block, so that's easy enough.


Code:
{{{image|
  {{#if: {{#pos:{{{image}}}|unavailable}}
   |<bgcolor=#CCC>[[File:{{{image}}}]]
   |[[File:{{{image}}}}]]
  }}
|[[Category:Page Needing Image]]}}}


Something like this maybe?  But you'd need to get support for pos from the admins I think:

Quote:All of these functions (len, pos, rpos, sub, replace, explode) are integrated from the StringFunctions extension, but are only available if an administrator sets $wgPFEnableStringFunctions = true; in LocalSettings.php.
"Kitto daijoubu da yo." - Sakura Kinomoto
Reply
RE: Need some MediaWiki help - evaluation in a template
#3
Thanks. Since I'm the founding admin of the freebie wiki, I suspect they'll at least listen to the request if I need to make it.
--
Rob Kelk

Sticks and stones can break your bones,
But words can break your heart.
- unknown
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)