Remove 'bot' check before trying the edit stash
[lhc/web/wiklou.git] / includes / Title.php
index 9c8ed47..1fdeca8 100644 (file)
@@ -206,7 +206,7 @@ class Title {
         * @return TitleFormatter
         */
        private static function getTitleFormatter() {
-               //NOTE: we know that getTitleParser() returns a MediaWikiTitleCodec,
+               // NOTE: we know that getTitleParser() returns a MediaWikiTitleCodec,
                //      which implements TitleFormatter.
                return self::getTitleParser();
        }
@@ -252,7 +252,7 @@ class Title {
         * 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 $text The link text; spaces, prefixes, and an
+        * @param string|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
@@ -264,9 +264,13 @@ class Title {
        public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
                if ( is_object( $text ) ) {
                        throw new InvalidArgumentException( '$text must be a string.' );
-               } elseif ( !is_string( $text ) ) {
+               }
+               if ( $text !== null && !is_string( $text ) ) {
                        wfDebugLog( 'T76305', wfGetAllCallers( 5 ) );
-                       wfWarn( __METHOD__ . ': $text must be a string. This will throw an InvalidArgumentException in future.', 2 );
+                       return null;
+               }
+               if ( $text === null ) {
+                       return null;
                }
 
                try {
@@ -292,7 +296,7 @@ class Title {
         */
        public static function newFromTextThrow( $text, $defaultNamespace = NS_MAIN ) {
                if ( is_object( $text ) ) {
-                       throw new MWException( 'Title::newFromTextThrow given an object' );
+                       throw new MWException( '$text must be a string, given an object' );
                }
 
                $cache = self::getTitleCache();
@@ -313,7 +317,7 @@ class Title {
                $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
 
                $t = new Title();
-               $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
+               $t->mDbkeyform = strtr( $filteredText, ' ', '_' );
                $t->mDefaultNamespace = intval( $defaultNamespace );
 
                $t->secureAndSplit();
@@ -345,10 +349,10 @@ class Title {
                # but some URLs used it as a space replacement and they still come
                # from some external search tools.
                if ( strpos( self::legalChars(), '+' ) === false ) {
-                       $url = str_replace( '+', ' ', $url );
+                       $url = strtr( $url, '+', ' ' );
                }
 
-               $t->mDbkeyform = str_replace( ' ', '_', $url );
+               $t->mDbkeyform = strtr( $url, ' ', '_' );
 
                try {
                        $t->secureAndSplit();
@@ -509,10 +513,10 @@ class Title {
                $t->mInterwiki = $interwiki;
                $t->mFragment = $fragment;
                $t->mNamespace = $ns = intval( $ns );
-               $t->mDbkeyform = str_replace( ' ', '_', $title );
+               $t->mDbkeyform = strtr( $title, ' ', '_' );
                $t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
                $t->mUrlform = wfUrlencode( $t->mDbkeyform );
-               $t->mTextform = str_replace( '_', ' ', $title );
+               $t->mTextform = strtr( $title, '_', ' ' );
                $t->mContentModel = false; # initialized lazily in getContentModel()
                return $t;
        }
@@ -526,7 +530,7 @@ class Title {
         * @param string $title Database key form
         * @param string $fragment The link fragment (after the "#")
         * @param string $interwiki Interwiki prefix
-        * @return Title The new object, or null on an error
+        * @return Title|null The new object, or null on an error
         */
        public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
                if ( !MWNamespace::exists( $ns ) ) {
@@ -1004,10 +1008,8 @@ class Title {
         */
        public function getNsText() {
                if ( $this->isExternal() ) {
-                       // This probably shouldn't even happen. ohh man, oh yuck.
-                       // But for interwiki transclusion it sometimes does.
-                       // Shit. Shit shit shit.
-                       //
+                       // This probably shouldn't even happen,
+                       // but for interwiki transclusion it sometimes does.
                        // Use the canonical namespaces if possible to try to
                        // resolve a foreign namespace.
                        if ( MWNamespace::exists( $this->mNamespace ) ) {
@@ -1416,10 +1418,11 @@ class Title {
         * Deprecated for public use, use Title::makeTitle() with fragment parameter.
         * Still in active use privately.
         *
+        * @private
         * @param string $fragment Text
         */
        public function setFragment( $fragment ) {
-               $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) );
+               $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
        }
 
        /**
@@ -1449,7 +1452,7 @@ class Title {
         */
        public function getPrefixedDBkey() {
                $s = $this->prefix( $this->mDbkeyform );
-               $s = str_replace( ' ', '_', $s );
+               $s = strtr( $s, ' ', '_' );
                return $s;
        }
 
@@ -1462,7 +1465,7 @@ class Title {
        public function getPrefixedText() {
                if ( $this->mPrefixedText === null ) {
                        $s = $this->prefix( $this->mTextform );
-                       $s = str_replace( '_', ' ', $s );
+                       $s = strtr( $s, '_', ' ' );
                        $this->mPrefixedText = $s;
                }
                return $this->mPrefixedText;
@@ -1610,7 +1613,7 @@ class Title {
         */
        public function getSubpageUrlForm() {
                $text = $this->getSubpageText();
-               $text = wfUrlencode( str_replace( ' ', '_', $text ) );
+               $text = wfUrlencode( strtr( $text, ' ', '_' ) );
                return $text;
        }
 
@@ -1621,7 +1624,7 @@ class Title {
         */
        public function getPrefixedURL() {
                $s = $this->prefix( $this->mDbkeyform );
-               $s = wfUrlencode( str_replace( ' ', '_', $s ) );
+               $s = wfUrlencode( strtr( $s, ' ', '_' ) );
                return $s;
        }
 
@@ -1939,10 +1942,9 @@ class Title {
         *   - quick  : does cheap permission checks from slaves (usable for GUI creation)
         *   - full   : does cheap and expensive checks possibly from a slave
         *   - secure : does cheap and expensive checks, using the master as needed
-        * @param bool $short Set this to true to stop after the first permission error.
         * @param array $ignoreErrors Array of Strings Set this to a list of message keys
         *   whose corresponding errors may be ignored.
-        * @return array Array of arguments to wfMessage to explain permissions problems.
+        * @return array Array of arrays of the arguments to wfMessage to explain permissions problems.
         */
        public function getUserPermissionsErrors(
                $action, $user, $rigor = 'secure', $ignoreErrors = array()
@@ -1951,9 +1953,12 @@ class Title {
 
                // Remove the errors being ignored.
                foreach ( $errors as $index => $error ) {
-                       $error_key = is_array( $error ) ? $error[0] : $error;
+                       $errKey = is_array( $error ) ? $error[0] : $error;
 
-                       if ( in_array( $error_key, $ignoreErrors ) ) {
+                       if ( in_array( $errKey, $ignoreErrors ) ) {
+                               unset( $errors[$index] );
+                       }
+                       if ( $errKey instanceof MessageSpecifier && in_array( $errKey->getKey(), $ignoreErrors ) ) {
                                unset( $errors[$index] );
                        }
                }
@@ -2052,6 +2057,9 @@ class Title {
                } elseif ( $result !== '' && is_string( $result ) ) {
                        // A string representing a message-id
                        $errors[] = array( $result );
+               } elseif ( $result instanceof MessageSpecifier ) {
+                       // A message specifier representing an error
+                       $errors[] = array( $result );
                } elseif ( $result === false ) {
                        // a generic "We don't want them to do that"
                        $errors[] = array( 'badaccess-group0' );
@@ -2945,7 +2953,7 @@ class Title {
                                        $this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
                                } else {
                                        $restriction = trim( $temp[1] );
-                                       if ( $restriction != '' ) { //some old entries are empty
+                                       if ( $restriction != '' ) { // some old entries are empty
                                                $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
                                        }
                                }
@@ -3370,7 +3378,7 @@ class Title {
 
                $this->mDbkeyform = $parts['dbkey'];
                $this->mUrlform = wfUrlencode( $this->mDbkeyform );
-               $this->mTextform = str_replace( '_', ' ', $this->mDbkeyform );
+               $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
 
                # We already know that some pages won't be in the database!
                if ( $this->isExternal() || $this->mNamespace == NS_SPECIAL ) {
@@ -4380,7 +4388,7 @@ class Title {
        /**
         * Updates page_touched for this page; called from LinksUpdate.php
         *
-        * @param integer $purgeTime TS_MW timestamp [optional]
+        * @param string $purgeTime [optional] TS_MW timestamp
         * @return bool True if the update succeeded
         */
        public function invalidateCache( $purgeTime = null ) {
@@ -4415,19 +4423,16 @@ class Title {
         * on the number of links. Typically called on create and delete.
         */
        public function touchLinks() {
-               $u = new HTMLCacheUpdate( $this, 'pagelinks' );
-               $u->doUpdate();
-
+               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks' ) );
                if ( $this->getNamespace() == NS_CATEGORY ) {
-                       $u = new HTMLCacheUpdate( $this, 'categorylinks' );
-                       $u->doUpdate();
+                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'categorylinks' ) );
                }
        }
 
        /**
         * Get the last touched timestamp
         *
-        * @param DatabaseBase $db Optional db
+        * @param IDatabase $db Optional db
         * @return string Last-touched timestamp
         */
        public function getTouched( $db = null ) {
@@ -4547,15 +4552,17 @@ class Title {
        public function isValidRedirectTarget() {
                global $wgInvalidRedirectTargets;
 
-               // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
-               if ( $this->isSpecial( 'Userlogout' ) ) {
-                       return false;
-               }
-
-               foreach ( $wgInvalidRedirectTargets as $target ) {
-                       if ( $this->isSpecial( $target ) ) {
+               if ( $this->isSpecialPage() ) {
+                       // invalid redirect targets are stored in a global array, but explicitly disallow Userlogout here
+                       if ( $this->isSpecial( 'Userlogout' ) ) {
                                return false;
                        }
+
+                       foreach ( $wgInvalidRedirectTargets as $target ) {
+                               if ( $this->isSpecial( $target ) ) {
+                                       return false;
+                               }
+                       }
                }
 
                return true;
@@ -4738,7 +4745,7 @@ class Title {
                        }
                } else {
                        // Even if there are no subpages in namespace, we still don't want "/" in MediaWiki message keys
-                       $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() );
+                       $editnoticeText = $editnotice_ns . '-' . strtr( $this->getDBkey(), '/', '-' );
                        $msg = wfMessage( $editnoticeText );
                        if ( $msg->exists() ) {
                                $html = $msg->parseAsBlock();
@@ -4759,4 +4766,26 @@ class Title {
                Hooks::run( 'TitleGetEditNotices', array( $this, $oldid, &$notices ) );
                return $notices;
        }
+
+       /**
+        * @return array
+        */
+       public function __sleep() {
+               return array(
+                       'mNamespace',
+                       'mDbkeyform',
+                       'mFragment',
+                       'mInterwiki',
+                       'mLocalInterwiki',
+                       'mUserCaseDBKey',
+                       'mDefaultNamespace',
+               );
+       }
+
+       public function __wakeup() {
+               $this->mArticleID = ( $this->mNamespace >= 0 ) ? -1 : 0;
+               $this->mUrlform = wfUrlencode( $this->mDbkeyform );
+               $this->mTextform = strtr( $this->mDbkeyform, '_', ' ' );
+       }
+
 }