Module:Sandbox/ElanHR/test-category-module explained

-- For unit tests, see local p =

local messageBox = require('Module:Message box')local mArguments -- Lazily initialise Module:Argumentslocal wd = require('Module:Wikidata')

local wikidata_category_subclasses =

-- local wd_id = 'Q4115189'local wd_id = wd.pageId

local set_cat_desc = 'Wikipedia:Categorization#Set category'

local topic_cat_desc = 'Wikipedia:Categorization#Topic category'

function p.get_page_type local page_types = -- check if it's an instance of (P31) a country (Q6256) and terminate the chain if it is local inst = mw.wikibase.getAllStatements(wd_id, "P31") if #inst > 0 then for k, v in ipairs(inst) do local instid = v.mainsnak.datavalue.value.id -- stop if it's a country (or a country within the United Kingdom if skip is true) --if instid

"Q6256" or (skip and instid

"Q3336843") then if instid

'Q59542487' then page_types['SET'] = true elseif instid

'Q59541917' then page_types['TOPIC'] = true elseif instid

'Q15647814' then page_types['ADMIN'] = true end end end

return page_typesend

--

-- definition--

-- }. " local sparql_queries = get_sparql_queries if sparql_queries then set_cat_text = set_cat_text .. '\n\n\nTools:\n

\n' for i, item in pairs(sparql_queries) do set_cat_text = set_cat_text .. '* ['.. p.get_wdqs_link_for_query_with_en_articles(item) ..' EN articles]\n' set_cat_text = set_cat_text .. '* ['.. p.get_wdqs_link_for_query_without_en_articles(item) ..' No EN articles]\n' set_cat_text = set_cat_text .. '* mw.title.getCurrentTitle.text ..'&edits%5Bflagged%5D=both&edits%5Banons%5D=both&cb_labels_any_l=1&project=wikipedia&cb_labels_no_l=1&depth=5&cb_labels_yes_l=1&langs_labels_any=&doit= petscan' set_cat_text = set_cat_text .. '

'

end end local output_wikitext = messageBox.main('cmbox',)

return output_wikitextend

function p._main(args) local page_types = p.get_page_type

if page_types['SET'] then return p.get_set_cat_template(args['first'], args['alternative']) --.. mw.title.getCurrentTitle.prefixedText .. '\n ' .. mw.title.getCurrentTitle.text .. '\n ' .. mw.title.getCurrentTitle.baseText .. '\n ' .. mw.title.getCurrentTitle.subpageText .. ' ' elseif page_types['TOPIC'] then return 'TOPIC CAT' end --if page_types['TOPIC'] then return tostring(page_types) ..' | HELLO |'.. tostring(wd_id) --endend

function p.set_cat_template(frame) mArguments = require('Module:Arguments') local args = mArguments.getArgs(frame,) local ret = p._main(args) return ret or end

function p.dump(o) if type(o)

'table' then local s = ' ' else return tostring(o) endend

return p