Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Erutuon/parameters
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 function errorf(level, ...) if type(level) == "number" then return error(string.format(...), level + 1) else -- level is actually the format string. return error(string.format(level, ...), 2) end end -- From [[wikt:Module:table]]. local function defaultKeySort(key1, key2) -- "number" < "string", so numbers will be sorted before strings. local type1, type2 = type(key1), type(key2) if type1 ~= type2 then return type1 < type2 else return key1 < key2 end end function p.make_param_list(params_set) local params_sorted = {} for param_name in pairs(params_set) do table.insert(params_sorted, param_name) end table.sort(params_sorted, defaultKeySort) return params_sorted end function p.get_parameters(pagename) local page if type(pagename) == "string" then page = mw.title.new(pagename) elseif type(pagename) == "table" and pagename.nsText then page = pagename pagename = page.fullText else errorf("Bad argument #1 to get_parameters (expected pagename or page title, got %s)", type(pagename)) end local content = page:getContent() if not content then errorf("The page '%s' does not have any content.", pagename) end local params = {} for param_name in content:gmatch '{{{([%w _]+)%f[|]' do -- Not a completely accurate pattern. --This code is not quite accurate, because PHP only converts integer -- parameter names to Lua numbers; float parameter names stay strings. if tonumber(param_name) then param_name = tonumber(param_name) end params[param_name] = true end return params end function p.check_params(frame) local template_title = mw.title.getCurrentTitle() local params_set = p.get_parameters(template_title) if frame.args.log then mw.log("get_parameters found the following parameters:", table.concat(p.make_param_list(params_set), ", ")) end local unrecognized_params = {} for param_name in pairs(frame:getParent().args) do if not params_set[param_name] then unrecognized_params[param_name] = true end end if next(unrecognized_params) then local unrecognized_params_list = p.make_param_list(unrecognized_params) errorf("The parameters %s %s not recognized", table.concat(unrecognized_params_list, ", "), unrecognized_params_list[2] and "are" or "is") end end function p.show_parameters(frame) local template_name = frame.args[1] if not template_name then error("Template name (parameter 1) is required") end template_name = "Template:" .. template_name return table.concat(p.make_param_list(p.get_parameters(template_name)), ", ") 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)
Templates used on this page:
Template:Speciesbox
(
edit
)
Module:Sandbox/Erutuon/parameters
(
edit
)
Module:Sandbox/Erutuon/parameters/doc
(
edit
)