<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ekatrafoundation.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AEdition</id>
	<title>Module:Edition - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ekatrafoundation.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AEdition"/>
	<link rel="alternate" type="text/html" href="https://wiki.ekatrafoundation.org/index.php?title=Module:Edition&amp;action=history"/>
	<updated>2026-04-22T16:41:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>https://wiki.ekatrafoundation.org/index.php?title=Module:Edition&amp;diff=1345&amp;oldid=prev</id>
		<title>Jayprakash12345: Created page with &quot;-------------------------------------------------------------------------------- -- Organisation of this module: the exports are listed at the bottom; their -- direct function...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.ekatrafoundation.org/index.php?title=Module:Edition&amp;diff=1345&amp;oldid=prev"/>
		<updated>2021-06-01T14:28:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-------------------------------------------------------------------------------- -- Organisation of this module: the exports are listed at the bottom; their -- direct function...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--------------------------------------------------------------------------------&lt;br /&gt;
-- Organisation of this module: the exports are listed at the bottom; their&lt;br /&gt;
-- direct functions are just above there, and supporting functions are higher&lt;br /&gt;
-- up.&lt;br /&gt;
--&lt;br /&gt;
-- Please add testcases before modifying anything.&lt;br /&gt;
--&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
instanceOfProp = &amp;#039;P31&amp;#039;&lt;br /&gt;
authorProp = &amp;#039;P50&amp;#039;&lt;br /&gt;
editionOrTranslationOfProp = &amp;#039;P629&amp;#039;&lt;br /&gt;
equivalentClassProp = &amp;#039;P1709&amp;#039;&lt;br /&gt;
topicsMainWikimediaPortalProp = &amp;#039;P1151&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Insert a value into a table, but not if it&amp;#039;s already there.&lt;br /&gt;
function tableInsertUnique( theTable, value )&lt;br /&gt;
	for _, item in pairs( theTable ) do&lt;br /&gt;
		if item == value then&lt;br /&gt;
			-- Already present&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- Otherwise, add the new value.&lt;br /&gt;
	table.insert( theTable, value )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- For the given author item, find the Wikisource sitelink. If there isn&amp;#039;t one,&lt;br /&gt;
-- check to see if there the author has a topicsMainWikimediaPortal statement,&lt;br /&gt;
-- and then see if that portal has a sitelink instead.&lt;br /&gt;
function get_author_sitelink( authorItem )&lt;br /&gt;
	local siteLink = authorItem:getSitelink( mw.language.getContentLanguage().code .. &amp;#039;wikisource&amp;#039; )&lt;br /&gt;
	if ( siteLink ~= nil ) then&lt;br /&gt;
		return siteLink&lt;br /&gt;
	end&lt;br /&gt;
	portalStatements = authorItem:getBestStatements( topicsMainWikimediaPortalProp )&lt;br /&gt;
	for _, mainPortal in pairs( portalStatements ) do&lt;br /&gt;
		local mainPortalId = mainPortal[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;][&amp;#039;id&amp;#039;]&lt;br /&gt;
		local mainPortalItem = mw.wikibase.getEntity( mainPortalId )&lt;br /&gt;
		siteLink = mainPortalItem:getSitelink( mw.language.getContentLanguage().code .. &amp;#039;wikisource&amp;#039; )&lt;br /&gt;
	end&lt;br /&gt;
	return siteLink&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Create the HTML (including wikitext link) for all provided authors,&lt;br /&gt;
-- and add it to the given authorLinks table (for later concatenation).&lt;br /&gt;
function process_authors( authorLinks, authors )&lt;br /&gt;
	if authors == nil or #authors == 0 then&lt;br /&gt;
		return&lt;br /&gt;
	end&lt;br /&gt;
	for _, author in pairs( authors ) do&lt;br /&gt;
		local authorId = author[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;][&amp;#039;id&amp;#039;]&lt;br /&gt;
		local authorItem =  mw.wikibase.getEntity( authorId )&lt;br /&gt;
		local siteLink = get_author_sitelink( authorItem )&lt;br /&gt;
		local authorName = authorItem:getLabel()&lt;br /&gt;
		if siteLink ~= nil then&lt;br /&gt;
			authorName = mw.title.new( siteLink ).text&lt;br /&gt;
		end&lt;br /&gt;
		local authorHtml = mw.html.create(&amp;#039;span&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;itemprop&amp;#039;, &amp;#039;author&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;itemscope&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;itemtype&amp;#039;, getSchemaorgItemtype( authorItem ) )&lt;br /&gt;
		local authorNameHtml = authorHtml:tag( &amp;#039;span&amp;#039; )&lt;br /&gt;
		authorNameHtml:attr( &amp;#039;itemprop&amp;#039;, &amp;#039;name&amp;#039; )&lt;br /&gt;
			:wikitext( authorName )&lt;br /&gt;
		local authorHtmlStr = tostring( authorHtml )&lt;br /&gt;
		if siteLink == nil then&lt;br /&gt;
			tableInsertUnique( authorLinks, authorHtmlStr )&lt;br /&gt;
		else&lt;br /&gt;
			tableInsertUnique( authorLinks, &amp;#039;[[&amp;#039; .. siteLink .. &amp;#039;|&amp;#039; .. authorHtmlStr .. &amp;#039;]]&amp;#039; )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Get the schema.org URL for the itemtype of the given item.&lt;br /&gt;
function getSchemaorgItemtype( item )&lt;br /&gt;
	local schemaPrefix = &amp;#039;http://schema.org/&amp;#039;&lt;br /&gt;
	for _, instanceOf in pairs( item:getBestStatements( instanceOfProp ) ) do&lt;br /&gt;
		local instanceOfId = instanceOf[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;][&amp;#039;id&amp;#039;]&lt;br /&gt;
		local instanceOfItem = mw.wikibase.getEntity( instanceOfId )&lt;br /&gt;
		-- Now go through each of the instance-of item&amp;#039;s class statements,&lt;br /&gt;
		-- seeing if we can find a matching schema.org URL.&lt;br /&gt;
		for _, equivClass in pairs( instanceOfItem:getBestStatements( equivalentClassProp ) ) do&lt;br /&gt;
			local val = equivClass[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;]&lt;br /&gt;
			if string.sub( val, 1, #schemaPrefix ) == schemaPrefix then&lt;br /&gt;
				-- This is a schema.org URL.&lt;br /&gt;
				return val&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- If we&amp;#039;ve not figured it out by now, give up with the default.&lt;br /&gt;
	return schemaPrefix .. &amp;#039;Thing&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Exported method.&lt;br /&gt;
--&lt;br /&gt;
function author_list( args )&lt;br /&gt;
	local item = getItem( args )&lt;br /&gt;
	if item == nil then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local authorLinks = {}&lt;br /&gt;
&lt;br /&gt;
	-- Collect the authors of this item.&lt;br /&gt;
	local authors = item:getBestStatements( authorProp )&lt;br /&gt;
	process_authors( authorLinks, authors )&lt;br /&gt;
&lt;br /&gt;
	-- Also collect the authors of the parent work.&lt;br /&gt;
	local works = item:getBestStatements( editionOrTranslationOfProp )&lt;br /&gt;
	for _, work in pairs( works ) do&lt;br /&gt;
		local workId = work[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;][&amp;#039;id&amp;#039;]&lt;br /&gt;
		local workItem = mw.wikibase.getEntity( workId )&lt;br /&gt;
		authors = workItem:getBestStatements( authorProp )&lt;br /&gt;
		if #authors &amp;gt; 0 then&lt;br /&gt;
			process_authors( authorLinks, authors )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Output the final list of links.&lt;br /&gt;
	local outHtml = mw.html.create()&lt;br /&gt;
	local separator = args.separator or &amp;#039;, &amp;#039;&lt;br /&gt;
	local last_separator = args.last_separator or &amp;#039;, and &amp;#039;&lt;br /&gt;
	local i = 1&lt;br /&gt;
	for _, link in pairs( authorLinks ) do&lt;br /&gt;
		outHtml:wikitext( link )&lt;br /&gt;
		if i == ( #authorLinks - 1 ) then&lt;br /&gt;
			outHtml:wikitext( last_separator )&lt;br /&gt;
		elseif #authorLinks &amp;gt; 1 and i ~= #authorLinks then&lt;br /&gt;
			outHtml:wikitext( separator )&lt;br /&gt;
		end&lt;br /&gt;
		i = i + 1&lt;br /&gt;
	end&lt;br /&gt;
	return tostring( outHtml )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Exported method.&lt;br /&gt;
--&lt;br /&gt;
function inline( args )&lt;br /&gt;
	local item = getItem( args )&lt;br /&gt;
	local outHtml = mw.html.create()&lt;br /&gt;
	mw.logObject(args)&lt;br /&gt;
	mw.logObject(item)&lt;br /&gt;
	if ( item == nil ) then&lt;br /&gt;
		outHtml:wikitext( &amp;#039;&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;Unable to determine the Wikidata item to use&amp;lt;/span&amp;gt;&amp;#039; )&lt;br /&gt;
		return tostring( outHtml )&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Make sure it&amp;#039;s an edition.&lt;br /&gt;
	local editionOrTranslationOfStmts = item:getBestStatements( editionOrTranslationOfProp )&lt;br /&gt;
	if #editionOrTranslationOfStmts == 0 then&lt;br /&gt;
		outHtml:wikitext( &amp;#039;&amp;lt;span class=&amp;quot;error&amp;quot;&amp;gt;&amp;#039; .. item.id .. &amp;#039; is not an edition or translation of a work (missing P629)&amp;lt;/span&amp;gt;&amp;#039; )&lt;br /&gt;
		return tostring( outHtml )&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	-- Title/label.&lt;br /&gt;
	local title = item:getSitelink( &amp;#039;enwikisource&amp;#039; )&lt;br /&gt;
	local label = item:getLabel( &amp;#039;en&amp;#039; )&lt;br /&gt;
	local hasWikisourcePage = false&lt;br /&gt;
	if title == nil or title == &amp;#039;&amp;#039; then&lt;br /&gt;
		title = label&lt;br /&gt;
	else&lt;br /&gt;
		hasWikisourcePage = true&lt;br /&gt;
		title = &amp;#039;[[&amp;#039; .. title .. &amp;#039;|&amp;#039; .. label .. &amp;#039;]]&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	outHtml:wikitext( title .. &amp;#039; &amp;#039; );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	-- Publication date&lt;br /&gt;
	local publicationDate = item:formatPropertyValues( &amp;#039;P577&amp;#039; )&lt;br /&gt;
	outHtml:wikitext( &amp;#039;(&amp;#039; .. publicationDate.value .. &amp;#039;) &amp;#039; )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	-- Scanned file on Wikimedia Commons.&lt;br /&gt;
	if not hasWikisourcePage then&lt;br /&gt;
		-- Add links to Index page or Commons file.&lt;br /&gt;
		local hasIndexOrCommonsLink = false&lt;br /&gt;
		local scannedFileOnWikimediaCommons = &amp;#039;P996&amp;#039;&lt;br /&gt;
		local scannedFileOnWikimediaCommonsStmts = item:getBestStatements( scannedFileOnWikimediaCommons )&lt;br /&gt;
		for _, stmt in pairs( scannedFileOnWikimediaCommonsStmts ) do&lt;br /&gt;
			local commonsFilename = stmt[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;]&lt;br /&gt;
			outHtml:wikitext( &amp;#039; &amp;#039; .. mw.getCurrentFrame():expandTemplate{ title = &amp;#039;Small scan link&amp;#039;, args = { commonsFilename } } )&lt;br /&gt;
			hasIndexOrCommonsLink = true;&lt;br /&gt;
		end&lt;br /&gt;
		-- Add link to the IA item if no links were added above.&lt;br /&gt;
		if not hasIndexOrCommonsLink then&lt;br /&gt;
			local internetArchiveIdProp = &amp;#039;P724&amp;#039;&lt;br /&gt;
			local internetArchiveIdStmts = item:getBestStatements( internetArchiveIdProp )&lt;br /&gt;
			for _, stmt in pairs( internetArchiveIdStmts ) do&lt;br /&gt;
				local internetArchiveId = stmt[&amp;#039;mainsnak&amp;#039;][&amp;#039;datavalue&amp;#039;][&amp;#039;value&amp;#039;]&lt;br /&gt;
				outHtml:wikitext( &amp;#039; &amp;#039; .. mw.getCurrentFrame():expandTemplate{ title = &amp;#039;IA small link&amp;#039;, args = { internetArchiveId } } )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	-- Wikidata and Wikipedia links.&lt;br /&gt;
	local img = &amp;#039;[[File:Wikidata-books-task-force-logo.svg|20px|alt=Wikidata books task force logo|link=d:&amp;#039; .. item.id .. &amp;#039;|View on Wikidata]]&amp;#039;&lt;br /&gt;
	outHtml:wikitext( img )&lt;br /&gt;
&lt;br /&gt;
	return tostring( outHtml )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Exported method. Get wikitext for displaying an edition&amp;#039;s badges from Wikidata.&lt;br /&gt;
-- To get an indicator, pass args.indicator = true&lt;br /&gt;
-- Testing: =p.badge({args={wikidata=&amp;#039;Q75043199&amp;#039;}})&lt;br /&gt;
--&lt;br /&gt;
function badge( args )&lt;br /&gt;
	local item = getItem( args )&lt;br /&gt;
	if not ( item and item.sitelinks and item.sitelinks.enwikisource and item.sitelinks.enwikisource.badges ) then&lt;br /&gt;
		return &amp;#039;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local badges = item.sitelinks.enwikisource.badges&lt;br /&gt;
	local out = &amp;#039;&amp;#039;&lt;br /&gt;
	for _, badge in pairs( badges ) do&lt;br /&gt;
		local badgeOut = &amp;#039;&amp;#039;&lt;br /&gt;
		local badgeItem = mw.wikibase.getEntity( badge )&lt;br /&gt;
		local badgeName = &amp;#039;&amp;#039;&lt;br /&gt;
		local wikisourceBadgeClass = &amp;#039;Q75042035&amp;#039;&lt;br /&gt;
		if badgeItem.claims.P31[1].mainsnak.datavalue.value.id == wikisourceBadgeClass and badgeItem.claims.P18 ~= nil then&lt;br /&gt;
			local imageName = badgeItem.claims.P18[1].mainsnak.datavalue.value&lt;br /&gt;
			if mw.wikibase.getLabel( badge ) ~= nil then&lt;br /&gt;
				badgeName = mw.wikibase.getLabel( badge )&lt;br /&gt;
			end&lt;br /&gt;
			badgeOut = &amp;#039;&amp;lt;span class=&amp;quot;indicator-badge&amp;quot;&amp;gt;[[File:&amp;#039; .. imageName .. &amp;#039;|16px|link=Help:Text status|&amp;#039; .. badgeName .. &amp;#039;]]&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
			if args.indicator ~= nil then&lt;br /&gt;
				badgeOut = &amp;#039;&amp;lt;indicator name=&amp;quot;wikisource-badge-&amp;#039; .. badgeName .. &amp;#039;&amp;quot;&amp;gt;&amp;#039; .. badgeOut .. &amp;#039;&amp;lt;/indicator&amp;gt;&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
			if args.category ~= nil and badgeItem.claims.P910 ~= nil then&lt;br /&gt;
				local categoryQid = badgeItem.claims.P910[1].mainsnak.datavalue.value.id&lt;br /&gt;
				local category = mw.wikibase.getEntity( categoryQid )&lt;br /&gt;
				badgeOut = badgeOut .. &amp;#039;[[&amp;#039; .. category.sitelinks.enwikisource.title .. &amp;#039;]]&amp;#039;&lt;br /&gt;
			end&lt;br /&gt;
			out = out .. badgeOut&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return mw.getCurrentFrame():preprocess( out )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Get an Item based on what&amp;#039;s passed in the &amp;#039;wikidata&amp;#039; or &amp;#039;page&amp;#039; parameters of&lt;br /&gt;
-- the args, or the current page&amp;#039;s ID otherwise.&lt;br /&gt;
function getItem( args )&lt;br /&gt;
	local id = nil&lt;br /&gt;
	-- If args is a table with an appropriate element, use it.&lt;br /&gt;
	if type( args ) == &amp;#039;table&amp;#039; then&lt;br /&gt;
		if args.wikidata ~= &amp;#039;&amp;#039; and args.wikidata ~= nil then&lt;br /&gt;
			id = args.wikidata&lt;br /&gt;
		elseif args.wikidata_id ~= &amp;#039;&amp;#039; and args.wikidata_id ~= nil then&lt;br /&gt;
			id = args.wikidata_id&lt;br /&gt;
		elseif args.page ~= &amp;#039;&amp;#039; and args.page ~= nil then&lt;br /&gt;
			local title = mw.title.new( args.page )&lt;br /&gt;
			id = mw.wikibase.getEntityIdForTitle( title.nsText .. title.text )&lt;br /&gt;
			-- If no entity for this page, maybe it&amp;#039;s a subpage and we should look for the root page&amp;#039;s entity.&lt;br /&gt;
			if id == nil then&lt;br /&gt;
				id = mw.wikibase.getEntityIdForTitle( title.nsText .. title.rootText )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if type( args ) == &amp;#039;string&amp;#039; and args ~= &amp;#039;&amp;#039; then&lt;br /&gt;
		id = args&lt;br /&gt;
	end&lt;br /&gt;
	return mw.wikibase.getEntity( id )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Exported method.&lt;br /&gt;
function authority_control( args )&lt;br /&gt;
	local item = getItem( args )&lt;br /&gt;
	-- Gather every &amp;#039;external-id&amp;#039; statement.&lt;br /&gt;
	local out = mw.html.create( &amp;#039;&amp;#039; )&lt;br /&gt;
	for propertyId,claims in pairs( item.claims) do&lt;br /&gt;
		local propItem = getItem( propertyId )&lt;br /&gt;
		for _,claim in pairs( claims ) do&lt;br /&gt;
			if claim.mainsnak.datatype == &amp;#039;external-id&amp;#039; then&lt;br /&gt;
				local propLabel = propertyId&lt;br /&gt;
				if propItem.aliases.en[1].value then&lt;br /&gt;
					propLabel = propItem.aliases.en[1].value&lt;br /&gt;
				end&lt;br /&gt;
				-- mw.logObject(propItem)&lt;br /&gt;
				out:wikitext( &amp;#039;* [[&amp;#039; .. propLabel .. &amp;#039;]]: &amp;#039; .. claim.mainsnak.datavalue.value .. &amp;#039;\n&amp;#039; )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return tostring( out )&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Export all public functions.&lt;br /&gt;
return {&lt;br /&gt;
	-- =p.author_list({args={wikidata=&amp;#039;Q28913867&amp;#039;}})&lt;br /&gt;
	author_list = function( frame ) return author_list( frame.args ) end;&lt;br /&gt;
	-- =p.inline({args={wikidata_id=&amp;#039;Q28913867&amp;#039;}})&lt;br /&gt;
	inline = function( frame ) return inline( frame.args ) end;&lt;br /&gt;
	-- =p.badge({args={wikidata=&amp;#039;Q28020002&amp;#039;}})&lt;br /&gt;
	badge = function( frame ) return badge( frame.args ) end;&lt;br /&gt;
	-- =p.authority_control({args={wikidata=&amp;#039;Q19035838&amp;#039;}})&lt;br /&gt;
	authority_control = function( frame ) return authority_control( frame.args ) end;&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>Jayprakash12345</name></author>
	</entry>
</feed>