Adding sanity check to Title::isRedirect().
authordaniel <daniel.kinzler@wikimedia.de>
Thu, 24 May 2012 14:42:26 +0000 (16:42 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 29 May 2012 13:39:43 +0000 (15:39 +0200)
isRedirect() assumes that the LinkCache already contains
information about this title. If that is not the case, it
currently returns false, even though it just doesn't know
whether this link is a redirect.

The new check asserts the assumption that this title
is already known to the link cache.

Amend: use Exception instead of assert()

Change-Id: Id3ad2d4e140b270b1f5ca1f7af9b3320cffff5a2

includes/Title.php

index cf428f9..c470cb5 100644 (file)
@@ -2817,7 +2817,13 @@ class Title {
                        return $this->mRedirect = false;
                }
                $linkCache = LinkCache::singleton();
-               $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+               $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+
+               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
+                       throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+               }
+
+               $this->mRedirect = (bool)$cached;
 
                return $this->mRedirect;
        }