Title: Always add title to LinkCache when necessary (in 3 methods)
authorKevin Israel <pleasestand@live.com>
Thu, 15 Jan 2015 22:24:03 +0000 (17:24 -0500)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Fri, 23 Jan 2015 20:19:32 +0000 (12:19 -0800)
Unless Title::GAID_FOR_UPDATE is specified, Title::getArticleID() will not
use the link cache if the Title already has the ID of the page. Account for
this by directly calling LinkCache::addLinkObj() in three other methods of
Title: getContentModel(), isRedirect(), and getLength().

Follows-up r33008 (aed9d4b91218) and dd5c1b7fb7ff, and reapplies part of
388b14a15de6.

Bug: T86974
Change-Id: I7eff0bffd4f632ceb8d2124af317d684dbcaf2cb

RELEASE-NOTES-1.25
includes/Title.php

index f0c00f3..aa421cb 100644 (file)
@@ -131,6 +131,8 @@ production.
 * (T85192) Captcha position modified in Usercreate template. As a result:
 ** extrafields parameter added to Usercreate.php to insert additional data
 ** 'extend' method added to QuickTemplate to append additional values to any field of data array
+* (T86974) Several Title methods now load from the database when necessary
+  (instead of returning incorrect results) even when the page ID is known.
 
 === Action API changes in 1.25 ===
 * (T67403) XML tag highlighting is now only performed for formats
index 2d0cfda..463f75e 100644 (file)
@@ -942,9 +942,9 @@ class Title {
         * @return string Content model id
         */
        public function getContentModel( $flags = 0 ) {
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->mContentModel && $this->getArticleID( $flags ) ) {
                        $linkCache = LinkCache::singleton();
+                       $linkCache->addLinkObj( $this ); # in case we already had an article ID
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
                }
 
@@ -3185,13 +3185,13 @@ class Title {
                if ( !is_null( $this->mRedirect ) ) {
                        return $this->mRedirect;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        $this->mRedirect = false;
                        return $this->mRedirect;
                }
 
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own
@@ -3220,12 +3220,12 @@ class Title {
                if ( $this->mLength != -1 ) {
                        return $this->mLength;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        $this->mLength = 0;
                        return $this->mLength;
                }
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()
@@ -3248,13 +3248,12 @@ class Title {
                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 ) ) {
                        $this->mLatestID = 0;
                        return $this->mLatestID;
                }
                $linkCache = LinkCache::singleton();
-               $linkCache->addLinkObj( $this );
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()