https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ALoadDataModule:LoadData - Revision history2025-05-25T23:42:40ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.2https://en.wikipedia.org/w/index.php?title=Module:LoadData&diff=1047451199&oldid=prevMusikBot II: Protected "Module:LoadData": High-risk template or module: 398 transclusions (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite))2021-09-30T22:57:10Z<p>Protected "<a href="/wiki/Module:LoadData" title="Module:LoadData">Module:LoadData</a>": <a href="/wiki/Wikipedia:High-risk_templates" title="Wikipedia:High-risk templates">High-risk template or module</a>: 398 transclusions (<a href="/wiki/User:MusikBot_II/TemplateProtector" title="User:MusikBot II/TemplateProtector">more info</a>) ([Edit=Require autoconfirmed or confirmed access] (indefinite))</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 22:57, 30 September 2021</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>MusikBot IIhttps://en.wikipedia.org/w/index.php?title=Module:LoadData&diff=1020204549&oldid=prevGKFX: Create more complex version of Module:Data with more options.2021-04-27T19:46:53Z<p>Create more complex version of Module:Data with more options.</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
-- Finds the next key key <= or >= the given i.<br />
-- operator is ±1<br />
local function findItemRange(data, i, operator)<br />
local bestIndex = nil<br />
i = i * operator<br />
for k, v in pairs(data) do<br />
local kop = type(k) == 'number' and k * operator<br />
if kop and kop <= i and (bestIndex == nil or kop > bestIndex * operator) then<br />
bestIndex = k<br />
end<br />
end<br />
if bestIndex then return data[bestIndex] else return nil end<br />
end<br />
<br />
local function load(datamodule, frame)<br />
local args = frame.args<br />
local data = mw.loadData(datamodule)<br />
for i = 1, 20 do<br />
if args[i] then data = data[tonumber(args[i]) or args[i]]<br />
elseif args[i .. ' lteq'] then<br />
data = findItemRange(data, tonumber(args[i .. ' lteq']), 1)<br />
elseif args[i .. ' gteq'] then<br />
data = findItemRange(data, tonumber(args[i .. ' gteq']), -1)<br />
else break end<br />
end<br />
<br />
if data == nil then<br />
return args['if_nil'] -- not a required argument, OK to return nil here.<br />
end<br />
<br />
if type(data) == 'table' then<br />
-- Put the table into another table because the return value of loadData<br />
-- is a "fake" table that only has certain metamethods.<br />
local realdata = {}<br />
for k, v in pairs(data) do<br />
realdata[k] = v<br />
end<br />
data = realdata<br />
else<br />
data = { data }<br />
end<br />
<br />
if args['template'] then<br />
return mw.text.unstripNoWiki(args['template']):format(unpack(data))<br />
elseif args['preprocess'] then<br />
return frame:preprocess(mw.text.unstripNoWiki(args['preprocess']):format(unpack(data)))<br />
else<br />
return table.concat(data)<br />
end<br />
end<br />
<br />
return setmetatable({}, {<br />
__index = function(t, k)<br />
return function(frame)<br />
return load('Module:' .. k, frame)<br />
end<br />
end<br />
})</div>GKFX