Modul:Transcluder: Perbedaan antara revisi

Konten dihapus Konten ditambahkan
Menyalin satu revisi oleh Sophivorus,Leoncastro: "Bugfix,Remove non-free images,Fix non-free image removal" dari mw:Module:Transcluder. (dokumentasi, terjemahan)
Menyalin satu revisi oleh Sophivorus: "(no summary)" dari mw:Module:Transcluder. (dokumentasi, terjemahan)
Baris 67:
end
 
-- List has the form { [1] = false, [2] = true, ['c'] = false }
-- Convert it to { [1] = true, [2] = true, ['c'] = true }
-- But if ANY value is set to false, treat the list as a blacklist
elseif type(value) == 'table' then
 
-- List has the form { [1] = false, [2] = true, ['c'] = false }
-- Convert it to { [1] = true, [2] = true, ['c'] = true }
-- But if ANY value is set to false, treat the list as a blacklist
for i, v in pairs(value) do
if v == false then blacklist = true end
Baris 83 ⟶ 82:
-- Helper function to see if a value matches any of the given flags
local function matchFlag(value, flags)
if type(not value) == 'number' then valuereturn = tostring(value)false end
value = tostring(value)
local lang = mw.language.getContentLanguage()
for flag in pairs(flags) do
if lang:lcfirst(value) == tostring(flag)
or lang:lcfirst(value) == flag
or lang:ucfirst(value) == flag
or ( not tonumber(flag) and mw.ustring.match(value, flag) ) then
return true
end
Baris 316 ⟶ 317:
temp = mw.ustring.gsub(temp, '\n%b{}\n', '\n') -- remove tables and block templates
temp = mw.ustring.gsub(temp, '\n==+[^=]+==+\n', '\n') -- remove section titles
temp = mw.ustring.gsub(temp, '\n\n\n+', '\n\n')
temp = mw.text.trim(temp)
 
-- Assume that anything remaining is a paragraph
local count = 0
for paragraph in mw.text.gsplit(temp, '\n\n+') do
if mw.text.trim(paragraph) ~= '' then
count = count + 1
Baris 375:
name = mw.ustring.match(reference, '<%s*[Rr][Ee][Ff][^>]*name%s*=%s*["\']?([^"\'>/]+)["\']?[^>]*%s*>')
count = count + 1
if not blacklist and ( not flags or flags[count] or flags[matchFlag(name], flags) )
or blacklist and flags and not flags[count] and not flags[matchFlag(name], flags) then
table.insert(references, reference)
else
Baris 539:
text = mw.ustring.gsub(text, '%[%[' .. lang:ucfirst(page) .. '|([^]]+)%]%]', '%1')
text = mw.ustring.gsub(text, '%[%[' .. lang:lcfirst(page) .. '|([^]]+)%]%]', '%1')
return text
end
 
-- Remove all wikilinks
function removeLinks(text)
text = mw.ustring.gsub(text, '%[%[[^|]+|([^]]+)%]%]', '%1')
text = mw.ustring.gsub(text, '%[%[([^]]+)%]%]', '%1')
return text
end
 
-- Remove HTML comments
function removeComments(text)
text = mw.ustring.gsub(text, '<!%-%-.-%-%->', '')
return text
end
 
-- Remove behavior switches, such as __NOTOC__
function removeBehaviorSwitches(text)
text = mw.ustring.gsub(text, '__[A-Z]+__', '')
return text
end
 
-- Remove bold text
function removeBold(text)
text = mw.ustring.gsub(text, "'''", '')
return text
end
Baris 563 ⟶ 588:
 
-- Keep only the requested elements
local elements
local only = parseFlags(options.only) or {}
local elements = {}
if options.sections or only.sections then
elements.sections, text = getSections(text, options.sections)
end
if options.lists or only.lists then
elements.lists, text = getLists(text, options.lists)
end
if options.files or only.files then
elements.files, text = getFiles(text, options.files)
end
if options.tables or only.tables then
elements.tables, text = getTables(text, options.tables)
end
if options.templates or only.templates then
elements.templates, text = getTemplates(text, options.templates)
end
if options.parameters or only.parameters then
elements.parameters, text = getParameters(text, options.parameters)
end
if options.paragraphs or only.paragraphs then
elements.paragraphs, text = getParagraphs(text, options.paragraphs)
end
if options.categories or only.categories then
elements.categories, text = getCategories(text, options.categories)
end
if options.references or only.references then
elements.references, text = getReferences(text, options.references)
end
 
-- If 'only' is set, return the elements in the requested order
if options.only then
if options.only == 'sections' then elements = getSections(text, options.sections) end
if options.only == 'lists' then elements = getLists(text, options.lists) end
if options.only == 'files' then elements = getFiles(text, options.files) end
if options.only == 'tables' then elements = getTables(text, options.tables) end
if options.only == 'templates' then elements = getTemplates(text, options.templates) end
if options.only == 'parameters' then elements = getParameters(text, options.parameters) end
if options.only == 'paragraphs' then elements = getParagraphs(text, options.paragraphs) end
if options.only == 'categories' then elements = getCategories(text, options.categories) end
if options.only == 'references' then elements = getReferences(text, options.references) end
text = ''
if elements then
for element in mw.text.gsplit(options.only, ',') do
for key, element in pairs(elements) do
element = elements[ mw.text.trim(element) ]
if text = text .. '\n' .. element then.. '\n'
for key, value in pairs(element) do
text = text .. '\n' .. value .. '\n'
end
end
end
end
 
-- Filter the requested elements
if options.sections and options.only ~= 'sections' then elements, text = getSections(text, options.sections) end
if options.lists and options.only ~= 'lists' then elements, text = getLists(text, options.lists) end
if options.files and options.only ~= 'files' then elements, text = getFiles(text, options.files) end
if options.tables and options.only ~= 'tables' then elements, text = getTables(text, options.tables) end
if options.templates and options.only ~= 'templates' then elements, text = getTemplates(text, options.templates) end
if options.parameters and options.only ~= 'parameters' then elements, text = getParameters(text, options.parameters) end
if options.paragraphs and options.only ~= 'paragraphs' then elements, text = getParagraphs(text, options.paragraphs) end
if options.categories and options.only ~= 'categories' then elements, text = getCategories(text, options.categories) end
if options.references and options.only ~= 'references' then elements, text = getReferences(text, options.references) end
 
-- Misc options
if truthy(options.fixReferences) then text = fixReferences(text, page, full) end
if truthy(options.linkBold) then text = linkBold(text, page) end
if truthy(options.noNonFreeFilesnoBold) then text = removeNonFreeFilesremoveBold(text) end
if truthy(options.noLinks) then text = removeLinks(text) end
if truthy(options.noSelfLinks) then text = removeSelfLinks(text) end
if truthy(options.noBoldnoNonFreeFiles) then text = mw.ustring.gsubremoveNonFreeFiles(text, "'''", '') end
if truthy(options.noBehaviorSwitches) then text = mw.ustring.gsubremoveBehaviorSwitches(text, '__[A-Z]+__', '') end
if truthy(options.noComments) then text = mw.ustring.gsubremoveComments(text, '<!%-%-.-%-%->', '') end
 
-- Remove multiple newlines left over from removing elements
Baris 656 ⟶ 669:
function p.matchFlag(value, flags) return matchFlag(value, flags) end
function p.getNamespaces(name) return getNamespaces(name) end
function p.removeBold(text) return removeBold(text) end
function p.removeLinks(text) return removeLinks(text) end
function p.removeSelfLinks(text) return removeSelfLinks(text) end
function p.removeNonFreeFiles(text) return removeNonFreeFiles(text) end
function p.removeBehaviorSwitches(text) return removeBehaviorSwitches(text) end
function p.removeComments(text) return removeComments(text) end
 
return p