Editing Module:Param Parse
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 6: | Line 6: | ||
local Infobox = require('Module:Infobox') |
local Infobox = require('Module:Infobox') |
||
local currency = require('Module:Currency').parse |
local currency = require('Module:Currency').parse |
||
local editbutton = require('Module:Edit button') |
|||
local edit = editbutton("'''?''' (edit)") |
|||
local parse = {} |
local parse = {} |
||
Line 180: | Line 178: | ||
size = '|x'..height..'px' |
size = '|x'..height..'px' |
||
end |
end |
||
if name then |
|||
local imagecheck = name and mw.smw.ask('[['..name..']]|?Modification date=data') |
|||
imagecheck = imagecheck~=nil and imagecheck[1]~=nil and imagecheck[1].data~=nil |
|||
if name and imagecheck then |
|||
return '[['..name..size..']]' |
return '[['..name..size..']]' |
||
elseif name then |
|||
return '[['..name..size..']][[Category:Needs image]]' |
|||
end |
end |
||
return nil |
return nil |
||
Line 213: | Line 207: | ||
-- Episode |
-- Episode |
||
local valid_episodes = { |
local valid_episodes = { |
||
['none'] = |
['none'] = 'None', |
||
['hopeport'] = |
['hopeport'] = 'Hopeport', |
||
['hopeforest'] = |
['hopeforest'] = 'Hopeforest', |
||
['mine of mantuban'] = |
['mine of mantuban'] = 'Mine of Mantuban', |
||
['crenopolis'] = |
['crenopolis'] = 'Crenopolis', |
||
['stonemaw hill'] = |
['stonemaw hill'] = 'Stonemaw Hill', |
||
['bleakholm crags'] = |
['bleakholm crags'] = 'Bleakholm Crags' |
||
} |
} |
||
function parse.episode_func(episode) |
function parse.episode_func(episode) |
||
local valid_episode = valid_episodes[string.lower(episode or '')] |
local valid_episode = valid_episodes[string.lower(episode or '')] |
||
if valid_episode then |
if valid_episode then |
||
if valid_episode == 'None' then |
|||
local sort = valid_episode[1] |
|||
return '[[File:Unknown episode icon.png|18px|link=]] None' |
|||
local name = valid_episode[2] |
|||
else |
|||
local link = name |
|||
return '[[File:'..valid_episode..' episode icon.png|18px|link='..valid_episode..']] [['..valid_episode..']]' |
|||
local label = '[[' .. name .. ']]' |
|||
if sort == 0 then |
|||
name = 'Unknown' |
|||
link = '' |
|||
label = 'None' |
|||
end |
end |
||
return ('<span data-sort-value="%s">[[File:%s episode icon.png|18px|link=%s]] %s</span>'):format(sort, name, link, label) |
|||
end |
end |
||
return nil |
return nil |
||
Line 240: | Line 229: | ||
local valid_episode = valid_episodes[string.lower(episode or '')] |
local valid_episode = valid_episodes[string.lower(episode or '')] |
||
if valid_episode then |
if valid_episode then |
||
return valid_episode |
return valid_episode |
||
end |
end |
||
return nil |
return nil |
||
Line 319: | Line 308: | ||
category_incomplete = 'Needs release date', |
category_incomplete = 'Needs release date', |
||
smw_property = 'Release Date', |
smw_property = 'Release Date', |
||
smw_func = parse.release_smw, |
|||
} |
|||
parse.removal = { |
|||
name = 'removal', |
|||
func = parse.release_func, |
|||
smw_property = 'Removal Date', |
|||
smw_func = parse.release_smw, |
smw_func = parse.release_smw, |
||
} |
} |
||
Line 330: | Line 313: | ||
-- Value |
-- Value |
||
function parse.value_func(val) |
function parse.value_func(val) |
||
if val == '' or val == ' ' then |
|||
return |
|||
elseif val == 'N/A' then |
|||
return 'N/A' |
|||
end |
|||
local status, val = pcall(currency, val) |
local status, val = pcall(currency, val) |
||
if status then |
if status then |
||
Line 456: | Line 434: | ||
end |
end |
||
function parse.variant_category_func(v) |
function parse.variant_category_func(v) |
||
v = parse.has_content(v) |
|||
if v == nil then |
if v == nil then |
||
return nil |
return nil |
||
elseif v == 'N/A' then |
|||
return 'N/A' |
|||
end |
end |
||
v = strip_link(v) |
v = strip_link(v) |
||
Line 468: | Line 443: | ||
end |
end |
||
return ('[[%s|%s]]'):format(v, name) |
return ('[[%s|%s]]'):format(v, name) |
||
end |
|||
function parse.variant_smw_func(v) |
|||
v = parse.has_content(v) |
|||
if v == 'N/A' then |
|||
return |
|||
end |
|||
return v |
|||
end |
end |
||
local function name_without_variant_category(name, variant_name) |
local function name_without_variant_category(name, variant_name) |
||
variant_name = |
if name:sub(-1-#variant_name) == ' '..variant_name then |
||
if variant_name and name:sub(-1-#variant_name) == ' '..variant_name then |
|||
-- Ends with the variant name. Remove it |
-- Ends with the variant name. Remove it |
||
name = name:sub(1, -2-#variant_name) |
name = name:sub(1, -2-#variant_name) |
||
Line 485: | Line 452: | ||
end |
end |
||
local function name_with_variant_category(name, v, passive, is_for_smw) |
local function name_with_variant_category(name, v, passive, is_for_smw) |
||
v = parse.variant_smw_func(v) |
|||
if v == nil then |
if v == nil then |
||
return name |
return name |
||
Line 529: | Line 495: | ||
name = 'variant', |
name = 'variant', |
||
func = parse.variant_category_func, |
func = parse.variant_category_func, |
||
smw_func = parse. |
smw_func = parse.has_content, |
||
smw_property = 'Variant of', |
smw_property = 'Variant of', |
||
category_incomplete = 'Needs variant' |
category_incomplete = 'Needs variant' |
||
Line 546: | Line 512: | ||
func = {name=parse.name_without_variant_category_func, params = {Infobox.raw_param('name'), Infobox.raw_param('variant')}}, |
func = {name=parse.name_without_variant_category_func, params = {Infobox.raw_param('name'), Infobox.raw_param('variant')}}, |
||
smw_property = 'Variant name' |
smw_property = 'Variant name' |
||
} |
|||
-- Variant type |
|||
local valid_variant_types = { |
|||
['item'] = 'Item', |
|||
['monster'] = 'Monster', |
|||
['skill node'] = 'Skill node', |
|||
['venture'] = 'Venture', |
|||
['bounty'] = 'Bounty' |
|||
} |
|||
function parse.variant_type_func(type) |
|||
local valid_type = valid_variant_types[string.lower(type or '')] |
|||
if valid_type then |
|||
return valid_type..'[[Category:'..valid_type..' variants]]' |
|||
else |
|||
return edit..'[[Category:Invalid variant type]]' |
|||
end |
|||
return nil |
|||
end |
|||
parse.variant_type = { |
|||
name = 'variant_type', |
|||
func = parse.variant_type_func, |
|||
smw_func = parse.has_content, |
|||
smw_property = 'Variant type', |
|||
category_incomplete = 'Needs variant type' |
|||
} |
} |
||
Line 584: | Line 524: | ||
function parse.duration_func(hours) |
function parse.duration_func(hours) |
||
hours = string.gsub(hours or '',',','') |
hours = string.gsub(hours or '',',','') |
||
return (tonumber(hours) .. " Hours") |
|||
return (hours .. " Hours") |
|||
end |
end |
||
Line 694: | Line 633: | ||
-- Unlock Level |
-- Unlock Level |
||
function parse. |
function parse.unlock_level_func(profession, level) |
||
if level == 'N/A' then |
|||
return parse.has_content(unlock_profession or 'N/A') |
|||
end |
|||
return parse.has_content(unlock_profession or profession) |
|||
end |
|||
function parse.unlock_profession_func_smw(unlock_profession, profession, level) |
|||
local prof = parse.unlock_profession_func(unlock_profession, profession, level) |
|||
if prof == 'N/A' then |
|||
return nil |
|||
end |
|||
return prof |
|||
end |
|||
function parse.unlock_level_func(unlock_profession, profession, level) |
|||
if parse.has_content(level) == 'N/A' then |
|||
-- unlock_profession set but level = N/A is not handled, handle it here |
|||
-- (and in the smw func) if needed for whatever reason |
|||
return 'N/A' |
|||
end |
|||
local level_valid = parse.number(level) |
local level_valid = parse.number(level) |
||
local profession_valid = parse. |
local profession_valid = parse.has_content(profession) |
||
local profession_valid_link = profession_valid |
local profession_valid_link = profession_valid |
||
if not profession_valid and not level_valid then |
if not profession_valid and not level_valid then |
||
return nil |
return nil |
||
end |
end |
||
if not profession_valid and level_valid then |
if not profession_valid and level_valid then |
||
-- Profession undefined but level defined, invalid, show an unknown profession |
-- Profession undefined but level defined, invalid, show an unknown profession |
||
Line 729: | Line 647: | ||
profession_valid_link = '' |
profession_valid_link = '' |
||
end |
end |
||
if profession_valid and not level_valid then |
if profession_valid and not level_valid then |
||
-- Profession defined without level, invalid, show an unknown level |
-- Profession defined without level, invalid, show an unknown level |
||
level_valid = '?' |
level_valid = '?' |
||
end |
end |
||
return '[[File:'..profession_valid..'_icon.png|link='..profession_valid_link..'|width=18x18]] '..level_valid |
return '[[File:'..profession_valid..'_icon.png|link='..profession_valid_link..'|width=18x18]] '..level_valid |
||
end |
end |
||
function parse.unlock_level_smw( |
function parse.unlock_level_smw(profession, level) |
||
local profession_valid = parse.has_content(profession) |
|||
return nil |
|||
end |
|||
local profession_valid = parse.unlock_profession_func(unlock_profession, profession) |
|||
local level_valid = parse.number(level) |
local level_valid = parse.number(level) |
||
if not profession_valid then |
if not profession_valid then |
||
return nil |
return nil |
||
end |
end |
||
if not level_valid then |
if not level_valid then |
||
return nil |
return nil |
||
Line 755: | Line 670: | ||
return level_valid |
return level_valid |
||
end |
end |
||
parse.unlock_profession = { |
|||
name = 'unlock_profession', |
|||
func = {name = parse.unlock_profession_func, params = {Infobox.raw_param('unlock_profession'), Infobox.raw_param('profession_a'), Infobox.raw_param('unlock_level')}}, |
|||
smw_property = 'Unlock profession', |
|||
smw_func = {name = parse.unlock_profession_func_smw, params = {Infobox.raw_param('unlock_profession'), Infobox.raw_param('profession_a'), Infobox.raw_param('unlock_level')}}, |
|||
} |
|||
parse.unlock_level = { |
parse.unlock_level = { |
||
name = 'unlock_level', |
name = 'unlock_level', |
||
func = {name = parse.unlock_level_func, params = { |
func = {name = parse.unlock_level_func, params = {Infobox.raw_param('profession_a'), Infobox.raw_param('unlock_level')}}, |
||
smw_property = 'Unlock level', |
smw_property = 'Unlock level', |
||
smw_func = {name = parse.unlock_level_smw, params = { |
smw_func = {name = parse.unlock_level_smw, params = {Infobox.raw_param('profession_a'), Infobox.raw_param('unlock_level')}}, |
||
category_incomplete = 'Needs unlock level', |
category_incomplete = 'Needs unlock level', |
||
} |
} |
||
Line 862: | Line 770: | ||
smw_property = 'Bank', |
smw_property = 'Bank', |
||
category_complete = 'Bankable items' |
category_complete = 'Bankable items' |
||
} |
|||
-- Transmog Event |
|||
parse.event = { |
|||
name = 'event', |
|||
func = parse.has_content, |
|||
smw_property = 'Event', |
|||
} |
|||
-- Transmog Equipment Slot |
|||
parse.slot = { |
|||
name = 'slot', |
|||
func = parse.has_content, |
|||
smw_property = 'Slot', |
|||
} |
|||
-- Event predecessor |
|||
parse.predecessor = { |
|||
name = 'predecessor', |
|||
func = parse.has_content |
|||
} |
|||
-- Event successor |
|||
parse.successor = { |
|||
name = 'successor', |
|||
func = parse.has_content |
|||
} |
} |
||