<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="nb">
	<id>https://www.wikisida.no/index.php?action=history&amp;feed=atom&amp;title=Modul%3AAutocategories</id>
	<title>Modul:Autocategories - Sideversjonshistorikk</title>
	<link rel="self" type="application/atom+xml" href="https://www.wikisida.no/index.php?action=history&amp;feed=atom&amp;title=Modul%3AAutocategories"/>
	<link rel="alternate" type="text/html" href="https://www.wikisida.no/index.php?title=Modul:Autocategories&amp;action=history"/>
	<updated>2026-04-17T07:16:43Z</updated>
	<subtitle>Versjonshistorikk for denne siden på wikien</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://www.wikisida.no/index.php?title=Modul:Autocategories&amp;diff=28424&amp;oldid=prev</id>
		<title>Wikisida: Én sideversjon ble importert</title>
		<link rel="alternate" type="text/html" href="https://www.wikisida.no/index.php?title=Modul:Autocategories&amp;diff=28424&amp;oldid=prev"/>
		<updated>2026-02-14T19:57:18Z</updated>

		<summary type="html">&lt;p&gt;Én sideversjon ble importert&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;nb&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Eldre sideversjon&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Sideversjonen fra 14. feb. 2026 kl. 19:57&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;nb&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(Ingen forskjell)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key c1wiki:diff:1.41:old-28423:rev-28424 --&gt;
&lt;/table&gt;</summary>
		<author><name>Wikisida</name></author>
	</entry>
	<entry>
		<id>https://www.wikisida.no/index.php?title=Modul:Autocategories&amp;diff=28423&amp;oldid=prev</id>
		<title>nb&gt;Tholme: Strict</title>
		<link rel="alternate" type="text/html" href="https://www.wikisida.no/index.php?title=Modul:Autocategories&amp;diff=28423&amp;oldid=prev"/>
		<updated>2023-01-10T23:56:58Z</updated>

		<summary type="html">&lt;p&gt;Strict&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ny side&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- module for replicating categories listed at Wikidata&lt;br /&gt;
-- © John Erling Blad, Creative Commons by Attribution 3.0&lt;br /&gt;
&lt;br /&gt;
-- don&amp;#039;t pollute with globals&lt;br /&gt;
require(&amp;#039;strict&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
-- @var our exposed table&lt;br /&gt;
local Autocategories = {}&lt;br /&gt;
&lt;br /&gt;
-- find the first entry that seems to be a Q-id&lt;br /&gt;
-- @param table args argument list from the frame&lt;br /&gt;
-- @return string first matching argument&lt;br /&gt;
function Autocategories._findQid( args )&lt;br /&gt;
	for key, value in ipairs( args ) do&lt;br /&gt;
		if value ~= &amp;#039;&amp;#039; and string.match(value, &amp;#039;^Q%d+$&amp;#039;) then&lt;br /&gt;
			return value&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local entity = mw.wikibase.getEntity()&lt;br /&gt;
	if entity then&lt;br /&gt;
		return entity[&amp;#039;id&amp;#039;]&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- find id for all statements&lt;br /&gt;
-- @param table statement well-defined structure for a statement&lt;br /&gt;
-- @return values for the provided statements&lt;br /&gt;
function Autocategories._findId(statements)&lt;br /&gt;
	local ids = {}&lt;br /&gt;
	for _,statement in pairs(statements) do&lt;br /&gt;
		local mainsnak = statement[&amp;quot;mainsnak&amp;quot;]&lt;br /&gt;
		if mainsnak then&lt;br /&gt;
			local datavalue = mainsnak[&amp;#039;datavalue&amp;#039;]&lt;br /&gt;
			if datavalue then&lt;br /&gt;
				local value = datavalue[&amp;#039;value&amp;#039;]&lt;br /&gt;
				if value then&lt;br /&gt;
					local entityType = value[&amp;#039;entity-type&amp;#039;]&lt;br /&gt;
					local numericId = value[&amp;#039;numeric-id&amp;#039;]&lt;br /&gt;
					if entityType and numericId and entityType == &amp;#039;item&amp;#039; then&lt;br /&gt;
						ids[1+#ids] = numericId&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return ids&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- find the P-ids from the argument lists&lt;br /&gt;
-- note that this maintain argument sequence&lt;br /&gt;
-- @param table vector forwarded from the method call&lt;br /&gt;
-- @return table hash of matching arguments&lt;br /&gt;
function Autocategories._findPidsInArgs( pids, args )&lt;br /&gt;
	for _,value in ipairs( args ) do&lt;br /&gt;
		local _,_,action,pid = string.find(value, &amp;#039;^%s*(!?)(P%d+)%s*$&amp;#039;)&lt;br /&gt;
		if pid then&lt;br /&gt;
			pids[pid] =  action == &amp;#039;&amp;#039; and true or nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return pids&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- find the P-ids from the frame lists&lt;br /&gt;
-- note that this maintain argument sequence&lt;br /&gt;
-- @param table vector forwarded from the method call&lt;br /&gt;
-- @return table hash of matching arguments&lt;br /&gt;
function Autocategories._findPidsInFrames( ... )&lt;br /&gt;
	local pids = {}&lt;br /&gt;
	--pids[1+#pids] = arg.n&lt;br /&gt;
	for i = 1,arg.n do&lt;br /&gt;
		local frame = arg[i]&lt;br /&gt;
		if frame then&lt;br /&gt;
			local firstArg = frame.args[1]&lt;br /&gt;
			--do return mw.text.split( firstArg, &amp;#039;,&amp;#039;, true ) end&lt;br /&gt;
			if firstArg then&lt;br /&gt;
				pids = Autocategories._findPidsInArgs( pids, mw.text.split( firstArg, &amp;#039;,&amp;#039;, true ) )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return pids&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- find the P-ids from the frame lists&lt;br /&gt;
-- note that this does not maintain argument sequence&lt;br /&gt;
-- @param table frames forwarded from the method call&lt;br /&gt;
-- @return table hash of matching arguments&lt;br /&gt;
function Autocategories.findPids( ... )&lt;br /&gt;
	local pids = Autocategories._findPidsInFrames( ... )&lt;br /&gt;
	local keys = {}&lt;br /&gt;
	for key,_ in pairs( pids ) do&lt;br /&gt;
		keys[1+#keys] = key&lt;br /&gt;
	end&lt;br /&gt;
	return keys&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- do all allowable categorizations&lt;br /&gt;
-- @param table frame arguments from invoke&lt;br /&gt;
-- @return string status report during development, should be an empty string&lt;br /&gt;
function Autocategories.run( frame )&lt;br /&gt;
	--local qid = Autocategories._findQid( frame.args )&lt;br /&gt;
	--first call is when the call is encapsulated in a template&lt;br /&gt;
	local pids = frame:getParent() and Autocategories.findPids( frame, frame:getParent() ) or Autocategories.findPids( frame )&lt;br /&gt;
	if #pids == 0 then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local entity = mw.wikibase.getEntity()&lt;br /&gt;
	if not entity then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local categories = {}&lt;br /&gt;
	for _,pid in pairs(pids) do&lt;br /&gt;
		local statements = entity:getBestStatements( pid )&lt;br /&gt;
		if statements then&lt;br /&gt;
			for _,id in pairs( Autocategories._findId( statements ) ) do&lt;br /&gt;
				local sitelink = mw.wikibase.sitelink( &amp;#039;Q&amp;#039;..id )&lt;br /&gt;
				if sitelink then&lt;br /&gt;
					categories[1+#categories] =&lt;br /&gt;
						(pid == &amp;#039;P910&amp;#039; and &amp;#039;[[&amp;#039;..sitelink..&amp;#039;| ]]&amp;#039; or &amp;#039;[[&amp;#039;..sitelink..&amp;#039;]]&amp;#039;)&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat( categories, &amp;#039;\n&amp;#039; )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- export the accesspoint&lt;br /&gt;
return Autocategories&lt;/div&gt;</summary>
		<author><name>nb&gt;Tholme</name></author>
	</entry>
</feed>