Bearbeiten von „Modul:Vorlage:Anker

Zur Navigation springen Zur Suche springen
Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird bei Bearbeitungen öffentlich sichtbar. Melde dich an oder erstelle ein Benutzerkonto, damit Bearbeitungen deinem Benutzernamen zugeordnet werden. Ein eigenes Benutzerkonto hat eine ganze Reihe von Vorteilen.

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:
local Anchors = { suite  = "Anchors",
local Anchor = { suite  = "AnchorTemplate",
                  serial  = "2020-04-10",
                serial  = "2019-12-24",
                  item    = 79414611,
                item    = 79414611
                  globals = { Multilingual = 47541920,
              }
                              TemplUtl    = 52364930 }
                }
--[=[
--[=[
Support Template:Anchor  {{Anker}}
Template:Anchor  {{Anker}}
]=]
]=]
local Failsafe = Anchors
local Failsafe = Anchor
local GlobalMod = Anchors






local Config = {
local Config = {
     badPattern    = "[#'\"%[%]<>|]",
     badPattern    = "[%%#'\"%[%]<>]",
     globalPage    = { "antispam-container",
     globalPage    = { "bodyContent",
                      "bodyContent",
                       "catlinks",
                       "catlinks",
                       "centralNotice",
                       "centralNotice",
                       "content",
                       "content",
                       "contentSub",
                       "contentSub",
                      "contentSub2",
                       "editform",
                       "editform",
                       "editpage-copywarn",
                       "editpage-copywarn",
Zeile 28: Zeile 23:
                       "fundraising",
                       "fundraising",
                       "jump-to-nav",
                       "jump-to-nav",
                      "language-settings-dialog",
                      "languagesettings-panels",
                       "page-actions",
                       "page-actions",
                       "siteNotice",
                       "siteNotice",
                       "siteSub",
                       "siteSub",
                       "toc",
                       "toc",
                      "toctitle",
                       "top" },
                       "top",
                      "wikiPreview" },
     globalPatterns = { "^mw%-[%l%-]+$",
     globalPatterns = { "^mw%-[%l%-]+$",
                       "^ca%-[%l%-]+$",
                       "^ca%-[%l%-]+$",
                       "^n%-[%l%-]+$",
                       "^n%-[%l%-]+$",
                      "^p%-%a%a[%a%-]+$",
                       "^pt?%-[%l%-]+$",
                       "^pt%-[%l%-]+$",
                       "^wp%u" },
                       "^wp%u" },
     errCat        = false,
     errCat        = false,
Zeile 56: Zeile 46:
                       de = "Parameter unbekannt:" }
                       de = "Parameter unbekannt:" }
}
}
local foreignModule = function ( access, advanced, append, alt, alert )
    -- Fetch global module
    -- Precondition:
    --    access    -- string, with name of base module
    --    advanced  -- true, for require(); else mw.loadData()
    --    append    -- string, with subpage part, if any; or false
    --    alt      -- number, of wikidata item of root; or false
    --    alert    -- true, for throwing error on data problem
    -- Postcondition:
    --    Returns whatever, probably table
    -- 2020-01-01
    local storage = access
    local finer = function ()
                      if append then
                          storage = string.format( "%s/%s",
                                                  storage,
                                                  append )
                      end
                  end
    local fun, lucky, r, suited
    if advanced then
        fun = require
    else
        fun = mw.loadData
    end
    GlobalMod.globalModules = GlobalMod.globalModules or { }
    suited = GlobalMod.globalModules[ access ]
    if not suited then
        finer()
        lucky, r = pcall( fun,  "Module:" .. storage )
    end
    if not lucky then
        if not suited  and
          type( alt ) == "number"  and
          alt > 0 then
            suited = string.format( "Q%d", alt )
            suited = mw.wikibase.getSitelink( suited )
            GlobalMod.globalModules[ access ] = suited or true
        end
        if type( suited ) == "string" then
            storage = suited
            finer()
            lucky, r = pcall( fun, storage )
        end
        if not lucky and alert then
            error( "Missing or invalid page: " .. storage )
        end
    end
    return r
end -- foreignModule()




Zeile 116: Zeile 53:
     --    apply  -- string, with message key
     --    apply  -- string, with message key
     -- Returns message text; at least English
     -- Returns message text; at least English
    -- TODO: Might be extended by tabData and Multilingual
     local entry = Config[ apply ]
     local entry = Config[ apply ]
     local r
     local r
Zeile 140: Zeile 76:
     --    adjust  -- string or nil
     --    adjust  -- string or nil
     -- Returns boolean
     -- Returns boolean
     local r
     local r = false
     if type( adjust ) == "string" then
     if adjust then
         r = mw.text.trim( adjust )
         r = mw.text.trim( adjust )
         if r ~= ""  and  r ~= "0" then
         if r ~= ""  and  r ~= "0" then
             r = true
             r = true
         end
         end
    else
        r = adjust or false
     end
     end
     return r
     return r
Zeile 156: Zeile 90:
local function fair( assembly )
local function fair( assembly )
     -- Create HTML code for anchors
     -- Create HTML code for anchors
     --    assembly  -- sequence table, with identifiers
     --    assembly  -- sequence table, with identtifiers
     -- Returns HTML string
     -- Returns HTML string
     local collection = mw.html.create( "" )
     local collection = mw.html.create( "" )
Zeile 190: Zeile 124:
     local scope = Config.errClass
     local scope = Config.errClass
     local story = factory( alert )
     local story = factory( alert )
     local TemplUtl = foreignModule( "TemplUtl",
     local lucky, TemplUtl = pcall( require, "Module:TemplUtl" )
                                    true,
                                    false,
                                    Anchors.globals.TemplUtl )
     local r, scope, style
     local r, scope, style
     if type( TemplUtl ) == "table"  and
     if type( TemplUtl ) == "table" then
      type( TemplUtl.TemplUtl ) == "function" then
         TemplUtl = TemplUtl.TemplUtl()
         TemplUtl = TemplUtl.TemplUtl()
    else
        TemplUtl = false
     end
     end
     if Config.self then
     if Config.self then
Zeile 215: Zeile 143:
         story = string.format( "%s %s", story, about )
         story = string.format( "%s %s", story, about )
     end
     end
     if TemplUtl then
     if type( TemplUtl ) == "table" then
         r = TemplUtl.failure( story,
         r = TemplUtl.failure( story,
                               not Config.errHide,
                               not Config.errHide,
Zeile 255: Zeile 183:
     return r
     return r
end -- fault()
end -- fault()
local function features( adapt )
    -- Set parameters on compliance
    if type( adapt ) == "table" then
        Config.limitMarkup = faculty( adapt.rejectMarkup )
        Config.limitMW    = faculty( adapt.rejectMW )
        Config.limitXML    = faculty( adapt.onlyXML )
        Config.lightXML    = faculty( adapt.softXML )
    end
end -- features()




Zeile 276: Zeile 192:
     -- Returns appropriate string
     -- Returns appropriate string
     local r
     local r
     if type( argsF ) == "table" then
     if argsF then
         Config.errCat    = argsF.errCat
         Config.errCat    = argsF.errCat
         Config.errClasses = argsF.errClasses
         Config.errClasses = argsF.errClasses
         Config.errHide    = faculty( argsF.errHide )
         Config.errHide    = faculty( argsF.errHide )
         Config.errNS      = argsF.errNS
         Config.errNS      = argsF.errNS
        features( argsF )
if mw.site.server:find( "de.wikipedia.org", 1, true ) then
if mw.site.server:find( "de.wikipedia.", 1, true ) then
     Config.errClasses = "Linkwartung"
     Config.errClasses = "Linkwartung"
     Config.errHide = true
     Config.errHide     = true
     Config.errNS = 0
     Config.errNS       = 0
    Config.limitMarkup = true
    Config.limitMW    = false
    Config.limitXML    = true
    Config.lightXML    = true
end
end
     end
     end
     if type( argsT ) == "table" then
     if type( argsT ) == "table" then
         local e, got, less, s, unknown
         local checked = { }
        local tocheck = { }
        local further = function ( add )
                            local s = mw.text.unstripNoWiki( add )
                            s = s:gsub( " +", "_" )
                                :gsub( "_+", "_" )
                            table.insert( checked, s )
                        end
        local s, unknown
         for k, v in pairs( argsT ) do
         for k, v in pairs( argsT ) do
             if type( k ) == "number" then
             s = type( k )
            if s == "number" then
                 v = mw.text.trim( v )
                 v = mw.text.trim( v )
                 if v == "" then
                 if v ~= "" then
                     v = false
                     table.insert( tocheck, v )
                 end
                 end
                less = ( k < 0 )
                 k = false
                 k = false
             else
             elseif s == "string" then
                 less = k:match( "^[x%-][1-9]%d*" )
                 if k:match( "^x[1-9]%d*" ) then
                if less then
                    further( v )
                     k = false
                     k = false
                 end
                 end
             end
             end
             if k then
             if k then
                 unknown = unknown  or  { }
                 if not unknown then
                    unknown = { }
                end
                 table.insert( unknown, k )
                 table.insert( unknown, k )
            elseif v then
                got      = got  or  { }
                v        = v:gsub( " +", "_" )
                            :gsub( "_+", "_" )
                got[ v ] = less
             end
             end
         end -- for k, v
         end -- for k, v
         if unknown then
         if unknown then
             e = mw.html.create( "code" )
             local e = mw.html.create( "code" )
                  :css( "white-space", "nowrap" )
                        :css( "white-space", "nowrap" )
                  :wikitext( table.concat( unknown, " " ) )
                        :wikitext( table.concat( unknown, " " ) )
             s = string.format( " in [[%s]]",
             s = string.format( " in [[%s]]",
                               Config.frame:getTitle() )
                               Config.frame:getTitle() )
Zeile 327: Zeile 243:
             :wikitext( s )
             :wikitext( s )
             r = fault( "errUnkown", tostring( e ) )
             r = fault( "errUnkown", tostring( e ) )
         elseif got then
         else
             local profile = { limitMarkup = false,
            local bad, e
                              limitMW    = false,
             local flop = function ( a, alter )
                              limitXML    = false }
                            if not bad then
             local bad, checked, legal, o, s
                                bad = { }
             for k, v in pairs( got ) do
                            end
                 if v then
                            e = mw.html.create( "code" )
                     o = profile
                                        :wikitext( a )
                            if alter then
                                e:css( "white-space", "nowrap" )
                            end
                            table.insert( bad, tostring( e ) )
                        end
             local legal, s
             for i = 1, #tocheck do
                s = tocheck[ i ]
                 if s:match( "^%d" )  or
                  s:match( Config.badPattern )  or
                  s:match( "&#%a+;" ) then
                     legal = false
                 else
                 else
                     o = false
                     legal = true
                end
                    for k = 1, #Config.globalPatterns do
                s, legal = Anchors.feasible( k, o )
                        if s:match( Config.globalPatterns[ k ] ) then
                if s then
                            legal = false
                     checked = checked  or  { }
                            break    -- k = 1, #Config.globalPatterns
                    table.insert( checked, s )
                        end
                     end -- k = 1, #Config.globalPatterns
                 end
                 end
                 if not legal then
                 if not legal then
                     bad = bad  or  { }
                     flop( mw.text.encode( s ),  true )
                    e  = mw.html.create( "code" )
                else
                                :css( "white-space", "nowrap" )
                     further( s )
                                :wikitext( mw.text.encode( k ) )
                     table.insert( bad, tostring( e ) )
                 end
                 end
             end -- for k, v
             end -- i = 1, #tocheck
            if checked then
            for i = 1, #checked do
                 r = fair( checked )
                s = checked[ i ]
             end
                for k = 1, #Config.globalPage do
                    if s == Config.globalPage[ k ] then
                        flop( s )
                        break    -- k = 1, #Config.globalPage
                    end
                 end -- k = 1, #Config.globalPage
             end -- i = 1, #checked
             if bad then
             if bad then
                 s = string.format( "%s in [[%s]]",
                 s = string.format( "%s in [[%s]]",
                                   table.concat( bad, ", " ),
                                   table.concat( bad, ", " ),
                                   Config.frame:getParent():getTitle() )
                                   Config.frame:getParent():getTitle() )
                 r = string.format( "%s%s",
                 r = fault( "errInvalid", s )
                                  r or "",
            elseif #checked == 0 then
                                  fault( "errInvalid", s ) )
                r = fault( "errNoFragments" )
            else
                r = fair( checked )
             end
             end
        else
            r = fault( "errNoFragments" )
         end
         end
     end
     end
     return r or ""
     return r or ""
end -- main()
end -- main()
Anchors.feasible = function ( analyse, allow )
    -- Check ID for compliance
    -- Precondition:
    --    analyse  -- string, with presumptive anchor
    --    allow    -- optional table, with compliance criteria
    --                  -- limitMarkup
    --                  -- limitMW
    --                  -- limitXML
    --                  -- lightXML
    -- Postcondition:
    --    Returns
    --        1.  -- string  -- with normalised anchor
    --              -- false  -- if not appropriate
    --        2.  -- true, if fully compliant
    local r1 = false
    local r2 = false
    if type( analyse ) == "string" then
        local s = mw.text.trim( analyse )
        if s ~= "" then
            local deny = { limitMarkup = Config.limitMarkup,
                          limitMW    = Config.limitMW,
                          limitXML    = Config.limitXML,
                          lightXML    = Config.lightXML }
            if type( allow ) == "table" then
                for k, v in pairs( deny ) do
                    if type( allow[ k ] ) == "boolean" then
                        deny[ k ] = allow[ k ]
                    end
                end -- for k, v
            end
            if deny.limitMW then
                r1 = true
            else
                s  = mw.text.unstripNoWiki( s )
                s  = mw.text.trim( s )
                r1 = ( s ~= "" )
            end
            if r1  and  deny.limitMarkup  and
              ( s:match( Config.badPattern )  or
                s:match( "&#%w+;" ) ) then
                r1 = false
            end
            if r1 then
                for k = 1, #Config.globalPage do
                    if s == Config.globalPage[ k ] then
                        r1 = false
                        break    -- k = 1, #Config.globalPage
                    end
                end -- k = 1, #Config.globalPage
                if r1 then
                    Config.badCtrl = Config.badCtrl  or
                                    string.format( "[%c-%c]", 1, 31 )
                    r1 = not s:find( Config.badCtrl )
                    if r1  and  s:match( "%%%x%x" ) then
                        r1 = false
                    end
                    if r1 then
                        for k = 1, #Config.globalPatterns do
                            if s:match( Config.globalPatterns[ k ] ) then
                                r1 = false
                                break    -- k = 1, #Config.globalPatterns
                            end
                        end -- k = 1, #Config.globalPatterns
                    end
                end
            end
            if r1 then
                r2 = true
                if deny.limitXML  and
                  ( s:match( "^%d" )  or
                    s:sub( 1, 1 ) == "-" ) then
                    r2 = false
                    if not deny.lightXML then
                        r1 = false
                    end
                end
            end
            if r1 then
                r1 = s:gsub( " +", "_" )
                      :gsub( "_+", "_" )
            end
        end
    end
    return r1, r2
end -- Anchors.feasible()




Zeile 521: Zeile 366:
end -- p.f()
end -- p.f()


p.feasible = function ( frame )
p.flops = function ( frame )
    local r1, r2
    Config.frame = frame
    features( frame.args )
    r1, r2 = Anchors.feasible( frame.args[ 1 ] )
    return r1 or ""
end -- p.feasible()
 
p.forbidden = function ()
     local r  = ""
     local r  = ""
     local sep = ""
     local sep = ""
Zeile 541: Zeile 378:
     end -- k = 1, #Config.globalPage
     end -- k = 1, #Config.globalPage
     return r
     return r
end -- p.forbidden()
end -- p.flops()


p.failsafe = function ( frame )
p.failsafe = function ( frame )
Zeile 560: Zeile 397:
     return Failsafe.failsafe( since )  or  ""
     return Failsafe.failsafe( since )  or  ""
end -- p.failsafe()
end -- p.failsafe()
p.Anchors = function ()
    return Anchors
end -- p.Anchors


return p
return p

Bitte beachte, dass alle Beiträge im Regiowiki von anderen Mitwirkenden bearbeitet, geändert oder gelöscht werden können. Reiche hier keine Texte ein, falls Du nicht willst, dass diese ohne Einschränkung geändert werden können.

Mit dem Speichern dieser Seite stimmst Du den Nutzungsbedingungen zu und versicherst, dass Du den Beitrag selbst verfasst hast bzw. dass er keine fremden Rechte verletzt, und willigst ein, ihn unter der Creative Commons Attribution/Share-Alike Lizenz 3.0 zu veröffentlichen. Übertrage ohne Genehmigung keine urheberrechtlich geschützten Inhalte!

Du stimmst einer Autorennennung mindestens durch URL oder Verweis auf den Artikel zu. Wenn Du nicht möchtest, dass Dein Text weiterbearbeitet und weiterverbreitet wird bzw. den Nutzungsbedingungen nicht zustimmst, dann speichere ihn nicht.

Abbrechen Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)

[] [[]] | {{}} {{{}}} “” ‘’ «» ‹› „“ ‚‘ · × ° § ~~~~ <s></s> <small></small> <sup></sup> <sub></sub> <tt></tt> <code></code> <pre></pre> &nbsp; [[Kategorie:]] [[Datei:]] [[Media:]] {{DEFAULTSORT:}} {{NAMESPACE}} {{PAGENAME}} #REDIRECT[[]] <gallery></gallery> <!-- --> <nowiki></nowiki> <code><nowiki></nowiki></code> <includeonly></includeonly> <noinclude></noinclude> <onlyinclude></onlyinclude> <translate></translate> <tvar|></> <languages/>

Die folgende Vorlage wird auf dieser Seite verwendet: