跳转到内容

模組:Fullurl

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书

local p = {}
local yesno = require('Module:Yesno')
local mError = require('Module:Error').error

function p._fullurl(args)
	local paid = ''
	local title = args['title'] or args[1] or args['1'] or tostring(mw.title.getCurrentTitle())
	if title == '' then
		--不能讓title變空值,否則url會返回nil
		title = tostring(mw.title.getCurrentTitle())
	end
	local text = args['text'] or args[2] or args['1'] or title
	for k, v in pairs( args ) do
		if ((k == 'title') or (k == 1) or (k == '1') or (k == 'text') or (k == 2) or (k == '2') or (k == 'onlyurl') or (k == 'paid')) then
			if (k == 'paid') then
				if paid == '' then
					paid = mw.text.trim(v)
				else
					paid = paid .. '&' .. mw.text.trim(v)
				end
			end
		else
			if paid == '' then
				paid = k .. '=' .. mw.text.trim(v)
			else
				paid = paid .. '&' .. k .. '=' .. mw.text.trim(v)
			end
		end
	end
    local url = tostring(mw.uri.fullUrl(title,paid))
    local plainlink = '<span class="plainlinks">[' .. url .. ' ' .. text .. ']</span>'
    if (args['action'] == 'submit') then
    	return plainlink .. mError{'[[Module:Fullur]]錯誤:<code>|action=submin</code>不是有效的值,請使用<code>|action=edit</code>。'}
    else
    	if yesno(args['onlyurl']) then
    		return url
    	else
    		return plainlink
    	end
    end
end

function p.fullurl(frame)
	local args = {}
	for k, v in pairs( frame.args ) do
		args[k] = v
	end
	for k, v in pairs( frame:getParent().args ) do
		args[k] = v
	end
    return p._fullurl(args)
end

function p._fullurl2(title ,paid, text)
    return '<span class="plainlinks">[' .. tostring(mw.uri.fullUrl(title,paid)) .. ' ' .. text .. ']</span>'
end
--[=[
function p.hosturl ()
    return "//wiki.gdrain.workers.dev"
end

function p.scripturl ()
    return p.hosturl () .. "/w"
end

function p.index ()
    return p.scripturl () .. "/index.php"
end


function p.articlepath ()
    return p () .. "/wiki"
end


p["index.php"] = function ()
    return p.index ()
end

p["api.php"] = function ()
    return p.scripturl () .. "/api.php"
end

p["rest.php"] = function (frame)
    return p.scripturl () .. "/rest.php"
end
]=]--
return p