Modul:WLink: Unterschied zwischen den Versionen

K
35 Versionen von wikivoyage:Modul:WLink importiert
w>Schniggendiller
(c/p aus https://de.wikipedia.beta.wmflabs.org/w/index.php?title=Modul:WLink&oldid=22453 (gemäß Spezial:PermaLink/179296556/1× c&p TIA))
K (35 Versionen von wikivoyage:Modul:WLink importiert)
 
(15 dazwischenliegende Versionen von 9 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local WLink = { suite  = "WLink",
local WLink = { suite  = "WLink",
                 serial = "2018-07-19",
                 serial = "2016-10-05" };
                item  = 19363224 };
--[=[
--[=[
ansiPercent()
ansiPercent()
Zeile 13: Zeile 12:
getLanguage()
getLanguage()
getNamespace()
getNamespace()
getNamespaced()
getPlain()
getPlain()
getProject()
getProject()
getTarget()
getTarget()
getTalkPage()
getTargetPage()
getTargetPage()
getTitle()
getTitle()
Zeile 28: Zeile 25:
isInterwiki()
isInterwiki()
isMedia()
isMedia()
isTalkPage()
isTitledLink()
isTitledLink()
isValidLink()
isValidLink()
Zeile 337: Zeile 333:
         end
         end
     end -- for --i
     end -- for --i
    r = mw.ustring.gsub(r, '^%*', '%%2A')
     return r;
     return r;
end -- WLink.ansiPercent()
end -- WLink.ansiPercent()
Zeile 439: Zeile 436:
     return r;
     return r;
end -- WLink.getBaseTitle()
end -- WLink.getBaseTitle()


function WLink.getEscapedTitle( attempt )
function WLink.getEscapedTitle( attempt )
Zeile 448: Zeile 443:
     -- Postcondition:
     -- Postcondition:
     --    Returns  string, with suitable link title
     --    Returns  string, with suitable link title
     return attempt:gsub( "\n", " " )
    local s = mw.text.trim( attempt );
                  :gsub( "%[", "[" )
     return s:gsub( "\n", " " )
                  :gsub( "%]", "]" )
            :gsub( "%[", "[" )
                  :gsub( "|",  "|" );
            :gsub( "%]", "]" )
            :gsub( "|",  "|" );
end -- WLink.getEscapedTitle()
end -- WLink.getEscapedTitle()


function WLink.getExtension( attempt )
function WLink.getExtension( attempt )
Zeile 598: Zeile 592:
     return r;
     return r;
end -- WLink.getNamespace()
end -- WLink.getNamespace()
function WLink.getNamespaced( area, attempt )
    -- Retrieve page in namespace
    -- Precondition:
    --    area    -- string or number, with some namespace spec
    --    attempt  -- string, with wikilink or page title or page name
    -- Postcondition:
    --    Returns  page prefixed by namespace,
    --              false if invalid
    local r = false;
    local s = type( area );
    local room;
    if s == "string" then
        room = mw.site.namespaces[ tonumber( area )  or  area ];
    elseif s == "number" then
        room = mw.site.namespaces[ area ];
    end
    if room then
        local m;
        s, m = WLink.getTarget( attempt );
        if not s then
            s = attempt;
        elseif m ~= 2 then
            s = false;
        end
        if s then
            local w = WLink.wikilink( s );
            if w  and  not w.lang  and  not w.project  and
              ( not w.ns  or  w.ns == room.id ) then
                r = string.format( "%s:%s",
                                  room.name, w.title );
            end
        end
    end
    return r;
end -- WLink.getNamespaced()




Zeile 647: Zeile 603:
     local r = attempt;
     local r = attempt;
     local i = 1;
     local i = 1;
     local j, k, n, lean, s, shift, span, space, suffix;
     local j, k, n, lean, s, shift, space, suffix;
     while ( true ) do
     while ( true ) do
         j = r:find( "[", i, true );
         j = r:find( "[", i, true );
Zeile 686: Zeile 642:
                     end
                     end
                 else
                 else
                     span, shift = extractExtlink( suffix );
                     s, shift = extractExtlink( suffix );
                     if span then
                     if not s then
                         if not shift then
                         s = "";
                            shift = "";
                    end
                        end
                     if not shift then
                     else
                         shift = "";
                         shift = string.format( "[%s]", s );
                     end
                     end
                     i = i - 1;
                     i = i - 1;
Zeile 733: Zeile 688:
     return r;
     return r;
end -- WLink.getProject()
end -- WLink.getProject()
function WLink.getTalkPage( attempt )
    -- Retrieve talk page name for attempt, or that page name itself
    -- Precondition:
    --    attempt  -- string, with presumable link somewhere
    -- Postcondition:
    --    Returns  string  or  false
    local r = false;
    local s, m = WLink.getTarget( attempt );
    if m ~= 2  and  attempt then
        s = mw.text.trim( attempt );
    end
    if s  and  s ~= "" then
        local w = mw.title.new( s );
        if w then
            w = w.talkPageTitle;
            if w then
                r = w.prefixedText;
            end
        end
    end
    return r;
end -- WLink.getTalkPage()




Zeile 870: Zeile 800:
     end
     end
     if URLutil.isResourceURL( attempt ) then
     if URLutil.isResourceURL( attempt ) then
         local site   = URLutil.getAuthority( attempt );
         local site = URLutil.getAuthority( attempt );
        local service = attempt;
         local show;
         local show;
         if #attempt == #site then
         if #attempt == #site then
Zeile 878: Zeile 807:
         show = URLutil.getTop3domain( "//" .. site );
         show = URLutil.getTop3domain( "//" .. site );
         if show then
         if show then
             local scan  = "[%./](%a[%a%%%-]*%a)(%.%l%l%.)(%a+)$";
             local scan  = "[%./](%a+)(%.%l%l%.)(%a+)$";
             local search = "." .. show;
             local search = "." .. show;
             local s1, s2, s3 = search:match( scan );
             local s1, s2, s3 = search:match( scan );
             if s2 then
             if s2 then
                 if not second:find( s2, 1, true ) then
                 if not second:find( s2, 1, true ) then
                     show = string.format( "%s%s", s2:sub( 2 ), s3 );
                     show = string.format( "%s.%s", s2, s3 );
                 end
                 end
             else
             else
Zeile 895: Zeile 824:
             end
             end
         end
         end
        if not service:match( "^[a-z:]*//.+/" ) then
         r = string.format( "[%s %s]", attempt, show );
            service = service .. "/";
        end
         r = string.format( "[%s %s]", service, show );
     else
     else
         r = attempt;
         r = attempt;
Zeile 1.037: Zeile 963:
     return r;
     return r;
end -- WLink.isMedia()
end -- WLink.isMedia()
function WLink.isTalkPage( attempt )
    -- Does attempt describe a talk page?
    -- Precondition:
    --    attempt  -- string, with presumable link somewhere
    -- Postcondition:
    --    Returns  boolean
    local r = false;
    local s, m = WLink.getTarget( attempt );
    if m ~= 2  and  attempt then
        s = mw.text.trim( attempt );
    end
    if s  and  s ~= "" then
        local w = mw.title.new( s );
        if w then
            r = w.isTalkPage;
        end
    end
    return r;
end -- WLink.isTalkPage()




Zeile 1.127: Zeile 1.031:
     -- Postcondition:
     -- Postcondition:
     --    Returns  table or false
     --    Returns  table or false
     --              table of assignments with { type, value }
     --              table of assignments with { type, value}
     --                      type is one of "lead",
     --                      type is one of "lead",
     --                          "project", "lang",
     --                          "project", "lang",
Zeile 1.201: Zeile 1.105:
     -- Retrieve versioning and check for compliance
     -- Retrieve versioning and check for compliance
     -- Precondition:
     -- Precondition:
     --    assert  -- string, with required version or "wikidata",
     --    assert  -- string, with required version, or false
    --                or false
     -- Postcondition:
     -- Postcondition:
     --    Returns  string with appropriate version, or false
     --    Returns  string with appropriate version, or false
    local since = assert;
     local r;
     local r;
     if since == "wikidata" then
     if assert and  assert > WLink.serial then
        local item = WLink.item;
        r = false;
        since = false;
     else
        if type( item ) == "number" and  item > 0 then
         r = WLink.serial;
            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 <= WLink.serial then
            r = WLink.serial;
        else
            r = false;
        end
     end
     end
     return r;
     return r
end -- WLink.failsafe()
end -- WLink.failsafe()


Zeile 1.255: Zeile 1.139:
                 s = mw.text.trim( v );
                 s = mw.text.trim( v );
             end
             end
         elseif ( k == 2  and  action == "getNamespaced" )  or
         elseif action == "ansiPercent"  and  k == "space" then
              ( k == "space"  and  action == "ansiPercent" ) then
             if v ~= "" then
             if v ~= "" then
                 space = v;
                 space = v;
Zeile 1.287: Zeile 1.170:
         end
         end
     else
     else
         local e = mw.html.create( "span" );
         r = string.format( "<span class=\"error\">%s</span>", r );
        r = tostring( e:addClass( "error" )
                      :wikitext( r ) );
     end
     end
     return r;
     return r;
Zeile 1.331: Zeile 1.212:
p.getNamespace = function ( frame )
p.getNamespace = function ( frame )
     return tostring( Template( frame, "getNamespace" ) );
     return tostring( Template( frame, "getNamespace" ) );
end
p.getNamespaced = function ( frame )
    return tostring( Template( frame, "getNamespaced" ) );
end
end
p.getPlain = function ( frame )
p.getPlain = function ( frame )
Zeile 1.340: Zeile 1.218:
p.getProject = function ( frame )
p.getProject = function ( frame )
     return Template( frame, "getProject" );
     return Template( frame, "getProject" );
end
p.getTalkPage = function ( frame )
    return Template( frame, "getTalkPage" );
end
end
p.getTarget = function ( frame )
p.getTarget = function ( frame )
Zeile 1.376: Zeile 1.251:
p.isMedia = function ( frame )
p.isMedia = function ( frame )
     return Template( frame, "isMedia" );
     return Template( frame, "isMedia" );
end
p.isTalkPage = function ( frame )
    return Template( frame, "isTalkPage" );
end
end
p.isTitledLink = function ( frame )
p.isTitledLink = function ( frame )
Zeile 1.393: Zeile 1.265:
end
end
p.failsafe = function ( frame )
p.failsafe = function ( frame )
    local s = type( frame );
     local since = frame.args[ 1 ];
     local since;
    if s == "table" then
        since = frame.args[ 1 ];
    elseif s == "string" then
        since = frame;
    end
     if since then
     if since then
         since = mw.text.trim( since );
         since = mw.text.trim( since );