local conf = require("Module:Science redirect/conf")
local p =
function p.R(frame) local template = mw.ustring.gsub(frame.args[1], ' ', '_') if conf.templates[template] then return p._main(frame, 'R_' .. template, conf.templates[template].name, conf.templates[template].from, conf.templates[template].to, conf.templates[template].category, conf.templates[template].info, conf.templates[template].removeA) elseif template then return '
The template '..template..'is not valid.\n' else return 'No template specified\n' endendfunction p.list(frame) local outstr = "" local ocats= for k, v in pairs(conf.cats) do if(v[2]) then ocats[v[2]] = v[1] end end for k, v in pairs(ocats) do local h = mw.ustring.match(v, ".* (.*)") outstr = outstr .. "\n
\n" for kk, vv in pairs (conf.templates) do outstr = outstr .. "*" .. frame:expandTemplate .. "\n" end end return outstrend
function p._main(frame, id, name, from, to, category, info, removeA) --initialize variables local args = frame:getParent.args local singleNoun, pluralNoun = , local outStr = --Check for known parameter 1 local cat = mw.ustring.match(mw.ustring.lower(args[1] or 'none'), '^(.-)s?$') if conf.cats[cat] then singleNoun, pluralNoun = conf.cats[cat][1], conf.cats[cat][2] else singleNoun, pluralNoun = 'an organism' outStr = '' end --strip article from singleNoun if removeA is true if removeA
'an organism' then singleNoun = else singleNoun = (mw.ustring.match(singleNoun, '^an? (.*)$') or singleNoun) end end --support alternative indications for printworthy if args[2]
'true' then args['printworthy'] = 'no' end --build template arguments local main_category = 'Redirects '..category if pluralNoun then main_category = main_category..' of '..pluralNoun end local outArgs = --build output string if frame.args['debug']
'..frame:extensionTag else outStr = frame:expandTemplate..outStr end return outStrend
return p