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
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 =
if year then
mf['ws-year'] = year
Line 101 ⟶ 108:
end
local function check_non_existent_author_pages(args,
-- check for cases that aren't supposed to produce a valid link
local tracking_cat = checkArgs.tracking_cat or 'Works with non-existent author pages'
if not param or not args[param] or yesno(args[param .. '-nolink']) then
return
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 = {
{param = 'author'},
{param = 'editor'},
{param = 'composer', tracking_cat = 'Works with non-existent composer pages'},
{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['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' and isMainPage then
if not args['nocat'] then
if args.language then
table.insert(categories, 'Wikisource translations
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
table.insert(categories, '
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 ''
local year = construct_year(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.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
-- 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
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'
-- title
args.main_title = header_title(args)
Line 403 ⟶ 456:
})
return
end
Line 421 ⟶ 474:
args.header_class = 'wst-translation-header'
args.template_name = 'Translation header'
args.notes_class = 'header-notes'
return
end
|