X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=4b39efd199e8830622d621e268e084fc2482a4a1;hb=23cfe1bba6984764cb582bf52b20d465e04d7b55;hp=aef696fbc845fd12236b78db55ad6b32bdc1a431;hpb=12f7ff32fcd46e8be4e336f5d92171f05f6abf26;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index aef696fbc8..4b39efd199 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -31,7 +31,7 @@ * and does not rely on global state or the database. */ class Title { - /** @var MapCacheLRU */ + /** @var HashBagOStuff */ static private $titleCache = null; /** @@ -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,13 +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 { @@ -296,24 +296,23 @@ 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(); + $titleCache = self::getTitleCache(); - /** - * Wiki pages often contain multiple links to the same page. - * Title normalization and parsing can become expensive on - * pages with many links, so we can save a little time by - * caching them. - * - * In theory these are value objects and won't get changed... - */ - if ( $defaultNamespace == NS_MAIN && $cache->has( $text ) ) { - return $cache->get( $text ); + // Wiki pages often contain multiple links to the same page. + // Title normalization and parsing can become expensive on pages with many + // links, so we can save a little time by caching them. + // In theory these are value objects and won't get changed... + if ( $defaultNamespace == NS_MAIN ) { + $t = $titleCache->get( $text ); + if ( $t ) { + return $t; + } } - # Convert things like é ā or 〗 into normalized (bug 14952) text + // Convert things like é ā or 〗 into normalized (bug 14952) text $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text ); $t = new Title(); @@ -322,7 +321,7 @@ class Title { $t->secureAndSplit(); if ( $defaultNamespace == NS_MAIN ) { - $cache->set( $text, $t ); + $titleCache->set( $text, $t ); } return $t; } @@ -363,11 +362,11 @@ class Title { } /** - * @return MapCacheLRU + * @return HashBagOStuff */ private static function getTitleCache() { if ( self::$titleCache == null ) { - self::$titleCache = new MapCacheLRU( self::CACHE_MAX ); + self::$titleCache = new HashBagOStuff( array( 'maxKeys' => self::CACHE_MAX ) ); } return self::$titleCache; } @@ -1008,10 +1007,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 ) ) { @@ -1420,6 +1417,7 @@ 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 ) { @@ -1945,7 +1943,7 @@ class Title { * - secure : does cheap and expensive checks, using the master as needed * @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() @@ -1954,9 +1952,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] ); } } @@ -2055,6 +2056,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' ); @@ -4383,7 +4387,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 ) { @@ -4418,12 +4422,9 @@ 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' ) ); } }