Bearbeiten von „Modul:TemplUtl

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 TemplUtl = { suite  = "TemplUtl",
local TemplUtl = { suite  = "TemplUtl",
                   serial = "2019-11-20",
                   serial = "2019-02-17" };
                  item  = 52364930 };
local Failsafe = TemplUtl;
 
 
 
local fallible = function ( adjust, ahead )
    -- Check for leading character disturbing syntax
    -- Precondition:
    --    adjust  -- string; trimmed wikitext
    --    ahead  -- true, if leading syntax shall start on new line
    -- Postcondition:
    --    Returns string, modified if necessary
    local r = adjust;
    local c = r:byte( 1, 1 );
    if c <= 59  and
      ( c==35 or c==42 or c==58 or c==59 ) then
        if ahead then
            r = "\n" .. r;
        else
            r = mw.text.nowiki( r:sub( 1, 1 ) )  ..  r:sub( 2 );
        end
    elseif ahead then
        local c2 = r:byte( 2, 1 );
        if ( c==123 and c2==124 )  or
          ( c==124 and c2==45 ) then
            r = "\n" .. r;
        end
    end
    return r;
end -- fallible()




Zeile 39: Zeile 9:
     --    accept  -- string; trimmed title
     --    accept  -- string; trimmed title
     -- Postcondition:
     -- Postcondition:
     --   Returns string with pattern
     --     Returns string with pattern
     local start = mw.ustring.sub( accept, 1, 1 );
     local start = mw.ustring.sub( accept, 1, 1 );
     local r;
     local r;
Zeile 92: Zeile 62:
         else
         else
             r = r:lower();
             r = r:lower();
             if r == "y"  or
             if r == "y"  or r == "yes"  or r == "true" then
              r == "yes"  or
              r == "true"  or
              r == "on" then
                 r = true;
                 r = true;
             elseif r == "n"  or
             elseif r == "n"  or r == "no"  or r == "false" then
                  r == "no"  or
                  r == "false"  or
                  r == "off" then
                 r = false;
                 r = false;
             else
             else
                 if not TemplUtl.boolang then
                 if not TemplUtl.L10N then
                     -- TODO: page language
                     local lucky;
                     local l, d = pcall( mw.ext.data.get, "i18n/01.tab" );
                     s = string.format( "Module:%s/local",
                     if type( d ) == "table"  and
                                      TemplUtl.suite );
                      type( d.data ) == "table" then
                     lucky, TemplUtl.L10N = pcall( mw.loadData, s );
                        local f = function ( at )
                end
                                  local e = d.data[ at ];
                if type( TemplUtl.L10N ) == "table" then
                                  l = e[ 1 ];
                    local entry;
                                  s = e[ 2 ];
                    if not TemplUtl.lang then
                                  if type( l ) == "boolean"  and
                        -- TODO: page language
                                    type( s ) == "string" then
                         TemplUtl.lang =
                                      s = mw.text.split( s, "|" );
                              mw.language.getContentLanguage():getCode();
                                      for i = 1, #s do
                                          TemplUtl.boolang[ s[ i ] ] = l;
                                      end -- for i
                                  end
                              end
                         TemplUtl.boolang = { };
                        f( 1 );
                        f( 2 );
                    else
                        TemplUtl.boolang = true;
                     end
                     end
                end
                    entry = TemplUtl.L10N[ TemplUtl.lang ];
                if type( TemplUtl.boolang ) == "table" then
                    if type( entry ) == "table" then
                    s = TemplUtl.boolang[ r ];
                        s = entry[ r ];
                    if type( s ) == "boolean" then
                        if type( s ) == "boolean" then
                        r = s;
                            r = s;
                        end
                     end
                     end
                else
                    TemplUtl.L10N = true;
                 end
                 end
                 if type( r ) ~= "boolean" then
                 if type( r ) ~= "boolean" then
                     s = type( another );
                     if type( another ) ~= "nil" then
                    if s == "nil" then
                        r = TemplUtl.faculty( another );
                    else
                         r = true;
                         r = true;
                    elseif s == "boolean" then
                        r = another;
                    else
                        r = TemplUtl.faculty( another );
                     end
                     end
                 end
                 end
Zeile 154: Zeile 108:
     return r;
     return r;
end -- TemplUtl.faculty()
end -- TemplUtl.faculty()
TemplUtl.failsafe = function ( assert )
    local r
    if not assert  or  assert <= TemplUtl.serial then
        r = TemplUtl.serial
    else
        r = false
    end
    return r
end -- TemplUtl.failsafe()




Zeile 202: Zeile 168:




TemplUtl.fake = function ( access )
TemplUtl.fake = function ( access, frame )
     -- Simulation of template transclusion
     -- Simulation of template transclusion
     -- Precondition:
     -- Precondition:
     --    access  -- string; page name (template)
     --    access  -- string, or nil; page name (template)
    --    frame  -- object, or nil
    local s;
     if type( access ) == "string" then
     if type( access ) == "string" then
         local s = mw.text.trim( access );
         s = mw.text.trim( access );
         if s ~= "" then
         if s == "" then
             local t = mw.title.new( s, 10 );
             s = false;
            if not mw.title.equals( mw.title.getCurrentTitle(), t ) and
        end
              t.exists then
    end
                t:getContent();
    if not s then
             end
        local cnf, lucky;
        s = string.format( "Module:%s/self", TemplUtl.suite );
        lucky, cnf = pcall( mw.loadData, s );
        if type( cnf ) == "table" and
          cnf.loop == true then
            s = mw.title.getCurrentTitle().text;
        else
             s = false;
         end
         end
    end
    if s then
        local f = function ()
                      framing( frame ):expandTemplate{ title = s };
                  end
        pcall( f );
     end
     end
end -- TemplUtl.fake()
end -- TemplUtl.fake()
Zeile 220: Zeile 201:




TemplUtl.fakes = function ( array, frame, ahead, answer )
TemplUtl.fakes = function ( array, frame, ahead )
     -- Simulation of template transclusions
     -- Simulation of template transclusions
     -- Precondition:
     -- Precondition:
     --    array   -- table, with template title strings
     --    array -- table, with template title strings
     --    frame   -- object, or nil
     --    frame -- object, or nil
     --    ahead   -- string, or nil, with common prefix
     --    ahead -- string, or nil, with common prefix
    --    answer  -- true, or nil, for list creation
    -- Postcondition:
    --    Returns string, if answer requested
     local e = framing( frame );
     local e = framing( frame );
     local f = function ( a )
     local f = function ( a )
Zeile 234: Zeile 212:
               end
               end
     local s = ahead or "";
     local s = ahead or "";
    local r;
     for k, v in pairs( array ) do
     for k, v in pairs( array ) do
         if type( k ) == "number" and
         if type( k ) == "number" and  
           type( v ) == "string" then
           type( v ) == "string" then
             v = s .. mw.text.trim( v );
             v = mw.text.trim( v );
             pcall( f, v );
             pcall( f, s .. v );
            if answer then
                if r then
                    r = r .. "\n";
                else
                    r = "";
                end
                r = string.format( "%s* [[Template:%s|%s]]", r, v, v );
            end
         end
         end
     end -- for k, v
     end -- for k, v
    return r;
end -- TemplUtl.fakes()
end -- TemplUtl.fakes()


Zeile 260: Zeile 228:
     --    address  -- string; what to inspect, URL presumed
     --    address  -- string; what to inspect, URL presumed
     -- Postcondition:
     -- Postcondition:
     --   Returns true, if URL beginning
     --     Returns true, if URL beginning
     local start, r = address:match( "^%s*((%a*:?)//)" );
     local start, r = address:match( "^%s*((%a*:?)//)" );
     if start then
     if start then
Zeile 290: Zeile 258:
     --    after  -- true, if only to search for "}}"
     --    after  -- true, if only to search for "}}"
     -- Postcondition:
     -- Postcondition:
     --   Returns
     --     Returns
     --          -- number; byte position in area
     --          -- number; byte position in area
     --            -- before "|" or "}}", may be at end
     --            -- before "|" or "}}", may be at end
Zeile 427: Zeile 395:
     --    at    -- optional number; byte position in area of "{{"
     --    at    -- optional number; byte position in area of "{{"
     -- Postcondition:
     -- Postcondition:
     --   Returns
     --     Returns
     --          -- table
     --          -- table
     --              [0]      -- template, page, parser function name
     --              [0]      -- template, page, parser function name
Zeile 494: Zeile 462:
     --    ask  -- string; parameter name
     --    ask  -- string; parameter name
     -- Postcondition:
     -- Postcondition:
     --   Returns string with trimmed parameter value, or nil
     --     Returns string with trimmed parameter value, or nil
     --    Does not return value if template inside
     --    Does not return value if template inside
     local r;
     local r;
Zeile 525: Zeile 493:
     --                                no colon (:)
     --                                no colon (:)
     -- Postcondition:
     -- Postcondition:
     --   Returns ustring position of "{{" in area, or false
     --     Returns ustring position of "{{" in area, or false
     -- Requires:
     -- Requires:
     --    fiatTitleRegExp()
     --    fiatTitleRegExp()
Zeile 591: Zeile 559:
--      3 4 5 6
--      3 4 5 6
--        more like 2
--        more like 2
TemplUtl.firstbreak = function ( adjust )
    -- Precede leading character with newline if specific syntax
    -- Precondition:
    --    adjust  -- string; trimmed wikitext
    -- Postcondition:
    --    Returns string, modified if necessary
    return fallible( adjust, true );
end -- TemplUtl.firstbreak()




Zeile 608: Zeile 565:
     -- Remove syntax elements that hide effective syntax only
     -- Remove syntax elements that hide effective syntax only
     -- Precondition:
     -- Precondition:
     --    area  -- string; unparsed wikitext to be reduced
     --    area  -- string; wikitext to be reduced
     -- Postcondition:
     -- Postcondition:
     --   Returns cleared wikitext
     --     Returns cleared wikitext
     local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" },
     local delimiters = { { "<%s*NOWIKI%s*>", "<%s*/%s*NOWIKI%s*>" },
                         { "<!--", "-->", true },
                         { "<!--", "-->", true },
Zeile 674: Zeile 631:
     return r;
     return r;
end -- TemplUtl.flat()
end -- TemplUtl.flat()
TemplUtl.nowiki1 = function ( adjust )
    -- HTML-escape leading character if disturbing syntax
    -- Precondition:
    --    adjust  -- string; trimmed wikitext
    -- Postcondition:
    --    Returns string, modified if necessary
    return fallible( adjust, false );
end -- TemplUtl.nowiki1()
Failsafe.failsafe = function ( atleast )
    -- Retrieve versioning and check for compliance
    -- Precondition:
    --    atleast  -- string, with required version or "wikidata" or "~"
    --                or false
    -- Postcondition:
    --    Returns  string  -- with queried version, also if problem
    --              false  -- if appropriate
    local last  = ( atleast == "~" )
    local since = atleast
    local r
    if last  or  since == "wikidata" then
        local item = Failsafe.item
        since = false
        if type( item ) == "number"  and  item > 0 then
            local entity = mw.wikibase.getEntity( string.format( "Q%d",
                                                                item ) )
            if type( entity ) == "table" then
                local seek = Failsafe.serialProperty or "P348"
                local vsn  = entity:formatPropertyValues( seek )
                if type( vsn ) == "table"  and
                  type( vsn.value ) == "string"  and
                  vsn.value ~= "" then
                    if last  and  vsn.value == Failsafe.serial then
                        r = false
                    else
                        r = vsn.value
                    end
                end
            end
        end
    end
    if type( r ) == "nil" then
        if not since  or  since <= Failsafe.serial then
            r = Failsafe.serial
        else
            r = false
        end
    end
    return r
end -- Failsafe.failsafe()




Zeile 760: Zeile 662:


function p.fakes( frame )
function p.fakes( frame )
     local list = ( frame.args.list == "1" );
     TemplUtl.fakes( frame.args, frame, frame.args.prefix );
    local r    = TemplUtl.fakes( frame.args,
     return "";
                                frame,
                                frame.args.prefix,
                                list );
     return r or "";
end -- p.fakes
end -- p.fakes
function p.firstbreak( frame )
    local r = ( frame.args[ 1 ] );
    if r then
        r = mw.text.trim( r );
        if r ~= "" then
            r = TemplUtl.firstbreak( r );
        end
    end
    return r or "";
end -- p.firstbreak
function p.from( frame )
    local r = frame:getParent():getTitle();
    if r then
        r = string.format( "&#123;&#123;%s&#125;&#125;", r );
    end
    return r or "";
end -- p.from


function p.isRedirect()
function p.isRedirect()
     return mw.title.getCurrentTitle().isRedirect and "1"  or  "";
     return mw.title.getCurrentTitle().isRedirect and "1"  or  "";
end -- p.isRedirect
end -- p.isRedirect
function p.nowiki1( frame )
    local r = ( frame.args[ 1 ] );
    if r then
        r = mw.text.trim( r );
        if r ~= "" then
            r = TemplUtl.nowiki1( r );
        end
    end
    return r or "";
end -- p.nowiki1


p.failsafe = function ( frame )
p.failsafe = function ( frame )
Zeile 817: Zeile 685:
         end
         end
     end
     end
     return Failsafe.failsafe( since )  or  ""
     return TemplUtl.failsafe( since )  or  ""
end -- p.failsafe
end -- p.failsafe()


p.TemplUtl = function ()
p.TemplUtl = function ()

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: