Modul:Vorlage:LuaModuleDoc: Unterschied zwischen den Versionen

2017-01-10
(2016-11-26)
(2017-01-10)
Zeile 1: Zeile 1:
local Serial = "2016-11-26"
local Serial = "2017-01-10"
--[=[
--[=[
Support {{LuaModuleDoc}}
Support {{LuaModuleDoc}}
* nav()
* nav()
* failsafe()
* failsafe()
require: LuaWiki
]=]
]=]


Zeile 10: Zeile 9:


-- Module globals
-- Module globals
local Lucky, LuaWiki = pcall( require, "Module:LuaWiki" )
local CurrentTitle
local CurrentTitle
local Frame
local Frame
local function fetch( arg, assign )
    -- Retrieve template argument
    -- Precondition:
    --    arg    -- string or number; argument identifier
    --    assign  -- any, optional; default value
    local r = Frame.args[ arg ]
    if type( r ) ~= "string" then
        if assign == nil then
            r = "{{{<" .. arg .. ">}}}"
        else
            r = assign
        end
    end
    return r
end -- fetch()




Zeile 23: Zeile 39:
     -- Uses:
     -- Uses:
     --    mw.title.makeTitle()
     --    mw.title.makeTitle()
     local s = LuaWiki.getArg( slot, "" )
     local s = fetch( slot, "" )
     local r
     local r
     if #s > 0 then
     if #s > 0 then
Zeile 40: Zeile 56:
     --    script  -- string; module name (main)
     --    script  -- string; module name (main)
     -- Uses:
     -- Uses:
     --    LuaWiki.getArg()
     --    fetch()
     --    >< CurrentTitle
     --    >< CurrentTitle
     -- Return:
     -- Return:
Zeile 57: Zeile 73:
             if repo  and  repo.path:match( "^/wiki/" ) then
             if repo  and  repo.path:match( "^/wiki/" ) then
                 local space
                 local space
                 space, s = mw.ustring.match( repo.path:sub( 7 ),
                 space, s = repo.path:sub( 7 ):match( "^([^:]+):(.+)$" )
                                            "^([^:]+):(.+)$" )
                 if space and s then
                 if space and s then
                     t = mw.title.makeTitle( space, s )
                     t = mw.title.makeTitle( space, s )
Zeile 70: Zeile 85:
                 end
                 end
             end
             end
             s = LuaWiki.getArg( "templateGlobal", "" )
             s = fetch( "templateGlobal", "" )
             if #s > 0 then
             if #s > 0 then
                 local lucky, code = pcall( require,
                 local lucky, code = pcall( require,
Zeile 108: Zeile 123:
             end
             end
         end
         end
         s = LuaWiki.getArg( "categoryWikiData", "" )
         s = fetch( "categoryWikiData", "" )
         if #s > 0 then
         if #s > 0 then
             local slot
             local slot
Zeile 153: Zeile 168:
     local n  = nsDocs
     local n  = nsDocs
     local r  = false
     local r  = false
     local sub = "/" .. LuaWiki.getArg( "subTest", "Test" )
     local sub = "/" .. fetch( "subTest", "Test" )
     local s  = string.format( "%s/%s%s", start, script, sub )
     local s  = string.format( "%s/%s%s", start, script, sub )
     local t  = mw.title.makeTitle( n, s )
     local t  = mw.title.makeTitle( n, s )
Zeile 189: Zeile 204:
     --    specific  -- string, optional; additional information
     --    specific  -- string, optional; additional information
     -- Uses:
     -- Uses:
     --    LuaWiki.getArg()
     --    fetch()
    --    LuaWiki.transclude()
     local show = fetch( "pageErr" )
    --    LuaWiki.error()
     local show = LuaWiki.getArg( "pageErr" )
     local r
     local r
     if type( show ) == "string" then
     if type( show ) == "string" then
Zeile 199: Zeile 212:
             table.insert( pars, specific )
             table.insert( pars, specific )
         end
         end
         r = LuaWiki.transclude( show, pars )
         r = Frame:expandTemplate{ title = show, args = pars }
     else
     else
         r = LuaWiki.error( "arg 'pageErr' missing" )
         local e = mw.html.create( "span" )
                        :attr( "class", "error" )
                        :wikitext( error( "arg 'pageErr' missing", 3 ) )
        r = tostring( e )
     end
     end
     return r
     return r
Zeile 257: Zeile 273:
     --            ... list of further language codes
     --            ... list of further language codes
     -- Uses:
     -- Uses:
     --    LuaWiki.getArg()
     --    fetch()
     --    navLang()
     --    navLang()
     --    mw.title.makeTitle()
     --    mw.title.makeTitle()
     local e, i, s, t
     local e, i, s, t
     local r = { }
     local r = { }
     local specified = LuaWiki.getArg( "langsRequest", false )
     local specified = fetch( "langsRequest", false )
     local super    = start .. "/" .. script .. "/"
     local super    = start .. "/" .. script .. "/"
     if type( specified ) == "string" then
     if type( specified ) == "string" then
Zeile 269: Zeile 285:
         end
         end
     end
     end
     navLang( LuaWiki.getArg( "langsDefault" ),  r,  specified )
     navLang( fetch( "langsDefault" ),  r,  specified )
     navLang( LuaWiki.getArg( "langsMore" ),  r,  true  )
     navLang( fetch( "langsMore" ),  r,  true  )
     navLang( specified, r, false )
     navLang( specified, r, false )
     if #r < 1 then
     if #r < 1 then
Zeile 310: Zeile 326:
     --    >< CurrentTitle
     --    >< CurrentTitle
     --    navLangs()
     --    navLangs()
    --    LuaWiki.transclude()
     --    navError()
     --    navError()
     --    mw.title.makeTitle()
     --    mw.title.makeTitle()
     --    LuaWiki.getArg()
     --    fetch()
     --    LuaWiki.isExisting()
     local server  = mw.site.server
     local super  = false
     local super  = false
     local collect = navLangs( nsDocs, start, script )
     local collect = navLangs( nsDocs, start, script )
     local t      = navDevelop( nsDocs, start, script )
     local t      = navDevelop( nsDocs, start, script )
     local r
     local low, r, s
    local s
     if t then
     if t then
         collect.Test = t
         collect.Test = t
Zeile 346: Zeile 360:
         end
         end
     end
     end
     r = LuaWiki.transclude( swift, collect )
     if server:match( "%.beta%.wmflabs%.org$" ) then
    t = CurrentTitle.talkPageTitle
        local slang, series = server:match( "//(%l+)%.(%l+)%." )
    if t then
        low = true
        s = t.exists
        if series == "wikipedia" then
    else
            if slang == "de" then
         s = false
                collect.BETA = "w:de:"  --Talk
            end
         end
     end
     end
     if not s then
    r = Frame:expandTemplate{ title = swift, args = collect }
         if super then
     if not low then
             s = "NoTalkCentral"
        t = CurrentTitle.talkPageTitle
         elseif ns == nsDocs + 1 then
         if t then
             s = t.exists
         else
             s = false
             s = false
        else
            s = "NoTalkRedir"
         end
         end
         if s then
         if not s then
             r = r .. navError( s )
             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
         end
     end
     end
Zeile 369: Zeile 394:
         local p1 = "^%s*" .. d .. "<onlyinclude>"
         local p1 = "^%s*" .. d .. "<onlyinclude>"
         local p2 = "%s*<noinclude>" .. d .. "</noinclude>"
         local p2 = "%s*<noinclude>" .. d .. "</noinclude>"
        local space, sub
         for i = 3, #collect do
         for i = 3, #collect do
             t = mw.title.makeTitle( nsDocs,  super .. collect[ i ] )
             t = mw.title.makeTitle( nsDocs,  super .. collect[ i ] )
Zeile 380: Zeile 406:
                                                 t.prefixedText ) )
                                                 t.prefixedText ) )
                 else
                 else
                     r = r .. LuaWiki.transclude( t.prefixedText )
                     r = r ..
                        Frame:expandTemplate{ title = t.prefixedText }
                     break    -- for i
                     break    -- for i
                 end
                 end
             end
             end
         end -- for i
         end -- for i
         s = LuaWiki.getArg( "pageTemplateInsert", "" )
         s = fetch( "pageTemplateInsert", "" )
         if LuaWiki.isExisting( s ) then
        space, sub = s:match( "^([^:]+):(.+)$" )
             local suppress = LuaWiki.getArg( "noHint", "" )
         if space  and  mw.title.makeTitle( space, sub ).exists then
             local suppress = fetch( "noHint", "" )
             if #suppress == 0 then
             if #suppress == 0 then
                 local swift = collect[ 1 ]
                 local swift = collect[ 1 ]
Zeile 393: Zeile 421:
                     swift = string.format( "%s/%s", swift, sub )
                     swift = string.format( "%s/%s", swift, sub )
                 end
                 end
                 r = r .. LuaWiki.transclude( s, { swift } )
                 r = r .. Frame:expandTemplate{ title = s,
                                              args = { swift } }
             end
             end
         end
         end
         s = LuaWiki.getArg( "categoryDocs", "" )
         s = fetch( "categoryDocs", "" )
         if #s > 0 then
         if #s > 0 then
             i = mw.title.makeTitle( "Category", s )
             i = mw.title.makeTitle( "Category", s )
Zeile 423: Zeile 452:
     -- Uses:
     -- Uses:
     --    >< CurrentTitle
     --    >< CurrentTitle
     --    LuaWiki.getArg()
     --    fetch()
     --    navError()
     --    navError()
     --    navMerge()
     --    navMerge()
     local r
     local r
     local start = LuaWiki.getArg( "pageDocRoot" )
     local start = fetch( "pageDocRoot" )
     if type( start ) == "string" then
     if type( start ) == "string" then
         local s      = "^"
         local s      = "^"
Zeile 435: Zeile 464:
         end
         end
         s = s .. "([^/]+)/(.*/?)$"
         s = s .. "([^/]+)/(.*/?)$"
         script, s = mw.ustring.match( CurrentTitle.text .. "/",  s )
         script, s = string.match( CurrentTitle.text .. "/",  s )
         if type( script ) == "string" then
         if type( script ) == "string" then
             local sub  = false
             local sub  = false
             local swift = LuaWiki.getArg( "pageNav" )
             local swift = fetch( "pageNav" )
             if type( s ) == "string" then
             if type( s ) == "string" then
                 if #s > 1 then
                 if #s > 1 then
Zeile 470: Zeile 499:
     -- Uses:
     -- Uses:
     --    >< CurrentTitle
     --    >< CurrentTitle
     --    LuaWiki.getArg()
     --    fetch()
     --    mw.title.getCurrentTitle()
     --    mw.title.getCurrentTitle()
     --    navPage()
     --    navPage()
     --    navError()
     --    navError()
     local r
     local r
     local nsDocs = LuaWiki.getArg( "nsDocs" )
     local nsDocs = fetch( "nsDocs" )
     if nsDocs then
     if nsDocs then
         CurrentTitle = mw.title.getCurrentTitle()
         CurrentTitle = mw.title.getCurrentTitle()
Zeile 500: Zeile 529:
function p.nav( frame )
function p.nav( frame )
     -- Uses:
     -- Uses:
    --    >  LuaWiki
     --    navigation()
     --    navigation()
     local r
     local lucky, r
     if type( LuaWiki ) == "table" then
     Frame = frame
        Frame = frame
    lucky, r = pcall( navigation )
        Lucky, r = pcall( navigation )
     if not lucky then
        r = r or ""
         local e = mw.html.create( "span" )
     else
                        :attr( "class", "error" )
         r = string.format( "<span class=\"error\">%s</span>", LuaWiki )
                        :wikitext( r )
        r = tostring( e )
     end
     end
     return r
     return r or ""
end
end


Anonymer Benutzer