# 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 );
}
$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().
/**
* Get the user's edit count.
- * @return int
+ * @return int, null for anonymous users
*/
public function getEditCount() {
if ( !$this->getId() ) {
// 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;
}
/**