Module:Transcluder: Difference between revisions

Created page with "-- Module:Transcluder is a general-purpose transclusion engine -- Documentation and master version: https://en.wikipedia.org/wiki/Module:Transcluder -- Authors: User:Sophivorus, User:Certes & others -- License: CC-BY-SA-3.0 local p = {} -- Helper function to test for truthy and falsy values -- @todo Somehow internationalize it local function truthy(value) if not value or value == '' or value == 0 or value == '0' or value == 'false' or value == 'no' or value == 'non' t..."
 
No edit summary
 
Line 155: Line 155:
-- For file pages, returns the content of the file description page
-- For file pages, returns the content of the file description page
local function getText(page, noFollow)
local function getText(page, noFollow)
page = mw.text.decode(page)
local title = mw.title.new(page)
local title = mw.title.new(page)
if not title then return false, false end
if not title then return false, false end
Line 242: Line 243:
for template in string.gmatch(text, '{%b{}}') do
for template in string.gmatch(text, '{%b{}}') do
if string.sub(template, 1, 3) ~= '{{#' then -- skip parser functions like #if
if string.sub(template, 1, 3) ~= '{{#' then -- skip parser functions like #if
name = mw.text.trim( string.match(template, '{{([^}|\n]+)') ) -- get the template name
name = mw.text.trim( string.match(template, '{{([^}|\n]+)') or "" ) -- get the template name
count = count + 1
if name ~= "" then
if not blacklist and ( not flags or flags[count] or matchFlag(name, flags) )
count = count + 1
or blacklist and flags and not flags[count] and not matchFlag(name, flags) then
if not blacklist and ( not flags or flags[count] or matchFlag(name, flags) )
table.insert(templates, template)
or blacklist and flags and not flags[count] and not matchFlag(name, flags) then
else
table.insert(templates, template)
text = removeString(text, template)
else
text = removeString(text, template)
end
end
end
end
end
Line 614: Line 617:
if not page then return throwError('no-page') end
if not page then return throwError('no-page') end
page = mw.text.trim(page)
page = mw.text.trim(page)
page = mw.text.decode(page)
if page == '' then return throwError('no-page') end
if page == '' then return throwError('no-page') end
local page, hash, section = string.match(page, '([^#]+)(#?)(.*)')
local page, hash, section = string.match(page, '([^#]+)(#?)(.*)')
Line 683: Line 687:
local ok, text = pcall(get, page, args)
local ok, text = pcall(get, page, args)
if not ok then return getError(text) end
if not ok then return getError(text) end
local raw = args['raw']
if raw then return text end
return frame:preprocess(text)
return frame:preprocess(text)
end
end