Go to the documentation of this file.
40 parent::__construct(
'Emailuser' );
49 if ( !$target instanceof
User ) {
50 return $this->
msg(
'emailuser-title-notarget' )->text();
53 return $this->
msg(
'emailuser-title-target', $target->getName() )->text();
63 $this->
getUser()->getUserPage(),
66 'label-message' =>
'emailfrom',
67 'id' =>
'mw-emailuser-sender',
73 $this->mTargetObj->getUserPage(),
74 $this->mTargetObj->getName()
76 'label-message' =>
'emailto',
77 'id' =>
'mw-emailuser-recipient',
81 'default' => $this->mTargetObj->getName(),
85 'default' => $this->
msg(
'defemailsubject',
87 'label-message' =>
'emailsubject',
95 'label-message' =>
'emailmessage',
100 'label-message' =>
'emailccme',
101 'default' => $this->
getUser()->getBoolOption(
'ccmeonemails' ),
109 $out->addModuleStyles(
'mediawiki.special' );
111 $this->mTarget = $par ?? $request->getVal(
'wpTarget', $request->getVal(
'target',
'' ) );
114 $request->setVal(
'wpTarget', $this->mTarget );
134 case 'blockedemailuser':
136 case 'actionthrottledtext':
139 case 'usermaildisabled':
143 list(
$title, $msg, $params ) = $error;
158 if ( !$this->mTargetObj instanceof
User ) {
173 if ( $target ==
'' ) {
174 wfDebug(
"Target is empty.\n" );
182 return $error ?: $nu;
194 if ( !$target instanceof
User || !$target->
getId() ) {
195 wfDebug(
"Target is invalid user.\n" );
200 if ( !$target->isEmailConfirmed() ) {
201 wfDebug(
"User has no valid email.\n" );
206 if ( !$target->canReceiveEmail() ) {
207 wfDebug(
"User does not allow user emails.\n" );
209 return 'nowikiemail';
212 if ( !$target->getOption(
'email-allow-new-users' ) && $sender->
isNewbie() ) {
213 wfDebug(
"User does not allow user emails from new users.\n" );
215 return 'nowikiemail';
218 $blacklist = $target->getOption(
'email-blacklist',
'' );
220 $blacklist = MultiUsernameFilter::splitIds( $blacklist );
222 $senderId = $lookup->centralIdFromLocalUser( $sender );
223 if ( $senderId !== 0 && in_array( $senderId, $blacklist ) ) {
224 wfDebug(
"User does not allow user emails from this user.\n" );
226 return 'nowikiemail';
243 if ( $config ===
null ) {
244 wfDebug( __METHOD__ .
' called without a Config instance passed to it' );
245 $config = MediaWikiServices::getInstance()->getMainConfig();
247 if ( !$config->get(
'EnableEmail' ) || !$config->get(
'EnableUserEmail' ) ) {
248 return 'usermaildisabled';
252 if ( !$user->isEmailConfirmed() ) {
253 return 'mailnologin';
256 if ( !MediaWikiServices::getInstance()
257 ->getPermissionManager()
258 ->userHasRight( $user,
'sendemail' )
263 if ( $user->isBlockedFromEmailuser() ) {
264 wfDebug(
"User is blocked from sending e-mail.\n" );
266 return "blockedemailuser";
271 if ( $user->pingLimiter(
'emailuser', 0 ) ) {
272 wfDebug(
"Ping limiter triggered.\n" );
274 return 'actionthrottledtext';
279 Hooks::run(
'UserCanSendEmail', [ &$user, &$hookErr ] );
280 Hooks::run(
'EmailUserPermissionsErrors', [ $user, $editToken, &$hookErr ] );
299 'label' => $this->
msg(
'emailusername' )->text(),
300 'id' =>
'emailusertarget',
307 ->setMethod(
'post' )
308 ->setSubmitCallback( [ $this,
'sendEmailForm' ] )
309 ->setFormIdentifier(
'userForm' )
310 ->setId(
'askusername' )
311 ->setWrapperLegendMsg(
'emailtarget' )
312 ->setSubmitTextMsg(
'emailusernamesubmit' )
320 if ( !$ret instanceof
User ) {
321 if ( $this->mTarget !=
'' ) {
323 $ret = ( $ret ==
'notarget' ) ?
'emailnotarget' : ( $ret .
'text' );
332 ->addPreText( $this->
msg(
'emailpagetext', $this->mTarget )->parse() )
333 ->setSubmitTextMsg(
'emailsend' )
334 ->setSubmitCallback( [ __CLASS__,
'submit' ] )
335 ->setFormIdentifier(
'sendEmailForm' )
336 ->setWrapperLegendMsg(
'email-legend' )
339 if ( !
Hooks::run(
'EmailUserForm', [ &$htmlForm ] ) ) {
343 $result = $htmlForm->show();
345 if ( $result ===
true || ( $result instanceof
Status && $result->
isGood() ) ) {
346 $out->setPageTitle( $this->
msg(
'emailsent' ) );
347 $out->addWikiMsg(
'emailsenttext', $this->mTarget );
348 $out->returnToMain(
false, $ret->getUserPage() );
366 if ( !$target instanceof
User ) {
373 $subject = $data[
'Subject'];
374 $text = $data[
'Text'];
377 $text = rtrim( $text ) .
"\n\n-- \n";
378 $text .=
$context->msg(
'emailuserfooter',
379 $from->name, $to->name )->inContentLanguage()->text();
381 if ( $config->get(
'EnableSpecialMute' ) ) {
384 'specialmute-email-footer',
385 $specialMutePage->getCanonicalURL(),
387 )->inContentLanguage()->text();
391 if (
$context->getUser()->pingLimiter(
'emailuser' ) ) {
396 if ( !
Hooks::run(
'EmailUser', [ &$to, &$from, &$subject, &$text, &$error ] ) ) {
397 if ( $error instanceof
Status ) {
399 } elseif ( $error ===
false || $error ===
'' || $error === [] ) {
402 } elseif ( $error ===
true ) {
405 } elseif ( is_array( $error ) ) {
407 foreach ( $error as $e ) {
416 $type = is_object( $error ) ? get_class( $error ) : gettype( $error );
417 wfDeprecated(
"EmailUser hook returning a $type as \$error",
'1.29' );
419 [
'$1', Message::rawParam( (
string)$error ) ],
'hookaborted'
424 if ( $config->get(
'UserEmailUseReplyTo' ) ) {
433 $mailFrom =
new MailAddress( $config->get(
'PasswordSender' ),
434 $context->msg(
'emailsender' )->inContentLanguage()->text() );
457 'replyTo' => $replyTo,
466 if ( $data[
'CCMe'] && $to != $from ) {
469 $ccSubject =
$context->msg(
'emailccsubject' )->plaintextParams(
470 $target->getName(), $subject )->text();
473 Hooks::run(
'EmailUserCC', [ &$ccTo, &$ccFrom, &$ccSubject, &$ccText ] );
475 if ( $config->get(
'UserEmailUseReplyTo' ) ) {
477 $config->get(
'PasswordSender' ),
478 $context->msg(
'emailsender' )->inContentLanguage()->text()
487 $ccTo, $mailFrom, $ccSubject, $ccText, [
488 'replyTo' => $replyTo,
493 Hooks::run(
'EmailUserComplete', [ $to, $from, $subject, $text ] );
527 $block = $this->
getUser()->mBlock;
528 $params = $block->getBlockErrorParams( $this->
getContext() );
530 $msg = $block->isSitewide() ?
'blockedtext' :
'blocked-email-user';
getPageTitle( $subpage=false)
Get a self-referential title object.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
getId()
Get the user's ID.
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
static send( $to, $from, $subject, $body, $options=[])
This function will perform a direct (authenticated) login to a SMTP Server to use for mail relaying i...
userForm( $name)
Form to ask for target user name.
getBlockedEmailError()
Builds an error message based on the block params.
static search( $audience, $search, $limit, $offset=0)
Do a prefix search of user names and return a list of matching user names.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Show an error when a user tries to do something they do not have the necessary permissions for.
getName()
Get the name of this Special Page.
static getTarget( $target, User $sender)
Validate target User.
static validateTarget( $target, User $sender)
Validate target User.
static newFromUser(User $user)
Create a new MailAddress object for the given user.
execute( $par)
Default execute method Checks user permissions.
Extension of RawMessage implementing IApiMessage.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Stores a single person's name and email address.
Interface for configuration instances.
isGood()
Returns whether the operation completed and didn't have any error or warnings.
An IContextSource implementation which will inherit context from another source but allow individual ...
getConfig()
Shortcut to get main config object.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
doesWrites()
Indicates whether this special page may perform database writes.
Show an error when the user hits a rate limit.
A special page that allows users to send e-mails to other users.
isNewbie()
Determine whether the user is a newbie.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getContext()
Gets the context this SpecialPage is executed in.
static newGood( $value=null)
Factory function for good results.
getRequest()
Get the WebRequest being used for this instance.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Interface for objects which can provide a MediaWiki context on request.
static getPermissionsError( $user, $editToken, Config $config=null)
Check whether a user is allowed to send email.
static submit(array $data, IContextSource $context)
Really send a mail.
setContext( $context)
Sets the context this SpecialPage is executed in.
MediaWiki Linker LinkRenderer null $linkRenderer
An error page which can definitely be safely rendered using the OutputPage.
static factory( $providerId=null)
Fetch a CentralIdLookup.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be l...
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.