24 namespace MediaWiki\Specials;
78 parent::__construct(
'Emailuser' );
79 $this->userNameUtils = $userNameUtils;
80 $this->userNamePrefixSearch = $userNamePrefixSearch;
81 $this->userOptionsLookup = $userOptionsLookup;
82 $this->emailUserFactory = $emailUserFactory;
83 $this->userFactory = $userFactory;
92 if ( !$target instanceof
User ) {
93 return $this->
msg(
'emailuser-title-notarget' );
96 return $this->
msg(
'emailuser-title-target', $target->getName() );
106 'default' => $linkRenderer->makeLink(
107 $user->getUserPage(),
110 'label-message' =>
'emailfrom',
111 'id' =>
'mw-emailuser-sender',
116 'default' => $linkRenderer->makeLink(
117 $this->mTargetObj->getUserPage(),
118 $this->mTargetObj->getName()
120 'label-message' =>
'emailto',
121 'id' =>
'mw-emailuser-recipient',
125 'default' => $this->mTargetObj->getName(),
129 'default' => $this->
msg(
'defemailsubject', $user->getName() )->inContentLanguage()->text(),
130 'label-message' =>
'emailsubject',
136 'type' =>
'textarea',
138 'label-message' =>
'emailmessage',
143 'label-message' =>
'emailccme',
144 'default' => $this->userOptionsLookup->getBoolOption( $user,
'ccmeonemails' ),
152 $out->addModuleStyles(
'mediawiki.special' );
154 $this->mTarget = $par ?? $request->getVal(
'wpTarget', $request->getVal(
'target',
'' ) );
174 case 'blockedemailuser':
177 case 'actionthrottledtext':
180 case 'usermaildisabled':
184 [ $title, $msg, $params ] = $error;
194 if ( !$this->mTargetObj instanceof
User ) {
211 if ( !$targetObject instanceof
User ) {
216 ->newEmailUser( $sender )
217 ->validateTarget( $targetObject );
218 if ( !$status->isGood() ) {
219 $msg = $status->getErrors()[0][
'message'];
220 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
222 $ret = $targetObject;
236 if ( !$target instanceof
User ) {
240 ->newEmailUser( $sender )
241 ->validateTarget( $target );
242 if ( $status->isGood() ) {
245 $msg = $status->getErrors()[0][
'message'];
246 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
265 $status = $authorize ? $emailUser->authorizeSend( (
string)$editToken )
266 : $emailUser->canSend( (
string)$editToken );
268 if ( $status->isGood() ) {
271 foreach ( $status->getErrors() as $err ) {
272 $errKey = $err[
'message'] instanceof
Message ? $err[
'message']->
getKey() : $err[
'message'];
273 if ( strpos( $errKey,
'blockedtext' ) !==
false ) {
275 return "blockedemailuser";
278 $error = $status->getErrors()[0];
279 if ( $status->getValue() !==
null ) {
281 return [ $status->getValue(), $error[
'message'], $error[
'params'] ];
283 return $error[
'message'];
297 'label-message' =>
'emailusername',
298 'id' =>
'emailusertarget',
301 'filter-callback' =>
static function ( $value ) use ( $name ) {
302 return $value ?? $name;
310 ->setSubmitCallback( [ $this,
'sendEmailForm' ] )
311 ->setId(
'askusername' )
312 ->setWrapperLegendMsg(
'emailtarget' )
313 ->setSubmitTextMsg(
'emailusernamesubmit' )
320 if ( !$this->mTargetObj instanceof
User ) {
321 if ( $this->mTarget !=
'' ) {
323 $msg = ( $this->mTargetObj ===
'notarget' ) ?
'emailnotarget' : ( $this->mTargetObj .
'text' );
333 ->addPreHtml( $this->
msg(
'emailpagetext', $this->mTarget )->parse() )
334 ->setSubmitTextMsg(
'emailsend' )
335 ->setSubmitCallback( [ $this,
'onFormSubmit' ] )
336 ->setWrapperLegendMsg(
'email-legend' )
339 if ( !$this->
getHookRunner()->onEmailUserForm( $htmlForm ) ) {
343 $result = $htmlForm->show();
345 if ( $result ===
true || ( $result instanceof
Status && $result->
isGood() ) ) {
346 $out->setPageTitleMsg( $this->
msg(
'emailsent' ) );
347 $out->addWikiMsg(
'emailsenttext', $this->mTarget );
348 $out->returnToMain(
false, $this->mTargetObj->getUserPage() );
358 $target = $this->userFactory->newFromName( $data[
'Target'] );
359 if ( !$target instanceof
User ) {
363 $emailUser = $this->emailUserFactory->newEmailUser( $this->
getAuthority() );
366 $status = $emailUser->authorizeSend( $this->
getRequest()->getVal(
'wpEditToken' ) );
368 if ( !$status->isOK() ) {
372 $res = $emailUser->sendEmailUnsafe(
379 if ( $res->hasMessage(
'hookaborted' ) ) {
402 if ( !$target instanceof
User ) {
409 $ret = $emailUser->sendEmailUnsafe(
411 (
string)$data[
'Subject'],
412 (
string)$data[
'Text'],
416 if ( $ret->hasMessage(
'hookaborted' ) ) {
419 } elseif ( $ret->hasMessage(
'noemailtarget' ) ) {
438 $search = $this->userNameUtils->getCanonical( $search );
444 return $this->userNamePrefixSearch
445 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
456 class_alias( SpecialEmailUser::class,
'SpecialEmailUser' );
An error page which can definitely be safely rendered using the OutputPage.
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...
Shortcut to construct a special page which is unlisted by default.
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.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
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.