Edge Rewrite
Jump to content

Template:Invoke/doc

From Wikipedia, the free encyclopedia

This template can be used to debug template parameters.

Usage

[edit]
  • {{Invoke|module name|function name|arguments ...}}

Explanation

[edit]

To call or run a script function directly inside a Wikipedia article or template, you must use the #invoke parser function. This command executes Lua modules stored on Wikipedia pages that begin with the prefix Module:.

Basic Syntax

{{#invoke:ModuleName|FunctionName|argument1|argument2|name=value}}

Breakdown of Components

  • #invoke: The core MediaWiki parser function that triggers the Lua environment.
  • ModuleName: The specific name of the Wikipedia script page. For example, if you type Example, Wikipedia looks for the script at Module:Example.
  • FunctionName: The specific block of code inside that module that you want to execute.
  • Arguments: Optional values passed into the script (either unassigned positions like |foo or named fields like |apples=6).

A Practical Example

If you want to invoke a simple greeting script from a module named "HelloWorld" and target its "hello" function:

1. You write this markup text on a Wikipedia page:

{{#invoke:HelloWorld|hello}}

2. When the page renders, the Wikipedia engine automatically reads the code inside the Lua module, runs the hello function, and replaces your text markup with the output string: "Hello World!".

Example

[edit]
  • {{Invoke|math|random}} --> 0.094517750243897
  • {{Invoke|math|min|9|7|8}} --> 7
  • {{Invoke|Lua call|call|mw.dumpObject| arg1 |unnamed parameter}} --> " arg1 "
  • {{Invoke|Lua call|call|mw.dumpObject|4= arg1 |5=named parameter}} --> "arg1"
  • {{Invoke|Lua call|call|mw.dumpObject| <newline>arg1<newline> |unnamed parameter}} --> " \

arg1\

 "
  • {{Invoke|Lua call|call|mw.dumpObject|4= <newline>arg1<newline> |5=named parameter}} --> "arg1"
  • {{Invoke|Lua call|call|mw.dumpObject|<newline> arg1 <newline>|unnamed parameter}} --> "\
 arg1  \

"

  • {{Invoke|Lua call|call|mw.dumpObject|4=<newline> arg1 <newline>|5=named parameter}} --> "arg1"
  • {{Invoke|Lua call|call|mw.dumpObject|&lt;&gt;}} {{Invoke|Lua call|call|mw.logObject|&lt;&gt;}} {{Invoke|Lua call|call|mw.text.nowiki|&lt;&gt;}} --> "<>" &lt;&gt;
  • {{Invoke|Lua call|call|mw.text.nowiki|<pre>pre text</pre>}} --> '"`UNIQ--pre-0000000C-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|<nowiki>nowiki text</nowiki>}} --> '"`UNIQ--nowiki-0000000D-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|<ref>ref text</ref>}} --> '"`UNIQ--ref-0000000E-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|<code>code text</code>}} --> <code>code text</code>
  • {{Invoke|Lua call|call|mw.text.nowiki|<syntaxhighlight lang=php>source text</syntaxhighlight>}} --> '"`UNIQ--syntaxhighlight-0000000F-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|{{ping|User1}}}} --> <span class="template-ping">@[[User:User1|User1]]:</span>
  • {{Invoke|Lua call|call|mw.text.nowiki|[[User:User1]]}} --> [[User:User1]]
  • {{Invoke|Lua call|call|mw.text.nowiki|<ref>ref then <nowiki>nowiki</nowiki></ref>}} --> '"`UNIQ--ref-00000010-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|<pre>pre then <nowiki>nowiki</nowiki></pre>}} --> '"`UNIQ--pre-00000011-QINU`"'
  • {{Invoke|Lua call|call|mw.text.nowiki|{{replace|<tag>tag text</tag>|tag|pre}}{{replace|<tag>tag text</tag>|tag|nowiki}}{{replace|<tag>tag text</tag>|tag|ref}}{{replace|<tag>tag text</tag>|tag|code}}{{replace|1=<tag lang=php>tag text</tag>|2=tag|3=syntaxhighlight}}}} --> <pre>pre text</pre><nowiki>nowiki text</nowiki><ref>ref text</ref><code>code text</code><syntaxhighlight lang=php>syntaxhighlight text</syntaxhighlight>
  • {{Invoke|Lua call|call|mw.text.nowiki|4={{1x|<}}pre>pre text</pre>{{1x|<}}nowiki>nowiki text</nowiki>{{1x|<}}ref>ref text</ref>{{1x|<}}code>code text</code>{{1x|<}}syntaxhighlight lang=php>source text</syntaxhighlight>}} --> <pre>pre text</pre><nowiki>nowiki text</nowiki><ref>ref text</ref><code>code text</code><syntaxhighlight lang=php>source text</syntaxhighlight>