X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialEmailuser.php;h=aebec2f38cb2782e6727a67bacc6d2888f518853;hb=acd7881d5fe6afd87a3bd0d7d9f40ece82b48c3f;hp=9248a407d33079ea9d741ff79c974b2ff764392d;hpb=5410cfccce9b0b84bc909506c9b66d3f27d6dba7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 9248a407d3..aebec2f38c 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -92,7 +92,6 @@ class SpecialEmailUser extends UnlistedSpecialPage { 'Text' => [ 'type' => 'textarea', 'rows' => 20, - 'cols' => 80, 'label-message' => 'emailmessage', 'required' => true, ], @@ -106,12 +105,16 @@ class SpecialEmailUser extends UnlistedSpecialPage { public function execute( $par ) { $out = $this->getOutput(); + $request = $this->getRequest(); $out->addModuleStyles( 'mediawiki.special' ); $this->mTarget = is_null( $par ) - ? $this->getRequest()->getVal( 'wpTarget', $this->getRequest()->getVal( 'target', '' ) ) + ? $request->getVal( 'wpTarget', $request->getVal( 'target', '' ) ) : $par; + // Make sure, that HTMLForm uses the correct target. + $request->setVal( 'wpTarget', $this->mTarget ); + // This needs to be below assignment of $this->mTarget because // getDescription() needs it to determine the correct page title. $this->setHeaders(); @@ -131,7 +134,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { case 'badaccess': throw new PermissionsError( 'sendemail' ); case 'blockedemailuser': - throw new UserBlockedError( $this->getUser()->mBlock ); + throw $this->getBlockedEmailError(); case 'actionthrottledtext': throw new ThrottledError; case 'mailnologin': @@ -142,45 +145,22 @@ class SpecialEmailUser extends UnlistedSpecialPage { list( $title, $msg, $params ) = $error; throw new ErrorPageError( $title, $msg, $params ); } - // Got a valid target user name? Else ask for one. - $ret = self::getTarget( $this->mTarget, $this->getUser() ); - if ( !$ret instanceof User ) { - if ( $this->mTarget != '' ) { - // Messages used here: notargettext, noemailtext, nowikiemailtext - $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' ); - $out->wrapWikiMsg( "

$1

", $ret ); - } - $out->addHTML( $this->userForm( $this->mTarget ) ); - - return; - } - - $this->mTargetObj = $ret; - - // Set the 'relevant user' in the skin, so it displays links like Contributions, - // User logs, UserRights, etc. - $this->getSkin()->setRelevantUser( $this->mTargetObj ); + // Make sure, that a submitted form isn't submitted to a subpage (which could be + // a non-existing username) $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $this->getPageTitle() ); // Remove subpage - $form = new HTMLForm( $this->getFormFields(), $context ); - // By now we are supposed to be sure that $this->mTarget is a user name - $form->addPreText( $this->msg( 'emailpagetext', $this->mTarget )->parse() ); - $form->setSubmitTextMsg( 'emailsend' ); - $form->setSubmitCallback( [ __CLASS__, 'uiSubmit' ] ); - $form->setWrapperLegendMsg( 'email-legend' ); - $form->loadData(); - - if ( !Hooks::run( 'EmailUserForm', [ &$form ] ) ) { - return; - } - - $result = $form->show(); - - if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) { - $out->setPageTitle( $this->msg( 'emailsent' ) ); - $out->addWikiMsg( 'emailsenttext', $this->mTarget ); - $out->returnToMain( false, $this->mTargetObj->getUserPage() ); + $this->setContext( $context ); + + // A little hack: HTMLForm will check $this->mTarget only, if the form was posted, not + // if the user opens Special:EmailUser/Florian (e.g.). So check, if the user did that + // and show the "Send email to user" form directly, if so. Show the "enter username" + // form, otherwise. + $this->mTargetObj = self::getTarget( $this->mTarget, $this->getUser() ); + if ( !$this->mTargetObj instanceof User ) { + $this->userForm( $this->mTarget ); + } else { + $this->sendEmailForm(); } } @@ -323,47 +303,62 @@ class SpecialEmailUser extends UnlistedSpecialPage { * @return string Form asking for user name. */ protected function userForm( $name ) { - $this->getOutput()->addModules( 'mediawiki.userSuggest' ); - $string = Html::openElement( - 'form', - [ 'method' => 'get', 'action' => wfScript(), 'id' => 'askusername' ] - ) . - Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) . - Html::openElement( 'fieldset' ) . - Html::rawElement( 'legend', null, $this->msg( 'emailtarget' )->parse() ) . - Html::label( - $this->msg( 'emailusername' )->text(), - 'emailusertarget' - ) . "\u{00A0}" . - Html::input( - 'target', - $name, - 'text', - [ - 'id' => 'emailusertarget', - 'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest - 'autofocus' => true, - 'size' => 30, - ] - ) . - ' ' . - Html::submitButton( $this->msg( 'emailusernamesubmit' )->text(), [] ) . - Html::closeElement( 'fieldset' ) . - Html::closeElement( 'form' ) . "\n"; - - return $string; + $htmlForm = HTMLForm::factory( 'ooui', [ + 'Target' => [ + 'type' => 'user', + 'exists' => true, + 'label' => $this->msg( 'emailusername' )->text(), + 'id' => 'emailusertarget', + 'autofocus' => true, + 'value' => $name, + ] + ], $this->getContext() ); + + $htmlForm + ->setMethod( 'post' ) + ->setSubmitCallback( [ $this, 'sendEmailForm' ] ) + ->setFormIdentifier( 'userForm' ) + ->setId( 'askusername' ) + ->setWrapperLegendMsg( 'emailtarget' ) + ->setSubmitTextMsg( 'emailusernamesubmit' ) + ->show(); } - /** - * Submit callback for an HTMLForm object, will simply call submit(). - * - * @since 1.20 - * @param array $data - * @param HTMLForm $form - * @return Status|bool - */ - public static function uiSubmit( array $data, HTMLForm $form ) { - return self::submit( $data, $form->getContext() ); + public function sendEmailForm() { + $out = $this->getOutput(); + + $ret = $this->mTargetObj; + if ( !$ret instanceof User ) { + if ( $this->mTarget != '' ) { + // Messages used here: notargettext, noemailtext, nowikiemailtext + $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' ); + return Status::newFatal( $ret ); + } + return false; + } + + $htmlForm = HTMLForm::factory( 'ooui', $this->getFormFields(), $this->getContext() ); + // By now we are supposed to be sure that $this->mTarget is a user name + $htmlForm + ->addPreText( $this->msg( 'emailpagetext', $this->mTarget )->parse() ) + ->setSubmitTextMsg( 'emailsend' ) + ->setSubmitCallback( [ __CLASS__, 'submit' ] ) + ->setFormIdentifier( 'sendEmailForm' ) + ->setWrapperLegendMsg( 'email-legend' ) + ->loadData(); + + if ( !Hooks::run( 'EmailUserForm', [ &$htmlForm ] ) ) { + return false; + } + + $result = $htmlForm->show(); + + if ( $result === true || ( $result instanceof Status && $result->isGood() ) ) { + $out->setPageTitle( $this->msg( 'emailsent' ) ); + $out->addWikiMsg( 'emailsenttext', $this->mTarget ); + $out->returnToMain( false, $ret->getUserPage() ); + } + return true; } /** @@ -438,7 +433,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { * SPF and bounce problems with some mailers (see below). */ $mailFrom = new MailAddress( $config->get( 'PasswordSender' ), - wfMessage( 'emailsender' )->inContentLanguage()->text() ); + $context->msg( 'emailsender' )->inContentLanguage()->text() ); $replyTo = $from; } else { /** @@ -482,7 +477,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { if ( $config->get( 'UserEmailUseReplyTo' ) ) { $mailFrom = new MailAddress( $config->get( 'PasswordSender' ), - wfMessage( 'emailsender' )->inContentLanguage()->text() + $context->msg( 'emailsender' )->inContentLanguage()->text() ); $replyTo = $ccFrom; } else { @@ -524,4 +519,17 @@ class SpecialEmailUser extends UnlistedSpecialPage { protected function getGroupName() { return 'users'; } + + /** + * Builds an error message based on the block params + * + * @return ErrorPageError + */ + private function getBlockedEmailError() { + $block = $this->getUser()->mBlock; + $params = $block->getBlockErrorParams( $this->getContext() ); + + $msg = $block->isSitewide() ? 'blockedtext' : 'blocked-email-user'; + return new ErrorPageError( 'blockedtitle', $msg, $params ); + } }