Editing Module:Variants
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
require('Module:Mw.html extension') |
|||
local p = {} |
local p = {} |
||
Line 9: | Line 8: | ||
end |
end |
||
function |
function format_entry(entry) |
||
-- Format the search result as [[Page]]. At the moment, don't include profession data in the table |
|||
local page = entry[1] |
|||
return page |
|||
end |
|||
function get_table_info(args) |
|||
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
||
local query = { |
local query = { |
||
'[[Variant of::'..variant_name..']]', |
'[[Variant of::'..variant_name..']]', |
||
'?Profession A |
-- '?Profession A', |
||
'?Profession B #', |
|||
'?Profession Level A', |
'?Profession Level A', |
||
-- '?Profession B', |
|||
'?Profession Level B', |
'?Profession Level B', |
||
'?Profession Level A High', |
|||
'?Profession Level B High', |
|||
get_images and '?Image#64px;x64px = Image' or nil, |
|||
limit = args.limit or 500, |
limit = args.limit or 500, |
||
} |
} |
||
local smw_data = mw.smw.ask(query) |
local smw_data = mw.smw.ask(query) |
||
table.sort(smw_data, sort_entries) |
|||
local table_contents = {} |
|||
return nil |
|||
for _, entry in ipairs(smw_data) do |
|||
table.insert(table_contents, format_entry(entry)) |
|||
end |
end |
||
return table_contents |
|||
table.sort(smw_data, sort_entries) |
|||
return smw_data |
|||
end |
end |
||
function p. |
function p.variant_table(args) |
||
local |
local elements = get_table_info(args) |
||
local table_contents = table.concat(elements, ' • ') |
|||
local contents |
|||
local html = mw.html.create('div'):addClass('variants-header'):wikitext(table_contents) |
|||
if smw_data then |
|||
return html |
|||
local formatted = {} |
|||
for _, entry in ipairs(smw_data) do |
|||
table.insert(formatted, entry[1]) |
|||
end |
|||
contents = table.concat(formatted, ' • ') |
|||
else |
|||
contents = '[[Category:Empty variant list]]' |
|||
end |
|||
return mw.html.create('div') |
|||
:addClass('variants-header') |
|||
:wikitext(contents) |
|||
:done() |
|||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
local args = frame:getParent().args |
local args = frame:getParent().args |
||
args.variant = args[1] or args.variant |
|||
return p.variants_header(args) |
|||
end |
|||
function p.variants_table(args) |
|||
local smw_data = get_table_info(args, true) |
|||
if not smw_data then |
|||
return ':No variants found.' |
|||
end |
|||
local profession_b_flag = false |
|||
for _, entry in ipairs(smw_data) do |
|||
if entry['Profession B'] or entry['Profession Level B'] then |
|||
profession_b_flag = true |
|||
end |
|||
break |
|||
end |
|||
local table = mw.html.create('table') |
|||
:addClass('sortable wikitable') |
|||
:tag('tr') |
|||
:tag('th') |
|||
:attr{ colspan = '2' } |
|||
:wikitext('Item') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Level') |
|||
:attrIf(profession_b_flag, 'colspan', 2) |
|||
:done() |
|||
:done() |
|||
local function formatProfessionLevel(profession, level, high) |
|||
if not (profession or level) then |
|||
return nil |
|||
end |
|||
profession = profession or 'Unknown profession' |
|||
local level_text = tostring(level or '?') |
|||
if high then |
|||
level_text = ('%s➨%d'):format(level_text, high) |
|||
end |
|||
return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession) |
|||
end |
|||
for _, entry in ipairs(smw_data) do |
|||
local profession_level_a = entry['Profession Level A'] or '?' |
|||
local profession_level_b = entry['Profession Level B'] or '?' |
|||
local profession_a = entry['Profession A'] or '' |
|||
local profession_b = entry['Profession B'] or '' |
|||
table |
|||
:tag('tr') |
|||
:tag('td') |
|||
:css{ ['border-right'] = 'none' } |
|||
:wikitext(entry.Image) |
|||
:done() |
|||
:tag('td') |
|||
:css{ ['border-left'] = 'none' } |
|||
:wikitext(entry[1]) |
|||
:done() |
|||
:tag('td') |
|||
:css{ ['text-align'] = 'right' } |
|||
:wikitext(formatProfessionLevel(entry['Profession A'], entry['Profession Level A'], entry['Profession Level A High'])) |
|||
:IF(profession_b_flag) |
|||
:tag('td') |
|||
:IF(entry['Profession B']) |
|||
:css{ ['text-align'] = 'right' } |
|||
:wikitext(formatProfessionLevel(entry['Profession B'], entry['Profession Level B'], entry['Profession Level B High'])) |
|||
:done() |
|||
:END() |
|||
:done() |
|||
end |
|||
return table |
|||
end |
|||
function p.main_table(frame) |
|||
local args = frame:getParent().args |
|||
args.variant = args[1] or args.variant |
|||
return p.variants_table(args) |
|||
end |
end |
||