return false;
}
-
// Ensure that the name can't be misresolved as a different title,
// such as with extra namespace keys at the start.
$parsed = Title::newFromText( $name );
* @note This no longer clears uncached lazy-initialised properties;
* the constructor does that instead.
*
- * @param $name string
+ * @param $name string|bool
*/
public function loadDefaults( $name = false ) {
wfProfileIn( __METHOD__ );
}
if ( $request->getSessionData( 'wsToken' ) ) {
- $passwordCorrect = $proposedUser->getToken( false ) === $request->getSessionData( 'wsToken' );
+ $passwordCorrect = ( $proposedUser->getToken( false ) === $request->getSessionData( 'wsToken' ) );
$from = 'session';
} elseif ( $request->getCookie( 'Token' ) ) {
- $passwordCorrect = $proposedUser->getToken( false ) === $request->getCookie( 'Token' );
+ # Get the token from DB/cache and clean it up to remove garbage padding.
+ # This deals with historical problems with bugs and the default column value.
+ $token = rtrim( $proposedUser->getToken( false ) ); // correct token
+ $passwordCorrect = ( strlen( $token ) && $token === $request->getCookie( 'Token' ) );
$from = 'cookie';
} else {
# No session or persistent login cookie
}
}
-
/**
* Get blocking information
* @param $bFromSlave Bool Whether to check the slave database first. To
/**
* Get the user's current token.
- * @param $forceCreation Force the generation of a new token if the user doesn't have one (default=true for backwards compatibility)
+ * @param $forceCreation bool Force the generation of a new token if the user doesn't have one (default=true for backwards compatibility)
* @return String Token
*/
public function getToken( $forceCreation = true ) {
* - 'registered' - preferences which are registered in core MediaWiki or
* by extensions using the UserGetDefaultOptions hook.
* - 'registered-multiselect' - as above, using the 'multiselect' type.
+ * - 'registered-checkmatrix' - as above, using the 'checkmatrix' type.
* - 'userjs' - preferences with names starting with 'userjs-', intended to
* be used by user scripts.
* - 'unused' - preferences about which MediaWiki doesn't know anything.
return array(
'registered',
'registered-multiselect',
+ 'registered-checkmatrix',
'userjs',
'unused'
);
$prefs = Preferences::getPreferences( $this, $context );
$mapping = array();
- // Multiselect options are stored in the database with one key per
- // option, each having a boolean value. Extract those keys.
+ // Multiselect and checkmatrix options are stored in the database with
+ // one key per option, each having a boolean value. Extract those keys.
$multiselectOptions = array();
foreach ( $prefs as $name => $info ) {
if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
unset( $prefs[$name] );
}
}
+ $checkmatrixOptions = array();
+ foreach ( $prefs as $name => $info ) {
+ if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
+ ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
+ $columns = HTMLFormField::flattenOptions( $info['columns'] );
+ $rows = HTMLFormField::flattenOptions( $info['rows'] );
+ $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name;
+
+ foreach ( $columns as $column ) {
+ foreach ( $rows as $row ) {
+ $checkmatrixOptions["$prefix-$column-$row"] = true;
+ }
+ }
+
+ unset( $prefs[$name] );
+ }
+ }
// $value is ignored
foreach ( $options as $key => $value ) {
$mapping[$key] = 'registered';
} elseif( isset( $multiselectOptions[$key] ) ) {
$mapping[$key] = 'registered-multiselect';
+ } elseif( isset( $checkmatrixOptions[$key] ) ) {
+ $mapping[$key] = 'registered-checkmatrix';
} elseif ( substr( $key, 0, 7 ) === 'userjs-' ) {
$mapping[$key] = 'userjs';
} else {
* and 'all', which forces a reset of *all* preferences and overrides everything else.
*
* @param $resetKinds array|string which kinds of preferences to reset. Defaults to
- * array( 'registered', 'registered-multiselect', 'unused' )
- * for backwards-compatibility.
+ * array( 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' )
+ * for backwards-compatibility.
* @param $context IContextSource|null context source used when $resetKinds
- * does not contain 'all', passed to getOptionKinds().
- * Defaults to RequestContext::getMain() when null.
+ * does not contain 'all', passed to getOptionKinds().
+ * Defaults to RequestContext::getMain() when null.
*/
public function resetOptions(
- $resetKinds = array( 'registered', 'registered-multiselect', 'unused' ),
+ $resetKinds = array( 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' ),
IContextSource $context = null
) {
$this->load();
*/
public function getStubThreshold() {
global $wgMaxArticleSize; # Maximum article size, in Kb
- $threshold = intval( $this->getOption( 'stubthreshold' ) );
+ $threshold = $this->getIntOption( 'stubthreshold' );
if ( $threshold > $wgMaxArticleSize * 1024 ) {
# If they have set an impossible value, disable the preference
# so we can use the parser cache again.
*
* @param $request WebRequest object to use; $wgRequest will be used if null
* is passed.
- * @param $secure Whether to force secure/insecure cookies or use default
+ * @param $secure bool Whether to force secure/insecure cookies or use default
*/
public function setCookies( $request = null, $secure = null ) {
if ( $request === null ) {
}
$this->load();
- if ( 0 == $this->mId ) return;
+ if ( 0 == $this->mId ) {
+ return;
+ }
if ( !$this->mToken ) {
// When token is empty or NULL generate a new one and then save it to the database
// This allows a wiki to re-secure itself after a leak of it's user table or $wgSecretKey
public static function createNew( $name, $params = array() ) {
$user = new User;
$user->load();
+ $user->setToken(); // init token
if ( isset( $params['options'] ) ) {
$user->mOptions = $params['options'] + (array)$user->mOptions;
unset( $params['options'] );
*/
public function addToDatabase() {
$this->load();
+ if ( !$this->mToken ) {
+ $this->setToken(); // init token
+ }
$this->mTouched = self::newTouchedTimestamp();
// 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->getOption( 'math' );
$confstr .= '!' . $this->getStubThreshold();
$confstr .= '!' . ( $this->getOption( 'numberheadings' ) ? '1' : '' );
$confstr .= '!' . $wgLang->getCode();
/**
* Generate a looking random token for various uses.
*
- * @param $salt String Optional salt value
* @return String The new random token
* @deprecated since 1.20; Use MWCryptRand for secure purposes or wfRandomString for pesudo-randomness
*/
- public static function generateToken( $salt = '' ) {
+ public static function generateToken() {
return MWCryptRand::generateHex( 32 );
}
/**
* Get the timestamp of account creation.
*
- * @return String|Bool Timestamp of account creation, or false for
- * non-existent/anonymous user accounts.
+ * @return String|Bool|Null Timestamp of account creation, false for
+ * non-existent/anonymous user accounts, or null if existing account
+ * but information is not in database.
*/
public function getRegistration() {
if ( $this->isAnon() ) {
/**
* Load the user options either from cache, the database or an array
*
- * @param $data Rows for the current user out of the user_properties table
+ * @param $data array Rows for the current user out of the user_properties table
*/
protected function loadOptions( $data = null ) {
global $wgContLang;