Редактирование: Модуль:HF/Infobox/Jutsu
Перейти к навигации
Перейти к поиску
Примечание. Ваши правки будут показаны в статье только после их проверки участником с соответствующими правами.
Правка может быть отменена. Проверьте сравнение версий ниже и нажмите «Записать страницу».
Если отменяемые вами изменения не вандализм, пожалуйста, допишите причину в описании правки.
Текущая версия | Ваш текст | ||
Строка 1: | Строка 1: | ||
local Infobox = {} | local Infobox = {} | ||
-- | ------------------------------------ | ||
-- Libraries and Global functions -- | |||
-- " | ------------------------------------ | ||
-- "High Frequency" functions | |||
local HF = require('Module:HF') | local HF = require('Module:HF') | ||
-- | -- Parses invocation and template parameters, trims whitespace, and removes blanks. | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
-- | -- Generates lists | ||
local L = require('Module:List') | local L = require('Module:List') | ||
-- | -- Language functions | ||
local language = mw.language.new(' | local language = mw.language.new('en') | ||
-- | -- Helper functions (local to not have to worry about namespaces) | ||
local arraymap = require('Module:HF/Infobox').arraymap | local arraymap = require('Module:HF/Infobox').arraymap | ||
local arrayTable = require('Module:HF/Infobox').arrayTable | local arrayTable = require('Module:HF/Infobox').arrayTable | ||
Строка 18: | Строка 19: | ||
local extra1 = require('Module:HF/Infobox').extra1 | local extra1 = require('Module:HF/Infobox').extra1 | ||
-- | -- The page title of whatever page is calling the function | ||
local pageTitle = mw.title.getCurrentTitle().text | local pageTitle = mw.title.getCurrentTitle().text | ||
-- | -- Convenient constants | ||
local stripLinkToTarget = '^%[*([^%[|]*)|?' | local stripLinkToTarget = '^%[*([^%[|]*)|?' | ||
local stripPageTitleToBase = "[^(]*" | local stripPageTitleToBase = "[^(]*" | ||
Строка 27: | Строка 28: | ||
local extra1pattern = '^[^~]*~([^~]*)' | local extra1pattern = '^[^~]*~([^~]*)' | ||
------------------------------------------------ | |||
-- | -- Local functions (used only in this Module) -- | ||
------------------------------------------------ | |||
-- Replaces {{IsUnnamed}} | -- Replaces {{IsUnnamed}} | ||
local function nameCheck ( target ) | local function nameCheck ( target ) | ||
local nq = mw.smw.ask{ HF.Link(target:match(stripLinkToTarget)), '? | local nq = mw.smw.ask{ HF.Link(target:match(stripLinkToTarget)), '?Maintenance' } | ||
if type(nq) == 'table' | if type(nq) == 'table' | ||
and ( | and ( | ||
nq[1][' | nq[1]['Maintenance'] == 'Name' | ||
or (type(nq[1][' | or (type(nq[1]['Maintenance']) == 'table' and table.concat(nq[1]['Maintenance']):match('Name')) | ||
) | ) | ||
then | then | ||
Строка 44: | Строка 45: | ||
end | end | ||
--------------------------------------------------------- | ---------------------------------------------------------- | ||
-- | -- Public functions (called from a Template or article) -- | ||
--------------------------------------------------------- | ---------------------------------------------------------- | ||
-- Creates the infobox main title | -- Creates the infobox main title | ||
function Infobox.titleJutsu(frame) | function Infobox.titleJutsu(frame) | ||
Строка 52: | Строка 53: | ||
local out = {} | local out = {} | ||
if mw.title.getCurrentTitle().isContentPage == true then | if mw.title.getCurrentTitle().isContentPage == true then | ||
table.insert( out, HF.Category(' | table.insert( out, HF.Category('Jutsu') ) | ||
if args[' | local _editFormURL = mw.html.create('span') | ||
:css('float','right'):css('font-size','x-small') | |||
:wikitext( HF.Link('Special:FormEdit/Jutsu/' .. pageTitle, 'edit') ):allDone() | |||
local editFormURL = tostring(_editFormURL) | |||
if args['english'] then | |||
mw.smw.set { | mw.smw.set { | ||
[' | ['English name'] = args['english'], | ||
[' | ['Names'] = args['english'] | ||
} | } | ||
end | end | ||
if args['kanji'] then | |||
if args[' | |||
mw.smw.set { | mw.smw.set { | ||
[' | ['Kanji name'] = args['kanji'], | ||
[' | ['Names'] = args['kanji'] | ||
} | } | ||
else | else | ||
mw.smw.set { [' | mw.smw.set { ['Maintenance'] = 'Kanji' } | ||
end | end | ||
if args['romaji'] then | |||
if args[' | |||
mw.smw.set{ | mw.smw.set{ | ||
[' | ['Romaji_name'] = args['romaji']:match(stripLinkToTarget), | ||
[' | ['Names'] = args['romaji'] | ||
} | } | ||
end | end | ||
if args['teams'] then | |||
if args[' | local teams = mw.text.split( args['teams'], ',%s*' ) | ||
local teams = mw.text.split( args[' | |||
for _, v in ipairs(teams) do | for _, v in ipairs(teams) do | ||
mw.smw.set{ [' | mw.smw.set{ ['Team'] = mw.text.trim(v) } | ||
end | end | ||
end | end | ||
if args['image'] then | |||
local images = mw.text.split( args['image'], '\n') | |||
if args[' | |||
local images = mw.text.split( args[' | |||
for _, image in ipairs(images) do | for _, image in ipairs(images) do | ||
if type(image) == 'string' then | if type(image) == 'string' then | ||
mw.smw.set{ [' | mw.smw.set{ ['Picture'] = 'File:' .. image:match("[^:;]*") } | ||
end | end | ||
end | end | ||
else | else | ||
mw.smw.set{ [' | mw.smw.set{ ['Maintenance'] = 'Missing image' } | ||
end | end | ||
if args['unnamed jutsu'] == 'Yes' then | |||
if args[' | mw.smw.set{ ['Maintenance'] = 'Name' } | ||
mw.smw.set{ [' | table.insert( out, ("''%s''"):format( pageTitle:match("[^(]*") ) ) | ||
table.insert( out, (''%s''):format( pageTitle:match("[^(]*") ) ) | |||
else | else | ||
table.insert( out, pageTitle:match("[^(]*") ) | table.insert( out, pageTitle:match("[^(]*") ) | ||
end | end | ||
local popup = frame:newParserValue( | |||
return table.concat( out ) .. ( args['ref'] or '' ) | "{{#queryformlink:form=Image query|link text=" .. | ||
"[[File:Camera font awesome.svg|15px|link=]]" .. | |||
"|query string=Image_query[jutsu]=" .. pageTitle .. | |||
"&_run|wpRunQuery=true|popup|tooltip=Images of " .. pageTitle .. " }}" | |||
) | |||
return table.concat( out ) .. popup:expand() .. ( args['ref'] or '' ) .. editFormURL | |||
elseif mw.title.getCurrentTitle().namespace == 10 | elseif mw.title.getCurrentTitle().namespace == 10 | ||
and not pageTitle:match('/testcases') then | and not pageTitle:match('/testcases') then | ||
return nil | return nil | ||
else | else | ||
if args[' | if args['unnamed jutsu'] == 'Yes' then | ||
table.insert( out, ("''%s''"):format( args[' | table.insert( out, ("''%s''"):format( args['english'] or pageTitle:match("[^(]*") ) ) | ||
else | else | ||
table.insert( out, args[' | table.insert( out, args['english'] or pageTitle:match("[^(]*") ) | ||
end | end | ||
return table.concat( out ) .. ( args['ref'] or '' ) | return table.concat( out ) .. ( args['ref'] or '' ) | ||
end | end | ||
Строка 127: | Строка 123: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local classifications = | local classifications = | ||
type(args[' | type(args['jutsu classification']) == 'string' | ||
and mw.text.split( args[' | and mw.text.split( args['jutsu classification'], ',%s*' ) | ||
if type(classifications) == 'table' then | if type(classifications) == 'table' then | ||
local out = {} | local out = {} | ||
local icons = {} | local icons = {} | ||
local kekkei = { | local kekkei = { | ||
[' | ['kekkei mōra'] = true, | ||
[' | ['kekkei tōta'] = true, | ||
[' | ['kekkei genkai'] = true | ||
} | } | ||
for _,classification in ipairs(classifications) do | for _,classification in ipairs(classifications) do | ||
Строка 142: | Строка 137: | ||
if classification:match(basepattern):lower() == 'hiden' then | if classification:match(basepattern):lower() == 'hiden' then | ||
local options = { | local options = { | ||
['SemanticPropertyName'] = ' | ['SemanticPropertyName'] = 'Clan', | ||
['PrependText'] = ' | ['PrependText'] = 'Ninja clan', | ||
['PrependTemplate'] = ' | ['PrependTemplate'] = 'Infobox_icon', | ||
['Print'] = 'none', | ['Print'] = 'none', | ||
['Link'] = 'default' | ['Link'] = 'default' | ||
Строка 152: | Строка 147: | ||
elseif kekkei[classification:match(basepattern):lower()] then | elseif kekkei[classification:match(basepattern):lower()] then | ||
local options = { | local options = { | ||
['SemanticPropertyName'] = ' | ['SemanticPropertyName'] = 'Kekkei Genkai', | ||
['PrependText'] = ' | ['PrependText'] = 'Kekkei Genkai', | ||
['PrependTemplate'] = ' | ['PrependTemplate'] = 'Infobox_icon', | ||
['Print'] = 'none', | ['Print'] = 'none', | ||
['Link'] = 'default' | ['Link'] = 'default' | ||
Строка 163: | Строка 158: | ||
end | end | ||
if classification:match(basepattern) and #classification > 1 then | if classification:match(basepattern) and #classification > 1 then | ||
mw.smw.set { [' | mw.smw.set { ['Jutsu classification'] = classification:match(basepattern) } | ||
table.insert( out, HF.Link(classification:match(basepattern)) ) | table.insert( out, HF.Link(classification:match(basepattern)) ) | ||
end | end | ||
Строка 175: | Строка 170: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = { | local options = { | ||
['SemanticPropertyName'] = ' | ['SemanticPropertyName'] = 'Chakra Nature', | ||
['PrependText'] = ' | ['PrependText'] = 'Nature', | ||
['PrependTemplate'] = ' | ['PrependTemplate'] = 'Infobox_icon', | ||
['Link'] = 'default' | ['Link'] = 'default' | ||
} | } | ||
local values = arrayTable ( args[' | local values = arrayTable ( args['jutsu type'], ',%s*', options, frame ) | ||
return L.makeList( 'unbulleted' , values ) | return L.makeList( 'unbulleted' , values ) | ||
end | end | ||
Строка 186: | Строка 181: | ||
function Infobox.jutsuRank(frame) | function Infobox.jutsuRank(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local array = mw.text.split( args[' | local array = mw.text.split( args['jutsu rank'], ',' ) | ||
local out = {} | local out = {} | ||
for _, v in ipairs( array ) do | for _, v in ipairs( array ) do | ||
table.insert( out , HF.Link(' | table.insert( out , HF.Link('Jutsu rank::'..v, v..'-rank') ) | ||
end | end | ||
return table.concat( out, ',' ) | return table.concat( out, ',' ) | ||
Строка 197: | Строка 192: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = { | local options = { | ||
['SemanticPropertyName'] = ' | ['SemanticPropertyName'] = 'Jutsu class type', | ||
['Link'] = 'none' | ['Link'] = 'none' | ||
} | } | ||
local classes = arrayTable ( args[' | local classes = arrayTable ( args['jutsu class type'], ',%s*', options, frame ) | ||
return table.concat( classes, ', ' ) | return table.concat( classes, ', ' ) | ||
end | end | ||
Строка 207: | Строка 202: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local ranges = { | local ranges = { | ||
[' | ['Short'] = 'Short range (0-5m)', | ||
[' | ['Mid'] = 'Mid range (5-10m)', | ||
[' | ['Long'] = 'Long range (10m+)', | ||
[' | ['Short, Mid, Long'] = 'All ranges', | ||
[' | ['Short, Mid'] = 'Short to Mid range (0-10m)', | ||
[' | ['Mid, Long'] = 'Mid to Long range (5m+)', | ||
[' | ['Short, Long'] = 'Short or Long range (0-5m or 10m+)' | ||
} | } | ||
arrayTable ( args[' | arrayTable ( args['jutsu range'], ',%s*', { ['SemanticPropertyName'] = 'Jutsu range' } ) | ||
return ranges[args[' | return ranges[args['jutsu range']] or args['jutsu range']..'-range' | ||
end | end | ||
Строка 222: | Строка 217: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = { | local options = { | ||
['SemanticPropertyName'] = ' | ['SemanticPropertyName'] = 'Parent', | ||
['Link'] = 'Unnamed', | ['Link'] = 'Unnamed', | ||
['UnnamedFormat'] = true | ['UnnamedFormat'] = true | ||
} | } | ||
local parents = arrayTable ( args[' | local parents = arrayTable ( args['parent jutsu'], ',%s*', options ) | ||
return L.makeList( 'unbulleted', parents ) | return L.makeList( 'unbulleted', parents ) | ||
end | end | ||
Строка 234: | Строка 229: | ||
local out = {} | local out = {} | ||
local mtypes = { | local mtypes = { | ||
[' | ['Movie'] = 'Jutsu/NonCanon', | ||
[' | ['Game'] = 'Jutsu/NonCanon', | ||
[' | ['Game, Movie'] = 'Jutsu/NonCanon' | ||
} | } | ||
local mq = mw.smw.ask { | local mq = mw.smw.ask { | ||
(HF.Link('Concept:%s')):format( mtypes[args[' | (HF.Link('Concept:%s')):format( mtypes[args['jutsu media']] or 'Jutsu/Canon' ), | ||
(HF.Link(' | (HF.Link('Parent::%s')):format( mw.title.getCurrentTitle().prefixedText ), | ||
'? | '?Appears in', | ||
'? | '?Maintenance', | ||
('userparam=%s'):format(args[' | ('userparam=%s'):format(args['jutsu media']), | ||
'mainlabel=main', | 'mainlabel=main', | ||
'limit=200' | 'limit=200' | ||
} | } | ||
local hasNCderivatives = mw.smw.ask { | local hasNCderivatives = mw.smw.ask { | ||
(HF.Link('Concept:%s')):format( ' | (HF.Link('Concept:%s')):format( 'Jutsu/NonCanon' ), | ||
(HF.Link(' | (HF.Link('Parent::%s')):format( mw.title.getCurrentTitle().prefixedText ) | ||
} | } | ||
if type(mq) == 'table' then | if type(mq) == 'table' then | ||
Строка 255: | Строка 250: | ||
local mainlink = | local mainlink = | ||
( | ( | ||
parent[' | parent['Maintenance'] == 'Name' | ||
or ( | or ( | ||
type(parent[' | type(parent['Maintenance']) == 'table' | ||
and table.concat(parent[' | and table.concat(parent['Maintenance']):match('Name') | ||
) | ) | ||
) | ) | ||
and (''%s''):format( | and ("''%s''"):format( | ||
HF.Link( | HF.Link( | ||
parent['main']:match(stripLinkToTarget), | parent['main']:match(stripLinkToTarget), | ||
Строка 272: | Строка 267: | ||
) | ) | ||
local dq = mw.smw.ask { | local dq = mw.smw.ask { | ||
(HF.Link('Concept:%s')):format( mtypes[args[' | (HF.Link('Concept:%s')):format( mtypes[args['jutsu media']] or 'Jutsu/Canon' ), | ||
(HF.Link(' | (HF.Link('Parent::%s')):format( parent['main']:match(stripLinkToTarget) ), | ||
('userparam=%s'):format( args[' | ('userparam=%s'):format( args['jutsu media'] or 'Anime, Manga' ), | ||
'mainlabel=main', | 'mainlabel=main', | ||
'named args=yes', | 'named args=yes', | ||
Строка 283: | Строка 278: | ||
for _, derived in ipairs(dq) do | for _, derived in ipairs(dq) do | ||
local dlink = ( | local dlink = ( | ||
derived[' | derived['Maintenance'] == 'Name' | ||
or type(derived[' | or type(derived['Maintenance']) == 'table' | ||
and table.concat(derived[' | and table.concat(derived['Maintenance']):match('Name') | ||
) | ) | ||
and ("''%s''"):format( | and ("''%s''"):format( | ||
Строка 309: | Строка 304: | ||
mw.title.new( 'SearchByProperty', 'Special' ).prefixedText | mw.title.new( 'SearchByProperty', 'Special' ).prefixedText | ||
local q = mw.uri.buildQueryString{ | local q = mw.uri.buildQueryString{ | ||
['property'] = ' | ['property'] = 'Parent', | ||
['value'] = mw.uri.encode( | ['value'] = mw.uri.encode( | ||
mw.title.getCurrentTitle().prefixedText, | mw.title.getCurrentTitle().prefixedText, | ||
Строка 317: | Строка 312: | ||
local searchlink = HF.ExternalLink( | local searchlink = HF.ExternalLink( | ||
tostring(mw.uri.fullUrl(t,q)), | tostring(mw.uri.fullUrl(t,q)), | ||
' | 'All derived jutsu' | ||
) | ) | ||
return ('<center class="smwsearch">%s</center>'):format( searchlink ) | return ('<center class="smwsearch">%s</center>'):format( searchlink ) | ||
Строка 325: | Строка 320: | ||
function Infobox.jutsuRelated(frame) | function Infobox.jutsuRelated(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
return arraymap( args[' | return arraymap( args['related jutsu'], ',%s*', HF.Link('%s'), ', ' ) | ||
end | end | ||
function Infobox.jutsuUsers(frame) | function Infobox.jutsuUsers(frame) | ||
local args = getArgs(frame) | |||
local out = {} | |||
-- Valid media types | |||
local mtypes = { | |||
anime = true, manga = true, novel = true, | |||
game = true, movie = true, ['movie canon'] = true | |||
} | |||
-- Divides users into actionable items (even if there's only one) | -- Divides users into actionable items (even if there's only one) | ||
local users = args[' | local users = args['users'] and mw.text.split( args['users'], ',%s*' ) | ||
-- Checks if any user entries exist, and if they don't, return nil | -- Checks if any user entries exist, and if they don't, return nil | ||
if type(users) ~= 'table' then return nil end | if type(users) ~= 'table' then return nil end | ||
Строка 356: | Строка 351: | ||
--- AdditionalInfo | --- AdditionalInfo | ||
-- Puppetry handling | -- Puppetry handling | ||
local puppetry = user:match('~~ | local puppetry = user:match('~~puppet~(.*)$') | ||
if puppetry then | if puppetry then | ||
puppetry = (' ( | puppetry = (' ([[Puppetry]] using %s)') | ||
:format(mw.text.listToText(mw.text.split(puppetry, '~'))) | :format(mw.text.listToText(mw.text.split(puppetry, '~'))) | ||
end | end | ||
-- "with" handling | -- "with" handling | ||
local with = user:match('~~ | local with = user:match('~~with~([^%~]*)') | ||
and (' ( | and (' (with %s)'):format(user:match('~~with~([^%~]*)')) | ||
local AdditionalInfo = puppetry or with or '' | local AdditionalInfo = puppetry or with or '' | ||
Строка 370: | Строка 365: | ||
if media | if media | ||
and mtypes[media:lower()] | and mtypes[media:lower()] | ||
and media:lower() ~= ' | and media:lower() ~= 'movie canon' | ||
then | then | ||
Media = ('<sup> (%s)</sup>') | Media = ('<sup> (%s only)</sup>') | ||
:format( language:ucfirst( media ) ) | :format( language:ucfirst( media ) ) | ||
elseif media | elseif media | ||
and media:lower() == ' | and media:lower() == 'movie canon' | ||
then | then | ||
Media = '<sup> ( | Media = '<sup> (Movie only)</sup>' | ||
end | end | ||
--- Summons | --- Summons | ||
local cq = mw.smw.ask { | local cq = mw.smw.ask { | ||
(HF.Link(' | (HF.Link('Contract::%s')):format( prime:match(stripLinkToTarget) ), | ||
'mainlabel=main' | 'mainlabel=main' | ||
} | } | ||
Строка 392: | Строка 387: | ||
end | end | ||
local Summons = ((#sl > 0) | local Summons = ((#sl > 0) | ||
and ( pageTitle == ' | and ( pageTitle == 'Summoning Technique' or pageTitle == 'Destruction Bug Host Technique' )) | ||
and ( ' (%s)' ):format( table.concat( sl, ", " ) ) | and ( ' (%s)' ):format( table.concat( sl, ", " ) ) | ||
or '' | or '' | ||
Строка 401: | Строка 396: | ||
or 'null' | or 'null' | ||
mw.smw.set { | mw.smw.set { | ||
[' | ['User tech'] = prime .. ';' .. setmtype | ||
} | } | ||