Jump to content

Module:Page assessment raw

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Dan Leonard (talk | contribs) at 22:29, 4 June 2025 (Copied limited portion of code from Module:Page assessment; see that page's history for attribution). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- Dependencies
require('strict')
local getArgs = require('Module:Arguments').getArgs
local mDisambiguation = require('Module:Disambiguation')

-- Packapge to export
local p = {}

-- Namespace for utlity functions
local util = {}

--[[
Entry point for invoking the module.
Gets the class rating as text.
]]--
function p.main(frame)
	local args = getArgs(frame, {
		parentFirst = true
	})
	return util.class(args[1])
end

--[[
Gets the class rating for a page

@param {string} pageName - either subject or talk page name
@returns {string} class rating, or empty string if none found
]]--
function util.class(pageName)
	local subjectPage = mw.title.new(pageName)                   -- create new object for given page title
	local subjectAssessment = subjectPage.pageAssessments[1]     -- save first-indexed pageAssessments property
    
    if subjectAssessment ~= nil then                             -- if there are assessments in pageAssessments
        return subjectAssessment["class"]                        -- return class parameter from pageAssessments
    end

	return ""
end

-- Export util, for testing purposes
p.test = util
return p