Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
wp>PerfektesChaos (update) |
wp>PerfektesChaos (update) |
||
Zeile 1: | Zeile 1: | ||
--[=[ 2013-05- | --[=[ 2013-05-13 | ||
Support {{LuaModuleDoc}} | Support {{LuaModuleDoc}} | ||
* nav() | * nav() | ||
Zeile 21: | Zeile 21: | ||
-- LuaWiki.getArg() | -- LuaWiki.getArg() | ||
-- LuaWiki.transclude() | -- LuaWiki.transclude() | ||
-- LuaWiki.error() | |||
local show = LuaWiki.getArg( "pageErr" ) | local show = LuaWiki.getArg( "pageErr" ) | ||
local r | local r | ||
Zeile 30: | Zeile 31: | ||
r = LuaWiki.transclude( show, pars ) | r = LuaWiki.transclude( show, pars ) | ||
else | else | ||
r = " | r = LuaWiki.error( "arg 'pageErr' missing" ) | ||
end | end | ||
return r | return r | ||
Zeile 61: | Zeile 62: | ||
-- navError() | -- navError() | ||
local r = LuaWiki.transclude( swift, collect ) | local r = LuaWiki.transclude( swift, collect ) | ||
local s = | local s = false | ||
local t = currentTitle.talkPageTitle | local t = currentTitle.talkPageTitle | ||
if t then | if t then | ||
s = t.exists | s = t.exists | ||
end | end | ||
r = "<!-- LuaModuleDoc::b -->" .. r .. "<!-- LuaModuleDoc::e -->" | |||
if not s then | if not s then | ||
if super then | if super then | ||
Zeile 83: | Zeile 85: | ||
s = super .. collect[ i ] | s = super .. collect[ i ] | ||
if LuaWiki.isExisting( s ) then | if LuaWiki.isExisting( s ) then | ||
r | s = LuaWiki.transclude( s ) | ||
r = r .. s:gsub( "<!-- LuaModuleDoc::b -->.*<!-- LuaModuleDoc::e -->", "" ) | |||
break | break | ||
end | end | ||
Zeile 96: | Zeile 99: | ||
s = LuaWiki.getArg( "categoryDocs", "" ) | s = LuaWiki.getArg( "categoryDocs", "" ) | ||
if #s > 0 then | if #s > 0 then | ||
i = mw.title.makeTitle( "Category", s ) | |||
if | if i.exists then | ||
r = r .. "[[" .. | r = r .. "[[" .. i.prefixedText | ||
.. "|" .. collect[ 1 ] .. "]]" | |||
end | end | ||
end | end | ||
Zeile 142: | Zeile 146: | ||
local function navLangs( script | local function navLangs( space, start, script ) | ||
-- Analyze languages | -- Analyze languages | ||
-- Precondition: | -- Precondition: | ||
-- current page is supposed to transclude LuaModuleDoc | -- current page is supposed to transclude LuaModuleDoc | ||
-- space -- string; central documentation namespace | |||
-- start -- string; central documentation root | |||
-- script -- string; basic module name | -- script -- string; basic module name | ||
-- Return: | -- Return: | ||
-- table: args for navigation template | -- table: args for navigation template | ||
Zeile 158: | Zeile 163: | ||
-- LuaWiki.getArg() | -- LuaWiki.getArg() | ||
-- navLang() | -- navLang() | ||
-- navError() | -- navError() | ||
local e, i, s | local e, i, s, t | ||
local r = { } | local r = { } | ||
local specified = LuaWiki.getArg( "langsRequest", false ) | local specified = LuaWiki.getArg( "langsRequest", false ) | ||
local super = start .. "/" .. script .. "/" | |||
if type( specified ) == "string" then | if type( specified ) == "string" then | ||
if specified:match( "^%s*$" ) then | if specified:match( "^%s*$" ) then | ||
Zeile 168: | Zeile 173: | ||
end | end | ||
end | end | ||
navLang( LuaWiki.getArg( "langsDefault" ), | navLang( LuaWiki.getArg( "langsDefault" ), r, specified ) | ||
navLang( specified, r, false ) | navLang( specified, r, false ) | ||
if #r < 1 then | if #r < 1 then | ||
Zeile 179: | Zeile 182: | ||
s = e[ 1 ] | s = e[ 1 ] | ||
if e[ 2 ] then | if e[ 2 ] then | ||
t = mw.title.makeTitle( space, super .. s ) | |||
if not t.exists then | |||
s = false | s = false | ||
end | end | ||
Zeile 204: | Zeile 208: | ||
-- nsDocs -- number; namespace for doc | -- nsDocs -- number; namespace for doc | ||
-- Uses: | -- Uses: | ||
-- >< currentTitle | |||
-- LuaWiki.getArg() | -- LuaWiki.getArg() | ||
-- navError() | -- navError() | ||
Zeile 212: | Zeile 217: | ||
if type( start ) == "string" then | if type( start ) == "string" then | ||
local light = false | local light = false | ||
local story = currentTitle.text .. "/" | |||
local script | local script | ||
if lead then | if lead then | ||
script = currentTitle.baseText | |||
script = | |||
else | else | ||
local sub = "/([^/]+)/(.*)$" | local sub = "/([^/]+)/(.*)$" | ||
script, sub = mw.ustring.match( story, | script, sub = mw.ustring.match( story, | ||
"^" .. start .. sub ) | |||
if type( script ) == "string" then | if type( script ) == "string" then | ||
light = ( #sub > 0 ) | light = ( #sub > 0 ) | ||
Zeile 231: | Zeile 236: | ||
if type( swift ) == "string" then | if type( swift ) == "string" then | ||
-- nsDocs is valid, since it equals ns | -- nsDocs is valid, since it equals ns | ||
local | local space = mw.site.namespaces[ nsDocs ].name | ||
super | local super | ||
local collect = navLangs( script | local collect = navLangs( space, start, script ) | ||
if ns == nsDocs and | if ns == nsDocs and | ||
story == start .. "/" .. script .. "/" then | story == start .. "/" .. script .. "/" then | ||
super = | super = space .. ":" .. start .. "/" .. script .. "/" | ||
else | else | ||
super = false | super = false |
Version vom 13. Mai 2013, 20:22 Uhr
Lua-Fehler in Modul:LuaWiki, Zeile 168: No transclude page 'Regiowiki:Lua/Modul-Navigationsfehler'
--[=[ 2013-05-13
Support {{LuaModuleDoc}}
* nav()
require: LuaWiki
]=]
-- Module globals
local import, LuaWiki = pcall( require, "Module:LuaWiki" )
local currentTitle
local function navError( say, specific )
-- Return error message, evaluate page .pageErr
-- Precondition:
-- say -- string; message key
-- specific -- string, optional; additional information
-- Uses:
-- LuaWiki.getArg()
-- LuaWiki.transclude()
-- LuaWiki.error()
local show = LuaWiki.getArg( "pageErr" )
local r
if type( show ) == "string" then
local pars = { say }
if type( specific ) == "string" then
table.insert( pars, specific )
end
r = LuaWiki.transclude( show, pars )
else
r = LuaWiki.error( "arg 'pageErr' missing" )
end
return r
end -- navError()
local function navInclude( collect, swift, super, ns, nsDocs )
-- Include external content into page
-- Precondition:
-- collect -- table; with arguments for pageNav transclusion
-- 1: basic module name
-- 2: number of language links + 1
-- 3...: language link codes
-- swift -- string; pageNav argument
-- super -- string or false
-- string: full page name of basic documentation
-- terminated by slash; then
-- include first existing language version
-- and brief template documentation
-- ns -- number; current namespace
-- nsDocs -- number; namespace for doc
-- args.pageNav defined
-- Uses:
-- >< currentTitle
-- LuaWiki.getArg()
-- LuaWiki.transclude()
-- LuaWiki.getVariable()
-- LuaWiki.isExisting()
-- navError()
local r = LuaWiki.transclude( swift, collect )
local s = false
local t = currentTitle.talkPageTitle
if t then
s = t.exists
end
r = "<!-- LuaModuleDoc::b -->" .. r .. "<!-- LuaModuleDoc::e -->"
if not s then
if super then
s = "NoTalkCentral"
elseif ns == nsDocs + 1 then
s = false
else
s = "NoTalkRedir"
end
if s then
r = r .. navError( s )
end
end
if super then
local i
for i = 3, #collect do
s = super .. collect[ i ]
if LuaWiki.isExisting( s ) then
s = LuaWiki.transclude( s )
r = r .. s:gsub( "<!-- LuaModuleDoc::b -->.*<!-- LuaModuleDoc::e -->", "" )
break
end
end -- for i
s = LuaWiki.getArg( "pageTemplateInsert", "" )
if LuaWiki.isExisting( s ) then
local suppress = LuaWiki.getArg( "noHint", "" )
if #suppress == 0 then
r = r .. LuaWiki.transclude( s, { collect[ 1 ] } )
end
end
s = LuaWiki.getArg( "categoryDocs", "" )
if #s > 0 then
i = mw.title.makeTitle( "Category", s )
if i.exists then
r = r .. "[[" .. i.prefixedText
.. "|" .. collect[ 1 ] .. "]]"
end
end
r = r .. "__NOEDITSECTION__"
end
return r
end -- navInclude()
local function navLang( suite, collect, lazy )
-- Append languages from string to collection
-- Precondition:
-- suite -- string; space separated source
-- collect -- table; to be extended
-- every element: { langCode, lazy }
-- lazy -- true if only existing page is to be linked
if type( suite ) == "string" then
local raw = mw.text.split( suite, "%s+" )
local e, i, j, s
for i = 1, #raw do
s = raw[ i ]
if #s > 1 then
for j = 1, #collect do
if s then
e = collect[ j ]
if e[ 1 ] == s then
s = false
if not lazy then
e[ 2 ] = false
end
end
end
end -- for j
if s then
table.insert( collect, { s, lazy } )
end
end
end -- for i
end
end -- navLang()
local function navLangs( space, start, script )
-- Analyze languages
-- Precondition:
-- current page is supposed to transclude LuaModuleDoc
-- space -- string; central documentation namespace
-- start -- string; central documentation root
-- script -- string; basic module name
-- Return:
-- table: args for navigation template
-- [1] basic module name
-- [2] number of language codes + 1
-- [3] first language code
-- [4] second language code
-- ... list of further language codes
-- Uses:
-- LuaWiki.getArg()
-- navLang()
-- navError()
local e, i, s, t
local r = { }
local specified = LuaWiki.getArg( "langsRequest", false )
local super = start .. "/" .. script .. "/"
if type( specified ) == "string" then
if specified:match( "^%s*$" ) then
specified = false
end
end
navLang( LuaWiki.getArg( "langsDefault" ), r, specified )
navLang( specified, r, false )
if #r < 1 then
r = { { "en", false } }
end
for i = #r, 1, -1 do
e = r[ i ]
s = e[ 1 ]
if e[ 2 ] then
t = mw.title.makeTitle( space, super .. s )
if not t.exists then
s = false
end
end
if s then
r[ i ] = s
else
table.remove( r, i )
end
end -- for i -1
table.insert( r, 1, script )
table.insert( r, 2, tostring( #r ) )
return r
end -- navLangs()
local function navPage( lead, ns, nsDocs )
-- Return navigation text; analyze page location
-- Precondition:
-- current namespace will support LuaModuleDoc
-- lead -- true: Module: namespace; false: text namespace
-- ns -- number; current namespace
-- nsDocs -- number; namespace for doc
-- Uses:
-- >< currentTitle
-- LuaWiki.getArg()
-- navError()
-- navLangs()
-- navInclude()
local r
local start = LuaWiki.getArg( "pageDocRoot" )
if type( start ) == "string" then
local light = false
local story = currentTitle.text .. "/"
local script
if lead then
script = currentTitle.baseText
else
local sub = "/([^/]+)/(.*)$"
script, sub = mw.ustring.match( story,
"^" .. start .. sub )
if type( script ) == "string" then
light = ( #sub > 0 )
else
r = navError( "BadPage" ) .. story
script = false
end
end
if script then
local swift = LuaWiki.getArg( "pageNav" )
if type( swift ) == "string" then
-- nsDocs is valid, since it equals ns
local space = mw.site.namespaces[ nsDocs ].name
local super
local collect = navLangs( space, start, script )
if ns == nsDocs and
story == start .. "/" .. script .. "/" then
super = space .. ":" .. start .. "/" .. script .. "/"
else
super = false
end
r = navInclude( collect, swift, super, ns, nsDocs )
else
r = navError( "configMissing", "pageNav" )
end
end
else
r = navError( "configMissing", "pageDocRoot" )
end
return r
end -- navPage()
local function navigation()
-- Start execution; return navigation text; analyze namespace
-- Uses:
-- >< currentTitle
-- LuaWiki.getArg()
-- mw.title.getCurrentTitle()
-- navPage()
-- navError()
local r
local nsDocs = LuaWiki.getArg( "nsDocs" )
if nsDocs then
currentTitle = mw.title.getCurrentTitle()
local ns = currentTitle.namespace
local lead = ( ns == mw.site.namespaces.Module.id )
nsDocs = tonumber( nsDocs )
if lead or ns == nsDocs or ns == nsDocs + 1 then
r = navPage( lead, ns, nsDocs )
else
r = navError( "BadNamespace" )
end
else
r = navError( "configMissing", "nsDocs" )
end
return r
end -- navigation()
-- Provide template access
local p = {}
function p.nav( frame )
-- Uses:
-- > LuaWiki
-- navigation()
local r
if type( LuaWiki ) == "table" then
r = navigation() or ""
else
r = "<span class='error'>" .. LuaWiki .. "</span>"
end
return r
end
return p