Moduł:Strony
Wygląd
|
Zobacz podstrony tego modułu.
|
local p={};
local function checkUri(uri)
if((not mw.ustring.match(uri,"^[^%s/]+://"))and(not mw.ustring.match(uri,"^//")))then
return nil;
end;
local urilen = #uri
for _,v in ipairs(mw.loadData("Module:Strony/dane").obslugiwaneUriSchematy) do
if (#v < urilen) and (string.lower(string.sub(uri,1, #v)) == v) then
return (string.match(uri, '^(%S*)//+([^%s/]+)') and true or false);
end
end
end
local function checkImageName(name)
if not name or (#name==0) or string.match(name, "[#<>%[%]|{}]") then
return false
end
local title = mw.title.makeTitle("Plik", name)
if not title then
return false
end
local res = {
prefix = {
plik = true,
image = true,
grafika = true,
file = true,
},
extension = {
jpg = true,
jpeg = true,
jpe = true,
png = true,
svg = true,
tif = true,
tiff = true,
gif = true,
xcf = true,
pdf = true,
djvu = true,
webp = true,
},
}
local prefix = string.match(name, "^:? *([^:]+) *:")
if prefix and res.prefix[string.lower(prefix)] then
return false
end
local extension = string.match(name, "%S.*%.([^%.]+)$")
return extension and res.extension[string.lower(extension)]
end;
local function findPlainHttp(text)
if text then
text = mw.ustring.gsub(text, "%[[hH][tT][tT][pP][sS]?://%S+", "_")
return string.match(text, "[hH][tT][tT][pP][sS]?://%S")
end
end;
local function findAnyHttp(text)
if text then
return string.match(text, "[hH][tT][tT][pP][sS]?://%S")
end
end
local function findFile(text)
-- schowaj wyjątek: obrazek generowany przez Szablon:Link-interwiki
text = mw.ustring.gsub(text, "%[%[Plik:Wikidata%-logo%-en%.svg|10x9px|link=:d:Q%d+|Informacje powiązane z artykułem „.-” w Wikidanych%]%]", "")
-- normalize
text = mw.ustring.gsub(text, "%s*[Pp]lik%s*:%s*", "Plik:")
text = mw.ustring.gsub(text, "%s*[Ff]ile%s*:%s*", "Plik:")
text = mw.ustring.gsub(text, "%s*[Gg]rafika%s*:%s*", "Plik:")
text = mw.ustring.gsub(text, "%s*[Ii]mage%s*:%s*", "Plik:")
return mw.ustring.match(text, "%[%[Plik:([^%[%]|]+)[|%]]")
end
function p.SprawdzanieURL(frame)
local parametry_modul=require("Module:Parametry");
local PobierzParametr=parametry_modul.PobierzParametr(frame);
local url=PobierzParametr("url") or PobierzParametr(1);
return checkUri(url);
end;
function p.SprawdzanieNazwyPlikowe(frame)
local parametry_modul=require("Module:Parametry");
local PobierzParametr=parametry_modul.PobierzParametr(frame);
local nazwa=PobierzParametr("nazwa") or PobierzParametr(1);
return checkImageName(nazwa);
end;
function p.ZnajdowanieNormalnychStronHttp(frame)
local parametry_modul=require("Module:Parametry");
local PobierzParametr=parametry_modul.PobierzParametr(frame);
local tekst=PobierzParametr("tekst") or PobierzParametr(1);
return findPlainHttp(tekst);
end;
function p.ZnajdowanieJakikolwiekStronHttp(frame)
local parametry_modul=require("Module:Parametry");
local PobierzParametr=parametry_modul.PobierzParametr(frame);
local tekst=PobierzParametr("tekst") or PobierzParametr(1);
return findAnyHttp(tekst);
end;
function p.ZnajdowaniePlikowe(frame)
local parametry_modul=require("Module:Parametry");
local PobierzParametr=parametry_modul.PobierzParametr(frame);
local tekst=PobierzParametr("tekst") or PobierzParametr(1);
return findFile(tekst);
end;
return p;