Wookieepedia

READ MORE

Wookieepedia
Advertisement
Wookieepedia
Module documentation follows
Note: the module above may sometimes be partially or fully invisible.
Visit Module:ArchiveAccess/doc to edit this documentation.

Usage instructions[]

{{#invoke:ArchiveAccess|main|nobackup=|nobackup_text=|template_name=|use_lua_subpage=|target=|archivedate=|archiveurl=|archivefile=|full_url=|no_archive=|par=|space=|text=|nolive=|nolive_text=|citation_type=|font_size=}}

This module is used in the following template(s):


-- ArchiveAccess implements rendering for web page archive links.
local p = {}

-- NS_MAIN holds the namespace number for the Main namespace.
local NS_MAIN = 0
-- NS_FILE holds the namespace number for the File namespace.
local NS_FILE = 6
--NS_INDEX holds the namespace number for the Index namespace
local NS_INDEX = 120
local NS_MODULE = 828

-- isCurrentPageMainSpaceOrFile determines whether the page being parsed is a mainspace or file page.
local function isCurrentPageMainSpaceOrFile()
	local title = mw.title.getCurrentTitle()

	return title.namespace == NS_MAIN or title.namespace == NS_FILE or title.namespace == NS_MODULE or title.namespace == NS_INDEX or string.find(title.fullText, 'Wookieepedia:Sources') or string.find(title.fullText, 'Wookieepedia:Appearances')
end

-- getArchiveTrackingCategories returns tracking categories based on whether the explicit archive date used for this invocation
-- matches the implicit archive date sourced from the /Archive subpage of the template on behalf of which this module is invoked.
-- This is generally only useful if said /Archive subpage exists.
local function getArchiveTrackingCategories(explicitArchiveDate, knownArchiveDate, templateName, noLive)
	if not isCurrentPageMainSpaceOrFile() then
		return ''
	end

	-- User-provided explicit archive date parameter matches the implicit archive date from template data.
	if knownArchiveDate == explicitArchiveDate then
		return '[[Category:' .. templateName .. ' usages with the same archivedate value]]'
	end

	-- User-provided explicit archive date parameter does not match the implicit archive date from template data.
	if knownArchiveDate then
		if noLive then
			return '\n[[Category:' .. templateName .. ' usages with custom archivedate and nolive flag]]'
		else
			return '\n[[Category:' .. templateName .. ' usages with custom archivedate]]'
		end
	end
	
	return '[[Category:' .. templateName .. ' usages with archived URLs not in Archive]]'
end

-- getMissingPermalinkTrackingCategory returns the tracking category to be used for the current owning template
-- if this invocation contained an archival link without a permalink timestamp.
-- It prefers to use a template-specific tracking category if one exists and a generic one otherwise.
local function getMissingPermalinkTrackingCategory(citationType, templateName)
	if not isCurrentPageMainSpaceOrFile() then
		return ''
	end

	local templateSpecificCategory = citationType .. ' with missing permanent archival links/' .. templateName

	-- Use the template-specific tracking category if possible
	if mw.title.makeTitle('Category', templateSpecificCategory).exists then
		return '[[Category:' .. templateSpecificCategory .. ']]'
	end

	return '[[Category:' .. citationType .. ' with missing permanent archival links]]'
end


local function determineArchiveDate(target, templateName, is_video)
	local templateData = require('Module:ArchiveAccess/' .. templateName)
	if is_video then
		return templateData.knownArchiveDates[target]
	end
	
	local match = templateData.knownArchiveDates[string.lower(target)]
	if not match and string.lower(target) ~= target then
		match = templateData.knownArchiveDates[target]
	end
	return match
end


-- getBackupLink generates a Wayback machine archive URL based on invocation parameters
-- with appropriate tracking categories appended.
local function getBackupLink(args)
	-- No backup link is available, so return a customizable disclaimer
	if args.nobackup then
		return (args.nobackup_text or 'content obsolete and backup link not available')
	end

	-- If the original link is now inaccessible, render a customizable disclaimer
	local obsoleteDisclaimer = args.nolive and (args.nolive_text or 'content now obsolete; ') or ''

	local archiveFile = args.archivefile
	if archiveFile then
		return obsoleteDisclaimer .. '[[:' .. archiveFile .. '|screenshot]]'
	end

	local archiveUrl = args.archiveurl
	local noArchive = args.no_archive
	local isVideo = args.is_video
	local archiveLinkText = args.text or 'backup link'
	local use_lua_subpage = args.use_lua_subpage
	local sharedSiteTemplate = args.shared_site

	-- Full Wayback URL given, so return it with appropriate tracking categories
	if archiveUrl then
		local trackingCategories = '[[Category:Archiveurl usages with non-Wayback URLs]]'
		if mw.ustring.find(archiveUrl, 'web.archive.org/web') and isCurrentPageMainSpaceOrFile() then
			trackingCategories = '[[Category:Archiveurl usages with Wayback URLs]]'
		end
		return obsoleteDisclaimer .. '[' .. archiveUrl .. ' ' .. archiveLinkText .. ']' .. trackingCategories
	end

	-- Determine the Wayback URL to use based on the archive date and full_url params, if given.
	local templateName = args.template_name or ''
	local fullUrl = args.full_url or ''
	local explicitArchiveDate = args.archivedate
	local target = args.target or ''
	local knownArchiveDate
	local templateForCategory = templateName

	-- If the 'target' parameter was forwarded to this invocation, attempt fetch known archive dates from a Lua module subpage
	if target and not noArchive then
		if use_lua_subpage then
			knownArchiveDate = determineArchiveDate(target, templateName, args.is_video)
		end
		
		if sharedSiteTemplate and not knownArchiveDate then
			knownArchiveDate = determineArchiveDate(target, sharedSiteTemplate, args.is_video)
			if knownArchiveDate then
				templateForCategory = sharedSiteTemplate
			end
		end
	end

	-- If an explicit archive date was given, use it to point to the Wayback snapshot at that given time
	-- and append appropriate tracking categories.
	if explicitArchiveDate then
		local trackingCategories = not noArchive and getArchiveTrackingCategories(explicitArchiveDate, knownArchiveDate, templateForCategory, args.nolive) or ''
		local bold = ""
		if knownArchiveDate == explicitArchiveDate then
			bold = "'''"
		end
		return obsoleteDisclaimer .. bold .. '[https://web.archive.org/web/' .. explicitArchiveDate .. '/' .. fullUrl .. ' ' .. archiveLinkText .. ']' .. bold .. trackingCategories
	end

	-- No explicit archive date was given, so use the archive date from the archive subpage of the owning template if possible
	if not noArchive and knownArchiveDate then
		return obsoleteDisclaimer .. '[https://web.archive.org/web/' .. knownArchiveDate .. '/' .. fullUrl .. ' ' .. archiveLinkText .. ']'
	end

	-- If optional param is given, then ignore tracking cateogry
	if args.optional then
		return ''
	else
		-- Neither an explicit nor implicit archive date is available, so point to the latest Wayback snapshot with a disclaimer
		local citationType = args.citation_type or ''
		local notVerifiedDisclaimer = ' [[Template:' .. templateForCategory .. '|<span style="color: red">\'\'\'not verified!\'\'\'</span>]]'
		local trackingCategory = getMissingPermalinkTrackingCategory(citationType, templateForCategory)
		return obsoleteDisclaimer .. '[https://web.archive.org/web/' .. fullUrl .. ' ' .. archiveLinkText .. '] (' .. target .. ') ' .. notVerifiedDisclaimer .. trackingCategory
	end
end

-- render outputs a full Wayback link wrapped in a container.
function p.render(args)
	local isSmallFont = args.font_size == 'small'
	local wrapInParentheses = args.par
	local useSpaceSeparator = args.space
	
	if not args.nobackup and not args.archivefile and not args.archiveurl and not args.archivedate and args.optional then
		return ''
	else
		return mw.ustring.format(
			'%s%s%s%s%s',
			isSmallFont and '<small>' or '',
			wrapInParentheses and '&#32;(' or (useSpaceSeparator and '&#32;' or ''),
			getBackupLink(args),
			wrapInParentheses and ')' or '',
			isSmallFont and '</small>' or ''
		)
	end
end

local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
	local args = getArgs(frame)
	return p.render(args)
end

return p
Advertisement