From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/specials/SpecialChangePassword.php | 248 ++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 includes/specials/SpecialChangePassword.php (limited to 'includes/specials/SpecialChangePassword.php') diff --git a/includes/specials/SpecialChangePassword.php b/includes/specials/SpecialChangePassword.php new file mode 100644 index 00000000..46562b36 --- /dev/null +++ b/includes/specials/SpecialChangePassword.php @@ -0,0 +1,248 @@ +readOnlyPage(); + return; + } + + $this->mUserName = $wgRequest->getVal( 'wpName' ); + $this->mOldpass = $wgRequest->getVal( 'wpPassword' ); + $this->mNewpass = $wgRequest->getVal( 'wpNewPassword' ); + $this->mRetype = $wgRequest->getVal( 'wpRetype' ); + $this->mDomain = $wgRequest->getVal( 'wpDomain' ); + + $this->setHeaders(); + $this->outputHeader(); + $wgOut->disallowUserJs(); + + if( !$wgRequest->wasPosted() && !$wgUser->isLoggedIn() ) { + $this->error( wfMsg( 'resetpass-no-info' ) ); + return; + } + + if( $wgRequest->wasPosted() && $wgRequest->getBool( 'wpCancel' ) ) { + $this->doReturnTo(); + return; + } + + if( $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { + try { + if ( isset( $_SESSION['wsDomain'] ) ) { + $this->mDomain = $_SESSION['wsDomain']; + } + $wgAuth->setDomain( $this->mDomain ); + if( !$wgAuth->allowPasswordChange() ) { + $this->error( wfMsg( 'resetpass_forbidden' ) ); + return; + } + + $this->attemptReset( $this->mNewpass, $this->mRetype ); + $wgOut->addWikiMsg( 'resetpass_success' ); + if( !$wgUser->isLoggedIn() ) { + LoginForm::setLoginToken(); + $token = LoginForm::getLoginToken(); + $data = array( + 'action' => 'submitlogin', + 'wpName' => $this->mUserName, + 'wpDomain' => $this->mDomain, + 'wpLoginToken' => $token, + 'wpPassword' => $this->mNewpass, + 'returnto' => $wgRequest->getVal( 'returnto' ), + ); + if( $wgRequest->getCheck( 'wpRemember' ) ) { + $data['wpRemember'] = 1; + } + $login = new LoginForm( new FauxRequest( $data, true ) ); + $login->execute( null ); + } + $this->doReturnTo(); + } catch( PasswordError $e ) { + $this->error( $e->getMessage() ); + } + } + $this->showForm(); + } + + function doReturnTo() { + global $wgRequest, $wgOut; + $titleObj = Title::newFromText( $wgRequest->getVal( 'returnto' ) ); + if ( !$titleObj instanceof Title ) { + $titleObj = Title::newMainPage(); + } + $wgOut->redirect( $titleObj->getFullURL() ); + } + + function error( $msg ) { + global $wgOut; + $wgOut->addHTML( Xml::element('p', array( 'class' => 'error' ), $msg ) ); + } + + function showForm() { + global $wgOut, $wgUser, $wgRequest; + + $self = $this->getTitle(); + if ( !$this->mUserName ) { + $this->mUserName = $wgUser->getName(); + } + $rememberMe = ''; + if ( !$wgUser->isLoggedIn() ) { + global $wgCookieExpiration, $wgLang; + $rememberMe = '' . + '' . + '' . + Xml::checkLabel( + wfMsgExt( 'remembermypassword', 'parsemag', $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) ), + 'wpRemember', 'wpRemember', + $wgRequest->getCheck( 'wpRemember' ) ) . + '' . + ''; + $submitMsg = 'resetpass_submit'; + $oldpassMsg = 'resetpass-temp-password'; + } else { + $oldpassMsg = 'oldpassword'; + $submitMsg = 'resetpass-submit-loggedin'; + } + $wgOut->addHTML( + Xml::fieldset( wfMsg( 'resetpass_header' ) ) . + Xml::openElement( 'form', + array( + 'method' => 'post', + 'action' => $self->getLocalUrl(), + 'id' => 'mw-resetpass-form' ) ) . "\n" . + Html::hidden( 'token', $wgUser->editToken() ) . "\n" . + Html::hidden( 'wpName', $this->mUserName ) . "\n" . + Html::hidden( 'wpDomain', $this->mDomain ) . "\n" . + Html::hidden( 'returnto', $wgRequest->getVal( 'returnto' ) ) . "\n" . + wfMsgExt( 'resetpass_text', array( 'parse' ) ) . "\n" . + Xml::openElement( 'table', array( 'id' => 'mw-resetpass-table' ) ) . "\n" . + $this->pretty( array( + array( 'wpName', 'username', 'text', $this->mUserName ), + array( 'wpPassword', $oldpassMsg, 'password', $this->mOldpass ), + array( 'wpNewPassword', 'newpassword', 'password', null ), + array( 'wpRetype', 'retypenew', 'password', null ), + ) ) . "\n" . + $rememberMe . + "\n" . + "\n" . + '' . + Xml::submitButton( wfMsg( $submitMsg ) ) . + Xml::submitButton( wfMsg( 'resetpass-submit-cancel' ), array( 'name' => 'wpCancel' ) ) . + "\n" . + "\n" . + Xml::closeElement( 'table' ) . + Xml::closeElement( 'form' ) . + Xml::closeElement( 'fieldset' ) . "\n" + ); + } + + function pretty( $fields ) { + $out = ''; + foreach ( $fields as $list ) { + list( $name, $label, $type, $value ) = $list; + if( $type == 'text' ) { + $field = htmlspecialchars( $value ); + } else { + $attribs = array( 'id' => $name ); + if ( $name == 'wpNewPassword' || $name == 'wpRetype' ) { + $attribs = array_merge( $attribs, + User::passwordChangeInputAttribs() ); + } + if ( $name == 'wpPassword' ) { + $attribs[] = 'autofocus'; + } + $field = Html::input( $name, $value, $type, $attribs ); + } + $out .= "\n"; + $out .= "\t"; + if ( $type != 'text' ) + $out .= Xml::label( wfMsg( $label ), $name ); + else + $out .= wfMsgHtml( $label ); + $out .= "\n"; + $out .= "\t"; + $out .= $field; + $out .= "\n"; + $out .= ""; + } + return $out; + } + + /** + * @throws PasswordError when cannot set the new password because requirements not met. + */ + protected function attemptReset( $newpass, $retype ) { + $user = User::newFromName( $this->mUserName ); + if( !$user || $user->isAnon() ) { + throw new PasswordError( wfMsg( 'nosuchusershort', $this->mUserName ) ); + } + + if( $newpass !== $retype ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'badretype' ) ); + throw new PasswordError( wfMsg( 'badretype' ) ); + } + + $throttleCount = LoginForm::incLoginThrottle( $this->mUserName ); + if ( $throttleCount === true ) { + throw new PasswordError( wfMsg( 'login-throttled' ) ); + } + + if( !$user->checkTemporaryPassword($this->mOldpass) && !$user->checkPassword($this->mOldpass) ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'wrongpassword' ) ); + throw new PasswordError( wfMsg( 'resetpass-wrong-oldpass' ) ); + } + + // Please reset throttle for successful logins, thanks! + if ( $throttleCount ) { + LoginForm::clearLoginThrottle( $this->mUserName ); + } + + try { + $user->setPassword( $this->mNewpass ); + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'success' ) ); + $this->mNewpass = $this->mOldpass = $this->mRetypePass = ''; + } catch( PasswordError $e ) { + wfRunHooks( 'PrefsPasswordAudit', array( $user, $newpass, 'error' ) ); + throw new PasswordError( $e->getMessage() ); + } + + $user->setCookies(); + $user->saveSettings(); + } +} -- cgit v1.2.3-54-g00ecf