Avoid unstubbing $wgUser before the end of Setup.php in User::getBlockedStatus()
[lhc/web/wiklou.git] / includes / Title.php
index 35d9c6b..55c7179 100644 (file)
@@ -30,7 +30,7 @@
  * @note Consider using a TitleValue object instead. TitleValue is more lightweight
  *       and does not rely on global state or the database.
  */
-class Title {
+class Title implements LinkTarget {
        /** @var HashBagOStuff */
        static private $titleCache = null;
 
@@ -130,12 +130,6 @@ class Title {
         */
        public $mDefaultNamespace = NS_MAIN;
 
-       /**
-        * @var bool Is $wgUser watching this page? null if unfilled, accessed
-        * through userIsWatching()
-        */
-       protected $mWatched = null;
-
        /** @var int The page length, 0 for special pages */
        protected $mLength = -1;
 
@@ -242,17 +236,28 @@ class Title {
         * @return Title
         */
        public static function newFromTitleValue( TitleValue $titleValue ) {
+               return self::newFromLinkTarget( $titleValue );
+       }
+
+       /**
+        * Create a new Title from a LinkTarget
+        *
+        * @param LinkTarget $linkTarget Assumed to be safe.
+        *
+        * @return Title
+        */
+       public static function newFromLinkTarget( LinkTarget $linkTarget ) {
                return self::makeTitle(
-                       $titleValue->getNamespace(),
-                       $titleValue->getText(),
-                       $titleValue->getFragment() );
+                       $linkTarget->getNamespace(),
+                       $linkTarget->getText(),
+                       $linkTarget->getFragment() );
        }
 
        /**
         * Create a new Title from text, such as what one would find in a link. De-
         * codes any HTML entities in the text.
         *
-        * @param string|null $text The link text; spaces, prefixes, and an
+        * @param string|int|null $text The link text; spaces, prefixes, and an
         *   initial ':' indicating the main namespace are accepted.
         * @param int $defaultNamespace The namespace to use if none is specified
         *   by a prefix.  If you want to force a specific namespace even if
@@ -265,7 +270,8 @@ class Title {
                if ( is_object( $text ) ) {
                        throw new InvalidArgumentException( '$text must be a string.' );
                }
-               if ( $text !== null && !is_string( $text ) ) {
+               // DWIM: Integers can be passed in here when page titles are used as array keys.
+               if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
                        wfDebugLog( 'T76305', wfGetAllCallers( 5 ) );
                        return null;
                }
@@ -274,7 +280,7 @@ class Title {
                }
 
                try {
-                       return Title::newFromTextThrow( $text, $defaultNamespace );
+                       return Title::newFromTextThrow( strval( $text ), $defaultNamespace );
                } catch ( MalformedTitleException $ex ) {
                        return null;
                }
@@ -1875,25 +1881,6 @@ class Title {
                return $s;
        }
 
-       /**
-        * Is $wgUser watching this page?
-        *
-        * @deprecated since 1.20; use User::isWatched() instead.
-        * @return bool
-        */
-       public function userIsWatching() {
-               global $wgUser;
-
-               if ( is_null( $this->mWatched ) ) {
-                       if ( NS_SPECIAL == $this->mNamespace || !$wgUser->isLoggedIn() ) {
-                               $this->mWatched = false;
-                       } else {
-                               $this->mWatched = $wgUser->isWatched( $this );
-                       }
-               }
-               return $this->mWatched;
-       }
-
        /**
         * Can $user perform $action on this page?
         * This skips potentially expensive cascading permission checks
@@ -3045,20 +3032,22 @@ class Title {
                        return;
                }
 
-               $method = __METHOD__;
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->onTransactionIdle( function () use ( $dbw, $method ) {
-                       $dbw->delete(
-                               'page_restrictions',
-                               array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
-                               $method
-                       );
-                       $dbw->delete(
-                               'protected_titles',
-                               array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
-                               $method
-                       );
-               } );
+               DeferredUpdates::addUpdate( new AtomicSectionUpdate(
+                       wfGetDB( DB_MASTER ),
+                       __METHOD__,
+                       function ( IDatabase $dbw, $fname ) {
+                               $dbw->delete(
+                                       'page_restrictions',
+                                       array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+                                       $fname
+                               );
+                               $dbw->delete(
+                                       'protected_titles',
+                                       array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+                                       $fname
+                               );
+                       }
+               ) );
        }
 
        /**
@@ -3572,7 +3561,7 @@ class Title {
                if ( $pageLang->hasVariants() ) {
                        $variants = $pageLang->getVariants();
                        foreach ( $variants as $vCode ) {
-                               $urls[] = $this->getInternalURL( '', $vCode );
+                               $urls[] = $this->getInternalURL( $vCode );
                        }
                }
 
@@ -4654,7 +4643,7 @@ class Title {
                        // Checking $wgLanguageCode hasn't changed for the benefit of unit
                        // tests.
                        $contentHandler = ContentHandler::getForTitle( $this );
-                       $langObj = wfGetLangObj( $contentHandler->getPageLanguage( $this ) );
+                       $langObj = $contentHandler->getPageLanguage( $this );
                        $this->mPageLanguage = array( $langObj->getCode(), $wgLanguageCode );
                } else {
                        $langObj = wfGetLangObj( $this->mPageLanguage[0] );