Pojdi na vsebino

Modul:Cite

Iz Wikipedije, proste enciklopedije
Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]
Slog Navajanja 1 predloge
{{Navedi arXiv}}arXiv preprint
{{Navedi AV medij}}avdio in vizualna dela
{{Navedi zaznamke iz AV medija}}avdio in video spremna beseda/zaznamki
{{Navedi knjigo}}knjige
{{Navedi konferenco}}zborniki konferenc
{{Navedi DVD-zaznamki}}DVD (film) spremna beseda/zaznamki
{{Navedi enciklopedijo}}edited collections
{{Navedi epizodo}}radijske ali televizijske epizode
{{Navedi intervju}}intervjuji
{{Navedi časopis}}akademski časopisi
{{Navedi revijo}}revije, periodika
{{Navedi poštni seznam}}javni poštni seznami
{{Navedi zemljevid}}zemljevidi
{{Navedi zaznamke ob izdaji glasbe}}avdio in video zaznamki ob izdaji
{{Navedi novice}}članki z novicami
{{Cite newsgroup}}online newsgroups
{{Cite podcast}}audio or video podcast
{{Navedi sporočilo za javnost}}sporočilo za javnost
{{Navedi poročilo}}poročila
{{Cite serial}}audio or video serials
{{Cite sign}}signs, plaques
{{Cite speech}}speeches
{{Navedi ssrn}}SSRN dokumenti
{{Cite techreport}}technical reports
{{Navedi disertacijo}}disertacije
{{Navedi citeseerx}}CiteSeerX dokumenti
{{Navedi splet}}spletni viri
Glej tudiPredloge specifičnih virov

Usage

[uredi kodo]

This module may be used to replace any of the cs1|2 templates in articles that are nearing the post-expand include size limit. Such use should only be done to prevent an article from exceeding the PEIS limit. If necessary, this module may be used in templates that wrap a cs1|2 template.

Examples

[uredi kodo]

This module requires no parameters but does require the canonical name of a cs1 template without the cite prefix: cite bookbook, cite webweb. To replace {{citation}} templates, use citation.

The structure for calls to this module:

{{#invoke:cite |<template name>|<cs1 parameters>}}

where:

#invoke:cite – calls this module: Module:cite
|<template name> – is the canonical name of the template without the cite prefix; this is the #invoke: function call; case insensitive
|<cs1 parameters> – are all of the parameters required by {{cite <template name>}}

To go from {{cite book}}:

{{cite book |author=EB Green |date=1915 |title=Title |publisher=PseudoRandom}}
EB Green (1915). Title. PseudoRandom.

write:

{{#invoke:cite |book |author=EB Green |date=1915 |title=Title |publisher=PseudoRandom}}
EB Green (1915). Title. PseudoRandom.
require ('strict');

local cfg = mw.loadData ('Modul:Cite/config');


--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------

Substitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when
<data_t> not nil; returns <message> else.

]]

local function substitute (message, data_t)
	return data_t and mw.message.newRawMessage (message, data_t):plain() or message;
end


--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------

Assembles an error message from module name, message text, help link, and error category.

]]

local function make_error_msg (frame, msg)
	local module_name = frame:getTitle();										-- get the module name for prefix and help-link label
	local namespace = mw.title.getCurrentTitle().namespace;						-- used for categorization

	local category_link = (0 == namespace) and substitute ('[[Kategorija:$1]]', {cfg.settings_t.err_category}) or '';
	return substitute ('<span style="color:#d33">Napaka: &#x7B;{[[$1|#invoke:$2]]}}: $3 ([[:$4|$5]])</span>$6',
		{
		module_name,															-- the module name with namespace
		module_name:gsub ('Modul:', ''),										-- the module name without namespace
		msg,																	-- the error message
		cfg.settings_t.help_text_link,											-- help wikilink to text at help page
		cfg.settings_t.help,													-- help wikilink display text
		category_link															-- link to error category (for main namespace errors only)
		})
end
	

--[[--------------------------< C I T E >---------------------------------------------------------------------

Function to call Module:Citation/CS1/sandbox with appropriate parameters.  For use when an article exceeds the
post-expand include size limit.

	{{#invoke:cite|book|title=Title}}

]]

local function cite (frame, template)
	local args_t = require ('Modul:Arguments').getArgs (frame, {frameOnly=true});

	template = template:lower();												-- lowercase for table indexes
	
	if not cfg.known_templates_t[template] then									-- do we recognize this template name?
		return make_error_msg (frame, substitute (cfg.settings_t.unknown_name, {template}));	-- nope; abandon with error message
	end

	local config_t = {['CitationClass'] = cfg.citation_classes_t[template] or template};	-- set CitationClass value
	return require ('Modul:Citation/CS1/peskovnik')._citation (nil, args_t, config_t);	-- go render the citation
end


--[[--------------------------< E X P O R T S >---------------------------------------------------------------
]]

return setmetatable({}, {__index =												-- returns an empty TABLE whose metatable has the __index set so that, for any given KEY, it returns
	function(_, template)														-- this anonymous function called as function(TABLE, KEY)
		return function (frame) return cite (frame, template) end;				-- which in turn returns a function that calls cite() with the KEY name
	end
})