Merge "More accurate function descriptions"
[lhc/web/wiklou.git] / includes / User.php
index 973e7cc..cca0458 100644 (file)
@@ -2299,7 +2299,7 @@ class User {
                # set it, and then it was disabled removing their ability to change it).  But
                # we don't want to erase the preferences in the database in case the preference
                # is re-enabled again.  So don't touch $mOptions, just override the returned value
-               if ( in_array( $oname, $wgHiddenPrefs ) && !$ignoreHidden ) {
+               if ( !$ignoreHidden && in_array( $oname, $wgHiddenPrefs ) ) {
                        return self::getDefaultOption( $oname );
                }
 
@@ -2379,6 +2379,49 @@ class User {
                $this->mOptions[$oname] = $val;
        }
 
+       /**
+        * Get a token stored in the preferences (like the watchlist one),
+        * resetting it if it's empty (and saving changes).
+        *
+        * @param string $oname The option name to retrieve the token from
+        * @return string|bool User's current value for the option, or false if this option is disabled.
+        * @see resetTokenFromOption()
+        * @see getOption()
+        */
+       public function getTokenFromOption( $oname ) {
+               global $wgHiddenPrefs;
+               if ( in_array( $oname, $wgHiddenPrefs ) ) {
+                       return false;
+               }
+
+               $token = $this->getOption( $oname );
+               if ( !$token ) {
+                       $token = $this->resetTokenFromOption( $oname );
+                       $this->saveSettings();
+               }
+               return $token;
+       }
+
+       /**
+        * Reset a token stored in the preferences (like the watchlist one).
+        * *Does not* save user's preferences (similarly to setOption()).
+        *
+        * @param string $oname The option name to reset the token in
+        * @return string|bool New token value, or false if this option is disabled.
+        * @see getTokenFromOption()
+        * @see setOption()
+        */
+       public function resetTokenFromOption( $oname ) {
+               global $wgHiddenPrefs;
+               if ( in_array( $oname, $wgHiddenPrefs ) ) {
+                       return false;
+               }
+
+               $token = MWCryptRand::generateHex( 40 );
+               $this->setOption( $oname, $token );
+               return $token;
+       }
+
        /**
         * Return a list of the types of user options currently returned by
         * User::getOptionKinds().
@@ -2672,7 +2715,7 @@ class User {
 
        /**
         * Get the user's edit count.
-        * @return int
+        * @return int, null for anonymous users
         */
        public function getEditCount() {
                if ( !$this->getId() ) {
@@ -2694,10 +2737,10 @@ class User {
                                // it has not been initialized. do so.
                                $count = $this->initEditCount();
                        }
-                       $this->mEditCount = intval( $count );
+                       $this->mEditCount = $count;
                        wfProfileOut( __METHOD__ );
                }
-               return $this->mEditCount;
+               return (int) $this->mEditCount;
        }
 
        /**