Content deleted Content added
m Changed protection level for "Module:Excerpt": Highly visible module, matching Template:Excerpt ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) |
|||
Line 750:
return frame:preprocess(text)
end
end
local function is(v)
return (v or '') ~= ''
end
local function 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>['
local title = mw.title.new(article) or mw.title.getCurrentTitle()
hatnote[8] = title:fullUrl('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">\n'
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.nobold=1
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 ""
if options.more and options.more == "" then options.more = "Read more..." end -- more= is short for this default text
local pagenames = { (article .. '#' .. (section or '')) }
local text = main(pagenames, options)
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[7] = '</' .. tag .. '>'
output[8] = is(args.indicator) and ('</' .. tag .. '>') or ''
output[9] = '</' .. tag .. '>'
output[10] = mw.title.getCurrentTitle().isContentPage and '[[Category:Articles with excerpts]]' or ''
return table.concat(output)
end
Line 758 ⟶ 826:
function p.random(frame) return invoke(frame, "random") end -- {{Transclude random excerpt}} reads any article (default for invoke with one argument)
function p.selected(frame) return invoke(frame, "selected") end -- {{Transclude selected excerpt}} reads the article whose key is in the selected= parameter
function p.excerpt(frame) return excerpt(frame) end -- {{Excerpt}} transcludes part of an article into another article
-- Entry points for other Lua modules
|