parent::__construct( 'Emailuser' );
}
+ public function doesWrites() {
+ return true;
+ }
+
public function getDescription() {
$target = self::getTarget( $this->mTarget );
if ( !$target instanceof User ) {
}
protected function getFormFields() {
- return array(
- 'From' => array(
+ return [
+ 'From' => [
'type' => 'info',
'raw' => 1,
'default' => Linker::link(
),
'label-message' => 'emailfrom',
'id' => 'mw-emailuser-sender',
- ),
- 'To' => array(
+ ],
+ 'To' => [
'type' => 'info',
'raw' => 1,
'default' => Linker::link(
),
'label-message' => 'emailto',
'id' => 'mw-emailuser-recipient',
- ),
- 'Target' => array(
+ ],
+ 'Target' => [
'type' => 'hidden',
'default' => $this->mTargetObj->getName(),
- ),
- 'Subject' => array(
+ ],
+ 'Subject' => [
'type' => 'text',
'default' => $this->msg( 'defemailsubject',
$this->getUser()->getName() )->inContentLanguage()->text(),
'maxlength' => 200,
'size' => 60,
'required' => true,
- ),
- 'Text' => array(
+ ],
+ 'Text' => [
'type' => 'textarea',
'rows' => 20,
+ 'cols' => 80,
'label-message' => 'emailmessage',
'required' => true,
- ),
- 'CCMe' => array(
+ ],
+ 'CCMe' => [
'type' => 'check',
'label-message' => 'emailccme',
'default' => $this->getUser()->getBoolOption( 'ccmeonemails' ),
- ),
- );
+ ],
+ ];
}
public function execute( $par ) {
$out = $this->getOutput();
- $request = $this->getRequest();
$out->addModuleStyles( 'mediawiki.special' );
$this->mTarget = is_null( $par )
- ? $request->getVal( 'wpTarget', '' )
+ ? $this->getRequest()->getVal( 'wpTarget', $this->getRequest()->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();
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 );
+ if ( !$ret instanceof User ) {
+ if ( $this->mTarget != '' ) {
+ // Messages used here: notargettext, noemailtext, nowikiemailtext
+ $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' );
+ $out->wrapWikiMsg( "<p class='error'>$1</p>", $ret );
+ }
+ $out->addHTML( $this->userForm( $this->mTarget ) );
- // 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 );
- if ( !$this->mTargetObj instanceof User ) {
- $this->userForm( $this->mTarget );
- } else {
- $this->sendEmailForm();
+ 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 );
+
+ $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() );
}
}
$hookErr = false;
- Hooks::run( 'UserCanSendEmail', array( &$user, &$hookErr ) );
- Hooks::run( 'EmailUserPermissionsErrors', array( $user, $editToken, &$hookErr ) );
+ Hooks::run( 'UserCanSendEmail', [ &$user, &$hookErr ] );
+ Hooks::run( 'EmailUserPermissionsErrors', [ $user, $editToken, &$hookErr ] );
if ( $hookErr ) {
return $hookErr;
* @return string Form asking for user name.
*/
protected function userForm( $name ) {
- $form = HTMLForm::factory( 'ooui', array(
- 'Target' => array(
- 'type' => 'user',
- 'exists' => true,
- 'label' => $this->msg( 'emailusername' )->text(),
- 'id' => 'emailusertarget',
- 'autofocus' => true,
- 'value' => $name,
- ),
- ), $this->getContext() );
-
- $form
- ->setMethod( 'post' )
- ->setSubmitCallback( array( $this, 'sendEmailForm' ) )
- ->setSubmitProgressive()
- ->setId( 'askusername' )
- ->addHiddenField( 'title', $this->getPageTitle()->getPrefixedText() )
- ->setWrapperLegendMsg( 'emailtarget' )
- ->setSubmitTextMsg( 'emailusernamesubmit' )
- ->show();
- }
-
- 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;
- }
-
- $context = new DerivativeContext( $this->getContext() );
- $context->setTitle( $this->getPageTitle() ); // Remove subpage
- $form = HTMLForm::factory( 'ooui', $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( array( __CLASS__, 'uiSubmit' ) );
- $form->setWrapperLegendMsg( 'email-legend' );
- $form->loadData();
-
- if ( !Hooks::run( 'EmailUserForm', array( &$form ) ) ) {
- return false;
- }
-
- $result = $form->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;
+ $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'
+ ) . ' ' .
+ 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;
}
/**
$from->name, $to->name )->inContentLanguage()->text();
$error = '';
- if ( !Hooks::run( 'EmailUser', array( &$to, &$from, &$subject, &$text, &$error ) ) ) {
+ if ( !Hooks::run( 'EmailUser', [ &$to, &$from, &$subject, &$text, &$error ] ) ) {
return $error;
}
$replyTo = null;
}
- $status = UserMailer::send( $to, $mailFrom, $subject, $text, array(
+ $status = UserMailer::send( $to, $mailFrom, $subject, $text, [
'replyTo' => $replyTo,
- ) );
+ ] );
if ( !$status->isGood() ) {
return $status;
// unless they are emailing themselves, in which case one
// copy of the message is sufficient.
if ( $data['CCMe'] && $to != $from ) {
- $cc_subject = $context->msg( 'emailccsubject' )->rawParams(
+ $ccTo = $from;
+ $ccFrom = $from;
+ $ccSubject = $context->msg( 'emailccsubject' )->rawParams(
$target->getName(), $subject )->text();
-
- // target and sender are equal, because this is the CC for the sender
- Hooks::run( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) );
-
- $ccStatus = UserMailer::send( $from, $from, $cc_subject, $text );
+ $ccText = $text;
+
+ Hooks::run( 'EmailUserCC', [ &$ccTo, &$ccFrom, &$ccSubject, &$ccText ] );
+
+ if ( $config->get( 'UserEmailUseReplyTo' ) ) {
+ $mailFrom = new MailAddress(
+ $config->get( 'PasswordSender' ),
+ wfMessage( 'emailsender' )->inContentLanguage()->text()
+ );
+ $replyTo = $ccFrom;
+ } else {
+ $mailFrom = $ccFrom;
+ $replyTo = null;
+ }
+
+ $ccStatus = UserMailer::send(
+ $ccTo, $mailFrom, $ccSubject, $ccText, [
+ 'replyTo' => $replyTo,
+ ] );
$status->merge( $ccStatus );
}
- Hooks::run( 'EmailUserComplete', array( $to, $from, $subject, $text ) );
+ Hooks::run( 'EmailUserComplete', [ $to, $from, $subject, $text ] );
return $status;
}
$user = User::newFromName( $search );
if ( !$user ) {
// No prefix suggestion for invalid user
- return array();
+ return [];
}
// Autocomplete subpage as user list - public to allow caching
return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );