Merge "API: Handle "special" options in action=options"
[lhc/web/wiklou.git] / includes / User.php
index d6e0a51..a762cd0 100644 (file)
@@ -465,7 +465,7 @@ class User {
         * user_name and user_real_name are not provided because the whole row
         * will be loaded once more from the database when accessing them.
         *
-        * @param array $row A row from the user table
+        * @param stdClass $row A row from the user table
         * @param array $data Further data to load into the object (see User::loadFromRow for valid keys)
         * @return User
         */
@@ -1041,7 +1041,7 @@ class User {
        /**
         * Initialize this object from a row from the user table.
         *
-        * @param array $row Row from the user table to load.
+        * @param stdClass $row Row from the user table to load.
         * @param array $data Further user data to load into the object
         *
         *      user_groups             Array with groups out of the user_groups table
@@ -1307,8 +1307,8 @@ class User {
 
                // Proxy blocking
                if ( !$block instanceof Block && $ip !== null && !$this->isAllowed( 'proxyunbannable' )
-                       && !in_array( $ip, $wgProxyWhitelist ) )
-               {
+                       && !in_array( $ip, $wgProxyWhitelist )
+               {
                        // Local list
                        if ( self::isLocallyBlockedProxy( $ip ) ) {
                                $block = new Block;
@@ -1632,8 +1632,8 @@ class User {
                $blocked = $this->isBlocked( $bFromSlave );
                $allowUsertalk = ( $wgBlockAllowsUTEdit ? $this->mAllowUsertalk : false );
                // If a user's name is suppressed, they cannot make edits anywhere
-               if ( !$this->mHideName && $allowUsertalk && $title->getText() === $this->getName() &&
-                 $title->getNamespace() == NS_USER_TALK ) {
+               if ( !$this->mHideName && $allowUsertalk && $title->getText() === $this->getName()
+                       && $title->getNamespace() == NS_USER_TALK ) {
                        $blocked = false;
                        wfDebug( __METHOD__ . ": self-talk page, ignoring any blocks\n" );
                }
@@ -2173,14 +2173,21 @@ class User {
        /**
         * Set the password for a password reminder or new account email
         *
-        * @param string $str New password to set
+        * @param $str New password to set or null to set an invalid
+        *  password hash meaning that the user will not be able to use it
         * @param bool $throttle If true, reset the throttle timestamp to the present
         */
        public function setNewpassword( $str, $throttle = true ) {
                $this->load();
-               $this->mNewpassword = self::crypt( $str );
-               if ( $throttle ) {
-                       $this->mNewpassTime = wfTimestampNow();
+
+               if ( $str === null ) {
+                       $this->mNewpassword = '';
+                       $this->mNewpassTime = null;
+               } else {
+                       $this->mNewpassword = self::crypt( $str );
+                       if ( $throttle ) {
+                               $this->mNewpassTime = wfTimestampNow();
+                       }
                }
        }
 
@@ -3033,8 +3040,9 @@ class User {
         * the next change of the page if it's watched etc.
         * @note If the user doesn't have 'editmywatchlist', this will do nothing.
         * @param $title Title of the article to look at
+        * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
         */
-       public function clearNotification( &$title ) {
+       public function clearNotification( &$title, $oldid = 0 ) {
                global $wgUseEnotif, $wgShowUpdatedMarker;
 
                // Do nothing if the database is locked to writes
@@ -3047,12 +3055,25 @@ class User {
                        return;
                }
 
-               if ( $title->getNamespace() == NS_USER_TALK &&
-                       $title->getText() == $this->getName() ) {
-                       if ( !wfRunHooks( 'UserClearNewTalkNotification', array( &$this ) ) ) {
+               // If we're working on user's talk page, we should update the talk page message indicator
+               if ( $title->getNamespace() == NS_USER_TALK && $title->getText() == $this->getName() ) {
+                       if ( !wfRunHooks( 'UserClearNewTalkNotification', array( &$this, $oldid ) ) ) {
                                return;
                        }
-                       $this->setNewtalk( false );
+
+                       $nextid = $oldid ? $title->getNextRevisionID( $oldid ) : null;
+
+                       if ( !$oldid || !$nextid ) {
+                               // If we're looking at the latest revision, we should definitely clear it
+                               $this->setNewtalk( false );
+                       } else {
+                               // Otherwise we should update its revision, if it's present
+                               if ( $this->getNewtalk() ) {
+                                       // Naturally the other one won't clear by itself
+                                       $this->setNewtalk( false );
+                                       $this->setNewtalk( true, Revision::newFromId( $nextid ) );
+                               }
+                       }
                }
 
                if ( !$wgUseEnotif && !$wgShowUpdatedMarker ) {
@@ -3069,13 +3090,11 @@ class User {
                // and when it does have to be executed, it can be on a slave
                // If this is the user's newtalk page, we always update the timestamp
                $force = '';
-               if ( $title->getNamespace() == NS_USER_TALK &&
-                       $title->getText() == $this->getName() )
-               {
+               if ( $title->getNamespace() == NS_USER_TALK && $title->getText() == $this->getName() ) {
                        $force = 'force';
                }
 
-               $this->getWatchedItem( $title )->resetNotificationTimestamp( $force );
+               $this->getWatchedItem( $title )->resetNotificationTimestamp( $force, $oldid );
        }
 
        /**
@@ -3103,14 +3122,12 @@ class User {
                if ( $id != 0 ) {
                        $dbw = wfGetDB( DB_MASTER );
                        $dbw->update( 'watchlist',
-                               array( /* SET */
-                                       'wl_notificationtimestamp' => null
-                               ), array( /* WHERE */
-                                       'wl_user' => $id
-                               ), __METHOD__
+                               array( /* SET */ 'wl_notificationtimestamp' => null ),
+                               array( /* WHERE */ 'wl_user' => $id ),
+                               __METHOD__
                        );
-               #       We also need to clear here the "you have new message" notification for the own user_talk page
-               #       This is cleared one page view later in Article::viewUpdates();
+                       // We also need to clear here the "you have new message" notification for the own user_talk page;
+                       // it's cleared one page view later in WikiPage::doViewUpdates().
                }
        }
 
@@ -3506,56 +3523,6 @@ class User {
                return (bool)$userblock->doAutoblock( $this->getRequest()->getIP() );
        }
 
-       /**
-        * Generate a string which will be different for any combination of
-        * user options which would produce different parser output.
-        * This will be used as part of the hash key for the parser cache,
-        * so users with the same options can share the same cached data
-        * safely.
-        *
-        * Extensions which require it should install 'PageRenderingHash' hook,
-        * which will give them a chance to modify this key based on their own
-        * settings.
-        *
-        * @deprecated since 1.17 use the ParserOptions object to get the relevant options
-        * @return string Page rendering hash
-        */
-       public function getPageRenderingHash() {
-               wfDeprecated( __METHOD__, '1.17' );
-
-               global $wgRenderHashAppend, $wgLang, $wgContLang;
-               if ( $this->mHash ) {
-                       return $this->mHash;
-               }
-
-               // stubthreshold is only included below for completeness,
-               // since it disables the parser cache, its value will always
-               // be 0 when this function is called by parsercache.
-
-               $confstr = $this->getOption( 'math' );
-               $confstr .= '!' . $this->getStubThreshold();
-               $confstr .= '!' . ( $this->getOption( 'numberheadings' ) ? '1' : '' );
-               $confstr .= '!' . $wgLang->getCode();
-               $confstr .= '!' . $this->getOption( 'thumbsize' );
-               // add in language specific options, if any
-               $extra = $wgContLang->getExtraHashOptions();
-               $confstr .= $extra;
-
-               // Since the skin could be overloading link(), it should be
-               // included here but in practice, none of our skins do that.
-
-               $confstr .= $wgRenderHashAppend;
-
-               // Give a chance for extensions to modify the hash, if they have
-               // extra options or other effects on the parser cache.
-               wfRunHooks( 'PageRenderingHash', array( &$confstr ) );
-
-               // Make it a valid memcached key fragment
-               $confstr = str_replace( ' ', '_', $confstr );
-               $this->mHash = $confstr;
-               return $confstr;
-       }
-
        /**
         * Get whether the user is explicitly blocked from account creation.
         * @return bool|Block
@@ -3655,9 +3622,9 @@ class User {
                        // Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
                        // Check for this with iconv
                        $cp1252Password = iconv( 'UTF-8', 'WINDOWS-1252//TRANSLIT', $password );
-                       if ( $cp1252Password != $password &&
-                               self::comparePasswords( $this->mPassword, $cp1252Password, $this->mId ) )
-                       {
+                       if ( $cp1252Password != $password
+                               && self::comparePasswords( $this->mPassword, $cp1252Password, $this->mId )
+                       {
                                return true;
                        }
                }
@@ -3822,8 +3789,9 @@ class User {
         */
        public function sendMail( $subject, $body, $from = null, $replyto = null ) {
                if ( is_null( $from ) ) {
-                       global $wgPasswordSender, $wgPasswordSenderName;
-                       $sender = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
+                       global $wgPasswordSender;
+                       $sender = new MailAddress( $wgPasswordSender,
+                               wfMessage( 'emailsender' )->inContentLanguage()->text() );
                } else {
                        $sender = new MailAddress( $from );
                }