Modul:Citation/CS1/Utilities
![]() | Denne modulen brukes på over 100 000 sider. Det anbefales at endringer testes i en sandkasse før de legges inn. Diskuter gjerne også endringer på diskusjonssiden først. |
Denne modulen og dens undermoduler er «motoren» bak CS1-stilen og de ulike kildemalene som følger denne ({{Kilde bok}}, {{Kilde www}}, osv…). Modulen er importert fra en:Module:Citation/CS1 og tilpasset norske forhold. De viktigste tilpasningene er i Modul:Citation/CS1/Configuration og Modul:Citation/CS1/Date validation, men det er gjort tilpasninger i omtrent alle undermodulene, så ved behov for å re-importere må man passe på dette. Re-importer alltid til sandkassene først.
Skal du gjøre endringer i denne modulen eller en av modulens undermoduler, prøv alltid i den tilhørende sandkassen først. Det finnes sandkasseversjoner av alle kildemalene som benytter Modul:Citation/CS1/sandkasse: {{Kilde bok/sandkasse}}, {{Kilde www/sandkasse}}, osv…, slik at du kan se hvordan disse blir påvirket av endringene dine.
Brukes av
Denne modulen brukes av følgende kildemaler:
- {{Kilde artikkel}}
- {{Kilde avhandling}}
- {{Kilde avis}}
- {{Kilde bok}}
- {{Kilde konferanse}}
- {{Kilde oppslagsverk}}
- {{Kilde pressemelding}}
- {{Kilde audiovisuelt medium}}
- {{Kilde www}}
Tilleggsmoduler
- Modul:Citation/CS1 • Modul:Citation/CS1/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Configuration • Modul:Citation/CS1/Configuration/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Whitelist • Modul:Citation/CS1/Whitelist/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Date validation • Modul:Citation/CS1/Date validation/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Utilities • Modul:Citation/CS1/Utilities/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Identifiers • Modul:Citation/CS1/Identifiers/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/COinS • Modul:Citation/CS1/COinS/sandkasse • forskjellig (diff)
- Modul:Citation/CS1/Arguments • Modul:Citation/CS1/Arguments/sandkasse • samme innhold
- Modul:Citation/CS1/Suggestions • Modul:Citation/CS1/Suggestions/sandkasse • forskjellig (diff)
Vedlikeholdskategorier
local u = {}
local z = {
error_categories = {}; -- for categorizing citations that contain errors
error_ids = {};
message_tail = {};
maintenance_cats = {}; -- for categorizing citations that aren't erroneous per se, but could use a little work
properties_cats = {}; -- for categorizing citations based on certain properties, language of source for instance
};
local cfg = mw.loadData ('Module:Citation/CS1/Configuration/sandbox');
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.
This function is global because it is called from both this module and from Date validation
]]
function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
Whether needle is in haystack
]]
local function in_array( needle, haystack )
if needle == nil then
return false;
end
for n,v in ipairs( haystack ) do
if v == needle then
return n;
end
end
return false;
end
--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------
Populates numbered arguments in a message string using an argument table.
]]
local function substitute( msg, args )
return args and mw.message.newRawMessage( msg, args ):plain() or msg;
end
--[[--------------------------< E R R O R _ C O M M E N T >----------------------------------------------------
Wraps error messages with css markup according to the state of hidden.
]]
local function error_comment( content, hidden )
return substitute( hidden and cfg.presentation['hidden-error'] or cfg.presentation['visible-error'], content );
end
--[[--------------------------< S E T _ E R R O R >--------------------------------------------------------------
Sets an error condition and returns the appropriate error message. The actual placement of the error message in the output is
the responsibility of the calling function.
]]
local function set_error( error_id, arguments, raw, prefix, suffix )
local error_state = cfg.error_conditions[ error_id ];
prefix = prefix or "";
suffix = suffix or "";
if error_state == nil then
error( cfg.messages['undefined_error'] );
elseif is_set( error_state.category ) then
table.insert( z.error_categories, error_state.category );
end
local message = substitute( error_state.message, arguments );
message = message .. " ([[" .. cfg.messages['help page link'] ..
"#" .. error_state.anchor .. "|" ..
cfg.messages['help page label'] .. "]])";
z.error_ids[ error_id ] = true;
if in_array( error_id, { 'bare_url_missing_title', 'trans_missing_title' } )
and z.error_ids['citation_missing_title'] then
return '', false;
end
message = table.concat({ prefix, message, suffix });
if raw == true then
return message, error_state.hidden;
end
return error_comment( message, error_state.hidden );
end
return { -- return exported functions and tables
is_set = is_set,
in_array = in_array,
substitute = substitute,
error_comment = error_comment,
set_error = set_error,
z = z,
}