« 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 chapterfullPageName
local PrintVersion = {}
for i,v in ipairs(lines_) do
if mw.text.trim(v) ~= '' then
chapterfullPageName = p.subpagegetFullPageName(BookName, v)
if chapterfullPageName ~= nil then
ChapterTitle = mw.title.new(chapterfullPageName)
if (ChapterTitle ~= nil and ChapterTitle.exists) then
PageName = mwp.ustring.gsubgetSubpageName(chapter, "[^"..sep.."]*"..sep.."*(.*)"BookName, "%1"fullPageName)
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 = ':' .. chapterfullPageName } .. '\n\n')
else
if debug then table.insert(PrintVersion, '<font color=red>Missing subpage "' .. chapterfullPageName .. '" on line "' .. v .. '" for the book:</font> ' .. BookName .. '\n\n') end
end
end
end
end
Ligne 78 :
 
 
function p.extract_subpageextract_fullPageName(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.subpagegetFullPageName(frame.args[1], frame.args[2])
end
 
 
function p.subpagegetFullPageName(BookName, chapter)
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 BookNamefooter = frame.args[1]{}
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
local currentPageName = frame.args[2]
else
if currentPageName == nil or currentPageName == '' then currentPageName =p.getSubpageName(BookName, mw.title.getCurrentTitle().subpageText endfullText)
end
if (currentPageName ~= nil and mw.text.trim(currentPageName) ~= "") then
currentPageName = mw.text.trim(currentPageName)
Ligne 160 ⟶ 181 :
return Error
end
if debug then table.insert(footer, "<font colorcurrentPageName =red>Page</font> '" .. currentPageName .. "' found\n\n") 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 chapterfullPageName
local footer = {}subpageName
local rawFullPageName
 
for i, v in ipairs(lines_) do
chapterrawFullPageName = pmw.subpagetext.trim(BookName, v)
if chapterrawFullPageName ~= nil'' then
if mw.ustringdebug then table.findinsert(chapterfooter, p" research into: " ._escapePattern(BookName. rawFullPageName .. sep)"\n") == nil thenend
chapterfullPageName = p.getFullPageName(BookName, .. sep .. chapterrawFullPageName)
if debug then table.insert(footer, "<font color=red>The page</font> '" .. chapter .. "' doesn't exist,extraction forof: '" .. currentPageNamefullPageName .. "'\n\n") end
end
ChapterTitleif fullPageName ~= mw.title.new(chapter)nil then
if mw.ustring.find(fullPageName, p._escapePattern(BookName .. sep)) == nil then
if (ChapterTitle ~= nil and ChapterTitle.exists) then
PageName fullPageName = mw.ustring.gsub(chapter,BookName "[^".. sep .."]*"..sep.."*(.*)", "%1")fullPageName
if (PageName ~= nil and PageName ~= "") thenend
if foundChapterTitle == true thenmw.title.new(fullPageName)
if debug then table.insert(footer,ChapterTitle "<font color~=red>Previous &nil nextand chapter insertion</font>\n"ChapterTitle.exists) endthen
ifsubpageName previousChapter == ""p.getSubpageName(BookName, thenfullPageName)
if debug then theTemplateLefttable.insert(footer, nb" =cut mw.ustring.gsub(templateLeft,subpage: "printf", BookName .. "|"subpageName .. TOC"\n") end
elseif (subpageName ~= nil and subpageName ~= "") 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
if previousChapter == "" PageNamethen
theTemplateLeft, nb = mw.ustring.gsub(templateLeft, "printf", BookName .. "|" .. TOC)
break else
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 .. PageNamesubpageName .. "|" .. PageNamesubpageName)
table.insert(footer, theTemplateRight)
break
elseif PageNamesubpageName == currentPageName then
if debug then table.insert(footer, "<font color=red>Page</font> '" .. currentPageName .. "' found\n\n") end
found = true
elseif mw.text.trim(v)fullPageName ~= "" then
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 current page</font> '" .. PageNamefullPageName .. "' isdoesn't exist, notfor '" .. currentPageName .. "'\n\n") 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
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