Module:Header: Difference between revisions

Content deleted Content added
fix current_title error
add option to require a language (use for translations)
 
(27 intermediate revisions by 2 users not shown)
Line 17:
local parent_links = require('Module:Auto parents')._parent_links
 
local headerStructureconstruct_header = require('Module:Header structure').construct_header
local headerAttributions = require('Module:Header/attribution')
local construct_defaultsort = require('Module:Header/sort')._construct_defaultsort
Line 23:
 
local current_title = mw.title.getCurrentTitle()
 
--[=[
Wrap stylesheet in noexport div
]=]
local function get_noexport_stylesheet(template)
return tostring(mw.html.create('div'):addClass('ws-noexport'):wikitext(mw.getCurrentFrame():extensionTag('templatestyles', '', {src = template .. '/styles.css'})))
end
 
--[=[
Line 76 ⟶ 83:
end
local year = args['override-year'] or args['year']
if year then
mf['ws-year'] = year
Line 101 ⟶ 108:
end
 
local function check_non_existent_author_pages(args, paramcategories, categoriescheckArgs)
-- check for cases that aren't supposed to produce a valid link
if args[param] then
-- some pages expect an invalid author
local lower_argparam = stringcheckArgs.lower(args[param])
local tracking_cat = checkArgs.tracking_cat or 'Works with non-existent author pages'
local attr_data = headerAttributions.attr_data[param] or headerAttributions.attr_data[string.gsub(param, 'section-', '')]
if not attr_data or not attr_data['special_cases'][lower_arg] then
if not param or not args[param] or yesno(args[param .. '-nolink']) then
local target = mw.title.makeTitle("Author", args[param])
return
-- expensive function!
if not target or not target.exists then
table.insert(categories, "Works with non-existent author pages")
end
end
end
local lower_arg = string.lower(args[param])
local attr_data = headerAttributions.attr_data[param] or headerAttributions.attr_data[string.gsub(param, 'section%-', '')]
if attr_data and attr_data['special_cases'] and attr_data['special_cases'][lower_arg] then
return
end
-- check if page exists
local target = mw.title.makeTitle('Author', args[param])
-- expensive function!
if not target or not target.exists then
table.insert(categories, tracking_cat)
end
return
end
 
Line 124 ⟶ 142:
if args['override-author'] then
table.insert(categories, "Pages with override author")
end
if args['override-translator'] then
table.insert(categories, "Pages with override translator")
end
if current_title:inNamespaces(0, 114) or args.testing then
local params_to_check = {
check_non_existent_author_pages(args, 'author', categories)
{param = 'author'},
check_non_existent_author_pages(args, 'editor', categories)
{param = 'editor'},
check_non_existent_author_pages(args, 'translator', categories)
check_non_existent_author_pages(args, {param = 'section-translator'}, categories)
{param = 'composer', tracking_cat = 'Works with non-existent composer pages'},
check_non_existent_author_pages(args, 'section-author', categories)
{param = 'illustrator', tracking_cat = 'Works with non-existent illustrator pages'}
}
for k, v in pairs(params_to_check) do
check_non_existent_author_pages(args, categories, v)
check_non_existent_author_pages(args, categories, {param = 'section-' .. v.param, tracking_cat = v.tracking_cat})
end
end
Line 142 ⟶ 170:
local author = args['override-author'] or args['author']
if author and (string.lower(author) == 'unknown') and not args['nocat'] then
if args.template_name == 'Translation header' then
table.insert(categories, 'Translations of anonymous works')
Line 151 ⟶ 179:
local editor = args['override-editor'] or args['editor']
if editor and not args['nocat'] then
editor = string.lower(editor)
if editor == 'unknown' or editor == '?' then
Line 161 ⟶ 189:
local translator = args['override-translator'] or args['translator']
if translator and not args['nocat'] then
translator = string.lower(translator)
if translator == 'unknown' or translator == 'not mentioned' or translator == '?' then
Line 176 ⟶ 204:
end
if args['override-year'] then
table.insert(categories, "Pages with override year")
end
if args['noyear'] then
table.insert(categories, "Pages with noyear")
Line 204 ⟶ 229:
-- translation header categories
local isMainPage = ((current_title:inNamespaces(0, 114) and not current_title.isSubpage) or args['testing'])
if args.template_name == 'Translation header' then
if args.template_name == 'Translation header' and isMainPage then
if args.language then
if not args['nocat'] then
table.insert(categories, 'Works originally in ' .. (args.language_name or 'an undefined language'))
if args.language then
else
table.insert(categories, 'Wikisource translations withof noworks originalin ' .. (args.language_name or 'an undefined language'))
else
table.insert(categories, 'Wikisource translations with no original language')
end
end
Line 214 ⟶ 242:
table.insert(categories, 'Wikisource translations with no original source')
end
elseif not args['nocat'] and isMainPage then
if not current_titleargs.isSubpagelanguage then
table.insert(categories, 'WikisourceWorks translationsoriginally in ' .. (args.language_name or 'an undefined language'))
elseif args['language-required'] then
table.insert(categories, 'Translations with no original language')
end
end
Line 289 ⟶ 319:
]=]
local function header_title(args)
local title = args.title or ''
return table.concat({
local titleSpan = tostring(mw.html.create('span'):attr('id', 'header-title-text'):wikitext(args.title)),
construct_year(args),
local year = construct_year(args)
headerAttributions.construct_attributions(args),
local attr = headerAttributions.construct_sectionconstruct_attributions(args)
local section = headerAttributions.construct_section(args)
})
if attr ~= '' and title ~= '' then
attr = '<br id=\"header-title=break\" />' .. attr
end
return table.concat({titleSpan, year, attr, section})
end
 
Line 346 ⟶ 382:
end
-- aliases
args.sortkey = args.defaultsort or args.sortkey
-- default values
args.template_name = args.template_name or 'Header'
args.title = args.title or parent_links({})
args.testing = yesno(args.testing or current_title.fullText == 'Template:Header/testcases' or current_title.fullText == 'Template:Translation header/testcases')
args.nocat = yesno(args.nocat) or false
-- add aliases to argsWithBlanks
-- noyearcat has different behavior for nil and false
if args.nocat == true then
args.noyearcat = true
end
if args.language then
args.language_name = ISO_639_language_name(args.language)
end
args['language-required'] = yesno(args['language-required']) or false
-- add values to argsWithBlanks
for k, v in pairs(args) do
if not argsWithBlanks[k] then
Line 360 ⟶ 409:
end
-- default valuevalues for title and section (allow override by setting section to blank)
if not argsWithBlanks['title'] then
args['title'] = parent_links({})
argsWithBlanks['title'] = args['title']
end
if not argsWithBlanks['section'] and current_title.isSubpage then
args['section'] = current_title.subpageText
argsWithBlanks['section'] = args['section']
end
Line 370 ⟶ 424:
args.header_class = 'wst-header ws-header ws-noexport noprint dynlayout-exempt ' .. (args.header_class or '')
args.main_class = 'headertemplate'
 
args.notes_id = args.notes_id or 'navigationNotes'
-- title
args.main_title = header_title(args)
Line 403 ⟶ 456:
})
return headerStructure.get_noexport_stylesheet('Header') .. headerStructure.construct_header(args)
end
 
Line 421 ⟶ 474:
args.header_class = 'wst-translation-header'
args.template_name = 'Translation header'
args.main_id = 'translationheadertemplate'
args.notes_id = 'translation-notes'
args.notes_class = 'header-notes'
if args.language then
args.language_name = ISO_639_language_name(args.language)
end
return headerStructure.get_noexport_stylesheet('Translation header') .. p._header(args, argsWithBlanks)
end