Module:Template link general: Difference between revisions
Content deleted Content added
oh this is why. Why did I fakepipe this? |
Antoniokf5 (talk | contribs) m 1 revision imported from wikipedia:Module:Template_link_general |
||
(24 intermediate revisions by 7 users not shown) | |||
Line 7:
return s ~= nil and s ~= ""
end
local nw = mw.text.nowiki
local function addTemplate(s)
Line 50 ⟶ 52:
if not _ne(textPart) then
if titleObj ~= nil then
textPart = titleObj
else
-- redlink
textPart =
end
end
if _ne(args.subst) then
-- HACK: the ns thing above is probably broken
textPart = 'subst:' .. textPart
end
if _ne(args.brace) then
textPart = nw('
elseif _ne(args.braceinside) then
textPart = nw('{') .. textPart .. nw('}')
end
titlePart = titlePart .. '|' .. textPart .. ']]'
if _ne(args.braceinside) then
titlePart = nw('
end
return titlePart
Line 75 ⟶ 78:
function p.main(frame)
local args = getArgs(frame
trim = true,
removeBlanks = false
})
return p._main(args)
end
Line 84 ⟶ 90:
local dontBrace = _ne(args.brace) or _ne(args.braceinside)
local code = _ne(args.code) or _ne(args.tt)
local show_result = _ne(args._show_result)
local expand = _ne(args._expand)
-- Build the link part
Line 92 ⟶ 100:
-- Build the arguments
local textPart = ""
local textPartBuffer = "|"
local i = 2
if not _ne(val) then break end▼
local j = 1
while args[i] do
if italic then val = '<span style="font-style:italic;">' .. val .. '</span>' end▼
local val = args[i]
textPart = textPart .. '|' .. val▼
if val ~= "" then
if _ne(args.nowiki) then
-- Unstrip nowiki tags first because calling nw on something that already contains nowiki tags will
-- mangle the nowiki strip marker and result in literal UNIQ...QINU showing up
val = nw(mw.text.unstripNoWiki(val))
end
local k, v = string.match(val, "(.*)=(.*)")
codeArguments[j] = val
j = j + 1
else
codeArguments[k] = v
end
codeArgumentsString = codeArgumentsString .. textPartBuffer .. val
if italic then
end
end
i = i + 1
end
-- final wrap
local ret = titlePart .. textPart
if not dontBrace then ret = nw('
if _ne(args.a) then ret = nw('
if _ne(args.kbd) then ret = '<kbd>' .. ret .. '</kbd>' end
if code then
Line 114 ⟶ 141:
if _ne(args.nowrap) then ret = '<span class="nowrap">' .. ret .. '</span>' end
--[[ Wrap as html??
local span = mw.html.create('span')
span:wikitext(ret)
--]]
if _ne(args.debug) then ret = ret .. '\n<pre>' .. mw.text.encode(mw.dumpObject(args)) .. '</pre>' end
if show_result then
local result = mw.getCurrentFrame():expandTemplate{title = addTemplate(args[1]), args = codeArguments}
ret = ret .. " → " .. result
end
if expand then
local query = mw.text.encode('{{' .. addTemplate(args[1]) .. string.gsub(codeArgumentsString, textPartBuffer, "|") .. '}}')
local url = mw.uri.fullUrl('special:ExpandTemplates', 'wpInput=' .. query)
mw.log()
ret = ret .. " [" .. tostring(url) .. "]"
end
return ret
end
|