Modulo:Transcluder: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Update to 1.1
Update from master using #Synchronizer
 
(6 versioni intermedie di 2 utenti non mostrate)
Riga 1:
-- Module:Transcluder is a general-purpose transclusion engine
-- Documentation and master version: https://wwwen.mediawikiwikipedia.org/wiki/Module:Transcluder
-- ByAuthors: User:Sophivorus, User:Certes & others
-- VersionLicense: 1CC-BY-SA-3.10
-- License CC-BY-SA-4.0
 
local p = {}
Line 103 ⟶ 102:
value = tostring(value)
local lang = mw.language.getContentLanguage()
local lcvalue = lang:lcfirst(value)
local ucvalue = lang:ucfirst(value)
for flag in pairs(flags) do
if value == tostring(flag)
or lang:lcfirst(value)lcvalue == flag
or lang:ucfirst(value)ucvalue == flag
or ( not tonumber(flag) and mw.ustring.match(value, flag) ) then
return true
Line 154 ⟶ 155:
-- For file pages, returns the content of the file description page
local function getText(page, noFollow)
page = mw.text.decode(page)
local title = mw.title.new(page)
if not title then return false, false end
Line 241 ⟶ 243:
for template in string.gmatch(text, '{%b{}}') do
if string.sub(template, 1, 3) ~= '{{#' then -- skip parser functions like #if
name = mw.text.trim( string.match(template, '{{([^}|\n]+)') or "" ) -- get the template name
countif =name count~= +"" 1then
count = count + 1
if not blacklist and ( not flags or flags[count] or matchFlag(name, flags) )
or blacklist and flags and not flags[count] and not matchFlag(name, flags) then
table.insert(templates, template)
else
text = removeString(text, template)
end
end
end
Line 259 ⟶ 263:
-- @return Map from parameter name to value, NOT IN THE ORIGINAL ORDER
-- @return Original wikitext minus requested parameters.
-- @return Order in which the parameters were parsed.
local function getParameters(text, flags)
local parameters, parameterOrder = {}, {}
local flags, blacklist = parseFlags(flags)
local params, count, parts, key, value
for template in string.gmatch(text, '{%b{}}') do
params = string.match(template, '{{[^|}]-|(.+*)}}')
if params then
count = 0
-- Temporarily replace pipes in subtemplates, tables and links to avoid chaos
for subtemplate in string.gmatch(params, '{%b{}}') do
params = string.gsub(params, escapeString(subtemplate), string.gsub(string.gsub(subtemplate, '%%'".", '{["%"]="%%%')", '["|'"]="@@:@@", '["="]="@@_@@'"}) )
end
for link in string.gmatch(params, '%b[]') do
params = string.gsub(params, escapeString(link), mw.ustringstring.gsub(link, '%%'".", '{["%"]="%%%') )", string.gsub(link, '["|'"]="@@:@@", '["="]="@@_@@'"}) )
end
for parameter in mw.text.gsplit(params, '|') do
parts = mw.text.split(parameter, '=')
key = mw.text.trim(parts[1])
valueif = table.concat(#parts, '=',= 1 2)then
if value == '' then
value = key
count = count + 1
key = count
else
value = mw.text.trim(valuetable.concat(parts, '=', 2))
end
value = string.gsub(string.gsub(value, '@@:@@', '|'), '@@_@@', '=')
if not blacklist and ( not flags or matchFlag(key, flags) )
or blacklist and flags and not matchFlag(key, flags) then
table.insert(parameterOrder, key)
parameters[key] = value
else
Line 295 ⟶ 300:
end
end
return parameters, text, parameterOrder
end
 
Line 334 ⟶ 339:
elements, temp = getFiles(temp, 0) -- remove files
temp = mw.text.trim((temp
:gsub('\n%b{} *\n', '\n%0\n') -- add spacing between tables and block templates
:gsub('\n%b{} *\n', '\n') -- remove tables and block templates
:gsub('\n==+[^=]+==+ *\n', '\n') -- remove section titles
))
 
Line 567 ⟶ 572:
local lang = mw.language.getContentLanguage()
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
local ucpage = lang:ucfirst(page)
local lcpage = lang:lcfirst(page)
text = text
:gsub('%[%[(' .. lang:ucfirst(page)ucpage .. ')%]%]', '%1')
:gsub('%[%[(' .. lang:lcfirst(page)lcpage .. ')%]%]', '%1')
:gsub('%[%[' .. lang:ucfirst(page)ucpage .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lang:lcfirst(page)lcpage .. '|([^]]+)%]%]', '%1')
return text
end
Line 578 ⟶ 585:
local function removeLinks(text)
text = text
:gsub('%[%[[^%]|]+|([^]]+)%]%]', '%1')
:gsub('%[%[([^]]+)%]%]', '%1')
:gsub('%[[^ ]+ ([^]]+)%]', '%1')
:gsub('%[([^]]+)%]', '%1')
return text
end
Line 608 ⟶ 617:
if not page then return throwError('no-page') end
page = mw.text.trim(page)
page = mw.text.decode(page)
if page == '' then return throwError('no-page') end
local page, hash, section = string.match(page, '([^#]+)(#?)(.*)')
local text, pagetemp = getText(page, options.noFollow)
if not pagetemp then return throwError('noinvalid-pagetitle', page) end
page = temp
if not text then return throwError('page-not-found', page) end
local full = text -- save the full text for fixReferences below
Line 676 ⟶ 687:
local ok, text = pcall(get, page, args)
if not ok then return getError(text) end
local raw = args['raw']
if raw then return text end
return frame:preprocess(text)
end