Module:Sandbox/Dorumin/DPL

local p = {} local getArgs = require('Dev:Arguments').getArgs

-- ExtDynamicPageList::$maxResultCount p.COUNT = 500

-- Generates dpl parser function from a key-value table function p.tag(tbl) local tag = '' return tag end

-- Gets the DPL parser function and returns its wikitext after parsing function p.parse(tbl) local frame = mw.getCurrentFrame return frame:preprocess(p.tag(tbl)) end

-- Returns all DPL results concatenated -- The count and noresultsheader parameters don't take effect function p.recursive(tbl) tbl['noresultsheader'] = '' tbl['count'] = p.COUNT local offset = tbl['offset'] or 0 local content = '' local parsed = p.parse(tbl) while parsed ~= tbl['noresultsheader'] do       content = content .. parsed offset = offset + p.COUNT tbl['offset'] = offset parsed = p.parse(tbl) end return content end

-- Returns an array (really just a table) of all pages that match a query -- The format parameter doesn't take effect function p.list(tbl) tbl['format'] = ',,%PAGE%#,' local content = p.recursive(tbl) local results = {} for page in parsed:gmatch("[^#]+") do       table.insert(results, page) end return results end

-- For usage in #invoke function p.main(frame) return p.parse(getArgs(frame)) end

-- For usage in #invoke function p.all(frame) return p.recursive(getArgs(frame)) end

return p