Module:Transcluder: Difference between revisions

m
Set enwiki as central version
m (1 revision imported: Templates and CSS files)
imported>Sophivorus
m (Set enwiki as central version)
 
Line 1: Line 1:
-- Module:Transcluder is a general-purpose transclusion engine
-- Module:Transcluder is a general-purpose transclusion engine
-- Documentation https://www.mediawiki.org/wiki/Module:Transcluder
-- Central version and documentation at https://en.wikipedia.org/wiki/Module:Transcluder
-- By User:Sophivorus, User:Certes & others
-- By User:Sophivorus, User:Certes & others
-- Version 1.3
-- Version 1.4.1
-- License CC-BY-SA-3.0
-- License CC-BY-SA-3.0


Line 267: Line 267:
local params, count, parts, key, value
local params, count, parts, key, value
for template in string.gmatch(text, '{%b{}}') do
for template in string.gmatch(text, '{%b{}}') do
params = string.match(template, '{{[^|}]-|(.+)}}')
params = string.match(template, '{{[^|}]-|(.*)}}')
if params then
if params then
count = 0
count = 0
-- Temporarily replace pipes in subtemplates, tables and links to avoid chaos
-- Temporarily replace pipes in subtemplates, tables and links to avoid chaos
for subtemplate in string.gmatch(params, '%b{}') do
for subtemplate in string.gmatch(params, '%b{}') do
params = string.gsub(params, escapeString(subtemplate), string.gsub(string.gsub(subtemplate, '%%', '%%%%'), '|', '@@@') )
params = string.gsub(params, escapeString(subtemplate), string.gsub(subtemplate, ".", {["%"]="%%", ["|"]="@@:@@", ["="]="@@_@@"}) )
end
end
for link in string.gmatch(params, '%b[]') do
for link in string.gmatch(params, '%b[]') do
params = string.gsub(params, escapeString( mw.ustring.gsub(link, '%%', '%%%%') ), string.gsub(link, '|', '@@@') )
params = string.gsub(params, escapeString(link), string.gsub(link, ".", {["%"]="%%", ["|"]="@@:@@", ["="]="@@_@@"}) )
end
end
for parameter in mw.text.gsplit(params, '|') do
for parameter in mw.text.gsplit(params, '|') do
parts = mw.text.split(parameter, '=')
parts = mw.text.split(parameter, '=')
key = mw.text.trim(parts[1])
key = mw.text.trim(parts[1])
value = table.concat(parts, '=', 2)
if #parts == 1 then
if value == '' then
value = key
value = key
count = count + 1
count = count + 1
key = count
key = count
else
else
value = mw.text.trim(value)
value = mw.text.trim(table.concat(parts, '=', 2))
end
end
value = string.gsub(value, '@@@', '|')
value = string.gsub(string.gsub(value, '@@:@@', '|'), '@@_@@', '=')
if not blacklist and ( not flags or matchFlag(key, flags) )
if not blacklist and ( not flags or matchFlag(key, flags) )
or blacklist and flags and not matchFlag(key, flags) then
or blacklist and flags and not matchFlag(key, flags) then
Line 571: Line 570:
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
local page = escapeString(mw.title.getCurrentTitle().prefixedText)
local ucpage = lang:ucfirst(page)
local lcpage = lang:lcfirst(page)
text = text
text = text
:gsub('%[%[(' .. lang:ucfirst(page) .. ')%]%]', '%1')
:gsub('%[%[(' .. ucpage .. ')%]%]', '%1')
:gsub('%[%[(' .. lang:lcfirst(page) .. ')%]%]', '%1')
:gsub('%[%[(' .. lcpage .. ')%]%]', '%1')
:gsub('%[%[' .. lang:ucfirst(page) .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. ucpage .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lang:lcfirst(page) .. '|([^]]+)%]%]', '%1')
:gsub('%[%[' .. lcpage .. '|([^]]+)%]%]', '%1')
return text
return text
end
end
Anonymous user