Module:Fullurl

勤求古训,博采众方
入我相思门留言 | 贡献2022年11月23日 (三) 21:12的版本 (创建页面,内容为“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 == 'titl…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
文档图示 模块文档[创建]
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 "//zh.wikipedia.org"
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