Bearbeiten von „Modul:PageUtil“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
--[=[ 2014-12-25 | |||
-- | |||
PageUtil | PageUtil | ||
* merge() | |||
]=] | ]=] | ||
PageUtil | -- table for export | ||
local PageUtil = {} | |||
Zeile 15: | Zeile 14: | ||
-- Format message with class="error" | -- Format message with class="error" | ||
-- alert -- string, with message | -- alert -- string, with message | ||
-- frame -- object | -- frame -- object | ||
-- Returns message with markup | -- Returns message with markup | ||
local | local r = alert | ||
if frame then | if frame then | ||
r = string.format( "%s * %s", frame:getTitle(), r ) | |||
end | end | ||
r = string.format( "<span class=\"error\">ERROR * %s</span>", r ) | |||
return r | |||
end -- fault() | end -- fault() | ||
Zeile 39: | Zeile 37: | ||
shift = v[ 2 ] | shift = v[ 2 ] | ||
source = ":?" .. source:gsub( " ", "[_ ]+" ) | source = ":?" .. source:gsub( " ", "[_ ]+" ) | ||
seek = "%[%[%s*" .. source .. "%s*(#[^%[|%]]*%]%])" | |||
seek = "%[%[%s*" .. source .. "(#[^%]]*%]%])" | |||
subst = "[[%1" | subst = "[[%1" | ||
r = r:gsub( seek, subst ) | r = r:gsub( seek, subst ) | ||
seek = "%[%[%s*" .. source .. "( | seek = "%[%[%s*" .. source .. "%s*(|[^%[%]]*%]%])" | ||
subst = "[[#" .. shift .. "%1" | subst = "[[#" .. shift .. "%1" | ||
r = r:gsub( seek, subst ) | r = r:gsub( seek, subst ) | ||
seek = "%[%[%s*(" .. source .. "%]%])" | seek = "%[%[%s*(" .. source .. "%s*%]%])" | ||
subst = "[[#" .. shift .. "|%1" | subst = "[[#" .. shift .. "|%1" | ||
r = r:gsub( seek, subst ) | r = r:gsub( seek, subst ) | ||
Zeile 61: | Zeile 57: | ||
-- frame -- object | -- frame -- object | ||
-- Returns content, or false | -- Returns content, or false | ||
local r | local r | ||
local seek = "^(#lstx?):%s*%[%[([^%[|%]\n]+)%]%]%s*(%S.*)%s*$" | local seek = "^(#lstx?):%s*%[%[([^%[|%]\n]+)%]%]%s*(%S.*)%s*$" | ||
Zeile 68: | Zeile 62: | ||
if source then | if source then | ||
local page = mw.title.new( source ) | local page = mw.title.new( source ) | ||
if page.exists then | if page.exists then | ||
section = mw.text.trim( section ) | section = mw.text.trim( section ) | ||
Zeile 77: | Zeile 70: | ||
end | end | ||
else | else | ||
r = | r = string.format( "<div class=\"error\">%s</div>", | ||
page.prefixedText ) | |||
end | end | ||
end | end | ||
Zeile 94: | Zeile 86: | ||
-- assembly -- table, with page infos | -- assembly -- table, with page infos | ||
-- Returns string with content, or nil | -- Returns string with content, or nil | ||
local page = mw.title.new( access ) | local page = mw.title.new( access ) | ||
local r | local r | ||
if page.exists then | |||
local source = page.prefixedText | |||
local segment = string.format( "PageUtilMerge-%d", alias ) | |||
local seed | |||
if page.namespace == 0 then | |||
seed = ":" .. source | |||
else | else | ||
seed = source | |||
end | end | ||
r = frame:expandTemplate( { title = seed } ) | |||
r = string.format( "<span id='%s'></span>\n%s", segment, r ) | |||
table.insert( assembly, { source, segment } ) | |||
else | else | ||
r = string.format( "%s | r = string.format( "<div class=\"error\">%s</div>", | ||
page.prefixedText ) | |||
end | end | ||
return r | return r | ||
end -- full() | end -- full() | ||
Zeile 222: | Zeile 123: | ||
end -- for k, v | end -- for k, v | ||
if max > 0 then | if max > 0 then | ||
local pages = { { mw.title.getCurrentTitle().prefixedText, | local pages = { { mw.title.getCurrentTitle().prefixedText, | ||
"" } } | "" } } | ||
Zeile 235: | Zeile 135: | ||
if swallow then | if swallow then | ||
s = fraction( swallow, frame ) | s = fraction( swallow, frame ) | ||
else | else | ||
swallow = s:match( "^%s*%[%[([^%[|%]\n]+)%]%]%s*$" ) | swallow = s:match( "^%s*%[%[([^%[|%]\n]+)%]%]%s*$" ) | ||
if swallow then | if swallow then | ||
s = full( swallow, frame, i, pages ) | s = full( swallow, frame, i, pages ) | ||
end | end | ||
end | end | ||
if s then | if s then | ||
r = r .. | r = r .. s | ||
end | end | ||
end | end | ||
Zeile 265: | Zeile 155: | ||
-- Export | -- Export | ||
local p = { } | local p = { } | ||
p.merge = function ( frame ) | p.merge = function ( frame ) | ||
Zeile 285: | Zeile 162: | ||
end | end | ||
return r | return r | ||
end | end | ||
function p.PageUtil() | function p.PageUtil() |