Modul:TemplateData: Unterschied zwischen den Versionen
2018-04-05
wp>PerfektesChaos (2018-04-03) |
wp>PerfektesChaos (2018-04-05) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = "2018-04- | serial = "2018-04-05", | ||
item = 46997995 } | item = 46997995 } | ||
--[=[ | --[=[ | ||
Zeile 1.265: | Zeile 1.265: | ||
if source:find( "|", 1, true ) then | if source:find( "|", 1, true ) then | ||
local scan = "^[\n ]*%{%{[\n _]*|[\n _]*=[\n _]*%}%}[\n ]*$" | local scan = "^[\n ]*%{%{[\n _]*|[\n _]*=[\n _]*%}%}[\n ]*$" | ||
if source:match( scan | if source:match( scan ) then | ||
code = source:gsub( "\n", "N" ) | code = source:gsub( "\n", "N" ) | ||
else | else | ||
Zeile 1.286: | Zeile 1.286: | ||
support == "*" then | support == "*" then | ||
Permit.builder[ s ] = true | Permit.builder[ s ] = true | ||
elseif s:match( "^[1-9]%d*" ) and | |||
Permit.builder.align then | |||
Permit.builder.align = tonumber( s ) | |||
else | else | ||
if unknown then | if unknown then | ||
Zeile 1.343: | Zeile 1.346: | ||
space = " " | space = " " | ||
end | end | ||
if Permit.builder.align == true then | if Permit.builder.align then | ||
local n | |||
s = " align" | |||
if Permit.builder.align == true then | |||
n = 0 | |||
if type( Data.got ) == "table" and | |||
type( Data.got.params ) == "table" then | |||
for k, v in pairs( Data.got.params ) do | |||
if type( v ) == "table" and | |||
not v.deprecated and | |||
type( k ) == "string" then | |||
k = mw.ustring.len( k ) | |||
if k > n then | |||
n = k | |||
end | |||
end | end | ||
end -- for k, v | |||
end | |||
if n > 1 then | else | ||
n = Permit.builder.align | |||
if type( n ) == "number" and n > 1 then | |||
s = string.format( "%s %d", s, n ) | |||
else | |||
n = 0 -- How comes? | |||
end | end | ||
end | end | ||
show = show .. | if n > 1 then | ||
spaced = string.rep( "_", n ) .. " " | |||
end | |||
show = show .. s | |||
elseif Permit.builder.after == true then | elseif Permit.builder.after == true then | ||
spaced = "" | spaced = "" | ||
Zeile 1.464: | Zeile 1.478: | ||
if Data.shared then | if Data.shared then | ||
local global = mw.html.create( "div" ) | local global = mw.html.create( "div" ) | ||
:attr( "id", "templatedata-global" ) | |||
local shift | local shift | ||
if TemplateData.ltr then | if TemplateData.ltr then | ||
Zeile 1.573: | Zeile 1.588: | ||
source = arglist.JSON | source = arglist.JSON | ||
elseif arglist.Global then | elseif arglist.Global then | ||
source = TemplateData.getGlobalJSON( arglist.Global ) | source = TemplateData.getGlobalJSON( arglist.Global, | ||
arglist.Local ) | |||
elseif arglist[ 1 ] then | elseif arglist[ 1 ] then | ||
local s = mw.text.trim( arglist[ 1 ] ) | local s = mw.text.trim( arglist[ 1 ] ) | ||
Zeile 1.654: | Zeile 1.670: | ||
TemplateData.getGlobalJSON = function ( access ) | TemplateData.getGlobalJSON = function ( access, adapt ) | ||
-- Retrieve | -- Retrieve TemplateData from a global repository (JSON) | ||
-- Parameter: | -- Parameter: | ||
-- access -- string, with page specifier (on WikiMedia Commons) | -- access -- string, with page specifier (on WikiMedia Commons) | ||
-- adapt -- JSON string or table with local overrides | |||
-- Returns true, if succeeded | -- Returns true, if succeeded | ||
local plugin = Fetch( "/global" ) | local plugin = Fetch( "/global" ) | ||
Zeile 1.663: | Zeile 1.680: | ||
if type( plugin ) == "table" and | if type( plugin ) == "table" and | ||
type( plugin.fetch ) == "function" then | type( plugin.fetch ) == "function" then | ||
local s, got = plugin.fetch( access ) | local s, got = plugin.fetch( access, adapt ) | ||
if got then | if got then | ||
Data.got = got | Data.got = got |