Module:shortcut box: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:


if args.temp then
if args.temp then
output[#output + 1] = "Temporary [[Wiktionary:Shortcut|shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
output[#output + 1] = "Temporary [[wikt:Wiktionary:Shortcut|shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
else
else
output[#output + 1] = "[[Wiktionary:Shortcut|Shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
output[#output + 1] = "[[wikt:Wiktionary:Shortcut|Shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
end
end
Line 57: Line 57:
local targetText = redirectTarget.fullText
local targetText = redirectTarget.fullText
if title.nsText == "Template" then
if title.nsText == "Template" then
if SUBPAGENAME == 'documentation' then
if SUBPAGENAME == 'doc' then
iattn = (targetText ~= BASEPAGENAME)
iattn = (targetText ~= BASEPAGENAME)
else
else
Line 63: Line 63:
end
end
else
else
if SUBPAGENAME == 'documentation' then
if SUBPAGENAME == 'doc' then
iattn = not (targetText == BASEPAGENAME
iattn = not (targetText == BASEPAGENAME
or targetText == FULLPAGENAME)
or targetText == FULLPAGENAME)
else
else
iattn = not (targetText == FULLPAGENAME
iattn = not (targetText == FULLPAGENAME
or targetText == FULLPAGENAME .. '/documentation')
or targetText == FULLPAGENAME .. '/doc')
end
end
end
end
Line 93: Line 93:
output[#output + 1] = '[[Category:Shortcut boxes needing attention]]'
output[#output + 1] = '[[Category:Shortcut boxes needing attention]]'
end
end
if SUBPAGENAME ~= 'documentation' then
if SUBPAGENAME ~= 'doc' then
output[#output + 1] = '[[Category:Wiktionary pages with shortcuts]]'
output[#output + 1] = '[[Category:Templates with shortcuts]]'
end
end
end
end

Revision as of 10:28, 25 March 2021



local export = {}

function export.show(frame)
	local output = {}
	-- Hacky way to allow function to be called from other modules.
	local args = (frame.getParent and frame:getParent().args) or frame
	local demo = false

	local FULLPAGENAME = mw.title.getCurrentTitle().fullText
	local BASEPAGENAME, SUBPAGENAME = FULLPAGENAME:match("^(.-)/([^/]-)$")
	-- BASEPAGENAME = BASEPAGENAME or FULLPAGENAME
	
	if frame.getParent and FULLPAGENAME == frame:getParent():getTitle() then
		demo = true
	end
	output[#output + 1] = [[<div class="plainlinks" style="border: 1px solid #aaa; color: black; background: #f9f9f9;
	margin: 0 0 .5em 1em; text-align: center; padding: 5px; float: right; clear: both; font-weight: bold; font-size: smaller;">]]

	if args.temp then
		output[#output + 1] = "Temporary [[wikt:Wiktionary:Shortcut|shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
	else
		output[#output + 1] = "[[wikt:Wiktionary:Shortcut|Shortcut" .. (args[2] and 's' or '') .. "]]:<br/>"
	end
	
	local attn = false

	for i, shortcut in ipairs(args) do
		local title = mw.title.new(shortcut)
		
		if not title then
			output[#output + 1] = '<span class="attentionseeking">(<code>' .. mw.text.nowiki(shortcut) .. '</code>)</span><br/>'
			attn = true
		else
			local iattn = false

			local item

			if not title.exists then
				attn = true
				local query = 'action=edit&redlink=1&preloadtext=' .. mw.uri.encode('#REDIRECT [[' .. FULLPAGENAME .. ']]')
				if title.nsText == "Template" then
					item = '<code>{{[' .. tostring(mw.uri.fullUrl(shortcut, query)) .. ' <span style="color:#c20;">' .. title.text .. '</span>]}}</code>'
				else
					item = '[' .. tostring(mw.uri.fullUrl(shortcut, query)) .. ' <span style="color:#c20;">' .. shortcut .. '</span>]'
				end
			else
				if title.nsText == "Template" then
					item = '<code>{{[' .. tostring(mw.uri.fullUrl(shortcut, 'redirect=no')) .. ' ' .. title.text .. ']}}</code>'
				else
					item = '[' .. tostring(mw.uri.fullUrl(shortcut, 'redirect=no')) .. ' ' .. shortcut .. ']'
				end
				
				if not demo then
					local redirectTarget = title.redirectTarget
					if redirectTarget then
						redirectTarget.fragment = '' -- remove fragment, if present
						local targetText = redirectTarget.fullText
						if title.nsText == "Template" then
							if SUBPAGENAME == 'doc' then
								iattn = (targetText ~= BASEPAGENAME)
							else
								iattn = (targetText ~= FULLPAGENAME)
							end
						else
							if SUBPAGENAME == 'doc' then
								iattn = not (targetText == BASEPAGENAME
									or targetText == FULLPAGENAME)
							else
								iattn = not (targetText == FULLPAGENAME
									or targetText == FULLPAGENAME .. '/doc')
							end
						end
					end
					
					if not (redirectTarget and redirectTarget.exists) then
						iattn = true
					end
				end
			end

			if iattn then
				item = '<span class="attentionseeking">' .. item .. '</span>'
			end

			output[#output + 1] = item .. '<br/>'
			
			attn = attn or iattn
		end
	end

	if not args.nocat then
		if attn then
			output[#output + 1] = '[[Category:Shortcut boxes needing attention]]'	
		end
		if SUBPAGENAME ~= 'doc' then
			output[#output + 1] = '[[Category:Templates with shortcuts]]'
		end
	end

	output[#output + 1] = '</div>'
	
	return table.concat(output)
end

return export