Modul:WLink: Unterschied zwischen den Versionen

720 Bytes hinzugefügt ,  6. September 2014
update
wp>Tsor
K (Schützte „Modul:WLink“ ([Bearbeiten=Nur angemeldete, nicht neue Benutzer] (unbeschränkt) [Verschieben=Nur Administratoren] (unbeschränkt)))
wp>PerfektesChaos
(update)
Zeile 1: Zeile 1:
--[=[ 2014-05-01
--[=[ 2014-05-03
WLink
WLink
]=]
]=]
Zeile 5: Zeile 5:




-- table for export
-- local globals
local WLink  = { };
local WLink  = { };
local URLutil = false;
local URLutil = false;
Zeile 37: Zeile 37:
     -- Precondition:
     -- Precondition:
     --    attempt  -- string, with presumable link
     --    attempt  -- string, with presumable link
     --                       the first char is expected to be "["
     --                         the first char is expected to be "["
     -- Postcondition:
     -- Postcondition:
     --    Returns  string, number, number
     --    Returns  string, number, number
Zeile 172: Zeile 172:
     -- Postcondition:
     -- Postcondition:
     --    Returns  string, encoded
     --    Returns  string, encoded
     local k;
     local k, s;
     local r = attempt;
     local r = attempt;
     for i = #attempt, 1, -1 do
     for i = mw.ustring.len( attempt ), 1, -1 do
         k = attempt:byte( i, i );
         k = mw.ustring.codepoint( attempt, i, i );
         if k <= 32  or  k > 126 then
         if k <= 32  or  k > 126 then
             r = string.format( "%s%%%2X%s",
             if k > 255 then
                               attempt:sub( 1,  i - 1 ),
                s = mw.ustring.sub( attempt, i, i );
                               k,
                if k > 2047 then
                               r:sub( 1,  i + 1 ) );
                    s = string.format( "%%%2X%%%2X%%%2X",
                                      s:byte( 1, 1 ),
                                      s:byte( 2, 2 ),
                                      s:byte( 3, 3 ) );
                else
                    s = string.format( "%%%2X%%%2X",
                                      s:byte( 1, 1 ),
                                      s:byte( 2, 2 ) );
                end
            else
                s = string.format( "%%%2X", k );
            end
            r = string.format( "%s%s%s",
                               mw.ustring.sub( attempt,  1,  i - 1 ),
                               s,
                               mw.ustring.sub( r,  i + 1 ) );
         end
         end
     end -- for --i
     end -- for --i
Zeile 204: Zeile 219:
     -- Precondition:
     -- Precondition:
     --    attempt  -- string, with wikilink (media link) or page title
     --    attempt  -- string, with wikilink (media link) or page title
     --                 if URL, PDF may be detected
     --                         if URL, PDF may be detected
     -- Postcondition:
     -- Postcondition:
     --    Returns  string, with detected downcased media type
     --    Returns  string, with detected downcased media type
Zeile 327: Zeile 342:
                         shift = "";
                         shift = "";
                     end
                     end
                    i = i - 1;
                 end
                 end
                 if j > 1 then
                 if j > 1 then
Anonymer Benutzer