Module:get IDs

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module is used to get all the IDs on a particular page. It used currently only used by MediaWiki:Gadget-OrangeLinks.js.

Example

{{#invoke:get IDs|show|tap|lakh|wiki}}

returns the IDs on tap, lakh, and wiki, separated by two newlines:

English Pronunciation Etymology_1 Noun English:_peg English:_device English:_tool Derived_terms Related_terms Translations Verb English:_deplete English:_games Conjugation Derived_terms_2 Translations_2 Etymology_2 Verb_2 English:_arrest English:_designate Conjugation_2 Derived_terms_3 Translations_3 Noun_2 Derived_terms_4 Translations_4 Etymology_3 Noun_3 Derived_terms_5 Translations_5 References Further_reading Anagrams Albanian Etymology Noun_4 Catalan Pronunciation_2 Noun_5 Derived_terms_6 Danish Etymology_1_2 Pronunciation_3 Noun_6 Inflection Etymology_2_2 Pronunciation_4 Noun_7 Inflection_2 Etymology_3_2 Verb_3 Dutch Etymology_4 Pronunciation_5 Noun_8 Usage_notes Synonyms Derived_terms_7 Descendants Icelandic Etymology_5 Pronunciation_6 Noun_9 Declension Related_terms_2 K'iche' Noun_10 Lashi Pronunciation_7 Verb_4 References_2 Malecite-Passamaquoddy Etymology_6 Noun_11 Middle_English Verb_5 Norwegian_Bokmål Pronunciation_8 Noun_12 Derived_terms_8 Related_terms_3 References_3 Norwegian_Nynorsk Pronunciation_9 Noun_13 Derived_terms_9 References_4 Old_Javanese Pronunciation_10 Etymology_1_3 Noun_14 Derived_terms_10 Etymology_2_3 Adjective Derived_terms_11 Phalura Etymology_7 Pronunciation_11 Adverb References_5 Semai Etymology_8 Verb_6 Synonyms_2 References_6 Spanish Noun_15

English Etymology Pronunciation Numeral Alternative_forms Coordinate_terms Derived_terms Translations Noun Alternative_forms_2 Translations_2 References Further_reading Anagrams French Etymology_2 Pronunciation_2 Noun_2

English Etymology Pronunciation Noun English:_Q171 Derived_terms Translations Verb Translations_2 See_also References Anagrams Catalan Alternative_forms Etymology_2 Pronunciation_2 Noun_2 Chinese Etymology_3 Pronunciation_3 Verb_2 Proper_noun Alternative_forms_2 Noun_3 Choctaw Alternative_forms_3 Adjective Danish Etymology_4 Pronunciation_4 Noun_4 Inflection Derived_terms_2 References_2 Anagrams_2 Dutch Etymology_5 Pronunciation_5 Noun_5 Derived_terms_3 Anagrams_3 Finnish Etymology_6 Pronunciation_6 Noun_6 Declension Derived_terms_4 Further_reading French Etymology_7 Pronunciation_7 Noun_7 Derived_terms_5 Anagrams_4 Hawaiian Etymology_8 Pronunciation_8 Verb_3 Derived_terms_6 References_3 Indonesian Etymology_9 Pronunciation_9 Noun_8 Further_reading_2 Japanese Romanization Kokota Etymology_10 Noun_9 References_4 Limburgish Etymology_11 Pronunciation_10 Noun_10 Inflection_2 Lower_Sorbian Etymology_12 Pronunciation_11 Noun_11 Declension_2 Derived_terms_7 References_5 Further_reading_3 Maori Etymology_1 Verb_4 Etymology_2_2 Noun_12 Etymology_3_2 Noun_13 Norwegian Etymology_13 Pronunciation_12 Noun_14 Inflection_3 Derived_terms_8 Portuguese Etymology_14 Pronunciation_13 Noun_15 Spanish Etymology_15 Pronunciation_14 Noun_16 Sranan_Tongo Etymology_16 Pronunciation_15 Noun_17 Swahili Etymology_17 Pronunciation_16 Noun_18 Synonyms References_6 Swedish Etymology_18 Pronunciation_17 Noun_19 Declension_3 Tocharian_A Etymology_19 Numeral Turkish Etymology_20 Pronunciation_18 Noun_20 Declension_4


local anchor_encode = mw.uri.anchorEncode
local concat = table.concat
local get_lang = require("Module:languages").getByCode
local new_title = mw.title.new
local parse = require("Module:template parser").parse
local type_or_class = require("Module:parser").type_or_class

local templates = require("Module:table").listToSet{"senseid", "etymid", "etymon"}

local export = {}

function export.show(frame)
	local output, output_n = {}, 0
	for _, pageName in ipairs(frame.args) do
		local page, seen, ids, id_n = new_title(pageName), {}, {}, 0
		
		for node in parse((page.redirectTarget or page):getContent()):__pairs("next_node") do
			local node_type = type_or_class(node)
			if node_type == "heading" then
				local name = anchor_encode(node:get_name())
				if seen[name] then
					local i, check = 1
					repeat
						i = i + 1
						check = name .. "_" .. i
					until not seen[check]
					name = check
				end
				seen[name] = true
				id_n = id_n + 1
				ids[id_n] = name
			elseif node_type == "template" then
				local name = node:get_name()
				if templates[name] then
					local templateArgs = node:get_params()
					id_n = id_n + 1
					ids[id_n] = anchor_encode(
						get_lang(frame:preprocess(templateArgs[1])):getCanonicalName() ..
							":_" .. frame:preprocess(templateArgs[name == "etymon" and "id" or 2])
					)
				end
			end
		end
		
		output_n = output_n + 1
		output[output_n] = concat(ids, " ")
	end

	return concat(output, "\n\n")
end

return export