Module:Cite certification/sandbox

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Cite certification/sandbox
local p = {}

local getArgs = require('Module:Arguments').getArgs
local cite = require('Module:Citation/CS1')
local handlers = require("Module:Cite certification/handlers/sandbox")
local makeURL = require('Module:Cite certification/URL/sandbox')
local makeArchiveURL = require('Module:Cite certification/archiveurl/sandbox')
local makeArchiveDate = require('Module:Cite certification/archivedate/sandbox')

local function notblank(v) return (v or '') ~= '' end

local function errorMessage(msg)
	local cat = (mw.title.getCurrentTitle().namespace == 0)
		and '[[Category:Cite certification used with missing parameters]]' or ''
	return string.format('<span style="color:red;">%s</span>%s', msg, cat)
end

local function makeTitle(args, titleRegion) -- implement Cite certification/Title
	return (notblank(titleRegion) and titleRegion or args.region) ..
		(notblank(args.digital) and ' digital' or '') ..
		(notblank(args.type) and (' ' .. args.type) or '') ..
		(notblank(args.streaming) and ' streaming' or '') ..
		' certifications' ..
		(notblank(args.artist) and (' - ' .. args.artist) or '') ..
		(notblank(args.title) and (' - ' .. args.title) or '')
end

local function buildCitation(args, opts)
	local citation
	
	if mw.ustring.lower(args.source or '') == 'book' then
		local citeArgs = {}
		for k, v in pairs(opts) do
			if k ~= 'note' then citeArgs[k] = v end
		end
		citation = cite._citation(nil, citeArgs, {CitationClass = 'book'})
	else
		local url = makeURL(args, opts.urlSource)

		if type(url) == 'table' then
			return errorMessage(url[1])
		end
		
		citation = cite._citation(nil,
			{
				url = url,
				title = notblank(opts.title) and opts.title or makeTitle(args, opts.titleRegion),
				publisher = opts.publisher,
		
				['access-date'] = notblank(args['access-date']) and args['access-date'] or args.accessdate,
				date = args.date,
				ref = args.ref,
		
				language = opts.language,
				website = opts.website,
				format = opts.format,
				['archive-url'] = (opts.archive == true) and makeArchiveURL(args) or nil,
				['archive-date'] = (opts.archive == true) and makeArchiveDate(args) or nil,
				['url-status'] = opts.urlStatus,
				['script-title'] = opts.scriptTitle,
				['trans-title'] = opts.transTitle,
			},
			{CitationClass = 'web'}
		)
	end
	
	return citation .. (opts.note or '')
end

function p._main(args)
	if notblank(args.region) then
		local region = mw.ustring.lower(args.region)
		if handlers[region] then
			local output = handlers[region](args)
			return type(output) == 'string' and errorMessage(output) or buildCitation(output)
		else
			return errorMessage('UNSUPPORTED REGION: "' .. args.region .. '".')
		end
	else
		return errorMessage('MISSING OR EMPTY REGION.')
	end
end

function p.main(frame)
	local args = getArgs(frame,{parentOnly=true,removeBlanks=true})
	return p._main(args)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.