Dokumentation Die folgende Dokumentation stammt von der Seite Modul:Exclusive/Dokumentation. (bearbeiten | Versionsgeschichte)
Siehe auch die englische Modulseite: Module:Exclusive. Sie enthält möglicherweise umfassendere oder aktuellere Informationen.
Diese Seite ist nicht oder unvollständig übersetzt. | |
Hilf mit, indem du den Text übersetzt und anschließend diesen Hinweis entfernst. Dies entfernt diese Seite auch aus der Liste von Seiten mit unzureichender Übersetzung. |
This module manages everything {{exclusive}}-related.
The three invokable functions are getInfo
, a general exclusivity function which stores information to dplvars, eicons
, which provides the functionality of {{eicons}}, and simpleEicons
, a helper function to be used in other modules like Module:Item.
Important Note for Porting
When porting {{exclusive}}-related templates/modules to separate language wikis, you might not want to use a cargo-based cache system like on the English wiki.
Please take the following steps in order to use a non-cargo cache system:
- Do not directly port
Module:Exclusive/data
from the en wiki. Instead, head to Template:Exclusive/luadata (en), copy the generated code from that page, and put it as source code ofModule:Exclusive/data
on the target language's wiki. Note that this process will need to be repeated in the future in order to keep the language wiki's exclusivity database up-to-date. - Make sure that the l10n auto translation switch for the target language in
Template:Exclusive
/Template:Eil
/Template:Eicons
/Template:Eversions
is set tofalse
(false
is the default value for non-English languages). - Make sure that the l10n cargo switch for the target language in
Template:Exclusive
(at the beginning) is set tofalse
.
-- l10n text, need to be translated.
local l10n = mw.loadData('Module:exclusive/l10n')
-- exclusive info database, please read the document of Module:exclusive/data
local exclusive_info = mw.loadData( 'Module:exclusive/data' )
------- The following is not related to l10n. --------------
local trim = mw.text.trim
local currentFrame -- cache
-- helper function
local getArg = function(key)
local value = trim(currentFrame.args[key] or '')
return (value ~= '') and value or nil
end
local function parameter(parameter, base)
if parameter then
if parameter == 'y' or parameter == 'yes' then
return 'y'
end
if parameter == 'n' or parameter == 'no' then
return nil
end
end
return base
end
local getInfo = function(page, invert)
-- standlize pagename.
page = mw.getContentLanguage():ucfirst(string.gsub(string.gsub(page, '#.*', ''), '_', ' '))
local raw , ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = exclusive_info[page]
if raw then
ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = raw:find('d'),raw:find('c'),raw:find('o'),raw:find('m'),raw:find('3'),raw:find('j'), 'y'
end
-- invert?
if invert then
ex_d = not ex_d
ex_c = not ex_c
ex_o = not ex_o
ex_m = not ex_m
ex_3 = not ex_3
if ex_j then
ex_j = false
end
end
return ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached
end
local eicons = function(ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, _small, _link, lang)
local link = ''
local space = false
local size
local result = ''
local l10n = l10n[lang] or l10n['en']
if ex_d then
result =
'[[File:Desktop only.png|' .. (_small and '12' or '16') ..'px|link='
.. (_link and l10n['icon_link_d'] or '') .. '|' .. l10n['icon_text_d'] .. ']]'
space = true
end
if ex_c then
result = result .. (space and ' ' or '') ..
'[[File:Console only.png|' .. (_small and '13' or '17') ..'px|link='
.. (_link and l10n['icon_link_c'] or '') .. '|' .. l10n['icon_text_c'] .. ']]'
space = true
end
if ex_o then
result = result .. (space and ' ' or '') ..
'[[File:Old-Gen Console only.png|' .. (_small and 'x12' or 'x16') ..'px|link='
.. (_link and l10n['icon_link_o'] or '') .. '|' .. l10n['icon_text_o'] .. ']]'
space = true
end
if ex_m then
result = result .. (space and ' ' or '') ..
'[[File:Mobile only.png|' .. (_small and 'x12' or 'x16') ..'px|link='
.. (_link and l10n['icon_link_m'] or '') .. '|' .. l10n['icon_text_m'] .. ']]'
space = true
end
if ex_3 then
result = result .. (space and ' ' or '') ..
'[[File:3DS.svg|' .. (_small and '24' or '32') ..'px|link='
.. (_link and l10n['icon_link_3'] or '') .. '|' .. l10n['icon_text_3'] .. ']]'
space = true
end
if ex_j then
result = result .. (space and ' ' or '') ..
'[[File:Flag jp.svg|' .. (_small and '12' or '16') ..'px|link='
.. (_link and l10n['icon_link_j'] or '') .. '|' .. l10n['icon_text_j'] .. ']]'
end
return mw.text.tag('span',{class='eico'}, result)
end
local getExclusiveInfo = function(page, invert)
local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j
if page then
ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getInfo(page, invert)
end
-- override
ex_d = parameter(getArg('dsk'), ex_d)
ex_c = parameter(getArg('cns'), ex_c)
ex_o = parameter(getArg('old'), ex_o)
ex_m = parameter(getArg('mbl'), ex_m)
ex_3 = parameter(getArg('3ds'), ex_3)
ex_j = parameter(getArg('jas'), ex_j)
return ex_d, ex_c, ex_o, ex_m, ex_3, ex_j
end
---------------------------------------------------------------------------------
return {
-- for template, get all exclusive info, setting in dplvars.
-- parameters: $1 = pagename, $lang = language, $autotr = apply auto translation on pagename? y/n
getInfo = function(frame)
currentFrame = frame -- cache
local page = getArg(1)
if not page then
frame:callParserFunction{ name = '#dplvar:set', args = {
'ex_d', '', 'ex_c', '', 'ex_o', '', 'ex_m', '', 'ex_3', '', 'ex_j', '', 'ex_cached', ''
} }
return
end
local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j, cached = getInfo(page, getArg('invert'))
frame:callParserFunction{ name = '#dplvar:set', args = {
'ex_d', ex_d and 'y' or '',
'ex_c', ex_c and 'y' or '',
'ex_o', ex_o and 'y' or '',
'ex_m', ex_m and 'y' or '',
'ex_3', ex_3 and 'y' or '',
'ex_j', ex_j and 'y' or '',
'ex_cached', cached and 'y' or ''
} }
end,
-- for {{eicons}}
eicons = function(frame)
currentFrame = frame -- cache
local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getExclusiveInfo(getArg(1), getArg('invert'))
if not(ex_d or ex_c or ex_o or ex_m or ex_3 or ex_j) then
return ''
end
return eicons(
ex_d, ex_c, ex_o, ex_m, ex_3, ex_j,
getArg('small'), getArg('link'), getArg('lang')
)
end,
-- for other module such as Module:item, simple eicons:
simpleEicons = function(page, lang, small, link)
local ex_d, ex_c, ex_o, ex_m, ex_3, ex_j = getInfo(page)
if not(ex_d or ex_c or ex_o or ex_m or ex_3 or ex_j) then
return ''
end
return eicons(
ex_d, ex_c, ex_o, ex_m, ex_3, ex_j,
small, link, lang
)
end,
}