Module:Taxonbar/exists

From MycoTaxa
Revision as of 11:17, 18 April 2024 by en>Tom.Reding (-)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

About

Checks the page for transclusions of {{Taxonbar}} and its redirects, returning true or false.

Usage

local taxonbarExists = require('Module:Taxonbar/exists').check

See also


local p = {}

function p.check( frame )
	local pagename = mw.title.getCurrentTitle().text
	local content = mw.title.new(pagename):getContent() or ''
	local getRegex = require('Module:Template redirect regex').main
	local tregex = getRegex('Taxonbar')
	for _, v in pairs (tregex) do
		local found = string.match(content, v)
		if found then
			local v_cmt_before = '%<%!%-%-%s*'..v
			local v_cmt_after  = v..'[^{}]*}}%s*-->'
			local found_cmt = mw.ustring.match(content, v_cmt_before) or mw.ustring.match(content, v_cmt_after)
			if found_cmt then return 'commented'
			else return true end
		end
	end
	return false
end

return p