From 3ed642bb1ced2aaae26fa94d45ee75314f02c7f5 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 13 May 2014 20:33:55 +0200 Subject: [PATCH] Improve a bit the code of SpecialAllpages::showChunk() - Early return when including the page, makes one indentation level less for the rest of the method - Directly put top and bottom links in an array, so that it is easier to see where they are going to be displayed - Group the HTML generation for the top form at the end of the method again for better readability Change-Id: I70c174a4c6363b2303cb5110782c5a3375640f2d --- includes/specials/SpecialAllpages.php | 177 +++++++++++++------------- 1 file changed, 88 insertions(+), 89 deletions(-) diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index 11425e9d21..e4fc54b97d 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -267,118 +267,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' ) ) . - ' - ' . - $nsForm . - ' - ' . - 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 ( isset( $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 .= ""; - } - $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' ) ) . + ' + ' . + $nsForm . + ' + ' . + $this->getLanguage()->pipeList( $topLinks ) . + ''; + + $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 ) ) ); } -- 2.20.1