Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
w>PerfektesChaos (update) |
K (27 Versionen von wikivoyage:Modul:PageTree importiert) |
||
| (22 dazwischenliegende Versionen von 3 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
--[=[ | local PageTree = { suite = "PageTree", | ||
Module: | serial = "2018-09-13", | ||
item = 56033297, | |||
maxSub = 10, | |||
strings = { "segment", | |||
"self", | |||
"stamped", | |||
"subpager", | |||
"suppress" }, | |||
toggles = { "lazy", | |||
"level", | |||
"lineup", | |||
"light", | |||
"linked", | |||
"limit", | |||
"list" } } | |||
--[=[ | |||
Module:PageTree | |||
Rendering and administration of hierarchical wiki page structures | |||
]=] | ]=] | ||
| Zeile 37: | Zeile 47: | ||
local lucky, r | local lucky, r | ||
if s:byte( 1, 1 ) == 47 then -- "/" | if s:byte( 1, 1 ) == 47 then -- "/" | ||
if | if PageTree.suite then | ||
s = | s = PageTree.suite .. s | ||
end | end | ||
end | end | ||
| Zeile 47: | Zeile 57: | ||
return r | return r | ||
end -- facility() | end -- facility() | ||
local function factory( apply ) | |||
-- Clone read-only table | |||
-- apply -- table, with basic data elements, read-only | |||
-- Returns message with markup | |||
local r = { } | |||
for k, v in pairs( apply ) do | |||
r[ k ] = v | |||
end -- for k, v | |||
return r | |||
end -- factory() | |||
| Zeile 55: | Zeile 78: | ||
-- Returns true if to be hidden | -- Returns true if to be hidden | ||
local r = false | local r = false | ||
for k, v in pairs( | for k, v in pairs( PageTree.hide ) do | ||
if ask:match( v ) then | if ask:match( v ) then | ||
r = true | r = true | ||
| Zeile 63: | Zeile 86: | ||
return r | return r | ||
end -- fade() | end -- fade() | ||
| Zeile 85: | Zeile 95: | ||
local r, s, title | local r, s, title | ||
local n = 0 | local n = 0 | ||
for k, v in pairs( | for k, v in pairs( PageTree.pages ) do | ||
n = n + 1 | n = n + 1 | ||
s = v.seed | s = v.seed | ||
| Zeile 98: | Zeile 108: | ||
"(-)" .. s ) | "(-)" .. s ) | ||
end | end | ||
elseif | elseif PageTree.linked and | ||
title.isRedirect then | title.isRedirect then | ||
table.insert( redirect, | table.insert( redirect, | ||
| Zeile 118: | Zeile 128: | ||
else | else | ||
n = table.maxn( redirect ) | n = table.maxn( redirect ) | ||
if n > 0 then | if n > 0 then | ||
r = string.format( "%s %s %s", r, s, | s = "*** unexpected redirect:" | ||
for i = 1, n do | |||
r = string.format( "%s %s %s", r, s, redirect[ i ] ) | |||
s = "|" | |||
end -- for i | |||
end | end | ||
end | end | ||
| Zeile 135: | Zeile 147: | ||
local r | local r | ||
if adopt:byte( 1, 1 ) == 47 then -- "/" | if adopt:byte( 1, 1 ) == 47 then -- "/" | ||
r = | r = PageTree.start .. adopt:sub( 2 ) | ||
else | else | ||
r = adopt | r = adopt | ||
| Zeile 145: | Zeile 157: | ||
return r | return r | ||
end -- fair() | end -- fair() | ||
local function fasten( adopt ) | |||
-- Format restrictions | |||
-- adopt -- string, with restriction entry | |||
-- Returns absolute page name, or false | |||
local designs = { | |||
autoconfirmed = "background:#FFFF80", | |||
editeditorprotected = "background:#FFFF00;border:#FF0000 1px solid", | |||
superprotect = "background:#FF0000;border:#FFFF00 9px solid", | |||
sysop = "background:#FFFF00;border:#FF0000 3px solid", | |||
["?????????"] = "border:#FF0000 5px solid;color:#FF0000" } | |||
local restrictions = mw.text.split( adopt, ":" ) | |||
local r = "" | |||
local start = "margin-left:2em;" | |||
local staff, strict, style | |||
for i = 1, #restrictions do | |||
strict, staff = restrictions[ i ]:match( "^(.*)=(.+)$" ) | |||
strict = mw.text.trim( strict ) | |||
if strict == "" then | |||
strict = "?????????" | |||
end | |||
style = designs[ staff ] | |||
if not style then | |||
style = designs[ "?????????" ] | |||
strict = strict .. "?????????" | |||
end | |||
if start then | |||
style = start .. style | |||
start = false | |||
end | |||
style = style .. ";padding-left:3px;padding-right:3px;" | |||
r = string.format( "%s<span style='%s'>%s</span>", | |||
r, style, strict ) | |||
end -- for i | |||
return r | |||
end -- fasten() | |||
local function fatal( alert ) | |||
-- Format disaster message with class="error" and put into category | |||
-- alert -- string, with message, or other data | |||
-- Returns message string with markup | |||
local ecat = mw.message.new( "Scribunto-common-error-category" ) | |||
local r = type( alert ) | |||
if r == "string" then | |||
r = alert | |||
else | |||
r = "???? " .. r | |||
end | |||
if ecat:isBlank() then | |||
ecat = "" | |||
else | |||
ecat = string.format( "[[Category:%s]]", ecat:plain() ) | |||
end | |||
r = string.format( "<span class=\"error\">FATAL LUA ERROR %s</span>", | |||
r ) | |||
.. ecat | |||
return r | |||
end -- fatal() | |||
| Zeile 151: | Zeile 225: | ||
-- Find parent page | -- Find parent page | ||
-- ancestor -- string, with page name | -- ancestor -- string, with page name | ||
-- Returns page name of parent, or | -- Returns page name of parent, or PageTree.series | ||
local r = ancestor:match( "^(.+)/[^/]+$" ) | local r = ancestor:match( "^(.+)/[^/]+$" ) | ||
if not r then | if not r then | ||
r = ancestor:match( "^([^:]+:).+$" ) | r = ancestor:match( "^([^:]+:).+$" ) | ||
if not r then | if not r then | ||
r = | r = PageTree.series | ||
end | end | ||
end | end | ||
| Zeile 174: | Zeile 248: | ||
local function features( apply, access ) | local function features( apply, access ) | ||
-- Fill | -- Fill PageTree.pages with elements | ||
-- apply -- table, with definitions, read-only | -- apply -- table, with definitions, read-only | ||
-- access -- string, with relative path of module | -- access -- string, with relative path of module | ||
| Zeile 192: | Zeile 266: | ||
if type( v.seed ) == "string" then | if type( v.seed ) == "string" then | ||
s = v.seed | s = v.seed | ||
e = | e = factory( v ) | ||
end | end | ||
end | end | ||
| Zeile 198: | Zeile 272: | ||
if type( v ) == "table" then | if type( v ) == "table" then | ||
s = k | s = k | ||
e = | e = factory( v ) | ||
end | end | ||
elseif k == true then -- root | elseif k == true then -- root | ||
if | if PageTree.pages[ true ] then | ||
bad[ "true" ] = "duplicated" | bad[ "true" ] = "duplicated" | ||
elseif type( v ) == "table" then | elseif type( v ) == "table" then | ||
if type( v.seed ) == "string" then | if type( v.seed ) == "string" then | ||
PageTree.pages[ true ] = factory( v ) | |||
PageTree.pages[ true ].children = { } | |||
else | else | ||
bad[ "true" ] = "seed missing" | bad[ "true" ] = "seed missing" | ||
| Zeile 222: | Zeile 296: | ||
end | end | ||
if s then | if s then | ||
if not | if not PageTree.pages[ s ] then | ||
e.seed = s | e.seed = s | ||
if e.super then | if e.super then | ||
| Zeile 228: | Zeile 302: | ||
e.super = fair( e.super ) | e.super = fair( e.super ) | ||
end | end | ||
elseif e.super == nil then | |||
e.super = father( s ) | e.super = father( s ) | ||
end | end | ||
e.children = { } | e.children = { } | ||
PageTree.pages[ s ] = e | |||
end | end | ||
end | end | ||
| Zeile 256: | Zeile 330: | ||
local function feed( access ) | local function feed( access ) | ||
-- Fill | -- Fill PageTree with data, if not yet set | ||
-- access -- string, with relative path of module | -- access -- string, with relative path of module | ||
-- Returns error message, if failed, or false, if fine | -- Returns error message, if failed, or false, if fine | ||
| Zeile 262: | Zeile 336: | ||
if type( r ) == "table" then | if type( r ) == "table" then | ||
local s | local s | ||
if type( r.maxSub ) == "number" then | |||
PageTree.maxSub = r.maxSub | |||
end | |||
if type( r.stamp ) == "string" then | if type( r.stamp ) == "string" then | ||
if | if PageTree.stamp then | ||
if | if PageTree.stamp < r.stamp then | ||
PageTree.stamp = r.stamp | |||
end | end | ||
else | else | ||
PageTree.stamp = r.stamp | |||
end | end | ||
end | end | ||
| Zeile 274: | Zeile 351: | ||
s = mw.text.trim( r.start ) | s = mw.text.trim( r.start ) | ||
if s ~= "" then | if s ~= "" then | ||
PageTree.start = s | |||
end | end | ||
end | end | ||
if not | if not PageTree.pages then | ||
PageTree.pages = { } | |||
end | end | ||
if type( r.pages ) == "table" then | if type( r.pages ) == "table" then | ||
if not | if not PageTree.pages then | ||
PageTree.pages = { } | |||
end | end | ||
s = features( r.pages, access ) | s = features( r.pages, access ) | ||
| Zeile 305: | Zeile 382: | ||
-- Format entry as link | -- Format entry as link | ||
-- about -- table, with entry | -- about -- table, with entry | ||
-- .show | -- .show -- link title | ||
-- .seed | -- .seed -- page name | ||
-- .shift | -- .shift -- redirect target | ||
-- .protection -- restrictions | |||
-- absolute -- true, if real page name to be shown | -- absolute -- true, if real page name to be shown | ||
-- Returns string | -- Returns string | ||
| Zeile 324: | Zeile 402: | ||
r = string.format( "%s %s", r, about.suffix ) | r = string.format( "%s %s", r, about.suffix ) | ||
end | end | ||
if | if PageTree.linked and type( about.shift ) == "string" then | ||
r = string.format( "%s <small>→[[%s]]</small>", | r = string.format( "%s <small>→[[%s]]</small>", | ||
r, fair( about.shift ) ) | r, fair( about.shift ) ) | ||
end | |||
if PageTree.limit and type( about.protection ) == "string" then | |||
r = string.format( "%s %s", | |||
r, fasten( about.protection ) ) | |||
end | end | ||
return r | return r | ||
| Zeile 337: | Zeile 419: | ||
-- adjust -- string, to be standardized | -- adjust -- string, to be standardized | ||
-- Returns string with key | -- Returns string with key | ||
if not Sort then | if not PageTree.Sort then | ||
r, Sort = pcall( require, "Module:Sort" ) | r, PageTree.Sort = pcall( require, "Module:Sort" ) | ||
if type( Sort ) == "table" then | if type( PageTree.Sort ) == "table" then | ||
Sort = Sort.Sort() | PageTree.Sort = PageTree.Sort.Sort() | ||
else | else | ||
error( "Module:Sort not ready" ) | error( "Module:Sort not ready" ) | ||
end | end | ||
end | end | ||
return string.upper( Sort.lex( adjust, "latin", false ) ) | return string.upper( PageTree.Sort.lex( adjust, "latin", false ) ) | ||
end -- filter() | end -- filter() | ||
| Zeile 352: | Zeile 434: | ||
local function first( a1, a2, abs ) | local function first( a1, a2, abs ) | ||
-- Compare a1 with a2 in lexicographical order | -- Compare a1 with a2 in lexicographical order | ||
-- a1 | -- a1 -- table, with page entry | ||
-- a2 | -- a2 -- table, with page entry | ||
-- | -- abs -- true, if .show to be used rather than .seed | ||
-- Returns true if a1 < a2 | -- Returns true if a1 < a2 | ||
if not a1.sort then | if not a1.sort then | ||
if | if abs then | ||
face( a1 ) | face( a1 ) | ||
a1.sort = filter( a1.show ) | a1.sort = filter( a1.show ) | ||
| Zeile 365: | Zeile 447: | ||
end | end | ||
if not a2.sort then | if not a2.sort then | ||
if | if abs then | ||
face( a2 ) | face( a2 ) | ||
a2.sort = filter( a2.show ) | a2.sort = filter( a2.show ) | ||
| Zeile 373: | Zeile 455: | ||
end | end | ||
return ( a1.sort < a2.sort ) | return ( a1.sort < a2.sort ) | ||
end -- first() | |||
local function firsthand( a1, a2 ) | |||
-- Compare a1 with a2, considering .show | |||
-- a1 -- string, with page name | |||
-- a2 -- string, with page name | |||
-- Returns true if a1 < a2 | |||
return first( a1, a2, true ) | |||
end -- first() | end -- first() | ||
| Zeile 382: | Zeile 474: | ||
-- a2 -- string, with page name | -- a2 -- string, with page name | ||
-- Returns true if a1 < a2 | -- Returns true if a1 < a2 | ||
local e1 = | local e1 = PageTree.pages[ a1 ] | ||
local e2 = | local e2 = PageTree.pages[ a2 ] | ||
local r | local r | ||
if e1.index then | if e1.index then | ||
| Zeile 405: | Zeile 497: | ||
-- ahead -- string, with syntax in case of .lazy | -- ahead -- string, with syntax in case of .lazy | ||
local r | local r | ||
if | if PageTree.lazy then | ||
r = ":" | r = ":" | ||
else | else | ||
| Zeile 412: | Zeile 504: | ||
return r | return r | ||
end -- flag() | end -- flag() | ||
local function flip( already, ahead, amount, above ) | |||
-- Render subtree as expandable/collapsible list of entries | |||
-- already -- number, of initially visible levels | |||
-- ahead -- string, leading list syntax, either "#" or "*" | |||
-- amount -- number, of leading elements | |||
-- above -- table, with top element (not shown) | |||
-- .children -- will be shown | |||
-- Returns string with story | |||
local n = table.maxn( above.children ) | |||
local r = "" | |||
if n > 0 then | |||
local live = ( already <= amount ) | |||
-- local span = "<span ></span>" | |||
local e, let, serial | |||
table.sort( above.children, firstly ) | |||
for i = 1, n do | |||
e = PageTree.pages[ above.children[ i ] ] | |||
if e.list == false then | |||
let = PageTree.list | |||
elseif PageTree.hide then | |||
let = not fade( e.seed ) | |||
else | |||
let = true | |||
end | |||
if let then | |||
local s | |||
if not e.less then | |||
PageTree.item = PageTree.item + 1 | |||
serial = string.format( "%s_%d", | |||
PageTree.serial, | |||
PageTree.item ) | |||
if table.maxn( e.children ) > 0 then | |||
s = "mw-collapsible" | |||
if amount >= already then | |||
s = s .. " mw-collapsed" | |||
end | |||
r = string.format( "%s\n<div class='%s' %s %s>", | |||
r, | |||
s, | |||
"data-expandtext='[+]'", | |||
"data-collapsetext='[-]'" ) | |||
s = "</div>" | |||
else | |||
s = "" | |||
end | |||
end | |||
r = string.format( "%s\n%s%s", | |||
r, | |||
string.rep( ahead, amount ), | |||
field( e, false ) ) | |||
if not e.less then | |||
local style | |||
if amount >= already then | |||
style = " style='display:none'" | |||
else | |||
style = "" | |||
end | |||
r = string.format( "%s\n<div %s%s>\n%s\n</div>%s", | |||
r, | |||
-- span, | |||
"class='mw-collapsible-content'", | |||
style, | |||
flip( already, | |||
ahead, | |||
amount + 1, | |||
e ), | |||
s ) | |||
end | |||
end | |||
end -- for i | |||
end | |||
return r | |||
end -- flip() | |||
| Zeile 419: | Zeile 587: | ||
-- acquire -- string, with page name | -- acquire -- string, with page name | ||
if type( acquire ) == "string" then | if type( acquire ) == "string" then | ||
local e = | local e = PageTree.pages[ acquire ] | ||
local s = false | local s = false | ||
if e then | if e then | ||
| Zeile 433: | Zeile 601: | ||
e = { children = { }, | e = { children = { }, | ||
seed = acquire } | seed = acquire } | ||
PageTree.pages[ acquire ] = e | |||
end | end | ||
e.super = s | e.super = s | ||
elseif e then | |||
e.super = true | |||
end | end | ||
end | end | ||
| Zeile 448: | Zeile 618: | ||
local function fluent() | local function fluent() | ||
-- Collect all .children; add .super where missing | -- Collect all .children; add .super where missing | ||
local let = true | |||
local e | local e | ||
for k, v in pairs( PageTree.pages ) do | |||
for k, v in pairs( | if v.super == nil then | ||
if | |||
flow( k ) | flow( k ) | ||
elseif not PageTree.pages[ v.super ] then | |||
flow( v.super ) | |||
end | end | ||
end -- for k, v | end -- for k, v | ||
for k, v in pairs( | for k, v in pairs( PageTree.pages ) do | ||
if | if PageTree.level then | ||
let = ( not v.seed:find( "/" ) ) | let = ( not v.seed:find( "/" ) ) | ||
end | end | ||
if let and v.super then | if let and v.super then | ||
e = | e = PageTree.pages[ v.super ] | ||
if e then | if e then | ||
table.insert( e.children, k ) | table.insert( e.children, k ) | ||
| Zeile 478: | Zeile 650: | ||
-- all -- true if all grandchildren shall be shown | -- all -- true if all grandchildren shall be shown | ||
-- Returns string with story | -- Returns string with story | ||
local n = table.maxn( above.children ) | local n = table.maxn( above.children ) | ||
local r = "" | local r = "" | ||
if n > 0 then | if n > 0 then | ||
local e | local e, let, lift | ||
local start = "\n" .. string.rep( ahead, amount ) | local start = "\n" .. string.rep( ahead, amount ) | ||
table.sort( above.children, firstly ) | table.sort( above.children, firstly ) | ||
for i = 1, n do | for i = 1, n do | ||
e = | e = PageTree.pages[ above.children[ i ] ] | ||
lift = ( all or above.long ) | lift = ( all or above.long ) | ||
if e.list == false then | if e.list == false then | ||
let = | let = PageTree.list | ||
elseif | elseif PageTree.hide then | ||
let = not fade( | let = not fade( e.seed ) | ||
else | else | ||
let = lift | let = lift | ||
| Zeile 498: | Zeile 669: | ||
r = string.format( "%s%s%s", | r = string.format( "%s%s%s", | ||
r, start, field( e, false ) ) | r, start, field( e, false ) ) | ||
if lift then | if lift and ( all or not e.less ) then | ||
r = r .. follow( ahead, amount + 1, e, all ) | r = r .. follow( ahead, amount + 1, e, all ) | ||
end | end | ||
| Zeile 511: | Zeile 682: | ||
local function formatAll() | local function formatAll() | ||
-- Render as single list of entries | -- Render as single list of entries | ||
local collect = { } | local collect = { } | ||
local n = 0 | local n = 0 | ||
for k, v in pairs( | local r, let | ||
for k, v in pairs( PageTree.pages ) do | |||
let = true | let = true | ||
if v.list == false and | if v.list == false and | ||
( not | ( not PageTree.list or v.loose or k == true ) then | ||
let = false | let = false | ||
elseif | elseif PageTree.level and v.seed:find( "/" ) then | ||
let = false | let = false | ||
elseif | elseif PageTree.hide then | ||
let = not fade( v.seed ) | let = not fade( v.seed ) | ||
end | end | ||
| Zeile 529: | Zeile 699: | ||
v.show = nil | v.show = nil | ||
end | end | ||
if | if PageTree.light then | ||
local j, k = v.seed:find( | local j, k = v.seed:find( PageTree.start ) | ||
if j == 1 then | if j == 1 then | ||
v.show = v.seed:sub( k + 1 ) | v.show = v.seed:sub( k + 1 ) | ||
| Zeile 541: | Zeile 711: | ||
if n > 0 then | if n > 0 then | ||
local start | local start | ||
local long = ( not | local long = ( not PageTree.light ) | ||
if | if PageTree.lineup then | ||
start = " * " | start = " * " | ||
else | else | ||
start = "\n" .. flag( "#" ) | start = "\n" .. flag( "#" ) | ||
end | end | ||
table.sort( collect, | table.sort( collect, firsthand ) | ||
r = "" | r = "" | ||
for k, v in pairs( collect ) do | for k, v in pairs( collect ) do | ||
| Zeile 560: | Zeile 730: | ||
return r | return r | ||
end -- formatAll() | end -- formatAll() | ||
local function formatExpand( ancestor, args ) | |||
-- Render entire tree as collapsible list text | |||
-- ancestor -- string, with name of root element, or false | |||
-- args -- table, with control information | |||
-- Returns string with story, or false | |||
local init, r | |||
if type( ancestor ) == "string" then | |||
r = ancestor | |||
else | |||
r = true | |||
end | |||
r = PageTree.pages[ r ] | |||
if r then | |||
if type( PageTree.init ) == "number" then | |||
init = PageTree.init | |||
if PageTree.init < 1 then | |||
init = 1 | |||
end | |||
else | |||
init = 1 | |||
end | |||
if type( PageTree.serial ) ~= "string" | |||
or PageTree.serial == "" then | |||
PageTree.serial = "pageTree" | |||
end | |||
PageTree.item = 0 | |||
r = flip( init, flag( "*" ), 1, r ) | |||
else | |||
r = false | |||
end | |||
return r | |||
end -- formatExpand() | |||
| Zeile 567: | Zeile 772: | ||
-- ancestor -- string, with name of root element, or false | -- ancestor -- string, with name of root element, or false | ||
-- Returns string with story | -- Returns string with story | ||
local sup = PageTree.self | |||
local sup = | local higher, i, r | ||
local r | |||
if ancestor then | if ancestor then | ||
higher = | higher = PageTree.pages[ ancestor ] | ||
if type( higher ) == "table" then | if type( higher ) == "table" then | ||
higher.super = false | higher.super = false | ||
end | |||
else | |||
local point = PageTree.pages[ sup ] | |||
if not point then | |||
sup = true | |||
elseif point.list == false then | |||
higher = PageTree.pages[ sup ] | |||
if type( higher ) == "table" then | |||
if not higher.loose then | |||
sup = true | |||
end | |||
else | |||
sup = true | |||
end | |||
end | end | ||
end | end | ||
for i = PageTree.maxSub, 0, -1 do | |||
higher = | higher = PageTree.pages[ sup ] | ||
if type( higher ) == "table" then | if type( higher ) == "table" then | ||
higher.long = true | higher.long = true | ||
sup = higher.super | sup = higher.super | ||
if not sup then | if not sup then | ||
break -- | break -- for | ||
end | end | ||
else | else | ||
higher = false | higher = false | ||
break -- | break -- for | ||
end | end | ||
end -- | end -- for --i | ||
if higher then | if higher then | ||
r = follow( flag( "*" ), 1, higher, false ) | r = follow( flag( "*" ), 1, higher, false ) | ||
| Zeile 603: | Zeile 821: | ||
-- amend -- string, with name of template, or false | -- amend -- string, with name of template, or false | ||
-- around -- object, with frame, or false | -- around -- object, with frame, or false | ||
-- Returns string with story | -- Returns string with story, or false | ||
local higher | local higher | ||
local n = 1 | local n = 1 | ||
local reverse = { } | local reverse = { } | ||
local sup = | local sup = PageTree.self | ||
local r | local r | ||
flow( | if type( sup ) == "string" and not sup:find( "/", 1, true ) then | ||
flow( sup ) | |||
repeat | |||
higher = PageTree.pages[ sup ] | |||
if type( higher ) == "table" then | |||
sup = higher.super | |||
reverse[ n ] = higher | |||
if higher.loose then | |||
n = -1 | |||
break -- repeat | |||
elseif sup then | |||
n = n + 1 | |||
if n > PageTree.maxSub then | |||
reverse[ n ] = { seed = "???????" } | |||
break -- repeat | |||
end | |||
else | |||
break -- repeat | |||
end | |||
else | else | ||
break -- repeat | break -- repeat | ||
end | end | ||
until not higher | |||
end | |||
if n > 1 then | if n > 1 then | ||
for i = n, 2, -1 do | for i = n, 2, -1 do | ||
| Zeile 661: | Zeile 888: | ||
-- ancestor -- string, with name of root element, or false | -- ancestor -- string, with name of root element, or false | ||
-- Returns string with story, or false | -- Returns string with story, or false | ||
local r | local r | ||
if type( | if type( ancestor ) == "string" then | ||
r = ancestor | |||
else | |||
r = true | r = true | ||
end | end | ||
r = | r = PageTree.pages[ r ] | ||
if r then | if r then | ||
r = follow( flag( "#" ), 1, r, true ) | r = follow( flag( "#" ), 1, r, true ) | ||
| Zeile 684: | Zeile 913: | ||
type( args.service ) == "string" and | type( args.service ) == "string" and | ||
type( args.suite ) == "string" then | type( args.suite ) == "string" then | ||
PageTree.series = args.series | |||
PageTree.service = args.service | |||
PageTree.suite = args.suite | |||
if type( args.hide ) == "table" then | if type( args.hide ) == "table" then | ||
PageTree.hide = args.hide | |||
elseif type( args.suppress ) == "string" then | elseif type( args.suppress ) == "string" then | ||
PageTree.hide = { } | |||
table.insert( | table.insert( PageTree.hide, args.suppress ) | ||
end | end | ||
if | if PageTree.series:match( "[:/]$" ) then | ||
PageTree.start = args.series | |||
else | else | ||
PageTree.start = args.series .. "/" | |||
end | end | ||
r = feed( "/" .. | r = feed( "/" .. PageTree.series ) | ||
if r then | if r then | ||
r = fault( r ) | r = fault( r ) | ||
else | else | ||
local life = true | local life = true | ||
if | if PageTree.service == "path" or | ||
PageTree.service == "subpages" then | |||
if args.self then | if args.self then | ||
PageTree.self = args.self | |||
else | else | ||
PageTree.page = mw.title.getCurrentTitle() | |||
PageTree.self = PageTree.page.prefixedText | |||
end | end | ||
if not | if not PageTree.pages[ PageTree.self ] then | ||
life = false | if type( PageTree.pages[ true ] ) == "table" then | ||
PageTree.self = true | |||
else | |||
life = false | |||
end | |||
end | end | ||
end | end | ||
if life then | if life then | ||
if | if PageTree.service == "subpages" then | ||
r = formatSub( args.subpager, args.frame ) | r = formatSub( args.subpager, args.frame ) | ||
elseif | elseif PageTree.service == "check" then | ||
PageTree.linked = args.linked | |||
r = failures() | r = failures() | ||
else | else | ||
for k, v in pairs( | for k, v in pairs( PageTree.toggles ) do | ||
PageTree[ v ] = args[ v ] | |||
end -- for k, v | end -- for k, v | ||
if | if PageTree.service == "all" then | ||
r = formatAll() | r = formatAll() | ||
else | else | ||
local | local segment | ||
if type( args. | if type( args.segment ) == "string" then | ||
segment = fair( args.segment ) | |||
if not PageTree.pages[ segment ] then | |||
PageTree.pages[ segment ] = | |||
{ seed = segment, | |||
children = { }, | |||
super = true, | |||
list = false } | |||
end | |||
end | end | ||
fluent() | fluent() | ||
if | if PageTree.service == "path" then | ||
r = formatPath( | r = formatPath( segment ) | ||
elseif PageTree.service == "expand" then | |||
r = formatExpand( segment, args ) | |||
else | else | ||
r = formatTree( | if args.limit == "1" or | ||
args.limit == true then | |||
PageTree.limit = true | |||
end | |||
r = formatTree( segment ) | |||
end | end | ||
end | end | ||
if args.stamped and | if r and args.stamped and PageTree.stamp then | ||
local babel = mw.language.getContentLanguage() | local babel = mw.language.getContentLanguage() | ||
local stamp = babel:formatDate( args.stamped, | local stamp = babel:formatDate( args.stamped, | ||
PageTree.stamp ) | |||
r = stamp .. r | r = stamp .. r | ||
end | end | ||
| Zeile 762: | Zeile 1.008: | ||
suite = frame:getTitle() } | suite = frame:getTitle() } | ||
local pars = frame.args | local pars = frame.args | ||
local r = pars[ 1 ] | local r = pars[ 1 ] | ||
if r then | if r then | ||
| Zeile 771: | Zeile 1.016: | ||
end | end | ||
if r then | if r then | ||
local lucky | |||
params.frame = frame | params.frame = frame | ||
for k, v in pairs( | for k, v in pairs( PageTree.strings ) do | ||
if pars[ v ] and pars[ v ] ~= "" then | |||
params[ v ] = pars[ v ] | |||
end | |||
end -- for k, v | |||
for k, v in pairs( PageTree.toggles ) do | |||
if pars[ v ] then | if pars[ v ] then | ||
params[ v ] = ( pars[ v ] == "1" ) | params[ v ] = ( pars[ v ] == "1" ) | ||
end | end | ||
end -- for k, v | end -- for k, v | ||
lucky, r = pcall( forward, params ) | |||
if not lucky then | |||
if | r = fatal( r ) | ||
end | end | ||
else | else | ||
r = "'1=' missing" | r = fault( "'1=' missing" ) | ||
end | end | ||
if | if not r then | ||
r = "" | r = "" | ||
end | end | ||
return r | return r | ||
end -- framed() | end -- framed() | ||
PageTree.failsafe = function ( assert ) | |||
-- Retrieve versioning and check for compliance | |||
-- Precondition: | |||
-- assert -- string, with required version or "wikidata", | |||
-- or false | |||
-- Postcondition: | |||
-- Returns string with appropriate version, or false | |||
local r | |||
local since = assert | |||
if since == "wikidata" then | |||
local item = PageTree.item | |||
since = false | |||
if type( item ) == "number" and item > 0 then | |||
local ent = mw.wikibase.getEntity( string.format( "Q%d", | |||
item ) ) | |||
if type( ent ) == "table" then | |||
local vsn = ent:formatPropertyValues( "P348" ) | |||
if type( vsn ) == "table" and | |||
type( vsn.value ) == "string" and | |||
vsn.value ~= "" then | |||
r = vsn.value | |||
end | |||
end | |||
end | |||
end | |||
if not r then | |||
if not since or since <= PageTree.serial then | |||
r = PageTree.serial | |||
else | |||
r = false | |||
end | |||
end | |||
return r | |||
end -- PageTree.failsafe() | |||
| Zeile 803: | Zeile 1.085: | ||
-- lazy = do not number but use bullets or nothing | -- lazy = do not number but use bullets or nothing | ||
-- level = top level entries only | -- level = top level entries only | ||
-- light = | -- light = strip prefix | ||
-- linked = show redirects | -- linked = show redirects | ||
-- list = show suppressed entries | -- list = show suppressed entries | ||
| Zeile 812: | Zeile 1.094: | ||
function p.check( frame ) | function p.check( frame ) | ||
return framed( frame, "check" ) | return framed( frame, "check" ) | ||
end -- p. | end -- p.check | ||
function p.expand( frame ) | |||
return framed( frame, "expand" ) | |||
end -- p.expand | |||
function p.path( frame ) | function p.path( frame ) | ||
| Zeile 831: | Zeile 1.116: | ||
-- Debugging | -- Debugging | ||
-- args -- table, with arguments; mandatory: | -- args -- table, with arguments; mandatory: | ||
-- .series -- tree | -- .series -- tree | ||
-- .service -- action mode | -- .service -- action mode | ||
-- .suite -- Module path | -- .suite -- Module path | ||
-- .self -- page name, in service="path" | |||
-- .limit -- show restrictions | |||
local lucky, r = pcall( forward, args ) | local lucky, r = pcall( forward, args ) | ||
return r or | return r or PageTree | ||
end -- p.test() | end -- p.test() | ||
p.failsafe = function ( frame ) | |||
-- Check or retrieve version information | |||
-- Precondition: | |||
-- frame -- object; #invoke environment | |||
-- Postcondition: | |||
-- Return string with error message or "" | |||
-- Uses: | |||
-- PageTree.failsafe() | |||
local s = type( frame ) | |||
local since | |||
if s == "table" then | |||
since = frame.args[ 1 ] | |||
elseif s == "string" then | |||
since = frame | |||
end | |||
if since then | |||
since = mw.text.trim( since ) | |||
if since == "" then | |||
since = false | |||
end | |||
end | |||
return PageTree.failsafe( since ) or "" | |||
end -- p.failsafe() | |||
return p | return p | ||