Modul:WLink: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(Die Seite wurde neu angelegt: „local WLink = { suite = "WLink", serial = "2017-10-14" }; --[=[ ansiPercent() formatURL() getArticleBase() getBaseTitle() getEscapedTitle() ge…“) |
wp>Septembermorgen (https://de.wikipedia.org/w/index.php?title=Wikipedia%3AAdministratoren%2FAnfragen&type=revision&diff=173391765&oldid=173390181#Zweimal_C&P) |
||
Zeile 1: | Zeile 1: | ||
local WLink = { suite = "WLink", | local WLink = { suite = "WLink", | ||
serial = " | serial = "2018-01-27", | ||
item = 19363224 }; | |||
--[=[ | --[=[ | ||
ansiPercent() | ansiPercent() | ||
Zeile 12: | Zeile 13: | ||
getLanguage() | getLanguage() | ||
getNamespace() | getNamespace() | ||
getNamespaced() | |||
getPlain() | getPlain() | ||
getProject() | getProject() | ||
Zeile 594: | Zeile 596: | ||
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 1.112: | Zeile 1.152: | ||
-- Retrieve versioning and check for compliance | -- Retrieve versioning and check for compliance | ||
-- Precondition: | -- Precondition: | ||
-- assert -- string, with required version, or false | -- assert -- string, with required version or "wikidata", | ||
-- 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 | if since == "wikidata" then | ||
local item = WLink.item; | |||
since = false; | |||
r = WLink.serial; | 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 <= WLink.serial then | |||
r = WLink.serial; | |||
else | |||
r = false; | |||
end | |||
end | end | ||
return r | return r; | ||
end -- WLink.failsafe() | end -- WLink.failsafe() | ||
Zeile 1.146: | Zeile 1.206: | ||
s = mw.text.trim( v ); | s = mw.text.trim( v ); | ||
end | end | ||
elseif action == " | elseif ( k == 2 and action == "getNamespaced" ) or | ||
( k == "space" and action == "ansiPercent" ) then | |||
if v ~= "" then | if v ~= "" then | ||
space = v; | space = v; | ||
Zeile 1.219: | Zeile 1.280: | ||
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 ) |