Module:Pagestats

-- Description : Page stats -- Shows some stats about a page --Syntax : --

local p = {} local u = require("Dev:Utility")

function p.main(frame) local args = u.getArgs(frame) local tStats = {} local hTable = mw.html.create("table") hTable:addClass("wikitable") hTable:tag("th") :wikitext("Stats") hTable:tag("th") :wikitext("Count") if args then local sPage = args["page" or 1] or "" local sStats = args["stats" or 2] or "" tStats = mw.text.split(sStats,",") if sPage then local mwPage = mw.title.new(sPage) local contentPage = mwPage:getContent tStats = getData(tStats,contentPage) for stats,count in pairs(tStats) do               hTable:tag("tr") hTable:tag("td") :wikitext(stats) hTable:tag("td") :wikitext(count) end end end hTable:done return hTable end

function getData(tDataTypes,contentPage) local tStatRegex = { links = "%[.-%]", templates ="", tables ="{|.-\n|}", references = "%", words = "(%a+)", }   local statTable,tReports = {},{} for _, sMatchType in pairs(tDataTypes) do       sMatchType = mw.text.trim(sMatchType or "") if tStatRegex[sMatchType] then statTable[sMatchType],tReports[sMatchType] = getMatches(contentPage,tStatRegex[sMatchType],sMatchType) end end return statTable,tReports end

function getMatches(contentPage,sRegex,sMatchType) local tLinks = contentPage:gmatch(sRegex) local count =0 local tReports ={} for matchvalue in tLinks do       count = count +1 if matchvalue and not tReports[matchvalue] then tReports[matchvalue] = 0 end tReports[matchvalue] = tReports[matchvalue] +1 end return count, tReports end

function p.test (frame) return frame:preprocess(mw.text.unstrip(frame.args[1])) end return p