Modul:Excerpt: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
k Melindungi "Modul:Excerpt" ([Sunting=Hanya untuk pengguna terdaftar otomatis] (selamanya) [Pindahkan=Hanya untuk pengguna terdaftar otomatis] (selamanya))
Update to 1.2
Baris 1:
-- Module:Excerpt implements the Excerpt template
-- Documentation https://www.mediawiki.org/wiki/Module:Excerpt
-- By User:Sophivorus, User:Certes & others
-- Version 1.2
-- License CC-BY-SA-4.0
 
local Transcluder = require('Module:Transcluder')
 
Baris 48 ⟶ 54:
page = title.prefixedText
 
-- Set variables from the template parameters
local fragmentsection = getArg(2, mw.ustring.match( getArg(1), 'fragment[^#]+#(.+)') )
local section = fragment or getArg(2, getArg('section', mw.ustring.match(getArg(1), '[^#]+#([^#]+)') ) )
local hat = yesno( getArg('hat', true) )
local edit = yesno( getArg('edit', true) )
Baris 60 ⟶ 65:
local templates = getArg('templates', getArg('template', ( only == 'template' and 1 ) ) )
local paragraphs = getArg('paragraphs', getArg('paragraph', ( only == 'paragraph' and 1 ) ) )
local references = getArg('references', getArg('reference', ( only == 'reference' and 1 ) ) )
local sectionssubsections = not yesno( getArg('sectionssubsections') )
local noBold = not yesno( getArg('bold') )
local freefiles = yesno( getArg('freefiles') )
local inline = yesno( getArg('inline') )
local quote = yesno( getArg('quote') )
local more = yesno( getArg('more') )
local class = getArg('class')
local blacklist = table.concat((config.templates or {}), ',')
 
-- Build the hatnote
Baris 83 ⟶ 88:
if section and not fragment then
hat = hat .. '[[:' .. page .. '#' .. mw.uri.anchorEncode(section) .. '|' .. page
.. ' § ' .. mw.ustring.gsub(section, '%[%[([^]|]+)|?[^]]*%]%]', '%1') .. ']].' -- remove nested links
else
hat = hat .. '[[:' .. page .. '|' .. page .. ']].'
end
if edit then
hat = hat .. "''" .. '<span class="mw-editsection-like plainlinks"><span class="mw-editsection-bracket">[</span>['
hat = hat .. title:fullUrl('action=edit') .. ' ' .. mw.message.new('editsection'):plain()
hat = hat .. ']<span class="mw-editsection-bracket">]</span></span>' .. "''"
end
if config.hat then
hat = config.hat .. hat .. '}}'
hat = frame:preprocess(hat)
else
hat = mw.html.create('div'):addClass('dablink excerpt-hat'):wikitext(hat)
end
hat = mw.html.create('div'):addClass('dablink excerpt-hat'):wikitext(hat)
else
hat = nil
Baris 109 ⟶ 115:
end
 
-- Build the options for Module:Transcluder out of the template argumentsparameters and the desired defaults
local options = {
files = files,
Baris 115 ⟶ 121:
tables = tables,
paragraphs = paragraphs,
sections = sectionssubsections,
templates = templates or '-' .. blacklist,
sections = sections,
categories = 0,
references = references,
Baris 122 ⟶ 127:
noBold = noBold,
noSelfLinks = true,
noNonFreeFiles = truefreefiles,
noBehaviorSwitches = true,
fixReferences = true,
Baris 132 ⟶ 137:
local ok, excerpt = pcall(Transcluder.get, title, options)
if not ok then return getError(excerpt) end
if mw.text.trim(excerpt) == '' and not only then
if section then return getError('section-empty', section) else return getError('lead-empty') end
end
 
-- If no file was found, try to excerptget one from the removed infoboxesinfobox
-- Add a line break in case the excerpt starts with a table or list
excerpt = '\n' .. excerpt
 
-- If no file was found, try to excerpt one from the removed infoboxes
local fileNamespaces = Transcluder.getNamespaces('File')
if ((only == 'file' or only == 'files') or (not only and (files ~= '0' or not files))) and not-- Transcluder.matchAny(excerpt,caller '%[%[',asked fileNamespaces,for ':') and config.captions thenfiles
not Transcluder.matchAny(excerpt, '%[%[', fileNamespaces, ':') and -- and there are no files in Transcluder's output
local templates = Transcluder.get(title, { only = 'templates', templates = blacklist, fixReferences = true } )
config.captions -- and we have the config option required to try finding files in templates
local parameters = Transcluder.getParameters(templates)
then
-- We cannot distinguish the infobox from the other templates so we search them all
local infobox = Transcluder.getTemplates(excerpt);
infobox = table.concat(infobox)
local parameters = Transcluder.getParameters(templatesinfobox)
local file, captions, caption
for _, pair in pairs(config.captions) do
Baris 155 ⟶ 162:
end
excerpt = '[[File:' .. file .. '|thumb|' .. (caption or '') .. ']]' .. excerpt
if ( freefiles ) then
excerpt = Transcluder.removeNonFreeFiles(excerpt)
end
break
end
end
end
 
-- Unlike other elements, templates are filtered here
-- because we had to search the infoboxes for files
local trash
if only and (only == 'template' or only == 'templates') then
trash, excerpt = Transcluder.getTemplates(excerpt, templates);
else -- Remove blacklisted templates
local blacklist = config.blacklist and table.concat((config.templates or {})blacklist, ',') or ''
if templates then
if string.sub(templates, 1, 1) == '-' then --Unwanted templates. Append to blacklist
templates blacklist = templates or.. '-,' .. blacklist,
else --Wanted templates. Replaces blacklist and acts as whitelist
blacklist = templates
end
else
blacklist = '-' .. blacklist
end
trash, excerpt = Transcluder.getTemplates(excerpt, blacklist);
end
 
-- Remove extra line breaks but leave one before and after so the parser interprets lists, tables, etc. correctly
excerpt = mw.text.trim(excerpt)
excerpt = string.gsub(excerpt, '\n\n\n+', '\n\n')
excerpt = '\n' .. excerpt .. '\n'
 
-- Remove nested categories