Content deleted Content added
Sophivorus (talk | contribs) Escape special characters in fragment names |
Create p.excerpt to replicate {{Excerpt}} entirely in lua for reduced post-expand include size |
||
Line 763:
return frame:preprocess(text)
end
end
local function is(v)
return (v or '') ~= ''
end
function p.excerpt(frame) -- Replicate {{Excerpt}} entirely in Lua for reduced Post-expand include size
local args = {} -- args[k] = frame.args[k] or frame:getParent().args[k] for all k in either (numeric or not)
for k, v in pairs(frame:getParent().args) do args[k] = v end
for k, v in pairs(frame.args) do args[k] = v end -- args from a Lua call have priority over parent args from template
local tag = is(args.tag) and args.tag or 'div'
local article = is(args.article) and args.article or args[1] or '{{{1}}}'
local section = is(args.section) and args.section or args[2]
local output = {}
output[1] = frame:extensionTag{ name = 'templatestyles', args = {src='Excerpt/styles.css'} }
output[2] = '<' .. tag .. 'class="excerpt-block">'
output[3] = is(args.indicator) and ('<' .. tag .. ' class="excerpt-indicator">') or ''
if is(args.nohat) then
output[4] = ''
else
local hatnote = {}
hatnote[1] = 'This' .. (is(args.indicator) and '' or ' section') .. ' is an excerpt from '
hatnote[2] = '[['
hatnote[3] = article .. (is(section) and frame:callParserFunction( 'urlencode', section, 'WIKI' ) or '')
hatnote[4] = '|'
hatnote[5] = article .. (is(section) and (frame:callParserFunction( '#tag:nowiki', ' § ' ) .. section) or '')
hatnote[6] = ']]'
hatnote[7] = "''" .. '<span class="mw-editsection-like plainlinks"><span>[ </span>['
hatnote[8] = frame:callParserFunction( 'fullurl', { article, action='edit' } ) .. edit
hatnote[9] = ']<span> ]</span></span>' .. "''"
output[4] = require('Module:Hatnote')_hatnote(table.concat(hatnote), {selfref=true})
end
output[5] = '<' .. tag .. 'class="excerpt">'
if article ~= '{{{1}}}' then
if is(args.fragment) then
output[6] = frame:callParserFunction( '#lst', article, args.fragment) or ''
else
local options = args -- pick up miscellaneous options: more, errors, fileargs
options.paraflags = numberflags(args.paragraphs or "") -- parse paragraphs, e.g. "1,3-5" → {"1","3-5"}
options.fileflags = numberflags(args.files or "1") -- parse file numbers
options.keepTables = is(args.tables) and args.tables or 1
options.keepRefs = is(args.references) and args.references or 1
options.keepSubsections = is(args.subsections) and args.subsections or 1
if options.more and options.more == "" then options.more = "Read more..." end -- more= is short for this default text
local text = main({ (article .. '#' .. section) }, options) or ''
if text == "" and d.brokenCategory and d.brokenCategory ~= "" and mw.title.getCurrentTitle().isContentPage then
output[6] = "[[Category:" .. d.brokenCategory .. "]]"
else
output[6] = frame:preprocess(text)
end
end
else
output[6] = err("No article provided")
end
output[6] = '</' .. tag .. '>'
output[7] = is(args.indicator) and ('</' .. tag .. '>') or ''
output[8] = '</' .. tag .. '>'
output[9] = mw.title.getCurrentTitle().isContentPage and '[[Category:Articles with excerpts]]' or ''
return table.concat(output)
end
|