词条 | Module:Sandbox/Galobtter/Related changes |
释义 | local p={} function getParam(frame) -- This is a longwinded way to return all the args (first choice) or parent.args (second choice) in an array. local parent, pargs, args local param={} parent = frame['parent'] if (parent) then pargs = parent['args'] end if (pargs) then for k,v in pairs(args) do param[k] = v end end args = frame['args'] if (args) then for k,v in pairs(args) do param[k] = v end end return param end function getIndexpage(page) -- get the contents of either the current page (inadvisable...) or a specified page -- returns either a title object or an error string, and a boolean true for successful completion local indexpage if (page) then indexpage = mw.title.new(page) if (not(indexpage)) then return 'Related changes error: failed to access page: ' + tostring(page) + '',false end else indexpage = mw.title.getCurrentTitle() if (not(indexpage)) then return 'Related changes bug: failed to access getCurrentTitle!',false end end return indexpage, true end function getLinks(frame,indexpage) local index = indexpage:getContent() or "" -- indexpage should exist, so no further checking for errors, just return blank local nextLink = mw.ustring.gmatch(index,"%[%[([^%]|]+)[^%]]-%]%]") local linklist = {} for link in nextLink do local linkval = frame:callParserFunction('REVISIONTIMESTAMP', link) if (mw.ustring.len(linkval) > 8) then -- don't even index pages that don't get meaningful results linklist[tostring(link)] = linkval .. '|' .. frame:callParserFunction('REVISIONUSER', link) end end return linklist end function display(linklist, options) if (not(options)) then options = 'd-' end local sorttype = mw.ustring.match(options,'([%l%u])') if (sorttype == 'n') then sorttype = 'name' if (sortdir == '-') then sortdir = 'descending' else sortdir = 'ascending' end sorttype = 'date' if (sortdir == '+') then sortdir = 'ascending' else sortdir = 'descending' end end local outsort, outarray = {}, {'{| class="wikitable sortable"\!Name\!Last edited\!Last editor'} for k,v in pairs(linklist) do if sorttype == 'name' then table.insert(outsort, k..'|'..v) else table.insert(outsort, v..'|'..k) end end table.sort(outsort) for i = 1,#outsort do local n, d, u, split split = mw.text.split(outsort[i],'|',true) if sorttype == 'name' then n, d, u= split[3], split[1], split[2] else d, u, n = split[1], split[2], split[3] end if ((mw.ustring.sub(n, 1, 5) == 'File:') or (mw.ustring.sub(n, 1, 6) == 'Image:')) then n = ':' .. n end table.insert(outarray,'\|-\|missing name') .. '\|' .. (d or 'Related changes bug: missing date') .. '\|' .. u .. '') end table.insert(outarray,'\|}') return table.concat(outarray) end function filter(linklist, action) -- pass end function p.main(frame) local param = getParam(frame) -- get all parameters in param tabel; args override parent.args local indexpage = getIndexpage(param.page) local linklist = getLinks(frame,indexpage) for operation = 1, #param do filter(linklist, param[operation]) end if param.nowiki then return frame:preprocess(''..display(linklist)..'') else return display(linklist,param.options) end end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。