Module:EB1911/sandbox
Jump to navigation
Jump to search
This is the module sandbox page for Module:EB1911 (diff). |
This module depends on the following other modules: |
Implements {{EB1911}}.
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local header = require('Module:Header')._header
function p._EB1911(args)
local current_title = mw.title.getCurrentTitle()
local tracking_cats = {}
local args2 = args
for k, v in pairs(args2) do
if k ~= 'wikipedia' and v == '' then
args[k] = nil
end
end
local newArgs = {}
local nilArgs = {}
for k, v in pairs(args) do
local newkey = string.gsub(string.gsub(string.gsub(k, '^author', 'section-author'), '_', '-'), 'contributor', 'section-author')
if newkey ~= tostring(k) then
if (args[newkey] and args[newkey] ~= '') or newArgs[newkey] then
table.insert(tracking_cats, '[[Category:' .. 'Pages using duplicate arguments in template calls' .. ']]')
end
if v ~= '' then
newArgs[newkey] = v
end
table.insert(nilArgs, k)
end
end
for k, v in pairs(nilArgs) do
args[v] = nil
end
for k, v in pairs(newArgs) do
args[k] = v
end
args.title = '[[1911 Encyclopædia Britannica|1911 \'\'Encyclopædia Britannica\'\']]'
if args.volume then
args.title = args.title .. ', [[1911 Encyclopædia Britannica/Volume ' .. args.volume .. '|Volume ' .. args.volume .. ']]'
elseif current_title:inNamespaces(0) then
table.insert(tracking_cats, '[[Category:' .. 'EB 1911 no volume' .. ']]')
end
if not args.section then
if current_title.baseText == '1911 Encyclopædia Britannica' then
args.section = current_title.subpageText
else
local parent = mw.title.new(current_title.baseText, current_title.nsText)
args.section = ' - [[' .. parent.prefixedText .. '|' .. parent.subpageText .. ']] ' .. current_title.subpageText
end
end
if args.previous then
args.previous = '[[' .. current_title.nsText .. ':' .. current_title.rootText .. '/' .. args.previous .. '|' .. args.previous .. ']]'
end
if args['next'] then
args['next'] = '[[' .. current_title.nsText .. ':' .. current_title.rootText .. '/' .. args['next'] .. '|' .. args['next'] .. ']]'
end
if current_title:inNamespaces(0) then
args.sortkey = args.sortkey or args.defaultsort or current_title.subpageText
end
args['allow-explicit-formatting'] = true
args.notes = args['override-notes']
if not args.notes then
local notes_table = {}
if args.edition then
table.insert(notes_table, 'Edition of ' .. args.edition .. '.')
end
local see_also_table = {}
if not args.wikipedia then
args.wikipedia = current_title.subpageText
end
if args.wikipedia == '' then
args.wikipedia = nil
end
if args.wikipedia2 == '' then
args.wikipedia2 = nil
end
if args.wikipedia or args.wikipedia2 then
local wikipedia_table = {}
if args.wikipedia then
table.insert(wikipedia_table, '[[w:' .. args.wikipedia .. '|' .. args.wikipedia .. ']]')
end
if args.wikipedia2 then
table.insert(wikipedia_table, '[[w:' .. args.wikipedia2 .. '|' .. args.wikipedia2 .. ']]')
end
table.insert(see_also_table, table.concat(wikipedia_table, ' and ') .. ' on [[w:Main_Page|Wikipedia]]')
end
args.wikipedia = nil
if args['other-projects'] then
table.insert(see_also_table, args['other-projects'])
end
table.insert(see_also_table, 'our [[Wikisource:WikiProject 1911 Encyclopædia Britannica/Project Disclaimer|1911 Encyclopædia Britannica disclaimer]]')
local see_also_text = see_also_table[#see_also_table]
if #see_also_table > 1 then
see_also_text = table.concat(see_also_table, '; ', 1, #see_also_table - 1) .. '; and ' .. see_also_table[#see_also_table]
end
see_also_text = "\'\'\'See also\'\'\' " .. see_also_text .. '.'
table.insert(notes_table, see_also_text)
args.notes = table.concat(notes_table, ' ')
end
if args['extra-notes'] then
args.notes = args.notes .. ' ' .. args['extra-notes']
end
if args.wiktionary then
table.insert(tracking_cats, '[[Category:' .. 'EB 1911 wiktionary links' .. ']]')
end
return header(args) .. table.concat(tracking_cats)
end
function p.EB1911(frame)
return p._EB1911(getArgs(frame, {removeBlanks = false}))
end
return p