Module:Citation/CS1: Difference between revisions

From AviationSafetyX Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Reverted
Line 3: Line 3:
local sandbox = ''
local sandbox = ''
if mw.getCurrentFrame():getTitle():find('/sandbox') then
if mw.getCurrentFrame():getTitle():find('/sandbox') then
sandbox = '/sandbox'
    sandbox = '/sandbox'
end
end


local status, cfg = pcall(function()
local status, cfg = pcall(function()
return mw.loadData('Module:Citation/CS1/Configuration' .. sandbox)
    return mw.loadData('Module:Citation/CS1/Configuration' .. sandbox)
end)
end)


if not status or type(cfg.date_names) ~= 'table' then
if not status or type(cfg.date_names) ~= 'table' then
cfg = {
    cfg = {
date_names = {
        date_names = {
en = {
            en = {
long = {
                long = {
January = "January", February = "February", March = "March",
                    January = "January", February = "February", March = "March",
April = "April", May = "May", June = "June",
                    April = "April", May = "May", June = "June",
July = "July", August = "August", September = "September",
                    July = "July", August = "August", September = "September",
October = "October", November = "November", December = "December"
                    October = "October", November = "November", December = "December"
},
                },
short = {
                short = {
January = "Jan", February = "Feb", March = "Mar",
                    January = "Jan", February = "Feb", March = "Mar",
April = "Apr", May = "May", June = "Jun",
                    April = "Apr", May = "May", June = "Jun",
July = "Jul", August = "Aug", September = "Sep",
                    July = "Jul", August = "Aug", September = "Sep",
October = "Oct", November = "Nov", December = "Dec"
                    October = "Oct", November = "Nov", December = "Dec"
}
                }
}
            }
}
        }
}
    }
end
end


local cs1_engine = require('Module:Citation/CS1/Engine' .. sandbox)
local cs1_engine = require('Module:Citation/CS1/Engine' .. sandbox)


-- FINAL, CORRECT FUNCTION
-- ABSOLUTE FIX: BLOCK EMPTY REFS
function p.citation(frame)
function p.citation(frame)
     local cite_result = cs1_engine.citation(frame, cfg)
     local cite_result = cs1_engine.citation(frame, cfg)
     if cite_result == nil or cite_result == '' then
     if cite_result == nil or cite_result:match('^%s*$') then
         -- Prevent empty refs from being generated
         -- Return blank if citation is empty
         return ''
         return ''
     end
     end

Revision as of 19:57, 31 March 2025

<section begin=header /><templatestyles src="Module:Message box/ombox.css"></templatestyles>

<templatestyles src="Module:Message box/ombox.css"></templatestyles>

<templatestyles src="Module:Message box/ombox.css"></templatestyles>

<templatestyles src="Module:Message box/ombox.css"></templatestyles>

Lua error: bad argument #1 to "get" (not a valid title).<section end=header /> This module and associated sub-modules support the Citation Style 1 and Citation Style 2 citation templates. In general, it is not intended to be called directly, but is called by one of the core CS1 and CS2 templates. <section begin=module_components_table /> These files comprise the module support for CS1|2 citation templates:

CS1 | CS2 modules
live sandbox diff description
Gold padlock Module:Citation/CS1 Module:Citation/CS1/sandbox [edit] diff Rendering and support functions
Module:Citation/CS1/Configuration Module:Citation/CS1/Configuration/sandbox [edit] diff Translation tables; error and identifier handlers
Module:Citation/CS1/Whitelist Module:Citation/CS1/Whitelist/sandbox [edit] diff List of active and deprecated CS1|2 parameters
Module:Citation/CS1/Date validation Module:Citation/CS1/Date validation/sandbox [edit] diff Date format validation functions
Module:Citation/CS1/Identifiers Module:Citation/CS1/Identifiers/sandbox [edit] diff Functions that support the named identifiers (ISBN, DOI, PMID, etc.)
Module:Citation/CS1/Utilities Module:Citation/CS1/Utilities/sandbox [edit] diff Common functions and tables
Module:Citation/CS1/COinS Module:Citation/CS1/COinS/sandbox [edit] diff Functions that render a CS1|2 template's metadata
Module:Citation/CS1/styles.css Module:Citation/CS1/sandbox/styles.css [edit] diff CSS styles applied to the CS1|2 templates
Silver padlock Module:Citation/CS1/Suggestions Module:Citation/CS1/Suggestions/sandbox [edit] diff List that maps common erroneous parameter names to valid parameter names

<section end=module_components_table />

Other documentation:

testcases


local p = {}

local sandbox = ''
if mw.getCurrentFrame():getTitle():find('/sandbox') then
    sandbox = '/sandbox'
end

local status, cfg = pcall(function()
    return mw.loadData('Module:Citation/CS1/Configuration' .. sandbox)
end)

if not status or type(cfg.date_names) ~= 'table' then
    cfg = {
        date_names = {
            en = {
                long = {
                    January = "January", February = "February", March = "March",
                    April = "April", May = "May", June = "June",
                    July = "July", August = "August", September = "September",
                    October = "October", November = "November", December = "December"
                },
                short = {
                    January = "Jan", February = "Feb", March = "Mar",
                    April = "Apr", May = "May", June = "Jun",
                    July = "Jul", August = "Aug", September = "Sep",
                    October = "Oct", November = "Nov", December = "Dec"
                }
            }
        }
    }
end

local cs1_engine = require('Module:Citation/CS1/Engine' .. sandbox)

-- ABSOLUTE FIX: BLOCK EMPTY REFS
function p.citation(frame)
    local cite_result = cs1_engine.citation(frame, cfg)
    if cite_result == nil or cite_result:match('^%s*$') then
        -- Return blank if citation is empty
        return ''
    end
    return cite_result
end

return p