Merge "Introduce ContentHandler::importTransform."
[lhc/web/wiklou.git] / includes / specials / SpecialAllpages.php
index fe49cf2..0490d82 100644 (file)
@@ -35,30 +35,6 @@ class SpecialAllpages extends IncludableSpecialPage {
         */
        protected $maxPerPage = 345;
 
-       /**
-        * Maximum number of pages to show on single index subpage.
-        *
-        * @var int $maxLineCount
-        */
-       protected $maxLineCount = 100;
-
-       /**
-        * Maximum number of chars to show for an entry.
-        *
-        * @var int $maxPageLength
-        */
-       protected $maxPageLength = 70;
-
-       /**
-        * Maximum number of pages in a hierarchical ("top level") list.
-        *
-        * Traversal of the entire page list by spidering the top levels is thought
-        * to require O(N^3) DB CPU time where N is the number of pages on the wiki.
-        * See bug 56840. If this limit is exceeded, the behaviour becomes like a
-        * simple alphabetic pager.
-        */
-       protected $maxTopLevelPages = 50000;
-
        /**
         * Determines, which message describes the input field 'nsfrom'.
         *
@@ -180,183 +156,12 @@ class SpecialAllpages extends IncludableSpecialPage {
         * @param bool $hideredirects Dont show redirects (default false)
         */
        function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
-               $output = $this->getOutput();
-
-               # TODO: Either make this *much* faster or cache the title index points
-               # in the querycache table.
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $out = "";
-               $where = array( 'page_namespace' => $namespace );
-
-               if ( $hideredirects ) {
-                       $where['page_is_redirect'] = 0;
-               }
-
                $from = Title::makeTitleSafe( $namespace, $from );
                $to = Title::makeTitleSafe( $namespace, $to );
                $from = ( $from && $from->isLocal() ) ? $from->getDBkey() : null;
                $to = ( $to && $to->isLocal() ) ? $to->getDBkey() : null;
 
-               if ( isset( $from ) ) {
-                       $where[] = 'page_title >= ' . $dbr->addQuotes( $from );
-               }
-
-               if ( isset( $to ) ) {
-                       $where[] = 'page_title <= ' . $dbr->addQuotes( $to );
-               }
-
-               global $wgMemc;
-               $key = wfMemcKey( 'allpages', 'ns', $namespace, sha1( $from ), sha1( $to ) );
-               $lines = $wgMemc->get( $key );
-
-               $count = $dbr->estimateRowCount( 'page', '*', $where, __METHOD__ );
-
-               // Don't show a hierarchical list if the number of pages is very large,
-               // since generating it will cause a lot of scanning
-               if ( $count > $this->maxTopLevelPages ) {
-                       $this->showChunk( $namespace, $from, $to, $hideredirects );
-
-                       return;
-               }
-
-               $maxPerSubpage = intval( $count / $this->maxLineCount );
-               $maxPerSubpage = max( $maxPerSubpage, $this->maxPerPage );
-
-               if ( !is_array( $lines ) ) {
-                       $options = array( 'LIMIT' => 1 );
-                       $options['ORDER BY'] = 'page_title ASC';
-                       $firstTitle = $dbr->selectField( 'page', 'page_title', $where, __METHOD__, $options );
-                       $lastTitle = $firstTitle;
-                       # This array is going to hold the page_titles in order.
-                       $lines = array( $firstTitle );
-                       # If we are going to show n rows, we need n+1 queries to find the relevant titles.
-                       $done = false;
-                       while ( !$done ) {
-                               // Fetch the last title of this chunk and the first of the next
-                               $chunk = ( $lastTitle === false )
-                                       ? array()
-                                       : array( 'page_title >= ' . $dbr->addQuotes( $lastTitle ) );
-                               $res = $dbr->select( 'page', /* FROM */
-                                       'page_title', /* WHAT */
-                                       array_merge( $where, $chunk ),
-                                       __METHOD__,
-                                       array( 'LIMIT' => 2, 'OFFSET' => $maxPerSubpage - 1, 'ORDER BY' => 'page_title ASC' )
-                               );
-
-                               $s = $dbr->fetchObject( $res );
-                               if ( $s ) {
-                                       array_push( $lines, $s->page_title );
-                               } else {
-                                       // Final chunk, but ended prematurely. Go back and find the end.
-                                       $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
-                                               array_merge( $where, $chunk ),
-                                               __METHOD__ );
-                                       array_push( $lines, $endTitle );
-                                       $done = true;
-                               }
-
-                               $s = $res->fetchObject();
-                               if ( $s ) {
-                                       array_push( $lines, $s->page_title );
-                                       $lastTitle = $s->page_title;
-                               } else {
-                                       // This was a final chunk and ended exactly at the limit.
-                                       // Rare but convenient!
-                                       $done = true;
-                               }
-                               $res->free();
-                       }
-                       $wgMemc->add( $key, $lines, 3600 );
-               }
-
-               // If there are only two or less sections, don't even display them.
-               // Instead, display the first section directly.
-               if ( count( $lines ) <= 2 ) {
-                       if ( !empty( $lines ) ) {
-                               $this->showChunk( $namespace, $from, $to, $hideredirects );
-                       } else {
-                               $output->addHTML( $this->namespaceForm( $namespace, $from, $to, $hideredirects ) );
-                       }
-
-                       return;
-               }
-
-               # At this point, $lines should contain an even number of elements.
-               $out .= Xml::openElement( 'table', array( 'class' => 'allpageslist' ) );
-               while ( count( $lines ) > 0 ) {
-                       $inpoint = array_shift( $lines );
-                       $outpoint = array_shift( $lines );
-                       $out .= $this->showline( $inpoint, $outpoint, $namespace, $hideredirects );
-               }
-               $out .= Xml::closeElement( 'table' );
-               $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
-
-               # Is there more?
-               if ( $this->including() ) {
-                       $out2 = '';
-               } else {
-                       if ( isset( $from ) || isset( $to ) ) {
-                               $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ) .
-                                       '<tr>
-                                                       <td>' .
-                                       $nsForm .
-                                       '</td>
-                                                       <td class="mw-allpages-nav">' .
-                                       Linker::link( $this->getPageTitle(), $this->msg( 'allpages' )->escaped(),
-                                               array(), array(), 'known' ) .
-                                       "</td>
-                                               </tr>" .
-                                       Xml::closeElement( 'table' );
-                       } else {
-                               $out2 = $nsForm;
-                       }
-               }
-               $output->addHTML( $out2 . $out );
-       }
-
-       /**
-        * Show a line of "ABC to DEF" ranges of articles
-        *
-        * @param string $inpoint Lower limit of pagenames
-        * @param string $outpoint Upper limit of pagenames
-        * @param int $namespace (Default NS_MAIN)
-        * @param bool $hideRedirects Don't show redirects. Default: false
-        * @return string
-        */
-       function showline( $inpoint, $outpoint, $namespace = NS_MAIN, $hideRedirects = false ) {
-               // Use content language since page titles are considered to use content language
-               global $wgContLang;
-
-               $inpointf = str_replace( '_', ' ', $inpoint );
-               $outpointf = str_replace( '_', ' ', $outpoint );
-
-               // Don't let the length runaway
-               $inpointf = $wgContLang->truncate( $inpointf, $this->maxPageLength );
-               $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength );
-
-               $queryParams = array(
-                       'from' => $inpoint,
-                       'to' => $outpoint,
-               );
-
-               if ( $namespace ) {
-                       $queryParams['namespace'] = $namespace;
-               }
-               if ( $hideRedirects ) {
-                       $queryParams['hideredirects'] = 1;
-               }
-
-               $url = $this->getPageTitle()->getLocalURL( $queryParams );
-               $inlink = Html::element( 'a', array( 'href' => $url ), $inpointf );
-               $outlink = Html::element( 'a', array( 'href' => $url ), $outpointf );
-
-               $out = $this->msg( 'alphaindexline' )->rawParams(
-                       "$inlink</td><td>",
-                       "</td><td>$outlink"
-               )->escaped();
-
-               return '<tr><td class="mw-allpages-alphaindexline">' . $out . '</td></tr>';
+               $this->showChunk( $namespace, $from, $to, $hideredirects );
        }
 
        /**
@@ -441,118 +246,117 @@ class SpecialAllpages extends IncludableSpecialPage {
                }
 
                if ( $this->including() ) {
-                       $out2 = '';
+                       $output->addHTML( $out );
+                       return;
+               }
+
+               if ( $from == '' ) {
+                       // First chunk; no previous link.
+                       $prevTitle = null;
                } else {
-                       if ( $from == '' ) {
-                               // First chunk; no previous link.
-                               $prevTitle = null;
-                       } else {
-                               # Get the last title from previous chunk
-                               $dbr = wfGetDB( DB_SLAVE );
-                               $res_prev = $dbr->select(
-                                       'page',
-                                       'page_title',
-                                       array( 'page_namespace' => $namespace, 'page_title < ' . $dbr->addQuotes( $from ) ),
-                                       __METHOD__,
-                                       array( 'ORDER BY' => 'page_title DESC',
-                                               'LIMIT' => $this->maxPerPage, 'OFFSET' => ( $this->maxPerPage - 1 )
-                                       )
-                               );
+                       # Get the last title from previous chunk
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $res_prev = $dbr->select(
+                               'page',
+                               'page_title',
+                               array( 'page_namespace' => $namespace, 'page_title < ' . $dbr->addQuotes( $from ) ),
+                               __METHOD__,
+                               array( 'ORDER BY' => 'page_title DESC',
+                                       'LIMIT' => $this->maxPerPage, 'OFFSET' => ( $this->maxPerPage - 1 )
+                               )
+                       );
 
-                               # Get first title of previous complete chunk
-                               if ( $dbr->numrows( $res_prev ) >= $this->maxPerPage ) {
-                                       $pt = $dbr->fetchObject( $res_prev );
-                                       $prevTitle = Title::makeTitle( $namespace, $pt->page_title );
+                       # Get first title of previous complete chunk
+                       if ( $dbr->numrows( $res_prev ) >= $this->maxPerPage ) {
+                               $pt = $dbr->fetchObject( $res_prev );
+                               $prevTitle = Title::makeTitle( $namespace, $pt->page_title );
+                       } else {
+                               # The previous chunk is not complete, need to link to the very first title
+                               # available in the database
+                               $options = array( 'LIMIT' => 1 );
+                               if ( !$dbr->implicitOrderby() ) {
+                                       $options['ORDER BY'] = 'page_title';
+                               }
+                               $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title',
+                                       array( 'page_namespace' => $namespace ), __METHOD__, $options );
+                               # Show the previous link if it s not the current requested chunk
+                               if ( $from != $reallyFirstPage_title ) {
+                                       $prevTitle = Title::makeTitle( $namespace, $reallyFirstPage_title );
                                } else {
-                                       # The previous chunk is not complete, need to link to the very first title
-                                       # available in the database
-                                       $options = array( 'LIMIT' => 1 );
-                                       if ( !$dbr->implicitOrderby() ) {
-                                               $options['ORDER BY'] = 'page_title';
-                                       }
-                                       $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title',
-                                               array( 'page_namespace' => $namespace ), __METHOD__, $options );
-                                       # Show the previous link if it s not the current requested chunk
-                                       if ( $from != $reallyFirstPage_title ) {
-                                               $prevTitle = Title::makeTitle( $namespace, $reallyFirstPage_title );
-                                       } else {
-                                               $prevTitle = null;
-                                       }
+                                       $prevTitle = null;
                                }
                        }
+               }
 
-                       $self = $this->getPageTitle();
-
-                       $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
-                       $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ) .
-                               '<tr>
-                                                       <td>' .
-                               $nsForm .
-                               '</td>
-                                                       <td class="mw-allpages-nav">' .
-                               Linker::link( $self, $this->msg( 'allpages' )->escaped() );
-
-                       # Do we put a previous link ?
-                       if ( isset( $prevTitle ) && $pt = $prevTitle->getText() ) {
-                               $query = array( 'from' => $prevTitle->getText() );
+               $self = $this->getPageTitle();
 
-                               if ( $namespace ) {
-                                       $query['namespace'] = $namespace;
-                               }
+               $topLinks = array(
+                       Linker::link( $self, $this->msg( 'allpages' )->escaped() )
+               );
+               $bottomLinks = array();
 
-                               if ( $hideredirects ) {
-                                       $query['hideredirects'] = $hideredirects;
-                               }
+               # Do we put a previous link ?
+               if ( $prevTitle && $pt = $prevTitle->getText() ) {
+                       $query = array( 'from' => $prevTitle->getText() );
 
-                               $prevLink = Linker::linkKnown(
-                                       $self,
-                                       $this->msg( 'prevpage', $pt )->escaped(),
-                                       array(),
-                                       $query
-                               );
-                               $out2 = $this->getLanguage()->pipeList( array( $out2, $prevLink ) );
+                       if ( $namespace ) {
+                               $query['namespace'] = $namespace;
                        }
 
-                       if ( $n == $this->maxPerPage && $s = $res->fetchObject() ) {
-                               # $s is the first link of the next chunk
-                               $t = Title::makeTitle( $namespace, $s->page_title );
-                               $query = array( 'from' => $t->getText() );
+                       if ( $hideredirects ) {
+                               $query['hideredirects'] = $hideredirects;
+                       }
 
-                               if ( $namespace ) {
-                                       $query['namespace'] = $namespace;
-                               }
+                       $prevLink = Linker::linkKnown(
+                               $self,
+                               $this->msg( 'prevpage', $pt )->escaped(),
+                               array(),
+                               $query
+                       );
+                       $topLinks[] = $prevLink;
+                       $bottomLinks[] = $prevLink;
+               }
 
-                               if ( $hideredirects ) {
-                                       $query['hideredirects'] = $hideredirects;
-                               }
+               if ( $n == $this->maxPerPage && $s = $res->fetchObject() ) {
+                       # $s is the first link of the next chunk
+                       $t = Title::makeTitle( $namespace, $s->page_title );
+                       $query = array( 'from' => $t->getText() );
 
-                               $nextLink = Linker::linkKnown(
-                                       $self,
-                                       $this->msg( 'nextpage', $t->getText() )->escaped(),
-                                       array(),
-                                       $query
-                               );
-                               $out2 = $this->getLanguage()->pipeList( array( $out2, $nextLink ) );
+                       if ( $namespace ) {
+                               $query['namespace'] = $namespace;
                        }
-                       $out2 .= "</td></tr></table>";
-               }
 
-               $output->addHTML( $out2 . $out );
+                       if ( $hideredirects ) {
+                               $query['hideredirects'] = $hideredirects;
+                       }
 
-               $links = array();
-               if ( isset( $prevLink ) ) {
-                       $links[] = $prevLink;
+                       $nextLink = Linker::linkKnown(
+                               $self,
+                               $this->msg( 'nextpage', $t->getText() )->escaped(),
+                               array(),
+                               $query
+                       );
+                       $topLinks[] = $nextLink;
+                       $bottomLinks[] = $nextLink;
                }
 
-               if ( isset( $nextLink ) ) {
-                       $links[] = $nextLink;
-               }
+               $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
+               $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ) .
+                       '<tr>
+                                               <td>' .
+                       $nsForm .
+                       '</td>
+                                               <td class="mw-allpages-nav">' .
+                       $this->getLanguage()->pipeList( $topLinks ) .
+                       '</td></tr></table>';
+
+               $output->addHTML( $out2 . $out );
 
-               if ( count( $links ) ) {
+               if ( count( $bottomLinks ) ) {
                        $output->addHTML(
                                Html::element( 'hr' ) .
                                        Html::rawElement( 'div', array( 'class' => 'mw-allpages-nav' ),
-                                               $this->getLanguage()->pipeList( $links )
+                                               $this->getLanguage()->pipeList( $bottomLinks )
                                        )
                        );
                }