X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fuser%2FUser.php;h=ee617a2caf9bc31c3ad2fe50f9f8c0aaba18db4f;hb=6164423de0f34b5c264bacebb8371811e07fdaa8;hp=a272b37d5f8ab28918799014ff10a4f1c0dd443c;hpb=54277fb7d5609c26b83d4fc7543b2c826fcae0bf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/User.php b/includes/user/User.php index a272b37d5f..ee617a2caf 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -20,14 +20,16 @@ * @file */ +use MediaWiki\MediaWikiServices; use MediaWiki\Session\SessionManager; +use MediaWiki\Session\Token; /** * String Some punctuation to prevent editing from broken text-mangling proxies. - * @deprecated since 1.27, use \\MediaWiki\\Session\\Token::SUFFIX + * @deprecated since 1.27, use \MediaWiki\Session\Token::SUFFIX * @ingroup Constants */ -define( 'EDIT_TOKEN_SUFFIX', MediaWiki\Session\Token::SUFFIX ); +define( 'EDIT_TOKEN_SUFFIX', Token::SUFFIX ); /** * The User object encapsulates all of the user-specific settings (user_id, @@ -53,7 +55,7 @@ class User implements IDBAccessObject { /** * Global constant made accessible as class constants so that autoloader * magic can be used. - * @deprecated since 1.27, use \\MediaWiki\\Session\\Token::SUFFIX + * @deprecated since 1.27, use \MediaWiki\Session\Token::SUFFIX */ const EDIT_TOKEN_SUFFIX = EDIT_TOKEN_SUFFIX; @@ -274,8 +276,8 @@ class User implements IDBAccessObject { protected $mImplicitGroups; /** @var array */ protected $mFormerGroups; - /** @var bool */ - protected $mBlockedGlobally; + /** @var Block */ + protected $mGlobalBlock; /** @var bool */ protected $mLocked; /** @var bool */ @@ -473,7 +475,7 @@ class User implements IDBAccessObject { */ protected static function getInProcessCache() { if ( !self::$inProcessCache ) { - self::$inProcessCache = new HashBagOStuff( ['maxKeys' => 10] ); + self::$inProcessCache = new HashBagOStuff( [ 'maxKeys' => 10 ] ); } return self::$inProcessCache; } @@ -1069,9 +1071,9 @@ class User implements IDBAccessObject { // Clean up name according to title rules, // but only when validation is requested (bug 12654) $t = ( $validate !== false ) ? - Title::newFromText( $name ) : Title::makeTitle( NS_USER, $name ); + Title::newFromText( $name, NS_USER ) : Title::makeTitle( NS_USER, $name ); // Check for invalid titles - if ( is_null( $t ) ) { + if ( is_null( $t ) || $t->getNamespace() !== NS_USER || $t->isExternal() ) { return false; } @@ -1533,7 +1535,8 @@ class User implements IDBAccessObject { foreach ( LanguageConverter::$languagesWithVariants as $langCode ) { $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode; } - foreach ( SearchEngine::searchableNamespaces() as $nsnum => $nsname ) { + $namespaces = MediaWikiServices::getInstance()->getSearchEngineConfig()->searchableNamespaces(); + foreach ( $namespaces as $nsnum => $nsname ) { $defOpt['searchNs' . $nsnum] = !empty( $wgNamespacesToBeSearchedDefault[$nsnum] ); } $defOpt['skin'] = Skin::normalizeKey( $wgDefaultSkin ); @@ -1991,8 +1994,22 @@ class User implements IDBAccessObject { * @return bool True if blocked, false otherwise */ public function isBlockedGlobally( $ip = '' ) { - if ( $this->mBlockedGlobally !== null ) { - return $this->mBlockedGlobally; + return $this->getGlobalBlock( $ip ) instanceof Block; + } + + /** + * Check if user is blocked on all wikis. + * Do not use for actual edit permission checks! + * This is intended for quick UI checks. + * + * @param string $ip IP address, uses current client if none given + * @return Block|null Block object if blocked, null otherwise + * @throws FatalError + * @throws MWException + */ + public function getGlobalBlock( $ip = '' ) { + if ( $this->mGlobalBlock !== null ) { + return $this->mGlobalBlock ?: null; } // User is already an IP? if ( IP::isIPAddress( $this->getName() ) ) { @@ -2001,9 +2018,17 @@ class User implements IDBAccessObject { $ip = $this->getRequest()->getIP(); } $blocked = false; - Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked ] ); - $this->mBlockedGlobally = (bool)$blocked; - return $this->mBlockedGlobally; + $block = null; + Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked, &$block ] ); + + if ( $blocked && $block === null ) { + // back-compat: UserIsBlockedGlobally didn't have $block param first + $block = new Block; + $block->setTarget( $ip ); + } + + $this->mGlobalBlock = $blocked ? $block : false; + return $this->mGlobalBlock ?: null; } /** @@ -2693,14 +2718,36 @@ class User implements IDBAccessObject { return Status::newGood( true ); } + $type = $oldaddr != '' ? 'changed' : 'set'; + $notificationResult = null; + + if ( $wgEmailAuthentication ) { + // Send the user an email notifying the user of the change in registered + // email address on their previous email address + if ( $type == 'changed' ) { + $change = $str != '' ? 'changed' : 'removed'; + $notificationResult = $this->sendMail( + wfMessage( 'notificationemail_subject_' . $change )->text(), + wfMessage( 'notificationemail_body_' . $change, + $this->getRequest()->getIP(), + $this->getName(), + $str )->text() + ); + } + } + $this->setEmail( $str ); if ( $str !== '' && $wgEmailAuthentication ) { // Send a confirmation request to the new address if needed - $type = $oldaddr != '' ? 'changed' : 'set'; $result = $this->sendConfirmationMail( $type ); + + if ( $notificationResult !== null ) { + $result->merge( $notificationResult ); + } + if ( $result->isGood() ) { - // Say to the caller that a confirmation mail has been sent + // Say to the caller that a confirmation and notification mail has been sent $result->value = 'eauth'; } } else { @@ -3453,7 +3500,7 @@ class User implements IDBAccessObject { */ public function isWatched( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( $title->isWatchable() && ( !$checkRights || $this->isAllowed( 'viewmywatchlist' ) ) ) { - return WatchedItemStore::getDefaultInstance()->isWatched( $this, $title ); + return MediaWikiServices::getInstance()->getWatchedItemStore()->isWatched( $this, $title ); } return false; } @@ -3467,7 +3514,7 @@ class User implements IDBAccessObject { */ public function addWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) { - WatchedItemStore::getDefaultInstance()->addWatchBatchForUser( + MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser( $this, [ $title->getSubjectPage(), $title->getTalkPage() ] ); @@ -3484,8 +3531,9 @@ class User implements IDBAccessObject { */ public function removeWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) { - WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getSubjectPage() ); - WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getTalkPage() ); + $store = MediaWikiServices::getInstance()->getWatchedItemStore(); + $store->removeWatch( $this, $title->getSubjectPage() ); + $store->removeWatch( $this, $title->getTalkPage() ); } $this->invalidateCache(); } @@ -3554,7 +3602,7 @@ class User implements IDBAccessObject { $force = 'force'; } - WatchedItemStore::getDefaultInstance() + MediaWikiServices::getInstance()->getWatchedItemStore() ->resetNotificationTimestamp( $this, $title, $force, $oldid ); } @@ -4199,7 +4247,7 @@ class User implements IDBAccessObject { * @since 1.27 * @param string|array $salt Array of Strings Optional function-specific data for hashing * @param WebRequest|null $request WebRequest object to use or null to use $wgRequest - * @return MediaWiki\\Session\\Token The new edit token + * @return MediaWiki\Session\Token The new edit token */ public function getEditTokenObject( $salt = '', $request = null ) { if ( $this->isAnon() ) { @@ -4229,7 +4277,7 @@ class User implements IDBAccessObject { /** * Get the embedded timestamp from a token. - * @deprecated since 1.27, use \\MediaWiki\\Session\\Token::getTimestamp instead. + * @deprecated since 1.27, use \MediaWiki\Session\Token::getTimestamp instead. * @param string $val Input token * @return int|null */ @@ -4265,7 +4313,7 @@ class User implements IDBAccessObject { * @return bool Whether the token matches */ public function matchEditTokenNoSuffix( $val, $salt = '', $request = null, $maxage = null ) { - $val = substr( $val, 0, strspn( $val, '0123456789abcdef' ) ) . self::EDIT_TOKEN_SUFFIX; + $val = substr( $val, 0, strspn( $val, '0123456789abcdef' ) ) . Token::SUFFIX; return $this->matchEditToken( $val, $salt, $request, $maxage ); }