« Module:Version imprimable » : différence entre les versions
Contenu supprimé Contenu ajouté
Aucun résumé des modifications |
MEP |
||
Ligne 46 :
-- Book subpages titles normalization to absolute names
local lines_ = mw.text.split(text, "\n")
local
local PrintVersion = {}
for i,v in ipairs(lines_) do
if mw.text.trim(v) ~= '' then
if
ChapterTitle = mw.title.new(
if (ChapterTitle ~= nil and ChapterTitle.exists) then
PageName =
if (PageName ~= nil and PageName ~= '') then
if Break ~= "" then table.insert(PrintVersion, frame:expandTemplate{title = Break}) end
table.insert(PrintVersion, '\n<div style="clear:both;"></div>\n=' .. PageName .. '=\n')
end
table.insert(PrintVersion, frame:expandTemplate{ title = ':' ..
else
if debug then table.insert(PrintVersion, '<font color=red>Missing subpage "' ..
end
end
end
end
Ligne 78 :
function p.
if frame == nil then return '' end
if frame.args == nil then return '' end
if frame.args[1] == nil then return '' end
if frame.args[2] == nil then return '' end
return p.
end
function p.
if (BookName ~= nil and mw.text.trim(BookName) ~= '') or (chapter ~= nil and mw.text.trim(chapter) ~= '') then
BookName = mw.text.trim(BookName)
Ligne 108 ⟶ 109 :
chapter = mw.ustring.gsub(chapter, "%/$", "")
if mw.ustring.find(chapter, "%[%[") ~= nil then
-- Pages titles extraction from the TOC
if mw.ustring.find(chapter, "%|") == nil or (mw.ustring.find(chapter, "%]") ~= nil and mw.ustring.find(chapter, "%|") > mw.ustring.find(chapter, "%]")) then
Ending = "%]"
else▼
if mw.ustring.find(chapter, "%/%|") == nil or mw.ustring.find(chapter, "%/%|") > mw.ustring.find(chapter, "%|") then▼
Ending = "%|"▼
else
▲ if mw.ustring.find(chapter, "%/%|") == nil or mw.ustring.find(chapter, "%/%|") > mw.ustring.find(chapter, "%|") then
Ending = "%/%|"▼
▲ Ending = "%|"
else▼
▲ Ending = "%/%|"
end▼
end
end▼
chapter = mw.text.split(chapter, Ending)[1] -- extraction of the line beginning
--chapter = mw.text.split(chapter, "%[%[")[2]
Ligne 135 ⟶ 136 :
if debug then chapter = "<font color=red>No internal link</font> for: " .. chapter .. "\n" else chapter = '' end
end
return chapter
end
function p.getSubpageName(bookName, fullPageName)
k, v = mw.ustring.gsub(fullPageName, bookName .. '/', '')
return k
end
function p.extract_subpageName(frame)
if frame == nil then return '' end
if frame.args == nil then return '' end
if frame.args[1] == nil then return '' end
if frame.args[2] == nil then return '' end
return p.getSubpageName(frame.args[1], frame.args[2])
end
Ligne 144 ⟶ 160 :
if frame.args == nil then return "" end
if frame.args[1] == nil then return "" end
local
local currentPageName = frame.args[2]▼
local BookName = frame.args[1]
if (BookName ~= nil and mw.text.trim(BookName) ~= "") then
title = mw.title.new(BookName)
Ligne 154 ⟶ 170 :
end
local currentPageName
if currentPageName == nil or currentPageName == '' then currentPageName = mw.title.getCurrentTitle().subpageText end▼
if frame.args[2] ~= nil and frame.args[2] ~= '' then
▲ else
▲
▲ end
if (currentPageName ~= nil and mw.text.trim(currentPageName) ~= "") then
currentPageName = mw.text.trim(currentPageName)
Ligne 160 ⟶ 181 :
return Error
end
if (title == nil or title == "") then return Error end
Ligne 167 ⟶ 189 :
-- Book subpages titles normalization to absolute names
local lines_ = mw.text.split(text, "\n")
local footer = {}▼
local previousChapter = ""
local found = false
local
local rawFullPageName
for i, v in ipairs(lines_) do
if
if
▲ end
if mw.ustring.find(fullPageName, p._escapePattern(BookName .. sep)) == nil then
if debug then
if found == true then▼
theTemplateLeft, nb = mw.ustring.gsub(templateLeft, "printf", BookName .. sep .. previousChapter .. "|" .. previousChapter)▼
if debug then table.insert(footer, "<font color=red>Previous & next chapter insertion</font>\n") end
theTemplateLeft, nb = mw.ustring.gsub(templateLeft, "printf", BookName .. "|" .. TOC)
▲ theTemplateLeft, nb = mw.ustring.gsub(templateLeft, "printf", BookName .. sep .. previousChapter .. "|" .. previousChapter)
end▼
table.insert(footer, theTemplateLeft)▼
theTemplateRight, nb = mw.ustring.gsub(templateRight, "printf", BookName .. sep ..
table.insert(footer, theTemplateRight)▼
break
if debug then table.insert(footer, "<font color=red>Page</font> '" .. currentPageName .. "' found\n\n") end
found = true
if debug then table.insert(footer, " " .. subpageName .. " is different from " .. currentPageName .. "\n") end
previousChapter = subpageName
else
if debug then table.insert(footer, "<font color=red>The current page</font> '" .. subpageName .. "' is not '" .. currentPageName .. "'") end
end
end
▲ table.insert(footer, theTemplateLeft)
▲ theTemplateRight, nb = mw.ustring.gsub(templateRight, "printf", BookName .. sep .. PageName .. "|" .. PageName)
▲ table.insert(footer, theTemplateRight)
▲ break
▲ 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
▲ 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
Ligne 209 ⟶ 239 :
if found == true and table.getn(footer) == 0 then
if debug then table.insert(footer, "<font color=red>No next chapter</font>\n") end
theTemplateLeft, nb = mw.ustring.gsub(templateLeft, "printf", BookName .. sep .. previousChapter .. "|" .. previousChapter)
table.insert(footer, theTemplateLeft)
theTemplateRight, nb = mw.ustring.gsub(templateRight, "printf", BookName .. "|" .. TOC)
table.insert(footer, theTemplateRight)
end
|