Module:Term Lite

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search

This module uses stored terms to determine whether the trailing parentheses in a page name are part of the actual term (e.g. Green Bokoblin (Archer) or simply a disambiguator (e.g. Wood (Character)). It also checks stored terms when the page name has a number in it, to determine whether the term has a # before the number (e.g. Swordsman Newsletter #1). Page names without parentheses or numbers are simply returned as-is.

Module:Term's ability to correct and update terms, while helpful, is not strictly necessary and can be done manually by editors instead. Module:Term is the biggest contributor to the wiki's slow page parsing/loading times. Its current usage is not tenable in the long term. This module should serve as an adequate replacement in most (if not all) cases.

This module exports the following functions.

link

link(pagename)

Returns

  • A link to pagename with the corresponding term value as its display text.

Examples

#InputOutputResultStatus
1
link("ChuChu")
"[[ChuChu]]"
ChuChu
2
link("Wood (Character)")
"[[Wood (Character)|Wood]]"
Wood
3
link("Green Bokoblin (Archer)")
"[[Green Bokoblin (Archer)]]"
Green Bokoblin (Archer)
4
link("Treasure Map 2")
"[[Treasure Map 2|Treasure Map #2]]"
Treasure Map #2
5
link("Force Gem 2")
"[[Force Gem 2]]"
Force Gem 2

term

term(pagename)

Returns

  • The term value corresponding to pagename.

Examples

#InputOutputResultStatus
Synonyms are returned as-is
6
term("ChuChu")
"ChuChu"
ChuChu
Disambiguators are stripped.
7
term("Wood (Character)")
"Wood"
Wood
Parentheses which are part of the actual term are kept.
8
term("Green Bokoblin (Archer)")
"Green Bokoblin (Archer)"
Green Bokoblin (Archer)
# is added to pages with number suffixes, when part of the stored term.
9
term("Treasure Map 2")
"Treasure Map #2"
Treasure Map #2
10
term("Force Gem 2")
"Force Gem 2"
Force Gem 2

local p = {}
local h = {}

function p.Main(frame)
	return p.link(frame:getParent().args[1])
end

function p.link(page)
	local term = p.term(page)
	if term == page then
		return "[["..page.."]]"
	else
		return "[["..page.."|"..term.."]]"
	end
end

function p.term(page)
	if string.find(page, "%)$") then
		return h.termFromPageWithParentheses(page)
	end
	if string.find(page, "[0-9]") then
		return h.termFromPageWithNumber(page)
	end
	return page
end

function h.termFromPageWithParentheses(page)
	-- mw.loadData ensures we do the Cargo query at most once per page
	local lookup = mw.loadData("Module:Term Lite/TermsWithTrailingParentheses")
	if lookup[page] then
		return page
	else
		return string.gsub(page, "%s+%([^%)]+%)$", "")
	end
end

function h.termFromPageWithNumber(page)
	local lookup = mw.loadData("Module:Term Lite/TermsWithNumberSign")
	return lookup[page] or page
end

return p