| Line 1: |
Line 1: |
| − | -- Minimal Main Engine for MW 1.35
| |
| | local p = {} | | local p = {} |
| − | local configuration = require('Module:Citation/CS1/Configuration')
| |
| | | | |
| − | -- Helper function to get arguments | + | -- Helper function to gather arguments from the template call |
| | local function get_args(frame) | | local function get_args(frame) |
| | local args = {} | | local args = {} |
| Line 12: |
Line 10: |
| | end | | end |
| | | | |
| − | -- The core citation function | + | -- Main function called by {{cite book}}, {{cite web}}, etc. |
| | function p.citation(frame) | | function p.citation(frame) |
| | local args = get_args(frame) | | local args = get_args(frame) |
| − | local config = configuration
| |
| | | | |
| − | -- Pick up basic parameters | + | -- 1. AUTHOR LOGIC (Handles last, first, and author-link) |
| − | local last = args.last or args.last1 or "" | + | local last = args.last or args.last1 or args.author or args.author1 or "" |
| | local first = args.first or args.first1 or "" | | local first = args.first or args.first1 or "" |
| | + | local author_link = args['author-link'] or args['authorlink'] or args['author-link1'] |
| | + | |
| | + | local author_str = "" |
| | + | if last ~= "" then |
| | + | author_str = last .. (first ~= "" and (", " .. first) or "") |
| | + | if author_link then |
| | + | author_str = "[[" .. author_link .. "|" .. author_str .. "]]" |
| | + | end |
| | + | author_str = author_str .. ". " |
| | + | end |
| | + | |
| | + | -- 2. TITLE & PERIODICAL (Journal/Magazine/Website) |
| | local title = args.title or "No Title" | | local title = args.title or "No Title" |
| | + | local journal = args.journal or args.work or args.periodical or args.website |
| | + | local series = args.series |
| | + | |
| | + | -- Format title: Italicize if it's a book, quoted if it's an article/webpage |
| | + | local title_str = "''" .. title .. "''" |
| | + | |
| | + | -- 3. CORE METADATA (Year, Location, Publisher) |
| | local year = args.year or args.date or "" | | local year = args.year or args.date or "" |
| − | local publisher = args.publisher or "" | + | local location = args.location or args.place or "" |
| | + | local publisher = args.publisher or args.institution or "" |
| | + | local vol = args.volume |
| | + | local issue = args.issue or args.number |
| | + | local pages = args.pages or args.page or args.p or args.pp |
| | + | |
| | + | -- 4. ASSEMBLY |
| | + | local res = author_str .. title_str |
| | | | |
| − | -- Format Author string | + | if series then res = res .. ". " .. series end |
| − | local author = "" | + | if journal then res = res .. ". ''" .. journal .. "''" end |
| − | if last ~= "" then | + | if vol then res = res .. " '''" .. vol .. "'''" end |
| − | author = last .. (first ~= "" and (", " .. first) or "") .. ". "
| + | if issue then res = res .. " (" .. issue .. ")" end |
| | + | if year ~= "" then res = res .. " (" .. year .. ")" end |
| | + | if location ~= "" then res = res .. ". " .. location end |
| | + | if publisher ~= "" then |
| | + | if location ~= "" then res = res .. ": " end |
| | + | res = res .. publisher |
| | end | | end |
| | + | if pages then res = res .. ". p. " .. pages end |
| | | | |
| − | -- Build the citation string (Simplified CS1 Style) | + | -- 5. IDENTIFIERS (ISBN, DOI, OCLC) |
| − | local result = author .. "''" .. title .. "''" | + | if args.isbn then |
| − | if year ~= "" then result = result .. " (" .. year .. ")" end
| + | local isbn_clean = args.isbn:gsub("[^%d%-X]", "") -- strip invalid chars |
| − | if publisher ~= "" then result = result .. ". " .. publisher end
| + | res = res .. ". [[ISBN]] [[Special:BookSources/" .. isbn_clean .. "|" .. args.isbn .. "]]" |
| | + | end |
| | | | |
| − | -- Wrap in Cite tag for the Reflist | + | if args.doi then |
| − | return frame:extensionTag('cite', result, {class = "citation"}) | + | res = res .. ". [[Digital object identifier|doi]]:[https://doi.org/" .. args.doi .. " " .. args.doi .. "]" |
| | + | end |
| | + | |
| | + | if args.oclc then |
| | + | res = res .. ". [[OCLC]] [https://www.worldcat.org/oclc/" .. args.oclc .. " " .. args.oclc .. "]" |
| | + | end |
| | + | |
| | + | -- Close the citation |
| | + | res = res .. "." |
| | + | |
| | + | -- Output as a <cite> tag for the reflist |
| | + | return frame:extensionTag('cite', res, {class = "citation"}) |
| | end | | end |
| | | | |
| | return p | | return p |