Difference between revisions 268504 and 268513 on ptwikibooksCada um dos links abaixo foi acessado 5 vezes, e a cada vez foi registrado o tempo gasto (em segundos) para a expansão de <code><nowiki>{{Navegação automática}}</nowiki></code>, de acordo com o comentário <code><nowiki><!-- Served by mw9999 in 9999 secs. --></nowiki></code> que aparecia no código HTML da página. No momento do teste, o [[Módulo:Book]] estava [[Special:PermaLink/268503|nesta versão]]. == Desempenho da navegação automática em um capítulo inexistente == * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Log%C3%ADstica%2FTESTE Logística/TESTE] ** 10.321 ** 10.244 ** 10.607 ** 10.290 ** 10.253 * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Panda3D%2FTESTE Panda3D/TESTE] ** 3.163 ** 3.187 ** 2.757 ** 3.634 ** 2.759 * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Portugu%C3%AAs%2FTESTE Português/TESTE] ** 1.879 ** 1.487 ** 1.296 ** 3.355 ** 1.773 == Desempenho da navegação automática no primeiro capítulo == * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Log%C3%ADstica%2FCapa Logística/Capa] ** 10.269 ** 10.219 ** 10.261 ** 10.211 ** 10.304 * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Panda3D%2FManual%2FIntrodu%C3%A7%C3%A3o+ao+Panda Panda3D/Manual/Introdução ao Panda] ** 9.585 ** 9.250 ** 8.928 ** 8.528 ** 10.429 * [https://pt.wikibooks.org/w/index.php?title=Especial:Expandir_predefini%C3%A7%C3%B5es&wpInput=%7B%7BNavega%C3%A7%C3%A3o+autom%C3%A1tica%7D%7D&wpContextTitle=Portugu%C3%AAs%2FCapa Português/Capa] ** 3.319 ** 3.738 ** 4.420 ** 3.932 ** 4.200local collectionPrefix = 'Wikilivros:Livros/' local arraySearch = function ( needle, haystack ) for k,v in pairs( haystack ) do if v == needle then result = k; end end return result; end local getBookName = function ( page ) page = page or mw.title.getCurrentTitle().text local pos = mw.ustring.find( page, '/' ) if pos == nil then return page else return mw.ustring.sub( page, 1, pos - 1 ) end end local getChapterName = function ( page ) page = page or mw.title.getCurrentTitle().text local pos = mw.ustring.find( page, '/' ) if pos == nil then return '' else return mw.ustring.sub( page, pos + 1 ) end end -- Based on parseCollectionLine from https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/Collection.git;a=blob;f=Collection.body.php;hb=f2bd4ee2be12ab3df5f2dcb3bd56ff17247fff66#l793) -- Get "Book/Title" from a line in any of these formats: -- :[[Book/Title]] -- :[[Book/Title|Text]] -- :[{{fullurl:Book/Title|oldid=12345}} Text] local getChapterFromLine = function ( line ) if mw.ustring.sub( line, 1, 1 ) ~= ':' then -- There is no chapter on this line return nil end line = mw.text.trim( mw.ustring.sub( line, 2, -1 ) ) local title = mw.ustring.match( line, '^%[%[:?(.-)|.-%]%]$' ) or mw.ustring.match( line, '^%[%[:?(.-)%]%]$' ) or mw.ustring.match( line, '^%[{{fullurl:(.-)|oldid=.-}}%s+.-%]$' ) or '' return title:gsub( '_',' ' ) end local getListOfChaptersFromText = function ( str, maxChaptersAfterThis ) local lines = mw.text.split( str, '[\r\n]+' ) local i, line, chapter local result = {} local curChapter = mw.title.getCurrentTitle().text local nextChapter for i, line in ipairs( lines ) do chapter = getChapterFromLine( line ) if chapter and chapter ~= '' then table.insert( result, chapter ) if maxChaptersAfterThis then if chapter == curChapter then nextChapter = 1 elseif nextChapter then nextChapter = nextChapter + 1 end if nextChapter > maxChaptersAfterThis then return result end end end end return result end local getChapters = function ( collectionPage ) collectionPage = collectionPage or ( collectionPrefix .. getBookName() ) local colContent = mw.title.new( collectionPage ):getContent() if colContent == nil then -- This book doesn't have a collection page return {} end local chapters = getListOfChaptersFromText( colContent ) return chapters end local getPrintableVersion = function ( chapters ) chapters = chapters or getChapters() local frame = mw.getCurrentFrame() local result = '' local i, chapter for i, chapter in ipairs( chapters ) do if mw.title.new( chapter ).exists then result = result .. '<h1>[[' .. chapter .. '|' .. getChapterName( chapter ) .. ']]</h1>\n' .. frame:expandTemplate{ title = ':' .. chapter } .. '\n\n' end end return result end local core = function ( chapters, page, pPosition, relPosition ) if pPosition == 'first' then return chapters[1]; end if pPosition == 'last' then return chapters[#chapters]; end if pPosition ~= nil and chapters[pPosition] then return chapters[pPosition]; end local cPosition = arraySearch( page, chapters ); if cPosition == nil then return ''; end if pPosition == 'prev' then return chapters[cPosition - 1]; end if pPosition == 'next' then return chapters[cPosition + 1]; end if relPosition == nil then return ''; end return chapters[cPosition + relPosition]; end local navBar = function ( collectionPage ) collectionPage = collectionPage or ( collectionPrefix .. getBookName() ) local colContent = mw.title.new( collectionPage ):getContent() if colContent == nil then -- This book doesn't have a collection page -- FIXME: Return an empty navigation bar? return '' end local curChapter = mw.title.getCurrentTitle().text -- Find the current chapter in the collection local a,b = mw.ustring.find( colContent, '[\r\n]:%s*%[%[:?' + curChapter + '|.-%]%]' ) or mw.ustring.find( colContent, '[\r\n]:%s*%[%[:?' + curChapter + '%]%]' ) or mw.ustring.find( colContent, '[\r\n]:%s*%[{{fullurl:' + curChapter + '|oldid=.-}}%s+.-%]' ) -- Find the previous chapter in the collection, starting before the current one -- TODO: implement this -- Find the next chapter in the collection, starting after the current one mw.log(a) mw.log(b) local linkAndText = '[\r\n]:%s*%[%[:?(.-)|.-%]%]' local link = '[\r\n]:%s*%[%[:?(.-)%]%]' local fullUrl = '[\r\n]:%s*%[{{fullurl:(.-)|oldid=.-}}%s+.-%]' local nextChapter = mw.ustring.match( line, linkAndText ) or mw.ustring.match( line, link ) or mw.ustring.match( line, fullUrl ) return chapters end return { _arraySearch = arraySearch, _getBookName = getBookName, _getChapterName = getChapterName, _getChapterFromLine = getChapterFromLine, _getListOfChaptersFromText = getListOfChaptersFromText, _getChapters = getChapters, _getPrintableVersion = getPrintableVersion, _core = core, getBookName = function( frame ) return getBookName( frame.args[1] ) end, getChapterName = function( frame ) return getChapterName( frame.args[1] ) end, getPrintableVersion = function( frame ) local bookName = frame.args[1] or getBookName() local chapters = getChapters( collectionPrefix .. bookName ) return getPrintableVersion( chapters ) end, nav = function ( frame ) local chapters = getChapters( frame.args['list'] ) -- On page [[*A'B&C"D]], {{PAGENAME}} returns "*A'B&C&#34;D", so decode it first! local page = mw.text.decode( frame.args['page'] or mw.title.getCurrentTitle().text ); local pPosition = frame.args['position']; local relPosition = frame.args['relative-position']; return core( chapters, page, pPosition, relPosition ); end }; All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://pt.wikibooks.org/w/index.php?diff=prev&oldid=268513.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|