Module:Sandbox/Ypnypn/Review

This is an old revision of this page, as edited by Ypnypn (talk | contribs) at 14:27, 11 November 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

function p.review(frame)
    page = frame.args['page'] or frame.args[1]
    article = mw.title.new(page,'')
    content = article:getContent()
    result = ''
    
    issues = critique(content)
    
    if frame.args['plain'] then
        for issue, details in pairs(issues) do
            result = result..'# '..issue..' = '..details..'\n'
        end
        return result
    else
       for issue, details in pairs(issues) do
           result = result..text(issue, details)
        end
        if result == '' then
            result = 'The article is perfect!'
        else
            result = 'The article has some problems:\n'..result
        end
        return result
    end
end

function critique(content)
    issues = {}

    --infobox
    if not string.match(content, '{{Infobox') then
        issues['infobox'] = 'false'
    end

    --categories
    if not string.match(content, '%[%[Category:') then
        issues['category'] = 'none'
    elseif not string.match(content, '%[%[Category:.+%[%[Category:') then
        issues['category'] = 'one'
    end

    return issues
end

function text(issue, details)

    if issue == 'infobox' then
        return '* There is no infobox.\n'
    end

    if issue == 'category' then
        if details == 'none' then
            return '* There are no categories.\n'
        elseif details == 'one' then
            return '* There is only one category.\n'
        end
    end

    return '<strong>Error: issue not found! Issue: '..issue..' = '..details..'</strong'
end

return p