Merge "Misc follow-ups to I2fc3966e (a161c5e)"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Feb 2013 08:55:30 +0000 (08:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Feb 2013 08:55:30 +0000 (08:55 +0000)
1  2 
includes/Title.php

diff --combined includes/Title.php
@@@ -681,6 -681,7 +681,7 @@@ class Title 
        public function getContentModel() {
                if ( !$this->mContentModel ) {
                        $linkCache = LinkCache::singleton();
+                       $linkCache->addLinkObj( $this );
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
                }
  
         */
        private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
                if ( $action == 'create' ) {
 -                      if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
 -                               ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
 +                      if (
 +                              ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
 +                              ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) )
 +                      ) {
                                $errors[] = $user->isAnon() ? array( 'nocreatetext' ) : array( 'nocreate-loggedin' );
                        }
                } elseif ( $action == 'move' ) {
                        $errors = $this->resultToError( $errors, $result );
                }
                // Check getUserPermissionsErrorsExpensive hook
 -              if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) &&
 -                       !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
 +              if (
 +                      $doExpensiveQueries
 +                      && !( $short && count( $errors ) > 0 )
 +                      && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) )
 +              ) {
                        $errors = $this->resultToError( $errors, $result );
                }
  
        public function userCanEditJsSubpage() {
                global $wgUser;
                wfDeprecated( __METHOD__, '1.19' );
 -              return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
 -                         || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
 +              return (
 +                      ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
 +                      || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform )
 +              );
        }
  
        /**
  
                if ( $getPages ) {
                        $cols = array( 'pr_page', 'page_namespace', 'page_title',
 -                                                 'pr_expiry', 'pr_type', 'pr_level' );
 +                              'pr_expiry', 'pr_type', 'pr_level' );
                        $where_clauses[] = 'page_id=pr_page';
                        $tables[] = 'page';
                } else {
                                                $pagerestrictions[$row->pr_type] = array();
                                        }
  
 -                                      if ( isset( $pagerestrictions[$row->pr_type] ) &&
 -                                               !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] ) ) {
 +                                      if (
 +                                              isset( $pagerestrictions[$row->pr_type] )
 +                                              && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
 +                                      ) {
                                                $pagerestrictions[$row->pr_type][] = $row->pr_level;
                                        }
                                } else {
         * @return Bool
         */
        public function isRedirect( $flags = 0 ) {
-               if ( !is_null( $this->mRedirect ) ) {
+               if ( !( $flags & Title::GAID_FOR_UPDATE ) && !is_null( $this->mRedirect ) ) {
                        return $this->mRedirect;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mRedirect = false;
                }
  
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
                if ( $cached === null ) {
-                       // TODO: check the assumption that the cache actually knows about this title
-                       // and handle this, such as get the title from the database.
-                       // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
-                       wfDebug( wfBacktrace() );
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
                }
  
                $this->mRedirect = (bool)$cached;
         * @return Int
         */
        public function getLength( $flags = 0 ) {
-               if ( $this->mLength != -1 ) {
+               if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLength != -1 ) {
                        return $this->mLength;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLength = 0;
                }
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
-               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
-                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       #      as a stop gap, perhaps log this, but don't throw an exception?
-                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
-                       wfDebug( wfBacktrace() );
+               if ( $cached === null ) {
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
                }
  
                $this->mLength = intval( $cached );
                if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) {
                        return intval( $this->mLatestID );
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLatestID = 0;
                }
                $linkCache = LinkCache::singleton();
                $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
-               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
-                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       #      as a stop gap, perhaps log this, but don't throw an exception?
-                       throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+               if ( $cached === null ) {
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know latest revision ID of this title: " . $this->getPrefixedDBkey() );
                }
  
                $this->mLatestID = intval( $cached );
                # Pages with "/./" or "/../" appearing in the URLs will often be un-
                # reachable due to the way web browsers deal with 'relative' URLs.
                # Also, they conflict with subpage syntax.  Forbid them explicitly.
 -              if ( strpos( $dbkey, '.' ) !== false &&
 -                       ( $dbkey === '.' || $dbkey === '..' ||
 -                         strpos( $dbkey, './' ) === 0  ||
 -                         strpos( $dbkey, '../' ) === 0 ||
 -                         strpos( $dbkey, '/./' ) !== false ||
 -                         strpos( $dbkey, '/../' ) !== false  ||
 -                         substr( $dbkey, -2 ) == '/.' ||
 -                         substr( $dbkey, -3 ) == '/..' ) )
 -              {
 +              if (
 +                      strpos( $dbkey, '.' ) !== false &&
 +                      (
 +                              $dbkey === '.' || $dbkey === '..' ||
 +                              strpos( $dbkey, './' ) === 0  ||
 +                              strpos( $dbkey, '../' ) === 0 ||
 +                              strpos( $dbkey, '/./' ) !== false ||
 +                              strpos( $dbkey, '/../' ) !== false  ||
 +                              substr( $dbkey, -2 ) == '/.' ||
 +                              substr( $dbkey, -3 ) == '/..'
 +                      )
 +              ) {
                        return false;
                }
  
                # underlying database field. We make an exception for special pages, which
                # don't need to be stored in the database, and may edge over 255 bytes due
                # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
 -              if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
 -                strlen( $dbkey ) > 512 )
 -              {
 +              if (
 +                      ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 )
 +                      || strlen( $dbkey ) > 512
 +              ) {
                        return false;
                }
  
                if ( strlen( $nt->getDBkey() ) < 1 ) {
                        $errors[] = array( 'articleexists' );
                }
 -              if ( ( $this->getDBkey() == '' ) ||
 -                       ( !$oldid ) ||
 -                       ( $nt->getDBkey() == '' ) ) {
 +              if (
 +                      ( $this->getDBkey() == '' ) ||
 +                      ( !$oldid ) ||
 +                      ( $nt->getDBkey() == '' )
 +              ) {
                        $errors[] = array( 'badarticleerror' );
                }
  
                }
                $old_cmp = '>';
                $new_cmp = '<';
 -              $options = (array) $options;
 +              $options = (array)$options;
                if ( in_array( 'include_old', $options ) ) {
                        $old_cmp = '>=';
                }