/**
* Lazy-initialized variables, invalidated with clearInstanceCache
*/
- var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mSkin, $mRights,
- $mBlockreason, $mBlock, $mEffectiveGroups, $mBlockedGlobally,
+ var $mNewtalk, $mDatePreference, $mBlockedby, $mHash, $mRights,
+ $mBlockreason, $mEffectiveGroups, $mBlockedGlobally,
$mLocked, $mHideName, $mOptions;
+ /**
+ * @var Skin
+ */
+ var $mSkin;
+
+ /**
+ * @var Block
+ */
+ var $mBlock;
+
static $idCacheByName = array();
/**
$this->clearInstanceCache( 'defaults' );
}
+ function __toString(){
+ return $this->getName();
+ }
+
/**
* Load the user table data for this object from the source given by mFrom.
*/
return false;
}
- if( preg_match( '/[' . preg_quote( $wgInvalidUsernameCharacters, '/' ) . ']/', $name ) ) {
- wfDebugLog( 'username', __METHOD__ .
- ": '$name' invalid due to wgInvalidUsernameCharacters" );
- return false;
+ // Preg yells if you try to give it an empty string
+ if( $wgInvalidUsernameCharacters !== '' ) {
+ if( preg_match( '/[' . preg_quote( $wgInvalidUsernameCharacters, '/' ) . ']/', $name ) ) {
+ wfDebugLog( 'username', __METHOD__ .
+ ": '$name' invalid due to wgInvalidUsernameCharacters" );
+ return false;
+ }
}
return self::isUsableName( $name );
}
}
- if ( $wgRequest->getCookie( 'UserID' ) !== null ) {
- $sId = intval( $wgRequest->getCookie( 'UserID' ) );
- if( isset( $_SESSION['wsUserID'] ) && $sId != $_SESSION['wsUserID'] ) {
+ $cookieId = $wgRequest->getCookie( 'UserID' );
+ $sessId = $wgRequest->getSessionData( 'wsUserID' );
+
+ if ( $cookieId !== null ) {
+ $sId = intval( $cookieId );
+ if( $sessId !== null && $cookieId != $sessId ) {
$this->loadDefaults(); // Possible collision!
- wfDebugLog( 'loginSessions', "Session user ID ({$_SESSION['wsUserID']}) and
+ wfDebugLog( 'loginSessions', "Session user ID ($sessId) and
cookie user ID ($sId) don't match!" );
return false;
}
- $_SESSION['wsUserID'] = $sId;
- } else if ( isset( $_SESSION['wsUserID'] ) ) {
- if ( $_SESSION['wsUserID'] != 0 ) {
- $sId = $_SESSION['wsUserID'];
- } else {
- $this->loadDefaults();
- return false;
- }
+ $wgRequest->setSessionData( 'wsUserID', $sId );
+ } else if ( $sessId !== null && $sessId != 0 ) {
+ $sId = $sessId;
} else {
$this->loadDefaults();
return false;
}
- if ( isset( $_SESSION['wsUserName'] ) ) {
- $sName = $_SESSION['wsUserName'];
- } else if ( $wgRequest->getCookie('UserName') !== null ) {
- $sName = $wgRequest->getCookie('UserName');
- $_SESSION['wsUserName'] = $sName;
+ if ( $wgRequest->getSessionData( 'wsUserName' ) !== null ) {
+ $sName = $wgRequest->getSessionData( 'wsUserName' );
+ } else if ( $wgRequest->getCookie( 'UserName' ) !== null ) {
+ $sName = $wgRequest->getCookie( 'UserName' );
+ $wgRequest->setSessionData( 'wsUserName', $sName );
} else {
$this->loadDefaults();
return false;
return false;
}
- if ( isset( $_SESSION['wsToken'] ) ) {
- $passwordCorrect = $_SESSION['wsToken'] == $this->mToken;
+ if ( $wgRequest->getSessionData( 'wsToken' ) !== null ) {
+ $passwordCorrect = $this->mToken == $wgRequest->getSessionData( 'wsToken' );
$from = 'session';
} else if ( $wgRequest->getCookie( 'Token' ) !== null ) {
$passwordCorrect = $this->mToken == $wgRequest->getCookie( 'Token' );
}
if ( ( $sName == $this->mName ) && $passwordCorrect ) {
- $_SESSION['wsToken'] = $this->mToken;
+ $wgRequest->setSessionData( 'wsToken', $this->mToken );
wfDebug( "User: logged in from $from\n" );
return true;
} else {
$this->mAllowUsertalk = 0;
# Check if we are looking at an IP or a logged-in user
- if ( $this->isIP( $this->getName() ) ) {
+ if ( $this->isAllowed( 'ipblock-exempt' ) ) {
+ # Exempt from all types of IP-block
+ $ip = '';
+ } elseif ( $this->isIP( $this->getName() ) ) {
$ip = $this->getName();
} else {
# Check if we are looking at the current user
}
}
- if ( $this->isAllowed( 'ipblock-exempt' ) ) {
- # Exempt from all types of IP-block
- $ip = '';
- }
-
# User/IP blocking
$this->mBlock = new Block();
$this->mBlock->fromMaster( !$bFromSlave );
* Reset all options to the site defaults
*/
function resetOptions() {
- $this->mOptions = User::getDefaultOptions();
+ $this->mOptions = self::getDefaultOptions();
}
/**
* @todo: FIXME : need to check the old failback system [AV]
*/
function getSkin( $t = null ) {
- if ( $t ) {
+ if( !$this->mSkin ) {
+ global $wgOut;
+ $this->mSkin = $this->createSkinObject();
+ $this->mSkin->setTitle( $wgOut->getTitle() );
+ }
+ if ( $t && ( !$this->mSkin->getTitle() || !$t->equals( $this->mSkin->getTitle() ) ) ) {
$skin = $this->createSkinObject();
$skin->setTitle( $t );
return $skin;
} else {
- if ( !$this->mSkin ) {
- $this->mSkin = $this->createSkinObject();
- }
-
- if ( !$this->mSkin->getTitle() ) {
- global $wgOut;
- $t = $wgOut->getTitle();
- $this->mSkin->setTitle($t);
- }
-
return $this->mSkin;
}
}
/**
* Set the default cookies for this session on the user's client.
+ *
+ * @param $request WebRequest object to use; $wgRequest will be used if null
+ * is passed.
*/
- function setCookies() {
+ function setCookies( $request = null ) {
+ if ( $request === null ) {
+ global $wgRequest;
+ $request = $wgRequest;
+ }
+
$this->load();
if ( 0 == $this->mId ) return;
$session = array(
}
wfRunHooks( 'UserSetCookies', array( $this, &$session, &$cookies ) );
- #check for null, since the hook could cause a null value
- if ( !is_null( $session ) && isset( $_SESSION ) ){
- $_SESSION = $session + $_SESSION;
+
+ foreach ( $session as $name => $value ) {
+ $request->setSessionData( $name, $value );
}
foreach ( $cookies as $name => $value ) {
if ( $value === false ) {
* @see logout()
*/
function doLogout() {
+ global $wgRequest;
+
$this->clearInstanceCache( 'defaults' );
- $_SESSION['wsUserID'] = 0;
+ $wgRequest->setSessionData( 'wsUserID', 0 );
$this->clearCookie( 'UserID' );
$this->clearCookie( 'Token' );
* 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
+ * @deprecated since 1.17 use the ParserOptions object to get the relevant options
* @return String Page rendering hash
*/
function getPageRenderingHash() {
* @return Boolean: True if the given password is correct, otherwise False.
*/
function checkPassword( $password ) {
- global $wgAuth;
+ global $wgAuth, $wgLegacyEncoding;
$this->load();
// Even though we stop people from creating passwords that
}
if ( self::comparePasswords( $this->mPassword, $password, $this->mId ) ) {
return true;
- } elseif ( function_exists( 'iconv' ) ) {
+ } elseif ( $wgLegacyEncoding ) {
# 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 ( self::comparePasswords( $this->mPassword, $cp1252Password, $this->mId ) ) {
+ if ( $cp1252Password != $password &&
+ self::comparePasswords( $this->mPassword, $cp1252Password, $this->mId ) )
+ {
return true;
}
}
* submission.
*
* @param $salt String|Array of Strings Optional function-specific data for hashing
+ * @param $request WebRequest object to use or null to use $wgRequest
* @return String The new edit token
*/
- function editToken( $salt = '' ) {
+ function editToken( $salt = '', $request = null ) {
+ if ( $request == null ) {
+ global $wgRequest;
+ $request = $wgRequest;
+ }
+
if ( $this->isAnon() ) {
return EDIT_TOKEN_SUFFIX;
} else {
- if( !isset( $_SESSION['wsEditToken'] ) ) {
+ $token = $request->getSessionData( 'wsEditToken' );
+ if ( $token === null ) {
$token = self::generateToken();
- $_SESSION['wsEditToken'] = $token;
- } else {
- $token = $_SESSION['wsEditToken'];
+ $request->setSessionData( 'wsEditToken', $token );
}
if( is_array( $salt ) ) {
$salt = implode( '|', $salt );
*
* @param $val String Input value to compare
* @param $salt String Optional function-specific data for hashing
+ * @param $request WebRequest object to use or null to use $wgRequest
* @return Boolean: Whether the token matches
*/
- function matchEditToken( $val, $salt = '' ) {
- $sessionToken = $this->editToken( $salt );
+ function matchEditToken( $val, $salt = '', $request = null ) {
+ $sessionToken = $this->editToken( $salt, $request );
if ( $val != $sessionToken ) {
wfDebug( "User::matchEditToken: broken session data\n" );
}
*
* @param $val String Input value to compare
* @param $salt String Optional function-specific data for hashing
+ * @param $request WebRequest object to use or null to use $wgRequest
* @return Boolean: Whether the token matches
*/
- function matchEditTokenNoSuffix( $val, $salt = '' ) {
- $sessionToken = $this->editToken( $salt );
+ function matchEditTokenNoSuffix( $val, $salt = '', $request = null ) {
+ $sessionToken = $this->editToken( $salt, $request );
return substr( $sessionToken, 0, 32 ) == substr( $val, 0, 32 );
}
* @private
*/
function confirmationToken( &$expiration ) {
+ global $wgUserEmailConfirmationTokenExpiry;
$now = time();
- $expires = $now + 7 * 24 * 60 * 60;
+ $expires = $now + $wgUserEmailConfirmationTokenExpiry;
$expiration = wfTimestamp( TS_MW, $expires );
$token = self::generateToken( $this->mId . $this->mEmail . $expires );
$hash = md5( $token );
static function getRightDescription( $right ) {
$key = "right-$right";
$name = wfMsg( $key );
- return $name == '' || wfEmptyMsg( $key, $name )
+ return $name == '' || wfEmptyMsg( $key )
? $right
: $name;
}
return $ret;
}
-
- /**
- * Format the user message using a hook, a template, or, failing these, a static format.
- * @param $subject String the subject of the message
- * @param $text String the content of the message
- * @param $signature String the signature, if provided.
- */
- static protected function formatUserMessage( $subject, $text, $signature ) {
- if ( wfRunHooks( 'FormatUserMessage',
- array( $subject, &$text, $signature ) ) ) {
-
- $signature = empty($signature) ? "~~~~~" : "{$signature} ~~~~~";
-
- $template = Title::newFromText( wfMsgForContent( 'usermessage-template' ) );
- if ( !$template
- || $template->getNamespace() !== NS_TEMPLATE
- || !$template->exists() ) {
- $text = "\n== $subject ==\n\n$text\n\n-- $signature";
- } else {
- $text = '{{'. $template->getText()
- . " | subject=$subject | body=$text | signature=$signature }}";
- }
- }
-
- return $text;
- }
-
- /**
- * Leave a user a message
- * @param $subject String the subject of the message
- * @param $text String the message to leave
- * @param $signature String Text to leave in the signature
- * @param $summary String the summary for this change, defaults to
- * "Leave system message."
- * @param $editor User The user leaving the message, defaults to
- * "{{MediaWiki:usermessage-editor}}"
- * @param $flags Int default edit flags
- *
- * @return boolean true if it was successful
- */
- public function leaveUserMessage( $subject, $text, $signature = "",
- $summary = null, $editor = null, $flags = 0 ) {
- if ( !isset( $summary ) ) {
- $summary = wfMsgForContent( 'usermessage-summary' );
- }
-
- if ( !isset( $editor ) ) {
- $editor = User::newFromName( wfMsgForContent( 'usermessage-editor' ) );
- if ( !$editor->isLoggedIn() ) {
- $editor->addToDatabase();
- }
- }
-
- $article = new Article( $this->getTalkPage() );
- wfRunHooks( 'SetupUserMessageArticle',
- array( $this, &$article, $subject, $text, $signature, $summary, $editor ) );
-
-
- $text = self::formatUserMessage( $subject, $text, $signature );
- $flags = $article->checkFlags( $flags );
-
- if ( $flags & EDIT_UPDATE ) {
- $text = $article->getContent() . $text;
- }
-
- $dbw = wfGetDB( DB_MASTER );
- $dbw->begin();
-
- try {
- $status = $article->doEdit( $text, $summary, $flags, false, $editor );
- } catch ( DBQueryError $e ) {
- $status = Status::newFatal("DB Error");
- }
-
- if ( $status->isGood() ) {
- // Set newtalk with the right user ID
- $this->setNewtalk( true );
- wfRunHooks( 'AfterUserMessage',
- array( $this, $article, $subject, $text, $signature, $summary, $editor ) );
- $dbw->commit();
- } else {
- // The article was concurrently created
- wfDebug( __METHOD__ . ": Error ".$status->getWikiText() );
- $dbw->rollback();
- }
-
- return $status->isGood();
- }
}