Latest revision as of 15:31, 28 December 2024 view sourceTrappist the monk (talk | contribs)Administrators479,893 edits sync from sandbox; |
Latest revision as of 01:00, 5 January 2025 edit Trappist the monk (talk | contribs)Administrators479,893 editsNo edit summary |
Line 1: |
Line 1: |
|
|
--[[ |
|
|
History of changes since last sync: 2024-12-28 |
|
|
|
|
|
]] |
|
|
|
|
require ('strict'); |
|
require ('strict'); |
|
|
|
|
Line 30: |
Line 35: |
|
local added_numeric_name_errs; -- Boolean flag so we only emit one numeric name error / category and stop testing names once an error is encountered |
|
local added_numeric_name_errs; -- Boolean flag so we only emit one numeric name error / category and stop testing names once an error is encountered |
|
local added_numeric_name_maint; -- Boolean flag so we only emit one numeric name maint category and stop testing names once a category has been emitted |
|
local added_numeric_name_maint; -- Boolean flag so we only emit one numeric name maint category and stop testing names once a category has been emitted |
|
local Frame; -- holds the module's frame table |
|
|
local is_preview_mode; -- true when article is in preview mode; false when using 'Preview page with this template' (previewing the module) |
|
local is_preview_mode; -- true when article is in preview mode; false when using 'Preview page with this template' (previewing the module) |
|
local is_sandbox; -- true when using sandbox modules to render citation |
|
local is_sandbox; -- true when using sandbox modules to render citation |
Line 4,379: |
Line 4,383: |
|
|
|
|
|
|
|
|
|
--[[--------------------------< C I T A T I O N >-------------------------------------------------------------- |
|
--[[--------------------------< _ C I T A T I O N >------------------------------------------------------------ |
|
|
|
|
|
|
Module entry point |
|
This is used by templates such as {{cite book}} to create the actual citation text. |
|
|
|
|
|
|
frame – from template call (citation()); may be nil when called from another module |
|
|
args – table of all cs1|2 parameters in the template (the template frame) |
|
|
config – table of template-supplied parameter (the #invoke frame) |
|
|
|
|
|
]] |
|
]] |
|
|
|
|
|
⚫ |
local function _citation (frame, args, config) -- save a copy in case we need to display an error message in preview mode |
⚫ |
local function citation(frame) |
|
|
|
if not frame then |
⚫ |
Frame = frame; -- save a copy in case we need to display an error message in preview mode |
|
|
|
frame = mw.getCurrentFrame(); -- if called from another module, get a frame for frame-provided functions |
|
|
|
|
⚫ |
end |
⚫ |
local config = {}; -- table to store parameters from the module {{#invoke:}} |
|
⚫ |
for k, v in pairs( frame.args ) do -- get parameters from the {{#invoke}} frame |
|
⚫ |
config = v; |
|
⚫ |
-- args = v; -- crude debug support that allows us to render a citation from module {{#invoke:}}; skips parameter validation; TODO: keep? |
|
⚫ |
end |
|
|
-- i18n: set the name that your wiki uses to identify sandbox subpages from sandbox template invoke (or can be set here) |
|
-- i18n: set the name that your wiki uses to identify sandbox subpages from sandbox template invoke (or can be set here) |
|
local sandbox = ((config.SandboxPath and '' ~= config.SandboxPath) and config.SandboxPath) or '/sandbox'; -- sandbox path from {{#invoke:Citation/CS1/sandbox|citation|SandboxPath=/...}} |
|
local sandbox = ((config.SandboxPath and '' ~= config.SandboxPath) and config.SandboxPath) or '/sandbox'; -- sandbox path from {{#invoke:Citation/CS1/sandbox|citation|SandboxPath=/...}} |
Line 4,398: |
Line 4,402: |
|
sandbox = is_sandbox and sandbox or ''; -- use i18n sandbox to load sandbox modules when this module is the sandox; live modules else |
|
sandbox = is_sandbox and sandbox or ''; -- use i18n sandbox to load sandbox modules when this module is the sandox; live modules else |
|
|
|
|
|
local pframe = frame:getParent() |
|
|
local styles; |
|
⚫ |
|
|
|
cfg = mw.loadData ('Module:Citation/CS1/Configuration' .. sandbox); -- load sandbox versions of support modules when {{#invoke:Citation/CS1/sandbox|...}}; live modules else |
|
cfg = mw.loadData ('Module:Citation/CS1/Configuration' .. sandbox); -- load sandbox versions of support modules when {{#invoke:Citation/CS1/sandbox|...}}; live modules else |
|
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist' .. sandbox); |
|
whitelist = mw.loadData ('Module:Citation/CS1/Whitelist' .. sandbox); |
Line 4,407: |
Line 4,408: |
|
identifiers = require ('Module:Citation/CS1/Identifiers' .. sandbox); |
|
identifiers = require ('Module:Citation/CS1/Identifiers' .. sandbox); |
|
metadata = require ('Module:Citation/CS1/COinS' .. sandbox); |
|
metadata = require ('Module:Citation/CS1/COinS' .. sandbox); |
|
styles = 'Module:Citation/CS1' .. sandbox .. '/styles.css'; |
|
|
|
|
|
|
utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables |
|
utilities.set_selected_modules (cfg); -- so that functions in Utilities can see the selected cfg tables |
Line 4,418: |
Line 4,418: |
|
is_preview_mode = not utilities.is_set (frame:preprocess ('{{REVISIONID}}')); |
|
is_preview_mode = not utilities.is_set (frame:preprocess ('{{REVISIONID}}')); |
|
|
|
|
|
local args = {}; -- table where we store all of the template's arguments |
|
-- table where we store all of the template's arguments |
|
local suggestions = {}; -- table where we store suggestions if we need to loadData them |
|
local suggestions = {}; -- table where we store suggestions if we need to loadData them |
|
local error_text; -- used as a flag |
|
local error_text; -- used as a flag |
Line 4,424: |
Line 4,424: |
|
local capture; -- the single supported capture when matching unknown parameters using patterns |
|
local capture; -- the single supported capture when matching unknown parameters using patterns |
|
local empty_unknowns = {}; -- sequence table to hold empty unknown params for error message listing |
|
local empty_unknowns = {}; -- sequence table to hold empty unknown params for error message listing |
|
for k, v in pairs( pframe.args ) do -- get parameters from the parent (template) frame |
|
for k, v in pairs( args ) do -- get parameters from the parent (template) frame |
|
v = mw.ustring.gsub (v, '^%s*(.-)%s*$', '%1'); -- trim leading/trailing whitespace; when v is only whitespace, becomes empty string |
|
v = mw.ustring.gsub (v, '^%s*(.-)%s*$', '%1'); -- trim leading/trailing whitespace; when v is only whitespace, becomes empty string |
|
if v ~= '' then |
|
if v ~= '' then |
Line 4,502: |
Line 4,502: |
|
|
|
|
|
return table.concat ({ |
|
return table.concat ({ |
|
frame:extensionTag ('templatestyles', '', {src=styles}), |
|
frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1' .. sandbox .. '/styles.css'}), |
|
citation0( config, args) |
|
citation0( config, args) |
|
}); |
|
}); |
|
|
end |
|
|
|
|
|
|
|
|
--[[--------------------------< C I T A T I O N >-------------------------------------------------------------- |
|
|
|
|
|
Template entry point |
|
|
|
|
|
]] |
|
|
|
|
⚫ |
local function citation (frame) |
|
⚫ |
local config_t = {}; -- table to store parameters from the module {{#invoke:}} |
|
|
local args_t = frame:getParent().args; -- get template's preset parameters |
|
|
|
|
⚫ |
for k, v in pairs (frame.args) do -- get parameters from the {{#invoke}} frame |
|
⚫ |
config_t = v; |
|
⚫ |
-- args_t = v; -- crude debug support that allows us to render a citation from module {{#invoke:}}; skips parameter validation; TODO: keep? |
|
|
end |
|
|
return _citation (frame, args_t, config_t) |
|
end |
|
end |
|
|
|
|
Line 4,511: |
Line 4,529: |
|
]] |
|
]] |
|
|
|
|
|
return {citation = citation}; |
|
return { |
|
|
citation = citation, |
|
⚫ |
|
|
|
_citation = _citation, |
|
|
} |