Modul:Transcluder: Perbedaan antara revisi
Konten dihapus Konten ditambahkan
Sophivorus (bicara | kontrib) Menyalin satu revisi oleh Sophivorus,Leoncastro: "Bugfix,Remove non-free images,Fix non-free image removal" dari mw:Module:Transcluder. (dokumentasi, terjemahan) |
Sophivorus (bicara | kontrib) 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
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
value = tostring(value)
local lang = mw.language.getContentLanguage()
for flag in pairs(flags) do
if
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.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
or blacklist and flags and not flags[count] and not
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
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 key, element in pairs(elements) do
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.
if truthy(options.noLinks) then text = removeLinks(text) end
if truthy(options.noSelfLinks) then text = removeSelfLinks(text) end
if truthy(options.
if truthy(options.noBehaviorSwitches) then text =
if truthy(options.noComments) then text =
-- 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
|