Jump to content

Module:Page assessment: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
can't use class mask, that expects to operate on the current page
fix
Line 16: Line 16:
return nil, nil
return nil, nil
end
end
local subjectTitle = title.isTalkPage and title.subjectPageTitle or title
local subjectTitle = title.subjectPageTitle
local talkpageTitle = title.isTalkPage and title or title.talkPageTitle
local talkpageTitle = title.talkPageTitle
return subjectTitle:getContent(), talkpageTitle:getContent()
return subjectTitle:getContent(), talkpageTitle:getContent()
end
end
Line 39: Line 39:
return "unassessed"
return "unassessed"
else
else
local classParam = mw.text.trim(
local classParam = mw.ustring.match(talkpageWikitext, "{{.-%|%s*class%s*=([^}%|]*)", 0) or ""
return mw.text.trim(classParam)
mw.ustring.find(subjectWikitext, util.paramValuePattern("class")) or ""
)
return classParam == "" and "unassessed" or classParam
end
end
end
end

Revision as of 13:07, 22 December 2020

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