This module can dump a table by displaying its contents as text. It can also display formatted html text. That may help develop other modules.
An alternative is to use mw.dumpObject
but the result from this module is clearer and is close to valid Lua source.
When working with Wikidata, it can be useful to examine a table representing an entity.
For example, Southern African Large Telescope is . That entity can be viewed as a Lua table by previewing:
<nowiki>{{#invoke:dump|wikidata|Q833639}}</nowiki>
To do that, edit your sandbox and replace its contents with the above line, then click Show preview. shows this example.
If wanted, the width of each indented column can be set, for example to two spaces or to use tab characters:
<nowiki>{{#invoke:dump|wikidata|Q833639|indent=2}}</nowiki>
<nowiki>{{#invoke:dump|wikidata|Q833639|indent=tab}}</nowiki>
A property such as can also be displayed:
<nowiki>{{#invoke:dump|wikidata|P2386}}</nowiki>
If there is a problem debugging a module, it can be helpful to use a sandbox copy of the module to display the contents of a table to confirm that it contains expected data. The following shows how a module can dump a table.
With the above code in Module:Example, the result could be displayed by previewing:
<nowiki>{{#invoke:example|main}}</nowiki>
The module contains a complex table for testing. The table can be displayed by previewing:
<nowiki>{{#invoke:dump|testcase}}</nowiki>
A module can use mw.html to generate html. For testing, it may be useful to display the formatted result. The following shows how a module can create and dump html text.
loss'):done :done :tag('tr') :tag('td'):wikitext('February'):done :tag('td'):wikitext('$200') local html = tostring(tbl) local dumphtml = require('Module:Dump')._dumphtml return dumphtml(html)end
return
With the above code in Module:Example, the result could be displayed by previewing:
<nowiki>{{#invoke:example|main}}</nowiki>
The result is:
<table class="wikitable"> <caption>Table demonstration</caption> <tr> <th>Month</th> <th>Amount</th> </tr> <tr> <td>January</td> <td>$100<br>loss</td> </tr> <tr> <td>February</td> <td>$200</td> </tr> </table>
The main
function in the code above could be modified to return the html table by replacing the last two lines with:
In that case, the result could be displayed by previewing the following (the 1=
is needed if the text contains "=
"):
<nowiki>{{#invoke:dump|dumphtml|1={{#invoke:example|main}}}}</nowiki>
Previewing the following examples in a sandbox may be useful to examine the results of a template, such as, that generates html.
{{#invoke:dump|dumphtml|1= {{navbox/sandbox |group1 = Group1 |list1 = List1 |group2 = Group2 |list2 = List2 |group3 = Group3 |list3 = List3 }} }}
The dumphtml procedure only works reliably with valid html. In the following example, extra text (<div>
) is inserted at the start because the output from a subgroup (child) navbox starts with </div>
.
{{#invoke:dump|dumphtml|1=<div> {{navbox/sandbox|subgroup |group1 = Group1 |list1 = List1 |group2 = Group2 |list2 = List2 |group3 = Group3 |list3 = List3 }} }}
is useful if there is a need to view the wikitext returned by a template or module. However, ExpandTemplates does not always show exactly what a module would receive. For example, the following template gives the output shown in ExpandTemplates, but the wikitext passed to a module would actually contains strip markers.
<nowiki>{{convert|1+2/3<ref>Example</ref>|ft|in}}</nowiki>
ExpandTemplates output, rearranged on multiple lines for clarity:
<nowiki><templatestyles src="Fraction/styles.css"></templatestyles></nowiki>
<nowiki><span class="frac" role="math">1<span class="sr-only">+</span></nowiki>
<nowiki><span class="num">2</span>⁄<span class="den">3</span></span></nowiki>
<nowiki><ref>Example</ref></nowiki>
<nowiki> feet (20 in)</nowiki>
The args
function shows what a module receives in its arguments.
<nowiki>{{#invoke:dump|args|1={{convert|1+2/3<ref>Example</ref>|ft|in}}}}</nowiki>
The output follows. For clarity, it has been rearranged on multiple lines and each delete character has been replaced with ♢
.
<nowiki>♢'"`UNIQ--templatestyles-00000002-QINU`"'♢</nowiki>
<nowiki><span class="frac" role="math">1<span class="sr-only">+</span></nowiki>
<nowiki><span class="num">2</span>⁄<span class="den">3</span></span></nowiki>
<nowiki>♢'"`UNIQ--ref-00000001-QINU`"'♢</nowiki>
<nowiki> feet (20 in)</nowiki>
A template might invoke the main
function in the example above. Any parameters passed to the template or the module can be displayed for debugging. That would be to investigate an unexpected result in a page, for example, Albedo. To see what parameters are received by a module used in that article, edit the module and insert the following line at the start of the main function:
A Lua program could execute
An edit in a sandbox can be previewed to see what data the program would receive. To do that, preview the following wikitext:<nowiki>{{#invoke:dump|Wikipedia statistics/data.tab}}</nowiki>
The dump module accepts any text as the parameter and will apply special processing if the text is recognized. Structured data is identified as text ending with .tab
.
In Lua, _G
is a global variable which is a table holding information about all global variables. The _G
table can be displayed by previewing (both G
and _G
work):
<nowiki>{{#invoke:dump|testcase|G}}</nowiki>
If wanted, the width of each indented column can be set, for example to 2 spaces:
<nowiki>{{#invoke:dump|testcase|G|indent=2}}</nowiki>