X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=8a15b541d72e29953d01a2aaeb748e98f492c8b0;hb=e66ee985e0792d2c28ebb0d5b299af5bce87eb9b;hp=601211d1b11cc40e4d3ae9d432088e8e8100f976;hpb=f61844cbe3dfa15b164573672ed87324aa14a51a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 601211d1b1..8a15b541d7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -313,7 +313,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 +345,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 +509,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; } @@ -1419,7 +1419,7 @@ class Title { * @param string $fragment Text */ public function setFragment( $fragment ) { - $this->mFragment = str_replace( '_', ' ', substr( $fragment, 1 ) ); + $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' ); } /** @@ -1449,7 +1449,7 @@ class Title { */ public function getPrefixedDBkey() { $s = $this->prefix( $this->mDbkeyform ); - $s = str_replace( ' ', '_', $s ); + $s = strtr( $s, ' ', '_' ); return $s; } @@ -1462,7 +1462,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 +1610,7 @@ class Title { */ public function getSubpageUrlForm() { $text = $this->getSubpageText(); - $text = wfUrlencode( str_replace( ' ', '_', $text ) ); + $text = wfUrlencode( strtr( $text, ' ', '_' ) ); return $text; } @@ -1621,7 +1621,7 @@ class Title { */ public function getPrefixedURL() { $s = $this->prefix( $this->mDbkeyform ); - $s = wfUrlencode( str_replace( ' ', '_', $s ) ); + $s = wfUrlencode( strtr( $s, ' ', '_' ) ); return $s; } @@ -3309,6 +3309,14 @@ class Title { $this->mIsBigDeletion = null; } + public static function clearCaches() { + $linkCache = LinkCache::singleton(); + $linkCache->clear(); + + $titleCache = self::getTitleCache(); + $titleCache->clear(); + } + /** * Capitalize a text string for a title if it belongs to a namespace that capitalizes * @@ -3362,7 +3370,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 ) { @@ -3624,7 +3632,7 @@ class Title { ); } - return $errors ? : true; + return $errors ?: true; } /** @@ -4372,9 +4380,10 @@ class Title { /** * Updates page_touched for this page; called from LinksUpdate.php * + * @param integer $purgeTime TS_MW timestamp [optional] * @return bool True if the update succeeded */ - public function invalidateCache() { + public function invalidateCache( $purgeTime = null ) { if ( wfReadOnly() ) { return false; } @@ -4386,11 +4395,13 @@ class Title { $method = __METHOD__; $dbw = wfGetDB( DB_MASTER ); $conds = $this->pageCond(); - $dbw->onTransactionIdle( function () use ( $dbw, $conds, $method ) { + $dbw->onTransactionIdle( function () use ( $dbw, $conds, $method, $purgeTime ) { + $dbTimestamp = $dbw->timestamp( $purgeTime ?: time() ); + $dbw->update( 'page', - array( 'page_touched' => $dbw->timestamp() ), - $conds, + array( 'page_touched' => $dbTimestamp ), + $conds + array( 'page_touched < ' . $dbw->addQuotes( $dbTimestamp ) ), $method ); } ); @@ -4536,15 +4547,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; @@ -4727,7 +4740,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(); @@ -4748,4 +4761,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, '_', ' ' ); + } + }