uk =
local messages =
local config =
local category_prefix =
--[Helper methods ] ------------------------------------------------------------------
--local function sprintf(s, tab) return (s:gsub('%%%((%a%w*)%)([-0-9%.]*[cdeEfgGiouxXsq])', function(k, fmt) return tab[k] and ("%"..fmt):format(tab[k]) or '%('..k..')'..fmt end))end
local function make_error(template, arg) return string.format('', config['error_message_template'], string.format(messages[template], arg))end
local function parse_args(frame) local args = local kwargs = for k, v in pairs(frame.args) do v = mw.text.trim(frame:preprocess(v)) if v ~= then if type(k)
local function shift_args(in_args) local args = for i, v in ipairs(in_args) do if i > 1 then args[i - 1] = v end end return in_args[1], argsend
local function format_plural(items, item_type) if #items
1 then return items[1] end return mw.text.listToText(items, ', ', ' ' .. messages['or'] .. ' ')end
local function format_plural_criterion(items, item_type) local value = format_plural(items, item_type) if #items
1 then return string.format(messages[item_type .. '_criterion_singular'], value) end return string.format(messages[item_type .. '_criterion_plural'], value)end
local function make_template_list(args) local templates = for i, v in ipairs(args) do local lang, link = string.match(v, '^([a-z]+):(.+)$') if lang then table.insert(templates, string.format('', config['template_link_template'], link, lang)) else table.insert(templates, string.format('', config['template_link_template'], v)) end end return templatesend
local function make_category_link(v) local lang = 'default' local name = v local m, n = string.match(v, '^([a-z]+):(.+)$') if m then lang = m name = n end return string.format('%s', category_prefix[lang], name, name)end
local function make_category_list(args) local category_links = for i, v in ipairs(args) do v = mw.text.trim(v) if v ~= then table.insert(category_links, make_category_link(v)) end end return category_linksend
local function pagelist(args) local r = for i, v in ipairs(args) do v = mw.text.trim(v) if v ~= then local lang, page = string.match(v, '^([a-z]+):(.+)$') if lang then table.insert(r, string.format('%s', lang, page, page)) else table.insert(r, string.format('', v)) end end end return rend
local function nslist(args) local r = local namespaceName = messages['article'] for i, namespaceId in ipairs(args) do namespaceId = mw.text.trim(namespaceId) if namespaceId ~= then if namespaceId ~= "0" then namespaceName = '' end table.insert(r, namespaceName) end end return rend
--[Criterion format methods ]-------------------------------------------------------------
local criterion =
function criterion.backlinks(args, kwargs, frame) return format_plural_criterion(pagelist(args), 'backlinks')end
function criterion.bytes(args, kwargs, frame) return string.format(messages['bytes_criterion'], args[1])end
function criterion.categories(args, kwargs, frame) local msg = format_plural_criterion(make_category_list(args), 'categories')
if args.ignore ~= nil then r = mw.text.split(args.ignore, ',') for i, v in ipairs(r) do v = mw.text.trim(v) r[i] = make_category_link(v) end msg = msg .. string.format(messages['category_criterion_ignore'], mw.text.listToText(r, ', ', ' ' .. messages['or'] .. ' ')) end
return msgend
function criterion.existing(args, kwargs, frame) return messages['existing_criterion']end
function criterion.forwardlinks(args, kwargs, frame) return format_plural_criterion(pagelist(args), 'forwardlinks')end
function criterion.namespaces(args, kwargs, frame) local site = kwargs.site local msg = format_plural_criterion(nslist(args, site), 'namespaces') if site ~= nil then return sprintf(messages['page_at_site'],) end return msgend
function criterion.new(args, kwargs, frame) local msg = messages['new_criterion'] if kwargs.redirects ~= nil then msg = messages['new_criterion_with_redirects'] end return msgend
function criterion.pages(args, kwargs, frame) return format_plural_criterion(pagelist(args), 'pages')end
function criterion.sparql(args, kwargs, frame) local query = 'SELECT ?item WHERE ' local url = 'http://query.wikidata.org/#' .. frame:callParserFunction('urlencode',) local vizUrl = 'https://tools.wmflabs.org/hay/vizquery/#' .. frame:callParserFunction('urlencode',)
if kwargs.description ~= nil then return sprintf(messages['sparql_criterion_with_explanation'],) end
return sprintf(messages['sparql_criterion'],)end
function criterion.stub(args, kwargs, frame) -- deprecated return messages['stub_criterion']end
function criterion.templates(args, kwargs, frame) return format_plural_criterion(make_template_list(args), 'templates')end
function criterion.format(frame) local args, kwargs = parse_args(frame) local criterion_arg, args = shift_args(args)
-- Try to find the corresponding formatter or bail out if not found if criterion_arg
nil or criterion[formatter]
-- Use manual description if given if kwargs.description ~= nil and formatter ~= 'sparql' then return kwargs.description end
-- Generate auto-generated description return frame:preprocess(criterion[formatter](args, kwargs, frame))end
--[Rule format methods ]-------------------------------------------------------------
local rule =
function rule.image(points, args, kwargs) local out local tplargs = if kwargs.initialimagelimit ~= nil then out = messages['image_rule_limited'] tplargs['initialimagelimit'] = kwargs.initialimagelimit else out = messages['image_rule'] end if kwargs.ownimage ~= nil then out = out .. ' ' .. messages['image_rule_own'] tplargs['ownimage'] = kwargs.ownimage end return sprintf(out, tplargs)end
function rule.wikidata(points, args, kwargs) local out local params local arg_types = local results = if kwargs.properties
nil and kwargs.aliases
nil then return make_error('argument_missing', mw.text.listToText(arg_types, ', ', ' ' .. messages['or'] .. ' ')) end if kwargs.properties ~= nil then params = mw.text.split(kwargs.properties, ',') for k, v in pairs(params) do params[k] = string.format('%s', v, v) end table.insert(results, mw.text.listToText(params, ', ', ' ' .. messages['or'] .. ' ')) end if kwargs.labels ~= nil then params = mw.text.split(kwargs.labels, ',') table.insert(results, messages['label'] .. ' (' .. mw.text.listToText(params, ', ', ' ' .. messages['or'] .. ' ') .. ')') end if kwargs.aliases ~= nil then params = mw.text.split(kwargs.aliases, ',') table.insert(results, messages['alias'] .. ' (' .. mw.text.listToText(params, ', ', ' ' .. messages['or'] .. ' ') .. ')') end if kwargs.descriptions ~= nil then params = mw.text.split(kwargs.descriptions, ',') table.insert(results, messages['description'] .. ' (' .. mw.text.listToText(params, ', ', ' ' .. messages['or'] .. ' ') .. ')') end results = table.concat(results, ' ' .. messages['and'] .. ' ') if kwargs.all ~= nil then out = messages['wikidata_rule_all'] else out = messages['wikidata_rule_first'] end if kwargs.require_reference ~= nil then out = out .. ' ' .. messages['wikidata_rule_require_reference'] end return sprintf(out,)end
function rule.reference(points, args, kwargs) return sprintf(messages['reference_rule'],)end
function rule.templateremoval(points, args, kwargs) local templates = format_plural(make_template_list(args), 'templates') return sprintf(messages['templateremoval_rule'],)end
function rule.categoryremoval(points, args, kwargs) local categories = format_plural(make_category_list(args), 'categories') return sprintf(messages['categoryremoval_rule'],)end
function rule.bytebonus(points, args, kwargs) return sprintf(messages['bytebonus_rule'],)end
function rule.wordbonus(points, args, kwargs) return sprintf(messages['wordbonus_rule'],)end
function rule.format(frame) -- Make tables of anonymous and named arguments local args, kwargs = parse_args(frame) rule_arg, args = shift_args(args) points, args = shift_args(args)
-- Try to find the corresponding formatter or bail out if not found if rule_arg
nil then return frame:preprocess(make_error('invalid_rule', rule_arg)) end
-- All rules requires argument 1: number of points awarded if points
points = points:gsub('%.', config['decimal_separator'])
-- If there's a rule formatter function, use it. -- Otherwise, use the string from the messages table. local out if rule[formatter] ~= nil then out = rule[formatter](points, args, kwargs) else out = sprintf(messages[formatter .. '_rule'],) end
if kwargs.max ~= nil then out = sprintf(messages['base_rule_max'],) end
return frame:preprocess(out)end
-- Exportreturn