Jump to content

Module:Page assessment

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Evad37 (talk | contribs) at 13:07, 22 December 2020 (fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local util = {}

--[[
Gets the wikitext of a page and its related talk or subject page (nil if it does
not exist)

@param {string} pageName
@returns {string|nil, string|nil} subject page wikitext, talk page wikitex
]]--
function util.getWikitext(pageName)
	local title = mw.title.new(pageName)
	if not title then
		return nil, nil
	end
	local subjectTitle = title.subjectPageTitle
	local talkpageTitle = title.talkPageTitle
	return subjectTitle:getContent(), talkpageTitle:getContent()
end

--[[
Creates a pattern for finding the value given to a parameter within any template
call.

@param {string} param
@returns {string} pattern
]]--
function util.paramValuePattern(param)
	return "{{[^}]*|%s*" .. param .. "%s*=([^|{}]+)"
end

function p.class(pageName)
	local subjectWikitext, talkpageWikitext = util.getWikitext(pageName)
	if not subjectWikitext then -- page does not exist
		return "needed"
	elseif not subjectWikitext then -- talk page does not exist
		return "unassessed"
	else
		local classParam = mw.ustring.match(talkpageWikitext, "{{.-%|%s*class%s*=([^}%|]*)", 0) or ""
		return mw.text.trim(classParam)
	end
end

function p.main(frame)
	local args = getArgs(frame, {
		parentFirst = true
	})
	return p.class(args[1])
end

p.util = util
return p