Module:Fullurl
来自滚动的天空Wiki
local p={}
function p._fullurl(args)
args.title=args.title or args[1] or tostring(mw.title.getCurrentTitle())
args.text=args.text or args[2] or args.title
local title,text,class,style,hover
local q={}
for k,v in pairs(args) do
if k=="title" then
title=v
elseif k=="text" then
text=v
elseif k=="class" then
class=v
elseif k=="style" then
style=v
elseif k=="hover" then
hover=v
elseif type(k)=='string' then
q[k]=v
end
end
local keys_of_q = {}
for k,v in pairs(q) do
if type(k)=='string' then
table.insert(keys_of_q,k)
end
end
table.sort(keys_of_q)
setmetatable(q,{__pairs = function(q)
-- 确保迭代时按顺序进行
-- 来自简书 https://www.jianshu.com/p/a5f1f739a724
local i = 0
return function()
i = i + 1
return keys_of_q[i], q[keys_of_q[i]]
end
end})
local span=mw.html.create("span")
span:addClass("plainlinks internal")
if class then span:addClass(class) end
if style then span:cssText(style) end
span:attr("title",hover or title)
span:wikitext("[" .. tostring(mw.uri.fullUrl(title,q)) .." ".. text .. "]")
return tostring(span)
end
function p.fullurl(frame)
local args = {}
for k,v in pairs(frame:getParent().args) do
args[k] = v
end
return p._fullurl(args)
end
return p