Module:Page assessment raw
Appearance
| This module is rated as pre-alpha. It is incomplete and may or may not be in active development. Do not use it in article namespace pages. A module remains in pre-alpha until its developer, or another editor who adopts it if it is abandoned for some time, considers the basic structure complete. |
This is a simplified version of Module:Page assessment with limited functions, designed for usage in frequently-transcluded templates where limiting the expensive function count is needed. It is recommended to use the other module in most cases.
Usage
[edit]Returns the class as text.
{{#invoke:Page assessment raw|get_class|page=page name|project=WikiProject name}}
- Examples
{{#invoke:Page assessment raw|get_class|project=Project-independent assessment|page=Wikipedia}}→ B{{#invoke:Page assessment raw|get_class|project=Project-independent assessment|page=Wiktionary}}→ C{{#invoke:Page assessment raw|get_class|project=Project-independent assessment|page=Wikt}}→
-- Package to export
local p = {}
-- Namespace for utility functions
local util = {}
--[[
Entry point for invoking the module.
@param {string} frame.args.page subject page name
@param {string} frame.args.project WikiProject with class assessment
@return {string} The class rating as text, or empty string if none found
]]--
function p.get_class(frame)
return util.class(frame.args.page, frame.args.project)
end
--[[
Gets the class rating for a page
@param {string} namePage subject page name
@param {string} nameProject WikiProject with class assessment
@returns {string} The class rating as text, or empty string if none found
]]--
function util.class(namePage, nameProject)
local subjectAssessment = nil
local subjectPage = mw.title.new(namePage) -- create new object for given page title
for _, entry in ipairs(subjectPage.pageAssessments) do -- iterate over all assessments
if entry["name"] == nameProject then -- if assessment is for given WikiProject
subjectAssessment = entry -- save assessment of given WikiProject
end
end
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