Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/ProcrastinatingReader/Dbm
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local getArgs = require('Module:Arguments').getArgs -- Returns a table with the keys of the passed table as its values local function getTableKeys(tbl) local keys = {} for k,_ in pairs(tbl) do keys[#keys + 1] = k end table.sort(keys) return keys end -- Construct a table of the tagged CSDs and any arguments passed in for each CSD -- Example format: |G6|rationale{{=}}G6 rationale|xfd|G7|rationale{{=}}G7 rationale local function constructCsdTable(args) local tbl = {} local current = '' -- Code of current CSD being processed. Its value will be the last CSD-like param read (eg 'G6') local size = 0 for k,v in pairs(args) do if string.match(v, '^[GgAaFfCcUuRrTtPp]%d%d?$') then -- Begin collecting args for a new CSD current, size = string.lower(v), 0 tbl[current] = {['size'] = size} else -- Add the arg to the CSD being processed (ie, the corresponding CSD) local arg = mw.text.split(v, '=') tbl[current][string.lower(arg[1])] = arg[2] size = size + 1 -- Increment the 'size', ie number of params passed for a particular CSD tbl[current]['size'] = size end end return tbl end -- Build the Db-meta wrapper template local function build(frame, args) local passThruArgs = {'rationale', 'xfd', 'user', 'blanked', 'url', 'url2', 'url3', 'source', 'article', 'location', 'filename', 'criterion'} -- Arguments we'll pass through unchanged to the Db-meta wrapper local csdTable = constructCsdTable(args) local csdKeys = getTableKeys(csdTable) --if true then return mw.dumpObject(csdTable) end local builtCsdTemplates = {} local summary = "" -- Loop through CSDs (eg G1, G2) local n = 0 for k,v in pairs(csdTable) do n = n + 1 local templateArgs = { ['raw'] = 'yes', ['nocat'] = 'true' -- for test purposes } -- Add to summary the name of the CSD. Plus open brackets if we've got extra params summary = summary .. string.upper(k) .. (v['size'] > 0 and ' (' or '') -- add values to templateArgs (and summary) in any custom params we got for this CSD, eg Rationale, URL for _,arg in ipairs(passThruArgs) do if v[arg] then templateArgs[arg] = v[arg] summary = summary .. arg .. ': ' .. v[arg] .. (v['size'] > _ and ', ' or '') end end -- Close brackets if we had custom params. Add a comma if we've got another CSD summary = summary .. (v['size'] > 0 and ')' or '') .. (#csdKeys > n and ', ' or '') -- Save the built template table.insert(builtCsdTemplates, frame:expandTemplate{ title = 'Db-'..k, args = templateArgs }) end -- Construct Db-meta wrapper, composed of all the built CSD templates local dbTemplate = frame:expandTemplate{ title = 'Db-meta', args = { [1] = ' for the following reasons:</b><ul><li>'..table.concat(builtCsdTemplates, '</li><li>') .. '</li></ul> <b>The page may be deleted under any criterion that is valid', ['criterion'] = 'NA', ['temp'] = 'Db-notice-multiple', ['temp2'] = '|'..table.concat(csdKeys, '|'), ['summary'] = 'Multiple reasons: ' .. summary, -- forward given params to Db-meta ['bot'] = args['bot'] or '', ['blanked'] = args['blanked'] or (csdTable['g10'] and 'yes') or '', ['divblank'] = args['divblank'] or (csdTable['g10'] and 'yes') or '', ['help'] = args['help'] or '', }} return dbTemplate end -- Exports function p.main(frame) local args = getArgs(frame) return build(frame, args) end -- Test function p.dump(frame) return mw.dumpObject(mw.text.unstripNoWiki(frame.args[1])) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/ProcrastinatingReader/Dbm/doc
(
edit
)