Jump to content

Module:Article list

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by MSGJ (talk | contribs) at 12:14, 7 February 2022 (create). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {};

function p.getlinks(frame)
	local qids = frame.args[1]
	local removes = frame.args.remove or ""
	removelist = mw.text.split(removes,",")
	local links = {}
	if qids then
		for qid in qids:gmatch("Q%d+") do
			links[#links+1] = "* ".. p.getlink(qid)
		end
		return table.concat(links,"\n")
	else
		return "Error: no parameter"
	end
end

function p.getlink(qid)
	if qid then
		local slink = mw.wikibase.sitelink(qid)
		if slink then
			local pipe = p.removeword(slink)
			slink = "[[" .. slink .. "|" .. pipe .. "]]"
			return slink
		else
			return ""
		end
	else
		return "Error: no parameter"
	end
end

function p.removeword(link)
	for i,remove in ipairs(removelist) do
		local char1=string.sub(remove,1,1)
		local regex="%f[%w][" .. string.upper(char1) .. string.lower(char1) .. "]" .. string.sub(remove,2) .. "*%f[%W]"
		link=link:gsub(regex,"")
	end
	return link
end

return p