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 18:03, 7 February 2022 (ignore spaces in remove list). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {};

function p.getlinks(frame)
	local qids = frame.args[1]
	local removes = frame.args.remove or ""
	removelist = mw.text.split(removes,"%s*,%s*")
	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)
	local slink = mw.wikibase.sitelink(qid)
	local label = mw.wikibase.getLabel(qid)
	local pipe = ""
	if slink then
		if label then
			pipe = p.removeword(label)
		else
			pipe = p.removeword(slink)
		end
		slink = "[[" .. slink .. "|" .. pipe .. "]]"
		return slink
	else
		return ""
	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
	link = link:gsub("^(%l)", mw.ustring.upper)
	return link
end

return p