Merge "Fixed use of long memcached keys in AllPages."
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 1 Feb 2013 18:16:09 +0000 (18:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 1 Feb 2013 18:16:09 +0000 (18:16 +0000)
1  2 
includes/specials/SpecialAllpages.php

@@@ -188,13 -188,13 +188,13 @@@ class SpecialAllpages extends Includabl
                $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 );
 +              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, $from, $to );
+               $key = wfMemcKey( 'allpages', 'ns', $namespace, sha1( $from ), sha1( $to ) );
                $lines = $wgMemc->get( $key );
  
                $count = $dbr->estimateRowCount( 'page', '*', $where, __METHOD__ );
                                        : array( 'page_title >= ' . $dbr->addQuotes( $lastTitle ) );
                                $res = $dbr->select( 'page', /* FROM */
                                        'page_title', /* WHAT */
 -                                      array_merge($where,$chunk),
 +                                      array_merge( $where, $chunk ),
                                        __METHOD__,
 -                                      array ('LIMIT' => 2, 'OFFSET' => $maxPerSubpage - 1, 'ORDER BY' => 'page_title ASC')
 +                                      array( 'LIMIT' => 2, 'OFFSET' => $maxPerSubpage - 1, 'ORDER BY' => 'page_title ASC' )
                                );
  
                                $s = $dbr->fetchObject( $res );
                                } else {
                                        // Final chunk, but ended prematurely. Go back and find the end.
                                        $endTitle = $dbr->selectField( 'page', 'MAX(page_title)',
 -                                              array_merge($where,$chunk),
 +                                              array_merge( $where, $chunk ),
                                                __METHOD__ );
                                        array_push( $lines, $endTitle );
                                        $done = true;
                if( $this->including() ) {
                        $out2 = '';
                } else {
 -                      if( isset($from) || isset($to) ) {
 +                      if( isset( $from ) || isset( $to ) ) {
                                $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ).
                                                '<tr>
                                                        <td>' .
                $queryparams = $namespace ? "namespace=$namespace&" : '';
  
                $queryhideredirects = array();
 -              if ($hideredirects) {
 +              if ( $hideredirects ) {
                        $queryhideredirects[ 'hideredirects' ] = 1;
                }
  
                $special = $this->getTitle();
 -              $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint), $queryhideredirects ) );
 +              $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode( $inpoint ) . '&to=' . urlencode( $outpoint ), $queryhideredirects ) );
  
                $out = $this->msg( 'alphaindexline' )->rawParams(
                        "<a href=\"$link\">$inpointf</a></td><td>",
                global $wgContLang;
                $output = $this->getOutput();
  
 -              $fromList = $this->getNamespaceKeyAndText($namespace, $from);
 +              $fromList = $this->getNamespaceKeyAndText( $namespace, $from );
                $toList = $this->getNamespaceKeyAndText( $namespace, $to );
                $namespaces = $wgContLang->getNamespaces();
                $n = 0;
                                $res_prev = $dbr->select(
                                        'page',
                                        'page_title',
 -                                      array( 'page_namespace' => $namespace, 'page_title < '.$dbr->addQuotes($from) ),
 +                                      array( 'page_namespace' => $namespace, 'page_title < ' . $dbr->addQuotes( $from ) ),
                                        __METHOD__,
                                        array( 'ORDER BY' => 'page_title DESC',
 -                                              'LIMIT' => $this->maxPerPage, 'OFFSET' => ($this->maxPerPage - 1 )
 +                                              'LIMIT' => $this->maxPerPage, 'OFFSET' => ( $this->maxPerPage - 1 )
                                        )
                                );
  
                                                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 );
 +                                              $prevTitle = Title::makeTitle( $namespace, $reallyFirstPage_title );
                                        } else {
                                                $prevTitle = null;
                                        }
  
                        if( $n == $this->maxPerPage && $s = $res->fetchObject() ) {
                                # $s is the first link of the next chunk
 -                              $t = Title::makeTitle($namespace, $s->page_title);
 +                              $t = Title::makeTitle( $namespace, $s->page_title );
                                $query = array( 'from' => $t->getText() );
  
                                if( $namespace )
         * @param $text String: the name of the article
         * @return array( int namespace, string dbkey, string pagename ) or NULL on error
         */
 -      protected function getNamespaceKeyAndText($ns, $text) {
 +      protected function getNamespaceKeyAndText( $ns, $text ) {
                if ( $text == '' )
                        return array( $ns, '', '' ); # shortcut for common case
  
 -              $t = Title::makeTitleSafe($ns, $text);
 +              $t = Title::makeTitleSafe( $ns, $text );
                if ( $t && $t->isLocal() ) {
                        return array( $t->getNamespace(), $t->getDBkey(), $t->getText() );
                } elseif ( $t ) {
                }
  
                # try again, in case the problem was an empty pagename
 -              $text = preg_replace('/(#|$)/', 'X$1', $text);
 -              $t = Title::makeTitleSafe($ns, $text);
 +              $text = preg_replace( '/(#|$)/', 'X$1', $text );
 +              $t = Title::makeTitleSafe( $ns, $text );
                if ( $t && $t->isLocal() ) {
                        return array( $t->getNamespace(), '', '' );
                } else {