local categoryHandler = require('Module:Category handler').mainlocal TNT = require('Module:TNT')local lang = mw.getCurrentFrame:preprocess('')
local p =
local function format(msg) return TNT.formatInLanguage(lang, 'Sandbox/Commander Keane/I18n/Wish priority', msg) --try 1st arg as 'de' instead of langend
local function dispError(msg) return mw.text.tag('strong',, format(msg))end
function p.wishpriority(frame) local origArgs = frame:getParent.args local t = local data = local wishes = 0 local wishNumVal = --store wishes only
for k, v in pairs(origArgs) do if type(k) ~= 'string' then return dispError('error_params') end --do we really need this error? Yes. if mw.ustring.match(v,'%S') then if not mw.title.new(v) then dispError('error_characters') end if k:sub(0,4)
if wishes < 1 then if frame.args.example then --create pretty example for template page wishes = 1 table.insert(wishNumVal,) origArgs.score1 = 99 origArgs.notes1 = 'Example note.' else return dispError('error_nowishes') end end --data = for i = 1, wishes do local pos = wishNumVal[i][1] --retrieve the number part of the wish parameter name local title = wishNumVal[i][2] origArgs['score'..pos] = origArgs['score'..pos] or orgArgs['score'] or ' ' origArgs['notes'..pos] = origArgs['notes'..pos] or origArgs['notes'] or ' ' --create scores as numbers for calcs later local scoreNum = -0.01 --so wish with 0 score gets ranked above local a = tonumber(origArgs['score'..pos]) --will be nil if not a number if type(a)
--assign rank table.sort(data, function(u, v) --sort by score(6) but respect order of wish#(1) return u[6]>v[6] or (u[6]
data[1][7] = 1 --first rank always, 7 is a rank as number for calcs data[1][4] = '1' for i = 1, wishes - 1 do
if data[i][6]
--create wikitable, current table columns: Wish title ! Score ! Rank ! Notes --fetch translations local header = format('header') local title = format('title') local score = format('score') local rank = format('rank') local notes = format('notes') table.insert(t, '
-\n') wishLink = mw.ustring.format('%s', data[i][2], data[i][2] ) table.insert(t, ' | '..wishLink..'\n') table.insert(t, ' | '..data[i][3]..'\n') --make sure there is a space after the pipe to account for negative signs causing a new row table.insert(t, ' | '..data[i][4]..'\n') table.insert(t, ' | '..data[i][5]) end table.insert(t, '\n |
--append Category local category = categoryHandler category = category or
return table.concat(t) .. categoryend
return p