Jump to content

Module:Sandbox/Mr. Stradivarius/sandbox3

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 06:19, 7 September 2013 (use a class-making function for new classes, use a _type field and _inherits table to track object type and inheritance, revamp checkObject and makeCheckSelfFunction). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local dts = require( 'Module:User:Anomie/deepToString' ).deepToString -- for debugging

-- TODO:
-- define self.page

local htmlBuilder = require( 'Module:HtmlBuilder' )

----------------------------------------------------------
-- Define constants
----------------------------------------------------------

local currentTitleObject = mw.title.getCurrentTitle()

----------------------------------------------------------
-- Helper functions
----------------------------------------------------------

-- Checks to see if a given variable is a non-blank string. Returns the string if true,
-- and returns false if not.
local function checkString( s )
    if type( s ) == 'string' and s ~= '' then
        return s
    else
        return false
    end
end

-- Adds a string to an array. Returns nil on an attempt to add a non-string value, and returns
-- an error on an attempt to add a string to a non-table value. Checks that the string is not
-- the empty string, and if the array is not present, the function creates it.
local function addStringToArray( array, s )
    s = checkString( s )
    if s then
        if type( array ) == 'table' then
            table.insert( array, s )
        elseif type( array ) == 'nil' then
            array = {}
            table.insert( array, s )
        else
            error( mw.ustring.format(
                'Error in argument #1 to addStringToArray: expected type "table" or "nil", got type "%s"',
                type( array )
            ), 2 )
        end
    end
    return array or {}
end

-- Checks to see if a given variable is an object that has inherited from type objType.
-- Returns the object if true, and returns false if not.
local function checkObject( obj, objType )
    if type( obj ) == 'table' and type( obj._inherits ) == 'table' and obj._inherits[ objType ] then
        return obj
    else
        return false
    end
end

local function makeClass( classType )
    if not checkString( classType ) then
        error( 'makeClass: no class type specified, or the class type was invalid. Class types should be a non-blank string' )
    end
    local class = {}

    -- Set the class type and start the _inherits table. These track the type of the current object and what classes it has
    -- inherited from. Used in checkObject and in error messages.
    class._type = classType
    class._inherits = { [ classType ] = true }

    function class:new( init )
        init = type( init ) == 'table' and init or {}
        local obj = {}

        -- Set the object type if it is specified.
        if checkString( init.type ) then
            obj._type = init.type
        else
            obj._type = self._type
        end

        -- Copy the _inherits table and add the new object type.
        obj._inherits = {}
        for k, v in pairs( self._inherits ) do
            obj._inherits[ k ] = v
        end
        obj._inherits[ obj._type ] = true

        -- Set the index metamethod and the metatable.
        self.__index = self
        setmetatable( obj, self )
        
        return obj
    end

    -- Makes a function that raises an error if the dot syntax is used with methods. It only checks
    -- that the object is in the right object family, not that it is the right object, but it will catch
    -- the majority of cases, and it works with inheritance.
    function class:makeCheckSelfFunction()
        local classType = self._type -- Here, "self" refers to the class used to make the checkSelf function.
        return function( self, method )
            if type( self ) ~= 'table' or type( self._inherits ) ~= 'table' or not self._inherits[ classType ] then -- Here, "self" refers to the first parameter passed to the method being checked.
                error( mw.ustring.format(
                    '%s: invalid %s object. Did you call %s with a dot instead of a colon, i.e. %s.%s() instead of %s:%s()?',
                    classType, classType, method, classType, method, classType, method
                ), 3 )
            end
        end
    end

    return class
end

----------------------------------------------------------
-- Define the assessmentGrade class
--
-- The assessmentGrade class sets the categories and
-- aliases for one importance scale grade or quality scale
-- grade.
----------------------------------------------------------

local assessmentGrade = makeClass( 'assessmentGrade' )
local checkSelfAssessmentGrade = assessmentGrade:makeCheckSelfFunction()

-- Sets the name of the assessment grade. For example, for a C-class quality grade,
-- the grade name would be "c".
function assessmentGrade:setGradeName( s )
    checkSelfAssessmentGrade( self, 'setGradeName' )
    s = checkString( s )
    if s then
        self.gradeName = mw.ustring.lower( s )
    end
end

-- Gets the grade name.
function assessmentGrade:getGradeName()
    checkSelfAssessmentGrade( self, 'getGradeName' )
    return self.gradeName
end

-- Adds a trigger for the assessment grade. For example, if you want
-- the grade to be triggered by the code "|class=foo", then the trigger
-- would be "foo".
function assessmentGrade:addTrigger( s )
    checkSelfAssessmentGrade( self, 'addTrigger' )
    self.triggers = addStringToArray( self.triggers, s )
end

-- Adds an array of triggers to the assessment grade object.
function assessmentGrade:addTriggers( t )
    checkSelfAssessmentGrade( self, 'addTriggers' )
    if type( t ) ~= 'table' then return end
    for i, trigger in ipairs( t ) do
        self:addTrigger( trigger )
    end
end

-- Returns an array containing the trigger values for the assessment grade object.
function assessmentGrade:getTriggers()
    checkSelfAssessmentGrade( self, 'getTriggers' )
    return self.triggers or {}
end

-- Sets the category used by the assessment grade. This should only be used if the
-- category does not follow the default naming system. Normally categories are set
-- by the qualityScale and importanceScale objects or banner objects.
function assessmentGrade:setCategory( s )
    checkSelfAssessmentGrade( self, 'setCategory' )
    s = checkString( s )
    if s then
        self.category = s
    end
end

-- Gets the assessment grade's category.
function assessmentGrade:getCategory()
    checkSelfAssessmentGrade( self, 'getCategory' )
    return self.category
end

-- Sets the color of the icon box when the assessment grade is used.
function assessmentGrade:setColor( s )
    checkSelfAssessmentGrade( self, 'setColor' )
    s = checkString( s )
    if s then
        self.color = s
    end
end

-- Gets the color used for the assessment grade.
function assessmentGrade:getColor()
    checkSelfAssessmentGrade( self, 'getColor' )
    return self.color
end

-- Sets an icon for the assessment grade.
function assessmentGrade:setIcon( s )
    checkSelfAssessmentGrade( self, 'setIcon' )
    s = checkString( s )
    if s then
        self.icon = s
    end
end

-- Gets the assessment grade icon.
function assessmentGrade:getIcon()
    checkSelfAssessmentGrade( self, 'getIcon' )
    return self.icon
end

----------------------------------------------------------
-- Define the qualityGrade class
----------------------------------------------------------

local qualityGrade = assessmentGrade:new{ type = 'qualityGrade' }

----------------------------------------------------------
-- Define the importanceGrade class
----------------------------------------------------------

local importanceGrade = assessmentGrade:new{ type = 'importanceGrade' }

----------------------------------------------------------
-- Define the assessmentScale class
--
-- The assessmentScale class provides the infrastructure
-- for importance scales and quality scales. It uses
-- assessmentGrade objects to define each grade
-- on the assessment scale.
----------------------------------------------------------

local assessmentScale = makeClass( 'assessmentScale' )
local checkSelfAssessmentScale = assessmentScale:makeCheckSelfFunction()

-- 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

-- Sets the name of the category family. For example, for a quality scale with categories
-- such as [[Category:C-class tulips articles]] and [[Category:List-class tulips articles]]
-- the category family name would be "tulips articles".
function assessmentScale:setCategoryFamily( s )
    checkSelfAssessmentScale( self, 'setCategoryFamily' )
    s = checkString( s )
    if s then
        self.categoryFamily = s
    end    
end

-- Gets the category family name for the assessment object.
function assessmentScale:getCategoryFamily()
    checkSelfAssessment( self, 'getCategoryFamily' )
    return self.categoryFamily
end

-- Adds an assessment grade object.
function assessmentScale:addGrade( obj )
    checkSelfAssessmentScale( self, 'addGrade' )
    obj = checkObject( obj, 'assessmentGrade' )
    if obj then
        local gradeName = obj:getGradeName()
        if not checkString( gradeName ) then
            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
            self.grades = self.grades or {}
            if self.grades[ gradeName ] then
                error( mw.ustring.format( 'Attempted to add assessment grade %s, but assessment grade %s was already defined. Assessment grades can only be defined once', gradeName, gradeName ), 2 )
            else
                self.grades[ gradeName ] = obj
            end
        end
    end
end

-- Adds an array of grade objects.
function assessmentScale:addGrades( t )
    checkSelfAssessmentScale( self, 'addGrades' )
    if type( t ) ~= 'table' then return end
    for i, gradeObject in ipairs( t ) do
        self:addGrade( gradeObject )
    end
end

-- Removes an assessment grade object from the assessment scale.
function assessmentScale:removeGrade( s )
    checkSelfAssessmentScale( self, 'removeGrade' )
    s = checkString( s )
    if s and type( self.grades ) == 'table' and self.grades[ s ] then
        self.grades[ s ] = nil
    end
end

-- Removes multiple assessment grade objects from the assessment scale.
function assessmentScale:removeGrades( t )
    checkSelfAssessmentScale( self, 'removeGrades' )
    if type( t ) == 'table' then
        for i, grade in ipairs( t ) do
            self:removeGrade( grade )
        end
    end
end

-- Gets the object's grade table.
function assessmentScale:getGrades()
    checkSelfAssessmentScale( self, 'getGrades' )
    return self.grades or {}
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 gradeObj = self.grades[ gradeName ]
    if not checkObject( gradeObj, 'assessmentGrade' ) then
        error( mw.ustring.format( 'editGrade: no assessment grade object found with grade name "%s"', gradeName ), 2 )
    end
    if type( gradeObj[ 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.grades[ gradeName ], ... )
end

-- Checks for duplicate triggers for the grade objects added to the assessment scale.
-- If any are found, displays an error.
function assessmentScale:checkForDuplicateTriggers()
    checkSelfAssessmentScale( self, 'checkForDuplicateTriggers' )
    local grades = self.grades or {}
    if type( grades ) ~= 'table' then return end
    local exists = {}
    for name, gradeObj in pairs( grades ) do
        gradeObj = checkObject( gradeObj, 'assessmentGrade' )
        if gradeObj then
            local triggers = type( gradeObj.getTriggers ) == 'function' and gradeObj:getTriggers()
            if type( triggers ) == 'table' then
                for i, trigger in ipairs( triggers ) do
                    trigger = checkString( trigger )
                    if trigger then
                        if exists[ trigger ] then
                            error( mw.ustring.format(
                                'Duplicate trigger value "%s" detected in the assessment grade objects "%s" and "%s"',
                                trigger, exists[ trigger ],    name
                            ), 2 )
                        else
                            exists[ trigger ] = name
                        end
                    end
                end
            end
        end
    end
end

----------------------------------------------------------
-- Define the qualityScale class
----------------------------------------------------------

local qualityScale = assessmentScale:new{ type = 'qualityScale' }
local checkSelfQualityScale = qualityScale:makeCheckSelfFunction()

-- Sets the FA (Featured Article) grade with default settings.
function qualityScale:setFaGrade()
    checkSelfQualityScale( self, 'setFaGrade' )
    local faGrade = qualityGrade:new()
    faGrade:setGradeName( 'fa' )
    faGrade:addTrigger( 'fa' )
    faGrade:setColor( '#6699ff' )
    faGrade:setIcon( 'Featured article star.svg' )
    self:addGrade( faGrade )
end

-- Sets the A grade with default settings.
function qualityScale:setAGrade()
    checkSelfQualityScale( self, 'setAGrade' )
    local aGrade = qualityGrade:new()
    aGrade:setGradeName( 'a' )
    aGrade:addTrigger( 'a' )
    aGrade:setColor( '#66ffff' )
    aGrade:setIcon( 'Symbol a class.svg' )
    self:addGrade( aGrade )
end

-- Sets the GA (Good Article) grade with default settings.
function qualityScale:setGaGrade()
    checkSelfQualityScale( self, 'setGaGrade' )
    local gaGrade = qualityGrade:new()
    gaGrade:setGradeName( 'ga' )
    gaGrade:addTrigger( 'ga' )
    gaGrade:setColor( '#66ff66' )
    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:setGradeName( 'b' )
    bGrade:addTrigger( 'b' )
    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:setGradeName( 'c' )
    cGrade:addTrigger( 'c' )
    cGrade:setColor( '#ffff66' )
    self:addGrade( cGrade )
end

-- Sets the Start grade with default settings.
function qualityScale:setStartGrade()
    checkSelfQualityScale( self, 'setStartGrade' )
    local startGrade = qualityGrade:new()
    startGrade:setGradeName( 'start' )
    startGrade:addTrigger( 'start' )
    startGrade:setColor( '#ffaa66' )
    self:addGrade( startGrade )
end

-- Sets the Stub grade with default settings.
function qualityScale:setStubGrade()
    checkSelfQualityScale( self, 'setStubGrade' )
    local stubGrade = qualityGrade:new()
    stubGrade:setGradeName( 'stub' )
    stubGrade:addTrigger( 'stub' )
    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:setGradeName( 'fl' )
    flGrade:addTrigger( 'fl' )
    flGrade:setColor( '#6699ff' )
    flGrade:setIcon( 'Featured article star.svg' )
    self:addGrade( flGrade )
end

-- Sets the List grade with default settings.
function qualityScale:setListGrade()
    checkSelfQualityScale( self, 'setListGrade' )
    local listGrade = qualityGrade:new()
    listGrade:setGradeName( 'list' )
    listGrade:addTrigger( 'list' )
    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:setGradeName( 'na' )
    naGrade:addTriggers{ 'na', 'n/a' }
    naGrade:setColor( '#f5f5f5' )
    self:addGrade( naGrade )
end

-- Sets the Category grade with default settings.
function qualityScale:setCategoryGrade()
    checkSelfQualityScale( self, 'setCategoryGrade' )
    local categoryGrade = qualityGrade:new()
    categoryGrade:setGradeName( 'category' )
    categoryGrade:addTriggers{ 'category', 'cat', 'categ' }
    categoryGrade:setColor( '#ffdb58' )
    self:addGrade( categoryGrade )
end

-- Sets the Disambig (disambiguation) grade with default settings.
function qualityScale:setDisambigGrade()
    checkSelfQualityScale( self, 'setDisambigGrade' )
    local disambigGrade = qualityGrade:new()
    disambigGrade:setGradeName( 'disambig' )
    disambigGrade:addTriggers{ 'disambiguation', 'disambig', 'disamb', 'dab' }
    disambigGrade:setColor( '#00fa9a' )
    self:addGrade( disambigGrade )
end

-- Sets the File grade with default settings.
function qualityScale:setFileGrade()
    checkSelfQualityScale( self, 'setFileGrade' )
    local fileGrade = qualityGrade:new()
    fileGrade:setGradeName( 'file' )
    fileGrade:addTriggers{ 'file', 'img', 'image' }
    fileGrade:setColor( '#ddccff' )
    self:addGrade( fileGrade )
end

-- Sets the Portal grade with default settings.
function qualityScale:setPortalGrade()
    checkSelfQualityScale( self, 'setPortalGrade' )
    local portalGrade = qualityGrade:new()
    portalGrade:setGradeName( 'portal' )
    portalGrade:addTrigger( 'portal' )
    portalGrade:setColor( '#cc8899' )
    self:addGrade( portalGrade )
end

-- Sets the Project grade with default settings.
function qualityScale:setProjectGrade()
    checkSelfQualityScale( self, 'setProjectGrade' )
    local projectGrade = qualityGrade:new()
    projectGrade:setGradeName( 'project' )
    projectGrade:addTriggers{ 'project', 'proj', 'prj' }
    projectGrade:setColor( '#c0c090' )
    self:addGrade( projectGrade )
end

-- Sets the Template grade with default settings.
function qualityScale:setTemplateGrade()
    checkSelfQualityScale( self, 'setTemplateGrade' )
    local templateGrade = qualityGrade:new()
    templateGrade:setGradeName( 'template' )
    templateGrade:addTriggers{ 'template', 'temp', 'tpl', 'tmp', 'templ' }
    templateGrade:setColor( '#fbceb1' )
    self:addGrade( templateGrade )
end

-- Sets the Redirect grade with default settings.
function qualityScale:setRedirectGrade()
    checkSelfQualityScale( self, 'setRedirectGrade' )
    local redirectGrade = qualityGrade:new()
    redirectGrade:setGradeName( 'redirect' )
    redirectGrade:addTriggers{ 'redirect', 'red', 'redir' }
    redirectGrade:setColor( '#c0c0c0' )
    self:addGrade( redirectGrade )
end

-- Sets the Book grade with default settings.
function qualityScale:setBookGrade()
    checkSelfQualityScale( self, 'setBookGrade' )
    local bookGrade = qualityGrade:new()
    bookGrade:setGradeName( 'book' )
    bookGrade:addTriggers{ 'book', 'bk' }
    bookGrade:setColor( '#98ff98' )
    self:addGrade( bookGrade )
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:setColor( '#6699ff' )
    fmGrade:setIcon( 'Featured article star.svg' )
    self:addGrade( fmGrade )
end

-- Set the standard quality scale with default values.
function qualityScale:setStandardQualityScale()
    checkSelfQualityScale( self, 'setStandardQualityScale' )
    self:setFaGrade()
    self:setAGrade()
    self:setGaGrade()
    self:setBGrade()
    self:setCGrade()
    self:setStartGrade()
    self:setStubGrade()
    self:setFlGrade()
    self:setListGrade()
    self:setNaGrade()
end

-- Set the extended quality scale with default values.
function qualityScale:setExtendedQualityScale()
    checkSelfQualityScale( self, 'setExtendedQualityScale' )
    self:setStandardQualityScale()
    self:setCategoryGrade()
    self:setDisambigGrade()
    self:setFileGrade()
    self:setPortalGrade()
    self:setProjectGrade()
    self:setTemplateGrade()
end

----------------------------------------------------------
-- Define the importanceScale class
----------------------------------------------------------

local importanceScale = assessmentScale:new{ type = 'importanceScale' }
local checkSelfImportanceScale = importanceScale:makeCheckSelfFunction()

-- 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 row class
----------------------------------------------------------

local row = makeClass( 'row' )
local checkSelfRow = row:makeCheckSelfFunction()

-- Adds a category to the "categories" table of the row object. Creates the categories table if it doesn't exist.
function row:addCategory( s )
    checkSelfRow( self, 'addCategory' )
    self.categories = addStringToArray( self.categories, s )
end

-- Adds all categories in an array to the row's "categories" table.
function row:addCategories( t )
    checkSelfRow( self, 'addCategories' )
    if type( t ) == 'table' then
        for i, category in ipairs( t ) do
            self:addCategory( category )
        end
    end
end

-- Returns the row object's category table.
function row:getCategories()
    checkSelfRow( self, 'getCategories' )
    return self.categories or {}
end

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()
    rowIconOutput = checkString( rowIconOutput )
    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
        .tag( 'tr' )
        .tag( 'td' )
        .wikitext( rowIconOutput )
        .done()
        .tag( 'td' )
        .attr( 'colspan', '2' )
        .wikitext( rowContentOutput )
    elseif rowContentOutput and not rowIconOutput then
        ret
        .tag( 'tr' )
        .tag( 'td' )
        .attr( 'colspan', '3' )
        .wikitext( rowContentOutput )
    end
    return tostring( ret )
end

----------------------------------------------------------
-- Define the qualityRow class
----------------------------------------------------------

local qualityRow = row:new{ type = 'qualityRow' }
local checkSelfQualityRow = qualityRow:makeCheckSelfFunction()

-- Sets the quality scale for the quality row. The input must be a qualityScale object.
function qualityRow:setQualityScale( obj )
    checkSelfQualityRow( self, 'setQualityScale' )
    obj = checkObject( obj, 'qualityScale' )
    if obj and type( obj.setFaGrade ) == 'function' then
        self.qualityScale = obj
	end
end

-- Sets the standard quality scale with default settings.
function qualityRow:setStandardQualityScale()
	checkSelfQualityRow( self, 'setStandardQualityScale' )
	local standard = qualityScale:new()
	standard:setStandardQualityScale()
	self:setQualityScale( standard )
end

-- Sets the extended quality scale with default settings.
function qualityRow:setExtendedQualityScale()
	checkSelfQualityRow( self, 'setExtendedQualityScale' )
	local extended = qualityScale:new()
	extended:setExtendedQualityScale()
	self:setQualityScale( extended )
end

-- Gets the quality scale object if it is set.
function qualityRow:getQualityScale()
	checkSelfQualityRow( self, 'getQualityScale' )
	return self.qualityScale
end

----------------------------------------------------------
-- Define the importanceRow class
----------------------------------------------------------

local importanceRow = row:new{ type = 'importanceRow' }
local checkSelfImportanceRow = importanceRow:makeCheckSelfFunction()

-- Sets the importance scale for the importance row. The input must be a importanceScale object.
function importanceRow:setImportanceScale( obj )
	checkSelfImportanceRow( self, 'setImportanceScale' )
	obj = checkObject( obj, 'importanceScale' )
	if obj and type( obj.setTopGrade ) == 'function' then
		self.importanceScale = obj
	end
end

-- Sets the standard importance scale with default settings.
function importanceRow:setStandardImportanceScale()
	checkSelfImportanceRow( self, 'setStandardImportanceScale' )
	local standard = importanceScale:new()
	standard:setStandardImportanceScale()
	self:setImportanceScale( standard )
end

-- Gets the importance scale object if it is set.
function importanceRow:getImportanceScale()
	checkSelfImportanceRow( self, 'getImportanceScale' )
	return self.importanceScale
end

----------------------------------------------------------
-- Define the taskForce class
----------------------------------------------------------

local taskForce = row:new()

----------------------------------------------------------
-- Define the banner class
----------------------------------------------------------

local banner = makeClass( 'banner' )
local checkSelfBanner = banner:makeCheckSelfFunction()

-- Sets the project name.
function banner:setProject( s )
    checkSelfBanner( self, 'setProject' )
    s = checkString( s )
    if s then
        self.project = s
    end
end

-- Gets the project name.
function banner:getProject()
    checkSelfBanner( self, 'getProject' )
    return self.project
end

-- Sets the banner's main image.
function banner:setImage( s )
    checkSelfBanner( self, 'setImage' )
    s = checkString( s )
    if s then
        self.image = s
    end
end

-- Gets the banner's main image.
function banner:getImage()
    checkSelfBanner( self, 'getImage' )
    return self.image
end

-- Adds one category to the banner's "categories" table.
function banner:addCategory( s )
    checkSelfBanner( self, 'addCategory' )
    self.categories = addStringToArray( self.categories, s )
end

-- Adds all categories in a "categories" array to the banner's "categories" table.
function banner:addCategories( categoryTable )
    checkSelfBanner( self, 'addCategories' )
    if type( categoryTable ) == 'table' then
        for i, category in ipairs( rowObject.categories ) do
            self:addCategory( category )
        end
    end
end

-- Returns the banner object's category table.
function banner:getCategories()
    checkSelfBanner( self, 'getCategories' )
    return self.categories or {}
end

-- Returns a string of category links for the categories in obj.categories.
function banner:exportCategories()
    checkSelfBanner( self, 'exportCategories' )
    if type( self.categories ) == 'table' then
        local ret = {}
        for i, category in ipairs( self.categories ) do
            category = checkString( category )
            if category then
                table.insert( ret, mw.ustring.format(
                    '[[Category:%s|%s]]',
                    category,
                    type( self.page ) == 'string' and self.page or currentTitleObject.text
                ) )
            end
        end
        return table.concat( ret )
    end
    return ''
end        

-- Adds a row object to the banners "rows" table, and adds the row object's categories
-- to the banners "categories" table. Categories are deleted from the row object after
-- they have been transferred.
function banner:addRow( rowObj )
    checkSelfBanner( self, 'addRow' )
    self.rows = self.rows or {}
    rowObj = checkObject( rowObj, 'row' )
    if rowObj and type( rowObj.getCategories ) == 'function' then
        self:addCategories( rowObj:getCategories() )
        rowObj.categories = nil -- Erase the categories from the row object to make sure we don't add the same categories twice.
        table.insert( self.rows, rowObj )
    end
end

-- Adds an array of row objects to the banner object.
function banner:addRows( t )
    checkSelfBanner( self, 'addRows' )
    if type( t ) == 'table' then
        for i, rowObj in ipairs( t ) do
            self:addRow( rowObj )
        end
    end
end

function banner:setQualityRow( obj )
    checkSelfBanner( self, 'setQualityRow' )
end

function banner:setImportanceRow( obj )
end

function banner:export()
    checkSelfBanner( self, 'export' )
	local rowOutput = {}
	for i, row in ipairs( banner.rows ) do
		table.insert( ret, row:export() )
	end
	rowOutput = table.concat( rowOutput )
end

-----------------------------------------------------------------
-- Export objects and functions to be used from other modules
-----------------------------------------------------------------

local p = {}

p.banner = banner
p.row = row
p.makeCheckSelfFunction = makeCheckSelfFunction

-----------------------------------------------------------------
-- Testing area
-----------------------------------------------------------------

function p.test( frame )
    local myqs = qualityScale:new()
    myqs:setStandardQualityScale()
    local fooGrade = qualityGrade:new()
    fooGrade:addTrigger( 'foo' )
    fooGrade:setGradeName( 'foo' )
    myqs:addGrade( fooGrade )
    myqs:checkForDuplicateTriggers()
    myqs:editGrade( 'a', 'setIcon', 'foobar.svg' )
    return myqs.grades.a.icon
end

return p