<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FElanHR%2Ftest-category-module</id>
	<title>Module:Sandbox/ElanHR/test-category-module - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FElanHR%2Ftest-category-module"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/ElanHR/test-category-module&amp;action=history"/>
	<updated>2026-07-29T23:10:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/ElanHR/test-category-module&amp;diff=145363&amp;oldid=prev</id>
		<title>imported&gt;ElanHR: added tools to a collapsable div (collapsed by default)</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/ElanHR/test-category-module&amp;diff=145363&amp;oldid=prev"/>
		<updated>2019-11-18T02:11:36Z</updated>

		<summary type="html">&lt;p&gt;added tools to a collapsable div (collapsed by default)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- For unit tests, see [[Module:Bananas/testcases]]&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local messageBox = require(&amp;#039;Module:Message box&amp;#039;)&lt;br /&gt;
local mArguments -- Lazily initialise Module:Arguments&lt;br /&gt;
local wd = require(&amp;#039;Module:Wikidata&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local wikidata_category_subclasses = {&amp;#039;Q28326730&amp;#039;, &amp;#039;Q23894246&amp;#039;, &amp;#039;Q13331174&amp;#039;, &amp;#039;Q20010800&amp;#039;, &amp;#039;Q58118449&amp;#039;, &amp;#039;Q38084761&amp;#039;, &amp;#039;Q30330522&amp;#039;, &amp;#039;Q24514938&amp;#039;, &amp;#039;Q24046192&amp;#039;, &amp;#039;Q23894233&amp;#039;, &amp;#039;Q20769287&amp;#039;, &amp;#039;Q59542487&amp;#039;, &amp;#039;Q59541917&amp;#039;, &amp;#039;Q56428020&amp;#039;, &amp;#039;Q54662266&amp;#039;, &amp;#039;Q30432511&amp;#039;, &amp;#039;Q24574745&amp;#039;, &amp;#039;Q24571879&amp;#039;, &amp;#039;Q15647814&amp;#039;, &amp;#039;Q15407973&amp;#039;, &amp;#039;Q4167836&amp;#039;}&lt;br /&gt;
&lt;br /&gt;
-- local wd_id = &amp;#039;Q4115189&amp;#039;&lt;br /&gt;
local wd_id = wd.pageId()&lt;br /&gt;
&lt;br /&gt;
local set_cat_desc = &amp;#039;Wikipedia:Categorization#Set category&amp;#039;&lt;br /&gt;
&lt;br /&gt;
local topic_cat_desc = &amp;#039;Wikipedia:Categorization#Topic category&amp;#039;&lt;br /&gt;
&lt;br /&gt;
function p.get_page_type()&lt;br /&gt;
	local page_types = {}&lt;br /&gt;
	&lt;br /&gt;
	-- check if it&amp;#039;s an instance of (P31) a country (Q6256) and terminate the chain if it is&lt;br /&gt;
	local inst = mw.wikibase.getAllStatements(wd_id, &amp;quot;P31&amp;quot;)&lt;br /&gt;
	if #inst &amp;gt; 0 then&lt;br /&gt;
		for k, v in ipairs(inst) do&lt;br /&gt;
			local instid = v.mainsnak.datavalue.value.id&lt;br /&gt;
			-- stop if it&amp;#039;s a country (or a country within the United Kingdom if skip is true)&lt;br /&gt;
			--if instid == &amp;quot;Q6256&amp;quot; or (skip and instid == &amp;quot;Q3336843&amp;quot;) then&lt;br /&gt;
			if instid == &amp;#039;Q59542487&amp;#039; then&lt;br /&gt;
				page_types[&amp;#039;SET&amp;#039;] = true&lt;br /&gt;
			elseif instid == &amp;#039;Q59541917&amp;#039; then&lt;br /&gt;
				page_types[&amp;#039;TOPIC&amp;#039;] = true&lt;br /&gt;
			elseif instid == &amp;#039;Q15647814&amp;#039; then&lt;br /&gt;
				page_types[&amp;#039;ADMIN&amp;#039;] = true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	return page_types&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- {{#invoke:Message box|cmbox}}&lt;br /&gt;
&lt;br /&gt;
-- {{set cat}} definition&lt;br /&gt;
-- {{Cmbox&lt;br /&gt;
-- | type = notice&lt;br /&gt;
-- | text = This is a &amp;#039;&amp;#039;&amp;#039;[[Wikipedia:Categorization#Set category|set category]]&amp;#039;&amp;#039;&amp;#039;. It should only contain pages that are &amp;#039;&amp;#039;&amp;#039;{{#if:{{{first|}}}|{{{first}}}|{{#if:{{{alternative|}}}|{{{alternative}}}|{{PAGENAME}}}}}}&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;lists of {{#if:{{{alternative|}}}|{{{alternative}}}|{{PAGENAME}}}}&amp;#039;&amp;#039;&amp;#039;, as well as &amp;#039;&amp;#039;&amp;#039;[[Wikipedia:Categorization#Subcategorization|subcategories]]&amp;#039;&amp;#039;&amp;#039; containing those things. Topics about {{#if:{{{alternative|}}}|{{{alternative}}}|{{PAGENAME}}}} in general should be placed in {{#if:{{{topic|}}}|[[:Category:{{{topic}}}]] or one of it subcategories|relevant [[Wikipedia:Categorization#Topic category|topic categories]]}}. {{#if:{{{single}}}|Categories related to only an individual {{{single}}} should not be in this category.}}&lt;br /&gt;
-- }}&lt;br /&gt;
&lt;br /&gt;
-- {{Single namespace|category|[[Category:Set categories]]}&lt;br /&gt;
&lt;br /&gt;
-- {{Wikipedia category|container=yes|hidden=yes|tracking=yes|shortcut=WP:CINA}}&lt;br /&gt;
&lt;br /&gt;
local function get_sparql_queries()&lt;br /&gt;
	local sparql_queries = {}&lt;br /&gt;
	for i, item in pairs(mw.wikibase.getBestStatements(wd_id, &amp;#039;P3921&amp;#039; )) do&lt;br /&gt;
	   sparql_queries[i] = item[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;]&lt;br /&gt;
	end&lt;br /&gt;
	return sparql_queries&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- {{#if:{{{sparql|}}}|&lt;br /&gt;
--	[//query.wikidata.org/# {{urlencode:{{{sparql|}}}|PATH}} SPARQL] {{!}} }}&lt;br /&gt;
function p.get_wdqs_link_for_query_with_en_articles(query)&lt;br /&gt;
	local select_query = &amp;#039;SELECT ?item ?itemLabel ?itemDescription ?article  WHERE {SERVICE wikibase:label { bd:serviceParam wikibase:language &amp;quot;[AUTO_LANGUAGE],en&amp;quot;. }&amp;#039; .. query .. &amp;#039;  ?article schema:about ?item . ?article schema:isPartOf &amp;lt;https://en.wikipedia.org/&amp;gt;. }&amp;#039;&lt;br /&gt;
	local link_text = &amp;#039;&amp;#039;&lt;br /&gt;
	if query then &lt;br /&gt;
		link_text = &amp;quot;https://query.wikidata.org/#&amp;quot; .. mw.uri.encode( select_query, &amp;quot;PATH&amp;quot; ) ..&amp;quot;&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return link_text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.get_wdqs_link_for_query_without_en_articles(query)&lt;br /&gt;
	local select_query = &amp;#039;SELECT ?item ?itemLabel ?itemDescription ?article  WHERE {SERVICE wikibase:label { bd:serviceParam wikibase:language &amp;quot;[AUTO_LANGUAGE],en&amp;quot;. }&amp;#039; .. query .. &amp;#039;  FILTER NOT EXISTS { ?article schema:about ?item . ?article schema:isPartOf &amp;lt;https://en.wikipedia.org/&amp;gt;. } }&amp;#039;&lt;br /&gt;
	local link_text = &amp;#039;&amp;#039;&lt;br /&gt;
	if query then &lt;br /&gt;
		link_text = &amp;quot;https://query.wikidata.org/#&amp;quot; .. mw.uri.encode( select_query, &amp;quot;PATH&amp;quot; ) ..&amp;quot;&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return link_text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local function get_category_contains()&lt;br /&gt;
	return &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.hello()&lt;br /&gt;
	return &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.test_template()&lt;br /&gt;
	local box = messageBox.main( &amp;#039;cmbox&amp;#039;, {&lt;br /&gt;
	    type=&amp;#039;notice&amp;#039;,&lt;br /&gt;
	    text=&amp;#039;This is a test template. Wikidata ID:&amp;#039; .. wd.pageId(),&lt;br /&gt;
	    -- More parameters...&lt;br /&gt;
	})&lt;br /&gt;
	return box&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function p.get_set_cat_template(set_item, set_item_pluralized, topic)&lt;br /&gt;
	local _item&lt;br /&gt;
	&lt;br /&gt;
	if set_item then&lt;br /&gt;
		_item = set_item&lt;br /&gt;
	elseif set_item_pluralized then&lt;br /&gt;
		_item = set_item_pluralized&lt;br /&gt;
	else&lt;br /&gt;
		_item = mw.title.getCurrentTitle().text&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local _item_pluralized&lt;br /&gt;
	if set_item then&lt;br /&gt;
		_item_pluralized = set_item&lt;br /&gt;
	elseif set_item_pluralized then&lt;br /&gt;
		_item_pluralized = set_item_pluralized&lt;br /&gt;
	else&lt;br /&gt;
		_item_pluralized = mw.title.getCurrentTitle().text&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local _topic&lt;br /&gt;
	if topic then&lt;br /&gt;
		_topic = topic&lt;br /&gt;
	else&lt;br /&gt;
		_topic = &amp;quot;[[:Category:{{{topic}}}]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- local set_cat_item  = {}&lt;br /&gt;
	-- set_cat_item[&amp;#039;entity-type&amp;#039;] = &amp;#039;item&amp;#039;&lt;br /&gt;
	-- set_cat_item[&amp;#039;numeric-id&amp;#039;] = &amp;#039;59542487&amp;#039;&lt;br /&gt;
	local set_cat_text = &amp;quot;This is a  [[&amp;quot;.. set_cat_desc ..&amp;quot;|set category]]. It should only contain pages that are &amp;quot; .. _item .. &amp;quot; or lists of &amp;quot; .. _item_pluralized ..  &amp;quot;as well as [[Wikipedia:Categorization#Subcategorization|subcategories]] containing those things.&amp;quot;&lt;br /&gt;
	-- &amp;quot;Topics about &amp;quot; .. _item_pluralized .. &amp;quot; in general should be placed in &amp;quot; .. _topic .. &amp;quot; or one of it subcategories|relevant [[Wikipedia:Categorization#Topic category|topic categories]]}}. {{#if:{{{single}}}|Categories related to only an individual {{{single}}} should not be in this category.}}&amp;quot;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	local sparql_queries = get_sparql_queries()&lt;br /&gt;
	if sparql_queries then&lt;br /&gt;
		set_cat_text = set_cat_text .. &amp;#039;\n\n\nTools:\n&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;;&amp;quot;&amp;gt;\n&amp;#039;&lt;br /&gt;
		for i, item in pairs(sparql_queries) do&lt;br /&gt;
			set_cat_text = set_cat_text .. &amp;#039;* [&amp;#039;.. p.get_wdqs_link_for_query_with_en_articles(item) ..&amp;#039; EN articles]\n&amp;#039;&lt;br /&gt;
			set_cat_text = set_cat_text .. &amp;#039;* [&amp;#039;.. p.get_wdqs_link_for_query_without_en_articles(item) ..&amp;#039; No EN articles]\n&amp;#039;&lt;br /&gt;
			set_cat_text = set_cat_text .. &amp;#039;*  [https://petscan.wmflabs.org/?common_wiki_other=&amp;amp;edits%5Bbots%5D=both&amp;amp;ns%5B0%5D=1&amp;amp;wikidata_item=any&amp;amp;interface_language=en&amp;amp;language=en&amp;amp;search_max_results=500&amp;amp;categories=&amp;#039;.. mw.title.getCurrentTitle().text ..&amp;#039;&amp;amp;edits%5Bflagged%5D=both&amp;amp;edits%5Banons%5D=both&amp;amp;cb_labels_any_l=1&amp;amp;project=wikipedia&amp;amp;cb_labels_no_l=1&amp;amp;depth=5&amp;amp;cb_labels_yes_l=1&amp;amp;langs_labels_any=&amp;amp;doit= petscan]&amp;#039;&lt;br /&gt;
			set_cat_text = set_cat_text .. &amp;#039;&amp;lt;/div&amp;gt;&amp;#039;&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
			&lt;br /&gt;
&lt;br /&gt;
		end&lt;br /&gt;
	end &lt;br /&gt;
	&lt;br /&gt;
	local output_wikitext = messageBox.main( &amp;#039;cmbox&amp;#039;, {&lt;br /&gt;
	    type=&amp;#039;notice&amp;#039;,&lt;br /&gt;
	    text=set_cat_text&lt;br /&gt;
	    -- More parameters...&lt;br /&gt;
	})&lt;br /&gt;
&lt;br /&gt;
	return output_wikitext&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
	local page_types = p.get_page_type()&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
	if page_types[&amp;#039;SET&amp;#039;] then&lt;br /&gt;
		return p.get_set_cat_template(args[&amp;#039;first&amp;#039;], args[&amp;#039;alternative&amp;#039;])&lt;br /&gt;
		--.. mw.title.getCurrentTitle().prefixedText .. &amp;#039;\n      &amp;#039; .. mw.title.getCurrentTitle().text .. &amp;#039;\n      &amp;#039; .. mw.title.getCurrentTitle().baseText .. &amp;#039;\n      &amp;#039; .. mw.title.getCurrentTitle().subpageText .. &amp;#039;      &amp;#039;&lt;br /&gt;
	elseif page_types[&amp;#039;TOPIC&amp;#039;] then&lt;br /&gt;
		return &amp;#039;TOPIC CAT&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	--if page_types[&amp;#039;TOPIC&amp;#039;] then&lt;br /&gt;
		return tostring(page_types) ..&amp;#039; | HELLO |&amp;#039;.. tostring(wd_id)&lt;br /&gt;
		&lt;br /&gt;
	--end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.set_cat_template(frame)&lt;br /&gt;
	mArguments = require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
	local args = mArguments.getArgs(frame, {removeBlanks = false})&lt;br /&gt;
	local ret = p._main(args)&lt;br /&gt;
	return ret or &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function p.dump(o)&lt;br /&gt;
	if type(o) == &amp;#039;table&amp;#039; then&lt;br /&gt;
	  local s = &amp;#039;{ &amp;#039;&lt;br /&gt;
	  for k,v in pairs(o) do&lt;br /&gt;
	     if type(k) ~= &amp;#039;number&amp;#039; then k = &amp;#039;&amp;quot;&amp;#039;..k..&amp;#039;&amp;quot;&amp;#039; end&lt;br /&gt;
	     s = s .. &amp;#039;[&amp;#039;..k..&amp;#039;] = &amp;#039; .. dump(v) .. &amp;#039;,&amp;#039;&lt;br /&gt;
	  end&lt;br /&gt;
	  return s .. &amp;#039;} &amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
	  return tostring(o)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;ElanHR</name></author>
	</entry>
</feed>