79 parent::__construct(
'Emailuser' );
80 $this->userNameUtils = $userNameUtils;
81 $this->userNamePrefixSearch = $userNamePrefixSearch;
82 $this->userOptionsLookup = $userOptionsLookup;
83 $this->emailUserFactory = $emailUserFactory;
84 $this->userFactory = $userFactory;
93 if ( !$target instanceof
User ) {
94 return $this->
msg(
'emailuser-title-notarget' );
97 return $this->
msg(
'emailuser-title-target', $target->getName() );
107 'default' => $linkRenderer->makeLink(
108 $user->getUserPage(),
111 'label-message' =>
'emailfrom',
112 'id' =>
'mw-emailuser-sender',
117 'default' => $linkRenderer->makeLink(
118 $this->mTargetObj->getUserPage(),
119 $this->mTargetObj->getName()
121 'label-message' =>
'emailto',
122 'id' =>
'mw-emailuser-recipient',
126 'default' => $this->mTargetObj->getName(),
130 'default' => $this->
msg(
'defemailsubject', $user->getName() )->inContentLanguage()->text(),
131 'label-message' =>
'emailsubject',
137 'type' =>
'textarea',
139 'label-message' =>
'emailmessage',
144 'label-message' =>
'emailccme',
145 'default' => $this->userOptionsLookup->getBoolOption( $user,
'ccmeonemails' ),
153 $out->addModuleStyles(
'mediawiki.special' );
155 $this->mTarget = $par ?? $request->getVal(
'wpTarget', $request->getVal(
'target',
'' ) );
175 case 'blockedemailuser':
178 case 'actionthrottledtext':
181 case 'usermaildisabled':
185 [ $title, $msg, $params ] = $error;
195 if ( !$this->mTargetObj instanceof
User ) {
213 if ( !$targetObject instanceof
User ) {
218 ->newEmailUser( $sender )
219 ->validateTarget( $targetObject );
220 if ( !$status->isGood() ) {
221 $msg = $status->getErrors()[0][
'message'];
222 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
224 $ret = $targetObject;
239 if ( !$target instanceof
User ) {
243 ->newEmailUser( $sender )
244 ->validateTarget( $target );
245 if ( $status->isGood() ) {
248 $msg = $status->getErrors()[0][
'message'];
249 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
269 $emailUser->setEditToken( (
string)$editToken );
270 $status = $authorize ? $emailUser->authorizeSend() : $emailUser->canSend();
272 if ( $status->isGood() ) {
275 foreach ( $status->getErrors() as $err ) {
276 $errKey = $err[
'message'] instanceof
Message ? $err[
'message']->
getKey() : $err[
'message'];
277 if ( strpos( $errKey,
'blockedtext' ) !==
false ) {
279 return "blockedemailuser";
282 $error = $status->getErrors()[0];
283 if ( $status->getValue() !==
null ) {
285 return [ $status->getValue(), $error[
'message'], $error[
'params'] ];
287 return $error[
'message'];
296 $htmlForm = HTMLForm::factory(
'ooui', [
301 'label-message' =>
'emailusername',
302 'id' =>
'emailusertarget',
307 'filter-callback' =>
static function ( $value ) use ( $name ) {
308 return str_replace(
'_',
' ',
309 ( $value !==
'' && $value !==
false && $value !==
null ) ? $value : $name );
317 ->setSubmitCallback( [ $this,
'sendEmailForm' ] )
318 ->setId(
'askusername' )
319 ->setWrapperLegendMsg(
'emailtarget' )
320 ->setSubmitTextMsg(
'emailusernamesubmit' )
327 if ( !$this->mTargetObj instanceof
User ) {
328 if ( $this->mTarget !=
'' ) {
330 $msg = ( $this->mTargetObj ===
'notarget' ) ?
'emailnotarget' : ( $this->mTargetObj .
'text' );
331 return Status::newFatal( $msg );
340 ->addPreHtml( $this->
msg(
'emailpagetext', $this->mTarget )->parse() )
341 ->setSubmitTextMsg(
'emailsend' )
342 ->setSubmitCallback( [ $this,
'onFormSubmit' ] )
343 ->setWrapperLegendMsg(
'email-legend' )
346 if ( !$this->
getHookRunner()->onEmailUserForm( $htmlForm ) ) {
350 $result = $htmlForm->show();
352 if ( $result ===
true || ( $result instanceof
Status && $result->
isGood() ) ) {
353 $out->setPageTitleMsg( $this->
msg(
'emailsent' ) );
354 $out->addWikiMsg(
'emailsenttext', $this->mTarget );
355 $out->returnToMain(
false, $this->mTargetObj->getUserPage() );
366 $target = $this->userFactory->newFromName( $data[
'Target'] );
367 if ( !$target instanceof
User ) {
368 return StatusValue::newFatal(
'emailnotarget' );
371 $emailUser = $this->emailUserFactory->newEmailUser( $this->
getAuthority() );
372 $emailUser->setEditToken( $this->
getRequest()->getVal(
'wpEditToken' ) );
375 $status = $emailUser->authorizeSend();
377 if ( !$status->isOK() ) {
381 $res = $emailUser->sendEmailUnsafe(
388 if ( $res->hasMessage(
'hookaborted' ) ) {
393 $res = Status::wrap( $res );
410 if ( !$target instanceof
User ) {
411 return Status::newFatal(
'emailnotarget' );
417 $ret = $emailUser->sendEmailUnsafe(
419 (
string)$data[
'Subject'],
420 (
string)$data[
'Text'],
424 if ( $ret->hasMessage(
'hookaborted' ) ) {
427 } elseif ( $ret->hasMessage(
'noemailtarget' ) ) {
430 return Status::newFatal(
'notargettext' );
432 $ret = Status::wrap( $ret );
446 $search = $this->userNameUtils->getCanonical( $search );
452 return $this->userNamePrefixSearch
453 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
471class_alias( SpecialEmailUser::class,
'SpecialEmailUser' );
An error page which can definitely be safely rendered using the OutputPage.
A class containing constants representing the names of configuration variables.
const EnableUserEmail
Name constant for the EnableUserEmail setting, for use with Config::get()
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
The Message class deals with fetching and processing of interface message into a variety of formats.
getKey()
Returns the message key.
Show an error when a user tries to do something they do not have the necessary permissions for.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
Show an error when the user hits a rate limit.
Show an error when the user tries to do something whilst blocked.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.