wiki:Internal Functions  

Wiki:Documentation

The wiki is an ever-evolving project, with new functions being added as needed. Functions that have been proposed but not implemented, are documented at Proposed Functions.

Contents [hide]

Decision-Making Functions

#if

syntax: {{#if: condition|then|else}}

  • Examples:
    • {{#if: {{{1|}}}|{{{1}}}|none}} - displays the first parameter if the first parameter is defined and is not blank, else it displays none.
    • {{#if: {{{2|}}}|{{{2}}}|{{{1}}}}}

#ifeq

syntax: {{#ifeq:value1|value2|code if equal|code if not equal}}

  • NOTE: leading and trailing spaces in value1 and value2 are significant in this function!

#ifexist

syntax: {{#ifexist: pagename|then|else}}

  • Returns True if the page exists.
    • game db wiki namespace references will return True if the db entry OR the wiki text exists.

#ifexistwiki

  • Rationale: #ifexistwiki, coupled with #ifblank, would allow us to do things, or specifically NOT do things, in the pre and post templates dependent on the wiki text record existing and being not blank. It would also allow us to auto-categorize all db entries that have NO wiki text, helping us to locate records in need of CM love.
syntax: {{#ifexistwiki:game_id|db_name:pagename|then|else}}
  • Returns True only if the wiki text record for the referenced game db entry exists.
  • Note: To test the existence of the db half, use #db with the id field. ALL db pages must have this, so #db will return nothing (false) if the db entry does not exist!

#ifblank

syntax: {{#ifblank:pagename|then|else}}

  • Returns True if the wiki text record for pagename is blank or is not defined.

#switch, #ciswitch

syntax:

{{#switch: target
|value1|valuen...=output
|valuea|valuez...=output
|#default=default_output
|default_output}}
  • This is like a case statement.
  • #ciswitch is identical to #switch except that it is case-insensitive!

Alternately, the default can be explicitly defined using the #default operator.
syntax: {{#switch: target|value1|valuen...=output|valuea|valuez...=output|#default=default_output|}}

The #default operator is useful if the expanded content of default_output might contain an equals sign (=). Also, switch does NOT like having one and only one value line. In this case, if you are planning for future expansion or just need an ifeq with multiple possible matching values, use #default to give it 2 value lines. It just makes it feel better. If #default is used, you still MUST end the function with |}}

As I mentioned, #switch does not like single-output uses, so I often add a value-output pair like |junk=junk just to work around this. In #switch, output cannot be blank so |value=  should be used. Blank is treated as null here, so a blank space for output will NOT work, but   will!

default_output on the final line may be null, but not on #default=, if used.

#lthan:, #gthan:

syntax: {{#lthan:string1|string2}}
{{#gthan:string1|string2}}
Returns 1 (true) if string1 is less than (or greater than) string2, else returns null (false). IF string1 and string2 are both numeric, this is a numeric comparison, else it is a string comparison.

Examples: {{#if:{{#lthan:1|2}}|this is true|not seen}}

{{#if:{{#gthan:1|2}}|not seen|this is false}}
{{#if:{{#gthan:A|z}}|this is true|not seen}}

Numerical Functions

#arith

syntax: {{#arith:value1|operator|value2|min_chars|decimals|debug}}

Will apply operator against value1 and value2.

Valid operators are: + - / * % ^ < > <= >= ==

If value1 or value2 is not numeric, or would result in an undefined value, the function returns null.

For division: if value2 is zero, the function returns null.

For modulus, if value2 is zero or a non-integer, the function returns null.

For fractional operations, min_chars is the minimum number of total characters to display, including the decimal (.) and any sign (-). If greater than the result it will cause left-zero-padding. Also, decimals will round the decimal portion to the indicated number of digits. Lastly, if debug is "1" and ONLY if the viewer is an Admin the function will display additional debugging information.

formatnum

syntax: {{formatnum:value}}

  • Receives a number (value) and formats it for standard numeric output
  • value may contain commas and a decimal point.

See MediaWiki Documentation of this function

Examples:

  • {{formatnum:1257}} would output 1,257
  • {{formatnum:135.6}} would output 135.6
  • {{formatnum:2,582}} would output 2,582

String Manipulation Functions

#replace

syntax: {{#replace:string|regex|value}}

  • Replaces characters matching regex in string with value, where the delimiter is defined by regex. This is NOT a full regex line, it is a mask. If you were writing regex, this would be the pattern matching portion of that.
  • For a definition and simple reference of regex, see this article at Wikipedia
  • Pipe ("|") can be used as a delimeter by using &#124; for the value of regex

#explode

syntax: {{#explode:string|regex|n}}

  • Returns the nth (BASE 0) "word" in string, where the delimiter is defined by regex. This is NOT a full regex line, it is a mask. If you were writing regex, this would be the pattern matching portion of that.
  • If regex is null, #explode returns nth character, not nth word!
  • Use \s for space, so {{#explode:This is a test|\s|1}} should return: is
  • If n is negative, distance is measured from the end of the string.
  • Space is tricky to define, so space is the default delimiter.
  • Negative values for n will return the nth "word" from the end.
  • Pipe ("|") can be used as a delimeter by using &#124; for the value of regex

Examples:

  • {{#explode:This is a test|\s|2}} returns: a
  • {{#explode:This is a test|\s}} returns: This
  • {{#explode:This is a test|\s|-1}} returns: test
  • {{#explode:x,y,z|,|0}} returns: x
  • {{#explode:bippity,boppity,boo|,|1}} returns: boppity

#strlen:

syntax: {{#strlen:string}}

Returns the length of the string.

Example: {{#if:{{#gthan:{{#strlen:Bludwyng}}|5}}|this is true|not seen}}

uc:

syntax: {{uc:string}}

  • Converts all of string to upper-case

lc:

syntax: {{lc:string}}

  • Converts all of string to lower-case

ucfirst:

syntax: {{ucfirst:string}}

  • Converts the first character in string to upper-case

lcfirst:

syntax: {{lcfirst:string}}

  • Converts the first character in string to lower-case

#strftime:

syntax: {{#strftime:mask}}

  • Outputs all or part of the current date/time
    • Works exactly as the C function of the same name. See this page for the full values available for mask.

List Manipulation Functions

#commalist

syntax: {{#commalist:pattern|separator|list1|list2|listn..}}

  • Accepts one to seven comma-delimited lists of items, and expands the lists, substituting the values from the lists into pattern wherever it sees %value1%, %value2%, ... %value7%.
  • separator is placed between output values, but not before the first one, and not after the last one. separator may be null.
  • Special codes found in pattern:
    • %value1%, %value2%, ... %value7% tells the function where to place the values it slices from list1,list2, etc.
    • %pipe% allows the inclusion of the pipe character (|) in the output.
    • %space% is, obviously, a space.
    • %lbrace% and %rbrace% makes it possible for the pattern to create a template call.

The primary list (list1) controls the output. If the other lists are longer the output will be no longer than list1.

NOTE: #if expressions in the pattern cannot use fields in the parent template, only %valuex% values. In other words {{{field}}} will not work as a conditional expression inside the pattern.

If you need to use a comma inside of the list, you can use &#44; instead.

Examples:

  • Task: Produce category links from a list of places the mob is found
  • Code: {{#commalist:[[Category:%value1% (Aion Mobs by Place)]]|,%space%|place1,place2,place3}}
  • Returns: [[Category:place1 (Aion Mobs by Place)]], [[Category:place2 (Aion Mobs by Place)]], [[Category:place3 (Aion Mobs by Place)]]

  • Task: Produce the Related Mobs list in the right-hand column of a quest page.
  • Code: Related Mobs:<ul>{{#commalist:<li>[[%value1% (RoMMob)%pipe%%value%]]</li>||mob1,mob2,mob3}}</ul>
  • Returns: Related Mobs:<ul><li>[[mob1 (RoM Mob)|mob1]]</li><li>[[mob2 (RoM Mob)|mob2]]</li><li>[[mob3 (RoM Mob)|mob3]]</li></ul>

  • Task: Produce the Known Drops list in the right-hand column of a mob page. Note that 2 lists are used.
  • Code: Known Drops:<ul>{{#commalist:<li>%lbrace%%lbrace%AionItem%pipe%value1%%pipe%%pipe%%pipe%%value2%%rbrace%%rbrace%</li>|,|item1,item2,item3|quality1,quality2,quality3}}</ul>
  • Returns: Known Drops:<ul><li>{{AionItem|item1|||quality1}}</li><li>{{AionItem|item2|||quality2}}</li><li>{{AionItem|item3|||quality3}}</li></ul>

  • Task: Turn an unlinked comma-list into a linked comma-list of locations
  • Code: Location(s): {{#commalist:[[%value1% (Aion Place)]]|, |place1,place2,place3}}
  • Returns: Location(s): [[place1 (Aion Place)]], [[place2 (Aion Place)]], [[place3 (Aion Place)]]

#clistsorted

Syntax: {{#clistsorted:pattern|separator|sort_type|list1|list2|listn..}}
Returns: The output defined by pattern but the list(s) are sorted before pattern is used, based on list1. Any additional lists, if defined, sort in the same order as list1 to maintain the original relationship between the lists.

sort_type can be (case insensitive) asc or desc, or null for unsorted results.

All other parameters are as defined in #commalist, above.

PageName Functions

A PAGENAME has the format Name Space:Page Name (Suffix)

See also: Templated Extensions#PAGENAME Manipulation

NAMESPACE

syntax: {{NAMESPACE}}

  • Returns Name_Space, if any, without the colon, and with any spaces replaced by underscores.

PAGENAME

syntax: {{PAGENAME}}

  • Returns Page Name (Suffix), devoid of any Name Space.

PAGENAMEE

syntax: {{PAGENAMEE}}

  • Returns Page_Name_(Suffix), devoid of any Name Space, with all spaces replaced with underscores.

Database Access Functions

See Database Layouts for a list of tables and fields that can be referenced with the following functions.

#db

Dependent on the specific game database, but the general form is:
syntax: {{#db:game_id|db_name|record_title|field_name}}

  • returns the value stored in field field_name from the game_id db_name record with the title of record_title.
  • db_name is plural for all games except for LotRO. Example: items, not item; mobs, not mob.
  • example: {{#db:eq2|zones|East Freeport|type}} would return City.

#image

syntax: {{#image:page_name|n}}

  • returns the image system id number of the top-most image attached to page_name, or the nth from the top if n is defined.
  • example: [[image:{{#image:}}]] will display the top image of the current page. This is exactly the same as if n were 1.
  • example: [[image:{{#image:EQ2 Mob:a cow}}]] will display the top image of a cow.
  • example: {{#if:{{image:|2}}|[[image:{{#image:|2}}]]}} will display the 2nd image of the current page, if there is one.

#gameid

syntax: {{#gameid:[abbrev]|[default]|[<url|name[|break]|site|domain>]}}

  • Returns a number of normalized outputs based on a game abbreviation such as eq2, WOW, FFXI, war, RoM, lotro, etc., based on values in the gamelist db
  • abbrev and default are case-insensitive
  • if abbrev is ZAM (or if abbrev is invalid and default is ZAM) returns info for the top level site without looking in the gamelist db
  • break is ignored unless name is also used

Pre and Post Templates

This section really belongs on a different help page, but I am parking the information here for now. -Bludwyng

Because our Wikibase™ is an integration of Wiki and Database, we have a few special things to help us. For each game db in the system that is wikified, there is a pair of special templates that will be prepended or appended to the user-editable wiki text before the page is compiled. These allow us to do things like auto-generating category links and displaying the DB content within the wiki frame. The following is just one example:

For the EverQuest II game, for the mob database:


Tytania
The Relentless
Fae Wizard
Lucan D'Lere
EverQuest II
This template was created or is maintained by
Bludwyng
All the power in the universe in a small, flaming fairy package.

This page last modified 2013-06-17 00:01:25.