local p = {}
local builder = require( "Модуль:HtmlBuilder" )
local function renderError( msg )
local root = builder.create()
root
.tag( 'tr' )
.cssText( 'color: red; font-weight: bold' )
.tag( 'td' )
.attr( 'colspan', 3 )
.wikitext( 'Памылка: ' .. msg .. '.' )
.done()
return tostring( root )
end
local nomineePrefix = {
["featured"] = "Вікіпэдыя:Кандыдаты ў абраныя артыкулы",
["good"] = "Вікіпэдыя:Кандыдаты ў добрыя артыкулы"
}
local function renderScores( score )
return "<small>[" .. score.plus .. " — «за», " .. score.minus .. " — «супраць»]</small>"
end
local states = {
["пачатак"] = function ( title, score )
return "Новы кандыдат " .. renderScores( score )
end,
["павышэньне"] = function ( title, score )
return "Выстаўлены на [[" .. nomineePrefix.featured .. "/" .. title.subpageText .. "|галасаваньне ў абраныя]]"
end,
["паніжэньне"] = function ( title, score )
return "Выстаўлены на [[" .. nomineePrefix.good .. "/" .. title.subpageText .. "|галасаваньне ў добрыя]]"
end,
["пазбаўленьне"] = function ( title, score )
return "Пазбаўлены статусу абранага"
end,
["паніжэньне/добры"] = function ( title, score )
return "Статус паніжаны да добрага"
end,
["абраньне"] = function ( title, score )
return "Артыкул абраны"
end,
["адмова"] = function ( title, score )
return "Вылучэньне не падтрыманае " .. renderScores( score )
end
}
local colours = {
["пачатак"] = "inherit",
["павышэньне"] = "#E9E95E",
["паніжэньне"] = "#AFDAEB",
["пазбаўленьне"] = "#AAA",
["паніжэньне/добры"] = "#CCC",
["абраньне"] = "#FFD700",
["адмова"] = "#F06859"
}
local function renderStatus( status, score )
end
function p.renderItem( frame )
local mode = mw.ustring.lower( mw.text.trim( frame.args[1] ) )
local titleText = mw.text.trim( frame:getParent().args[1] )
local startDate = mw.text.trim( frame:getParent().args[2] )
local state = mw.ustring.lower( mw.text.trim( frame:getParent().args[3] ) )
local score = { ["plus"] = tonumber( mw.text.trim( tostring( frame:getParent().args[4] ) ) ~= "" and frame:getParent().args[4] or 0 ), ["minus"] = tonumber( mw.text.trim( tostring( frame:getParent().args[5] ) ) ~= "" and frame:getParent().args[5] or 0 ) }
if states[state] == nil then return renderError( 'пазначаны няслушны стан намінацыі' ) end
if mode == "абраны" then
titleText = nomineePrefix.featured .. "/" .. titleText
elseif mode == "добры" then
titleText = nomineePrefix.good .. "/" .. titleText
else
return 1 -- FIXME: print error
end
local title = mw.title.new( titleText )
if not title then return renderError( 'пазначаная няслушная назва старонкі' ) end -- FIMXE: print error
mw.log( title.prefixedText )
if not title.exists then return renderError( 'намінацыя для пазначанай старонкі ня створаная' ) end -- FIXME: print error
local root = builder.create()
local row = root
.tag( 'tr' )
.cssText( 'background: ' .. colours[state] )
.tag( 'td' )
.wikitext( mw.language.getContentLanguage():formatDate( 'j xg Y', startDate ) )
.done()
.tag( 'td' )
.wikitext( '[[' .. title.prefixedText .. '|' .. title.subpageText .. ']]' )
.done()
.tag( 'td' )
.wikitext( states[state]( title, score ) )
.done()
return tostring( root )
end
return p