Merge "format the tests/phpunit/TODO document for readability"
[lhc/web/wiklou.git] / includes / specials / SpecialAllpages.php
index 11425e9..ad92298 100644 (file)
@@ -156,32 +156,11 @@ 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 );
-               }
-
                $this->showChunk( $namespace, $from, $to, $hideredirects );
        }
 
@@ -267,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() );
+               $self = $this->getPageTitle();
 
-                       # Do we put a previous link ?
-                       if ( isset( $prevTitle ) && $pt = $prevTitle->getText() ) {
-                               $query = array( 'from' => $prevTitle->getText() );
+               $topLinks = array(
+                       Linker::link( $self, $this->msg( 'allpages' )->escaped() )
+               );
+               $bottomLinks = array();
 
-                               if ( $namespace ) {
-                                       $query['namespace'] = $namespace;
-                               }
+               # Do we put a previous link ?
+               if ( isset( $prevTitle ) && $pt = $prevTitle->getText() ) {
+                       $query = array( 'from' => $prevTitle->getText() );
 
-                               if ( $hideredirects ) {
-                                       $query['hideredirects'] = $hideredirects;
-                               }
-
-                               $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 )
                                        )
                        );
                }