Module:Scope hatnote: Difference between revisions
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Content deleted Content added
Tesinormed (talk | contribs) No edit summary |
Tesinormed (talk | contribs) No edit summary |
||
| (30 intermediate revisions by the same user not shown) | |||
| Line 13: | Line 13: | ||
local result = '' |
local result = '' |
||
-- remove parentheses |
-- remove parentheses from the displayed title |
||
if yesno(args['use_remove_parentheses'] or true) then |
if yesno(args['use_remove_parentheses'] or true) then |
||
for specifier in args['for']:gmatch('[^/]+') do |
|||
result = result .. require('Module:Remove parentheses').invoke( |
result = result .. require('Module:Remove parentheses').invoke(specifier) |
||
| ⚫ | |||
end |
end |
||
-- indicator |
|||
if yesno(args['use_indicator'] or true) and yesno(parentArgs['add_indicator'] or true) then |
if yesno(args['use_indicator'] or true) and yesno(parentArgs['add_indicator'] or true) then |
||
if args['file'] then args['indicator_file'] = args['file'] end |
|||
if args['file1'] then args['indicator_file'] = args['file1'] end |
|||
if not args['indicator_file'] then error('"indicator_file" argument is required') end |
|||
result = result .. frame:extensionTag{ |
result = result .. frame:extensionTag{ |
||
name = |
name = 'indicator', |
||
content = '[[File:' .. |
content = '[[File:' .. args['indicator_file'] |
||
.. '|28px' |
|||
.. '|class=attribute-loading-unset ' .. (args['indicator_class'] or args['file_class'] or '') |
|||
.. '|link=Scope:' .. args['for'] |
|||
.. '|Scope: ' .. args['for'] |
|||
.. ']]', |
|||
args = { |
args = { |
||
name = |
name = 'scope-' .. args['for']:lower():gsub(' ', '_'):gsub('/', '-') |
||
} |
} |
||
} |
} |
||
| Line 33: | Line 45: | ||
ref = args['rawcss_ref'] |
ref = args['rawcss_ref'] |
||
}) |
}) |
||
end |
|||
local use_hatnote_links = yesno(args['use_hatnote_links'] or false) and yesno(parentArgs['use_hatnote_links'] or yesno(args['default_hatnote_links'] or true)) |
|||
-- hatnote links |
|||
if use_hatnote_links and yesno(args['top_hatnote_links'] or false) then |
|||
| ⚫ | |||
title = 'Hatnote links', |
|||
args = args |
|||
} |
|||
end |
end |
||
| Line 39: | Line 61: | ||
-- hatnote links |
-- hatnote links |
||
if yesno(args[' |
if use_hatnote_links and not yesno(args['top_hatnote_links'] or false) then |
||
result = result .. frame:expandTemplate{ |
result = result .. frame:expandTemplate{ |
||
title = 'Hatnote links', |
|||
args = args |
|||
} |
|||
end |
end |
||
-- categories |
|||
if args['additional_text'] then |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- category |
|||
| ⚫ | |||
result = result .. args['categories'] |
result = result .. args['categories'] |
||
end |
end |
||
| Line 59: | Line 80: | ||
"label": "Add category", |
"label": "Add category", |
||
"description": "If the scope category should be added to the page", |
"description": "If the scope category should be added to the page", |
||
"type": "boolean", |
|||
"default": "true" |
|||
}, |
|||
"add_indicator": { |
|||
"label": "Add indicator", |
|||
"description": "If the scope indicator should be added to the page", |
|||
"type": "boolean", |
"type": "boolean", |
||
"default": "true" |
"default": "true" |
||
| Line 65: | Line 92: | ||
"label": "Use scope styling", |
"label": "Use scope styling", |
||
"description": "If the scope's styling should be used", |
"description": "If the scope's styling should be used", |
||
"type": "boolean", |
|||
"default": "true" |
|||
}, |
|||
"use_hatnote_links": { |
|||
"label": "Use hatnote links", |
|||
"description": "If the scope's meta pages should be linked", |
|||
"type": "boolean", |
"type": "boolean", |
||
"default": "true" |
"default": "true" |
||
} |
} |
||
}, |
}, |
||
"description": "Scope hatnote for ]] .. args['for'] .. [[", |
"description": "Scope hatnote for Scope:]] .. args['for'] .. [[", |
||
"format": "inline" |
"format": "inline" |
||
"paramOrder": [ |
|||
"add_category", |
|||
"use_scope_styling" |
|||
] |
|||
}]], |
}]], |
||
{}) .. '[[Category:META: Hatnote]]</noinclude>') |
{}) .. '[[Category:META: Hatnote]]</noinclude>') |
||
Latest revision as of 10:12, August 20, 2025
General template for scope hatnote templates
Parameters
for- Used in the description of the TemplateData
rawcss_ref- RawCSS application reference to use
categories- Categories to use (like
Category:Scope: Imagindarium's Creation) use_remove_parentheses- If Module:Remove parentheses should be used
use_hatnote_links- If Template:Hatnote links should be used
local yesno = require('Module:Yesno')
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
local parentArgs = require('Module:Arguments').getArgs(frame:getParent())
-- input validation
if not args['for'] then error('"for" argument is required') end
if not args['rawcss_ref'] then error('"rawcss_ref" argument is required') end
if not args['categories'] then error('"categories" argument is required') end
local result = ''
-- remove parentheses from the displayed title
if yesno(args['use_remove_parentheses'] or true) then
for specifier in args['for']:gmatch('[^/]+') do
result = result .. require('Module:Remove parentheses').invoke(specifier)
end
end
-- indicator
if yesno(args['use_indicator'] or true) and yesno(parentArgs['add_indicator'] or true) then
if args['file'] then args['indicator_file'] = args['file'] end
if args['file1'] then args['indicator_file'] = args['file1'] end
if not args['indicator_file'] then error('"indicator_file" argument is required') end
result = result .. frame:extensionTag{
name = 'indicator',
content = '[[File:' .. args['indicator_file']
.. '|28px'
.. '|class=attribute-loading-unset ' .. (args['indicator_class'] or args['file_class'] or '')
.. '|link=Scope:' .. args['for']
.. '|Scope: ' .. args['for']
.. ']]',
args = {
name = 'scope-' .. args['for']:lower():gsub(' ', '_'):gsub('/', '-')
}
}
end
-- scope styling
if yesno(parentArgs['use_scope_styling'] or true) then
result = result .. frame:extensionTag('rawcss', '', {
ref = args['rawcss_ref']
})
end
local use_hatnote_links = yesno(args['use_hatnote_links'] or false) and yesno(parentArgs['use_hatnote_links'] or yesno(args['default_hatnote_links'] or true))
-- hatnote links
if use_hatnote_links and yesno(args['top_hatnote_links'] or false) then
result = result .. frame:expandTemplate{
title = 'Hatnote links',
args = args
}
end
-- hatnote
result = result .. require('Module:Hatnote').main(frame)
-- hatnote links
if use_hatnote_links and not yesno(args['top_hatnote_links'] or false) then
result = result .. frame:expandTemplate{
title = 'Hatnote links',
args = args
}
end
-- categories
if yesno(parentArgs['add_category'] or true) and not mw.title.getCurrentTitle():inNamespace(2) then
result = result .. args['categories']
end
-- TemplateData
result = result .. frame:getParent():preprocess('<noinclude>' .. frame:extensionTag('templatedata',
[[{
"params": {
"add_category": {
"label": "Add category",
"description": "If the scope category should be added to the page",
"type": "boolean",
"default": "true"
},
"add_indicator": {
"label": "Add indicator",
"description": "If the scope indicator should be added to the page",
"type": "boolean",
"default": "true"
},
"use_scope_styling": {
"label": "Use scope styling",
"description": "If the scope's styling should be used",
"type": "boolean",
"default": "true"
},
"use_hatnote_links": {
"label": "Use hatnote links",
"description": "If the scope's meta pages should be linked",
"type": "boolean",
"default": "true"
}
},
"description": "Scope hatnote for Scope:]] .. args['for'] .. [[",
"format": "inline"
}]],
{}) .. '[[Category:META: Hatnote]]</noinclude>')
return result
end
return p