« Module:Version imprimable » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
MEP
Ligne 15 :
 
local p = {}
 
 
function p._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );
end
 
 
function p.displays_book(frame)
Ligne 26 ⟶ 32 :
BookName = frame.args[2]
else
if mw.ustring.find(BookName, p._escapePattern(sep .. TOC)) ~= nil then BookName = mw.ustring.gsub(BookName, "^(.*)" .. sep .. TOC .. "$", "%1") end
end
if frame.args[3] ~= nil then OnlySubpages = false end
Ligne 124 ⟶ 130 :
 
-- Book subpages only (and ignoring the other links like "see also")
if mw.ustring.find(chapter, p._escapePattern(BookName .. sep)) == nil then
if debug then chapter = '"<font color=red>No book subpage into the internal link:</font> '" .. chapter .. "' doesn't include '" .. BookName .. sep .. "'" else chapter = '' end
end
end
end
else
if debug then chapter = '"<font color=red>No internal link</font>' for: " .. chapter .. "\n" else chapter = '' end
end
return chapter
Ligne 137 ⟶ 143 :
 
function p.displays_footer(frame)
-- ébauche
if frame == nil then return '' end
if frame.args == nil then return '' end
if frame.args[1] == nil then return '' end
local BookName = frame.args[1]
local currentPageName = frame.args[2]
 
if (BookName ~= nil and mw.text.trim(BookName) ~= '') then
title = mw.title.new(BookName)
if mw.ustring.find(BookName, p._escapePattern(sep .. TOC)) ~= nil then BookName = mw.ustring.gsub(BookName, "^(.*)" .. sep .. TOC .. "$", "%1") end
else
return Error
end
 
if frame.args[2](currentPageName ~= nil and mw.text.trim(currentPageName) ~= '') then
local currentPageName = framemw.args[2]text.trim(currentPageName)
else
return Error
Ligne 169 ⟶ 176 :
chapter = p.subpage(BookName, v)
if chapter ~= nil then
if mw.ustring.find(chapter, p._escapePattern(BookName .. sep)) == nil then
chapter = BookName .. sep .. chapter
end
ChapterTitle = mw.title.new(chapter)
if (ChapterTitle ~= nil and ChapterTitle.exists) then
Ligne 179 ⟶ 189 :
elseif PageName == currentPageName then
found = true
if debug then table.insert(footer, "<font color=red>Page</font> '" .. currentPageName .. "' found\n\n") end
elseif mw.text.trim(v) ~= '' then
previousChapter = PageName
else
if debug then table.insert(footer, "<font color=red>The current page</font> '" .. PageName .. "' is not '" .. currentPageName .. "'") end
end
end
else
if debug then table.insert(footer, "<font color=red>The page</font> '" .. chapter .. "' doesn't exist, for '" .. currentPageName .. "'\n\n") end
end
end
end
 
if found == true and table.getn(footer) == 0 then
-- No next chapter
table.insert(footer, previousChapter)
table.insert(footer, '../')
end