Jump to content

Module:Sandbox/Gonnym/episodewikidata

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 09:47, 10 August 2019. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local getArgs = require('Module:Arguments').getArgs
local getWikiDataValue = require('Module:WikidataIB/sandbox')._getValue

p = {}

local function getPreviousEpisodeFromWikiData()
	return getWikiDataValue({"P155", fetchwikidata = "ALL", onlysourced = "no", qid = "Q20785929"})
end

local function getNextEpisodeFromWikiData()
	return getWikiDataValue({"P156", fetchwikidata = "ALL", onlysourced = "no", qid = "Q20785929"})
end

function p.getPreviousEpisodeFromWikiData()
	return getWikiDataValue({"P155", fetchwikidata = "ALL", onlysourced = "no", qid = "Q20785929"})
end

function p.getNextEpisodeFromWikiData()
	return getWikiDataValue({"P156", fetchwikidata = "ALL", onlysourced = "no", qid = "Q20785929"})
end

local function getFormattedPreviousEpisodeLink(args)
	local previousEpisodeRaw = args.rprev or args.RPrev
	local previousEpisode = args.prev or getPreviousEpisodeFromWikiData()

	local previousEpisodeLink
	if (previousEpisodeRaw) then
		previousEpisodeLink = previousEpisodeRaw
	elseif (previousEpisode) then
		previousEpisodeLink = '"' .. previousEpisode .. '"'
	else
		previousEpisodeLink = "—"
	end
end

local function getFormattedNextEpisodeLink(args)
	local nextEpisodeRaw = args.rnext or args.RNext
	local nextEpisode = args.next or getNextEpisodeFromWikiData()

	local nextEpisodeLink
	if (nextEpisodeRaw) then
		nextEpisodeLink = nextEpisodeRaw
	elseif (nextEpisode) then
		nextEpisodeLink = '"' .. nextEpisode .. '"'
	else
		nextEpisodeLink = "—"
	end

end

function p.getEpisodeChronology(frame)
	local args = getArgs(frame)
	local previousEpisodeLink = getFormattedPreviousEpisodeLink(args)
	local nextEpisodeLink = getFormattedNextEpisodeLink(args)
	
	--{{succession links|left=previousEpisodeLink|right=nextEpisodeLink}}
	return '! style="width:100%;" ! style="width: 50%; padding: 0.2em 0.1em 0.2em 0; text-align: center;" ! ←&nbsp;\'\'\'Previous\'\'\'<br />' .. previousEpisodeLink .. '! style="width: 50%; padding: 0.2em 0 0.2em 0.1em; text-align: center;" ! \'\'\'Next\'\'\'&nbsp;→<br />' .. nextEpisodeLink
end

function p.getHeaderTitle(frame)
	local args = getArgs(frame)
	local previousEpisode = args.prev or args.rprev or args.RPrev or getPreviousEpisodeFromWikiData()
	local nextEpisode = args.next or args.rnext or args.RNext or getNextEpisodeFromWikiData()
	
	if (previousEpisode or nextEpisode) then
		return "Episode chronology"
	end
end

return p