Bearbeiten von „Modul:PageUtil

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 PageUtil = { suite  = "PageUtil",
--[=[ 2015-03-11
                  serial = "2018-10-19",
                  item  = 0 }
--[=[
PageUtil
PageUtil
* merge()
]=]
]=]






PageUtil.maxPages = 200
-- table for export
local PageUtil = {}
local MaxPages = 200




Zeile 15: Zeile 15:
     -- Format message with class="error"
     -- Format message with class="error"
     --    alert  -- string, with message
     --    alert  -- string, with message
     --    frame  -- object, if known
     --    frame  -- object
     -- Returns message with markup
     -- Returns message with markup
     local scream = alert
     local r = alert
     if frame then
     if frame then
         scream = string.format( "%s * %s", frame:getTitle(), scream )
         r = string.format( "%s * %s", frame:getTitle(), r )
     end
     end
     return tostring( mw.html.create( "span" )
     r = string.format( "<span class=\"error\">ERROR * %s</span>", r )
                            :addClass( "error" )
    return r
                            :wikitext( scream ) )
end -- fault()
end -- fault()


Zeile 77: Zeile 76:
             end
             end
         else
         else
             r = tostring( mw.html.create( "div" )
             r = string.format( "<div class=\"error\">%s</div>",
                                :addClass( "error" )
                              source )
                                :wikitext( source ) )
         end
         end
     end
     end
Zeile 108: Zeile 106:
                 seed = source
                 seed = source
             end
             end
             r = string.format( "%s\n%s",
            r = frame:expandTemplate( { title = seed } )
                              tostring( mw.html.create( "span" )
             r = string.format( "<span id='%s'></span>\n%s", segment, r )
                                                :attr( "id", segment ) ),
                              frame:expandTemplate( { title = seed } ) )
             table.insert( assembly,  { source, segment } )
             table.insert( assembly,  { source, segment } )
         else
         else
             r = tostring( mw.html.create( "div" )
             r = string.format( "<div class=\"error\">%s</div>",
                                :addClass( "error" )
                              page.prefixedText )
                                :wikitext( page.prefixedText ) )
         end
         end
     else
     else
         r = string.format( "%s '%s'", "Unknown page", access )
         r = string.format( "<div class=\"error\">%s '%s'</div>",
        r = tostring( mw.html.create( "div" )
                          "Unknown page", access )
                            :addClass( "error" )
                            :wikitext( r ) )
     end
     end
     return r
     return r
end -- full()
end -- full()
PageUtil.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 since = assert
    local r
    if since == "wikidata" then
        local item = PageUtil.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 <= PageUtil.serial then
            r = PageUtil.serial
        else
            r = false
        end
    end
    return r
end -- PageUtil.failsafe()
PageUtil.getProtection = function ( access, action )
    -- Retrieve protection
    --    access  -- string or title or nil, with page, default: current
    --    action  -- string or nil, with action, default: edit
    -- Returns number: One of: 0, 0.5, 0.75, 1
    local t = type( access )
    local r = 0
    local p
    if t == "string" then
        t = mw.title.new( access )
    elseif t == "table" then
        t = access
    else
        t = mw.title.getCurrentTitle()
    end
    p = t.protectionLevels
    if type( p ) == "table" then
        local s
        if type( action ) == "string" then
            s = mw.text.trim( action )
            if s == "" then
                s = false
            end
        end
        p = p[ s or "edit" ]
        if type( p ) == "table" then
            for k, v in pairs( p ) do
                if v == "autoconfirmed" then
                    r = 0.5
                elseif v == "editeditorprotected" then
                    r = 0.75
                elseif v == "sysop" then
                    r = 1
                end
            end -- for k, v
        end
    end
    return r
end -- PageUtil.getProtection()




Zeile 246: Zeile 160:
                     r = r .. mw.text.trim( s )
                     r = r .. mw.text.trim( s )
                 end
                 end
                 if n > PageUtil.maxPages then
                 if n > MaxPages then
                     s = string.format( "'''Too many pages (max. %d)'''",
                     s = string.format( "'''Too many pages (max. %d)'''",
                                       PageUtil.maxPages )
                                       MaxPages )
                     r = string.format( "%s\n\n%s",
                     r = string.format( "%s\n\n%s",
                                       r,
                                       r,
Zeile 265: Zeile 179:
-- Export
-- Export
local p = { }
local p = { }
p.getProtection = function ( frame )
    local n = PageUtil.getProtection( frame.args[ 1 ], frame.args[ 2 ] )
    local t = { [ 0 ]    = "",
                [ 0.5 ]  = mw.ustring.char( 189 ),
                [ 0.75 ] = mw.ustring.char( 190 ),
                [ 1 ]    = "1" }
    return t[ n ]
end -- p.getProtection
function p.isRedirect()
    return mw.title.getCurrentTitle().isRedirect and "1"  or  ""
end -- p.isRedirect


p.merge = function ( frame )
p.merge = function ( frame )
Zeile 285: Zeile 186:
     end
     end
     return r
     return r
end -- p.merge
end
 
p.failsafe = function ( frame )
    -- Versioning interface
    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 PageUtil.failsafe( since )  or  ""
end -- p.failsafe()


function p.PageUtil()
function p.PageUtil()

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: