Vocaloid Wiki
Advertisement

Documentation for this module may be created at Module:Reciprocal link test/doc

-- <nowiki>

local export = {}
local replace = mw.ustring.gsub
local split = mw.text.split
local find = mw.ustring.find
local resolve_redirect = require("module:resolve redirect").show

local foobar = "title1 ?= ?"
local foobar2 = "{{pwt row\|1?=?"

function export.show(frame)
	local text = frame.args[1]

	text = replace(text, " ?<[Bb][Rr] ?%/?> ?", "\n") -- convert br to newline
	text = split(text, "\n")
	for i = 1, #text, 1 do
		if not find(text[i], "%[%[") then
			text[i] = "" -- dispose of lines that don't contain links
		else
			text[i] = replace(text[i], "%]%].+", "") -- remove stuff outside brackets (and the brackets too 'cos why not)
			text[i] = replace(text[i], ".+%[%[", "")
			text[i] = replace(text[i], "%|.+", "") -- remove stuff after pipes
			text[i] = replace(text[i], "%[%[", "") -- remove brackets
			text[i] = replace(text[i], "%]%]", "")
		end
	end

	local output = ''
	local song_page_title = mw.ustring.lower(mw.title.getCurrentTitle().text)
	song_page_title = replace(song_page_title, "([()*-.?%%])", "%%%1") -- escaping
	for i = 1, #text, 1 do
		local producer = text[i]
		if producer ~= "" and mw.title.new(producer).exists then
			local page_content = mw.title.new(producer):getContent()
			page_content = resolve_redirect(page_content)
			page_content = replace(page_content, "_", " ")
			page_content = mw.ustring.lower(page_content)
			local check = find(page_content, foobar .. song_page_title) or find(page_content, foobar2 .. song_page_title) or "failed"
			if check == "failed" then
				output = output .. '[[Category:Song pages not linked to from/' .. producer .. ']] '
			end
		end
	end

	return output
end

return export
Advertisement