Модул:glossary

Документација модула[прикажи] [уреди] [историја] [освежи]

The test_existence function tracks instances of {{glossary}} that link to anchors not found in Додатак:Речник. See Категорија:Pages linking to anchors not found in Додатак:Речник. It uses the data module Модул:glossary/data to determine if the anchor exists.

local export = {}

local gsub = mw.ustring.gsub

function format_def (term, definition)
	local anchor = gsub(term, "%[%[([^%]]+)%]%]", "%1") -- Remove wikilinks
	anchor = gsub(anchor, "^%w+:", "") -- Remove interwiki prefixes
	
	return "; <span id=\""..anchor.."\">"..term.."</span>\n: "..definition
end

function export.def (frame)
	local params = {
		[1] = { required = true, default = "", },
		[2] = { required = true, default = "", },
	}
	
	local args = require("Модул:parameters").process(frame:getParent().args, params)
	
	local term = args[1]
	local definition = args[2]
	
	return format_def (term, definition)
end

function export.test_existence(frame)
	local anchor = frame:getParent().args[1]
	if anchor then
		-- This won't work if the initial letter is non-ASCII.
		anchor = anchor:lower()
		
		if not mw.loadData("Модул:glossary/data")[anchor] then
			mw.log("Сидро " .. anchor .. " не постоји у Додатак:Речник.")
			return "[[Категорија:Страна повезана са сидром није пронађена у Додатак:Речник|" .. anchor .. "]]"
		end
	end
end

return export