Content deleted Content added
error message tweaks |
add the importanceScale class, fixes for qualityScale class methods, better makeCheckSelfFunction code, better error messages in checkForDuplicateTriggers, fix indentation |
||
Line 18:
-- Makes a simple function that raises an error if the dot syntax is used with methods.
-- It is not 100% reliable, but will catch the majority of cases, and works with inheritance.
-- The uniqueMethod variable should be the name of a method unique to the class.
local function makeCheckSelfFunction( libraryName, varName, selfObjDesc, uniqueMethod )
return function( self, method )
if type( self ) ~= 'table' or type( self.new ) ~= 'function' or type( self[ uniqueMethod ] ) ~= 'function' then
error( mw.ustring.format(
'%s: invalid %s. Did you call %s with a dot instead of a colon, i.e. %s.%s() instead of %s:%s()?',
Line 55 ⟶ 56:
s = checkString( s )
if s then
elseif type( array ) == 'nil' then
array = {}
table.insert( array, s )
return array or {}
end
Line 76 ⟶ 77:
local banner = {}
banner.__index = banner
local checkSelfBanner = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'banner', 'banner object', 'exportCategories' )
function banner:new( init )
init = type( init ) == 'table' and init or {}
local obj = {}
obj.objectName = init.objectName
if not obj.objectName then
error( [[No object name specified. Please use "banner:new{ objectName = 'myObject' }".]], 2 )
end
-- Set the project name and exit if its value is absent or invalid.
obj.project = init.project
if type( obj.project ) ~= 'string' or obj.project == '' then return end
-- Set the index metamethod and the metatable.
self.__index = self
Line 99 ⟶ 100:
function banner:setImage( s )
checkSelfBanner( self, 'setImage' )
end
-- Gets the banner's main image.
function banner:getImage()
end
Line 114 ⟶ 115:
function banner:addCategory( s )
checkSelfBanner( self, 'addCategory' )
end
Line 169 ⟶ 170:
-- Adds an array of row objects to the banner object.
function banner:addRows( t )
end
Line 187 ⟶ 188:
local row = {}
row.__index = row
local checkSelfRow = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'row', 'row object', 'getCategories' ) -- TODO: replace getCategories with a less generic function.
function row:new( init )
Line 201 ⟶ 202:
function row:addCategory( s )
checkSelfRow( self, 'addCategory' )
end
Line 222 ⟶ 223:
function row:export()
checkSelfRow( self, 'export' )
-- Get the result of the icon and content export functions, and check the results.
local rowIconOutput = type( self.exportRowIcon ) == 'function' and self:exportRowIcon()
Line 228 ⟶ 229:
local rowContentOutput = type( self.exportRowContent ) == 'function' and self:exportRowContent()
rowContentOutput = checkString( rowContentOutput )
-- Export the row html.
local ret = htmlBuilder.create()
if rowIconOutput and rowContentOutput then
ret
elseif rowContentOutput and not rowIconOutput then
ret
end
return tostring( ret )
Line 260 ⟶ 261:
local assessmentGrade = {}
assessmentGrade.__index = assessmentGrade
local checkSelfAssessmentGrade = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'assessmentGrade', 'assessmentGrade object', 'getGradeName' )
function assessmentGrade:new( init )
Line 274 ⟶ 275:
-- the grade name would be "c".
function assessmentGrade:setGradeName( s )
end
-- Gets the grade name.
function assessmentGrade:getGradeName()
end
Line 291 ⟶ 292:
-- would be "foo".
function assessmentGrade:addTrigger( s )
end
-- Adds an array of triggers to the assessment grade object.
function assessmentGrade:addTriggers( t )
end
-- Returns an array containing the trigger values for the assessment grade object.
function assessmentGrade:getTriggers()
end
Line 314 ⟶ 315:
-- by the qualityScale and importanceScale objects or banner objects.
function assessmentGrade:setCategory( s )
end
-- Gets the assessment grade's category.
function assessmentGrade:getCategory()
end
-- Sets the color of the icon box when the assessment grade is used.
function assessmentGrade:setColor( s )
end
-- Gets the color used for the assessment grade.
function assessmentGrade:getColor()
end
-- Sets an icon for the assessment grade.
function assessmentGrade:setIcon( s )
end
-- Gets the assessment grade icon.
function assessmentGrade:getIcon()
end
Line 380 ⟶ 381:
local assessmentScale = {}
assessmentScale.__index = assessmentScale
local checkSelfAssessmentScale = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'assessmentScale', 'assessmentScale object', 'addGrade' )
function assessmentScale:new( init )
Line 389 ⟶ 390:
self.__index = self
return setmetatable( obj, self )
end
-- Sets the name of the parameter that accepts trigger values from assessmentGrade objects.
-- For example, if an article was rated as |class=start, the parameter name would be "class".
function assessmentScale:setParamName( s )
checkSelfAssessmentScale( self, 'setParamName' )
s = checkString( s )
if s then
self.param = s
end
end
-- Gets the parameter name.
function assessmentScale:getParamName()
checkSelfAssessmentScale( self, 'getParamName' )
return self.param
end
Line 396 ⟶ 413:
function assessmentScale:setCategoryFamily( s )
checkSelfAssessmentScale( self, 'setCategoryFamily' )
self.categoryFamily = s
end
Line 410 ⟶ 427:
-- Adds an assessment grade object.
function assessmentScale:addGrade( gradeObject )
error( mw.ustring.format( 'Grade name not found (was type "%s"). Please set a grade name with the "setGradeName" method of the assessment grade object' , type( gradeName ) ), 2 )
else
end
end
-- Adds an array of grade objects.
function assessmentScale:addGrades( t )
end
-- Removes an assessment grade object from the assessment scale.
function assessmentScale:removeGrade( s )
end
-- Removes multiple assessment grade objects from the assessment scale.
function assessmentScale:removeGrades( t )
end
-- Gets the object's grade table.
function assessmentScale:getGrades()
end
-- Gets the specified grade object.
function assessmentScale:getGrade( gradeName )
checkSelfAssessmentScale( self, 'getGrade' )
self.grades = self.grades or {}
gradeName = checkString( gradeName )
if gradeName then
return self.grades[ gradeName ]
end
end
-- Edits a grade object in the grades table by calling one of its methods.
function assessmentScale:editGrade( gradeName, method, ... )
checkSelfAssessmentScale( self, 'editGrade' )
self.grades = self.grades or {}
gradeName = checkString( gradeName )
method = checkString( method )
if not ( gradeName and method ) then return end
local gradeObject = self.grades[ gradeName ]
if not checkObject( gradeObject ) then
error( mw.ustring.format( 'editGrade: no object found with grade name "%s"', gradeName ), 2 )
end
if type( gradeObject[ method ] ) ~= 'function' then
error( mw.ustring.format( 'editGrade: method "%s" was not found in the "%s" grade object', method, gradeName ), 2 )
end
self.grades[ gradeName ][ method ]( self, ... )
end
Line 468 ⟶ 509:
function assessmentScale:checkForDuplicateTriggers()
checkSelfAssessmentScale( self, 'checkForDuplicateTriggers' )
local grades = self
if type( grades ) ~= 'table' then return end
local exists = {}
Line 481 ⟶ 521:
if trigger then
if exists[ trigger ] then
error( mw.ustring.format(
'Duplicate trigger values "%s" detected in the assessment trigger, exists[ trigger ], name
), 2 )
else
exists[ trigger ] =
end
end
Line 497 ⟶ 540:
local qualityScale = assessmentScale:new()
local checkSelfQualityScale = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'qualityScale', 'qualityScale object', 'setFaGrade' )
-- Sets the FA (Featured Article) grade with default settings.
function qualityScale:setFaGrade()
checkSelfQualityScale( self, 'setFaGrade' )
local faGrade = qualityGrade:new()
end
-- Sets the A grade with default settings.
function qualityScale:setAGrade()
checkSelfQualityScale( self, 'setAGrade' )
local aGrade = qualityGrade:new()
aGrade:setColor( '#66ffff' )
aGrade:setIcon( 'Symbol a class.svg' )
end
-- Sets the GA (Good Article) grade with default settings.
function qualityScale:setGaGrade()
checkSelfQualityScale( self, 'setGaGrade' )
local gaGrade = qualityGrade:new()
gaGrade:setIcon( 'Symbol support vote.svg' )
self:addGrade( gaGrade )
end
-- Sets the B grade with default settings.
function qualityScale:setBGrade()
checkSelfQualityScale( self, 'setBGrade' )
local bGrade = qualityGrade:new()
bGrade:setColor( '#b2ff66' )
self:addGrade( bGrade )
end
-- Sets the C grade with default settings.
function qualityScale:setCGrade()
checkSelfQualityScale( self, 'setCGrade' )
local cGrade = qualityGrade:new()
cGrade:setColor( '#ffff66' )
self:addGrade( cGrade )
end
-- Sets the Start grade with default settings.
function qualityScale:setStartGrade()
checkSelfQualityScale( self, 'setStartGrade' )
startGrade:setColor( '#ffaa66' )
self:addGrade( startGrade )
end
-- Sets the Stub grade with default settings.
function qualityScale:setStubGrade()
checkSelfQualityScale( self, 'setStubGrade' )
stubGrade:setColor( '#ff6666' )
self:addGrade( stubGrade )
end
-- Sets the FL (Featured List) grade with default settings.
function qualityScale:setFlGrade()
checkSelfQualityScale( self, 'setFlGrade' )
local flGrade = qualityGrade:new()
flGrade:setIcon( 'Featured article star.svg' )
self:addGrade( flGrade )
end
-- Sets the List grade with default settings.
function qualityScale:setListGrade()
checkSelfQualityScale( self, 'setListGrade' )
listGrade:setColor( '#aa88ff' )
self:addGrade( listGrade )
end
-- Sets the NA (not applicable) grade with default settings.
function qualityScale:setNaGrade()
checkSelfQualityScale( self, 'setNaGrade' )
local naGrade = qualityGrade:new()
naGrade:setColor( '#f5f5f5' )
self:addGrade( naGrade )
end
-- Sets the Category grade with default settings.
function qualityScale:setCategoryGrade()
checkSelfQualityScale( self, 'setCategoryGrade' )
categoryGrade:setColor( '#ffdb58' )
self:addGrade( categoryGrade )
end
-- Sets the Disambig (disambiguation) grade with default settings.
function qualityScale:setDisambigGrade()
checkSelfQualityScale( self, 'setDisambigGrade' )
disambigGrade:addTriggers{ 'disambiguation', 'disambig', 'disamb', 'dab' } end
-- Sets the File grade with default settings.
function qualityScale:setFileGrade()
checkSelfQualityScale( self, 'setFileGrade' )
fileGrade:setColor( '#ddccff' )
self:addGrade( fileGrade )
end
-- Sets the Portal grade with default settings.
function qualityScale:setPortalGrade()
checkSelfQualityScale( self, 'setPortalGrade' )
portalGrade:setColor( '#cc8899' )
self:addGrade( portalGrade )
end
-- Sets the Project grade with default settings.
function qualityScale:setProjectGrade()
checkSelfQualityScale( self, 'setProjectGrade' )
projectGrade:setColor( '#c0c090' )
self:addGrade( projectGrade )
end
-- Sets the Template grade with default settings.
function qualityScale:setTemplateGrade()
checkSelfQualityScale( self, 'setTemplateGrade' )
templateGrade:setGradeName( 'template' )
templateGrade:setColor( '#fbceb1' )
self:addGrade( templateGrade )
end
-- Sets the Redirect grade with default settings.
function qualityScale:setRedirectGrade()
checkSelfQualityScale( self, 'setRedirectGrade' )
local redirectGrade = qualityGrade:new()
end
-- Sets the Book grade with default settings.
function qualityScale:setBookGrade()
checkSelfQualityScale( self, 'setBookGrade' )
local bookGrade = qualityGrade:new()
bookGrade:setGradeName( 'book' )
end
-- Sets the FM (Featured media) grade with default settings.
function qualityScale:setFmGrade()
checkSelfQualityScale( self, 'setFmGrade' )
local fmGrade = qualityGrade:new()
fmGrade:setGradeName( 'fm' )
fmGrade:addTrigger( 'fm' )
fmGrade:setIcon( 'Featured article star.svg' )
end
-- Set the standard quality scale with default values.
function qualityScale:setStandardQualityScale()
checkSelfQualityScale( self, 'setStandardQualityScale' )
self:setNaGrade()
end
-- Set the extended quality scale with default values.
function qualityScale:setExtendedQualityScale()
checkSelfQualityScale( self, 'setExtendedQualityScale' )
self:setTemplateGrade()
end
----------------------------------------------------------
-- Define the
----------------------------------------------------------
local
local checkSelfImportanceScale = makeCheckSelfFunction( 'Module:WikiProjectBanner', 'importanceScale', 'importanceScale object', 'setTopGrade' )
-- Sets the Top grade with default settings.
function importanceScale:setTopGrade()
checkSelfImportanceScale( self, 'setTopGrade' )
local topGrade = importanceGrade:new()
topGrade:setGradeName( 'top' )
topGrade:addTrigger( 'top' )
topGrade:setColor( '#ff00ff' )
self:addGrade( topGrade )
end
-- Sets the High grade with default settings.
function importanceScale:setHighGrade()
checkSelfImportanceScale( self, 'setHighGrade' )
local highGrade = importanceGrade:new()
highGrade:setGradeName( 'high' )
highGrade:addTrigger( 'high' )
highGrade:setColor( '#ff88ff' )
self:addGrade( highGrade )
end
-- Sets the Mid grade with default settings.
function importanceScale:setMidGrade()
checkSelfImportanceScale( self, 'setMidGrade' )
local midGrade = importanceGrade:new()
midGrade:setGradeName( 'mid' )
midGrade:addTrigger( 'mid' )
midGrade:setColor( '#ffbbff' )
self:addGrade( midGrade )
end
-- Sets the Low grade with default settings.
function importanceScale:setLowGrade()
checkSelfImportanceScale( self, 'setLowGrade' )
local lowGrade = importanceGrade:new()
lowGrade:setGradeName( 'low' )
lowGrade:addTrigger( 'low' )
lowGrade:setColor( '#ffddff' )
self:addGrade( lowGrade )
end
-- Sets the Bottom grade with default settings.
function importanceScale:setBottomGrade()
checkSelfImportanceScale( self, 'setBottomGrade' )
local bottomGrade = importanceGrade:new()
bottomGrade:setGradeName( 'bottom' )
bottomGrade:addTrigger( 'bottom' )
bottomGrade:setColor( '#ffeeff' )
self:addGrade( bottomGrade )
end
-- Sets the No grade with default settings.
function importanceScale:setNoGrade()
checkSelfImportanceScale( self, 'setNoGrade' )
local noGrade = importanceGrade:new()
noGrade:setGradeName( 'no' )
noGrade:addTrigger( 'no' )
noGrade:setColor( '#ffffff' )
self:addGrade( noGrade )
end
-- Sets the NA grade with default settings.
function importanceScale:setNaGrade()
checkSelfImportanceScale( self, 'setNaGrade' )
local naGrade = importanceGrade:new()
naGrade:setGradeName( 'na' )
naGrade:addTriggers{ 'na', 'n/a' }
naGrade:setColor( '#f5f5f5' )
self:addGrade( naGrade )
end
-- Sets the Core grade with default settings.
function importanceScale:setCoreGrade()
checkSelfImportanceScale( self, 'setCoreGrade' )
local coreGrade = importanceGrade:new()
coreGrade:setGradeName( 'core' )
coreGrade:addTrigger( 'core' )
coreGrade:setColor( '#ff00ff' )
self:addGrade( coreGrade )
end
-- Sets the standard importance scale with default settings.
function importanceScale:setStandardImportanceScale()
checkSelfImportanceScale( self, 'setStandardImportanceScale' )
self:setTopGrade()
self:setHighGrade()
self:setMidGrade()
self:setLowGrade()
self:setNaGrade()
end
----------------------------------------------------------
-- Define the taskForce class
|