68 parent::__construct(
'Emailuser' );
69 $this->userNameUtils = $userNameUtils;
70 $this->userNamePrefixSearch = $userNamePrefixSearch;
71 $this->userOptionsLookup = $userOptionsLookup;
72 $this->emailUserFactory = $emailUserFactory;
73 $this->userFactory = $userFactory;
81 return $this->
msg(
'emailuser-title-notarget' );
91 'default' => $linkRenderer->makeLink(
95 'label-message' =>
'emailfrom',
96 'id' =>
'mw-emailuser-sender',
101 'default' => $linkRenderer->makeLink(
105 'label-message' =>
'emailto',
106 'id' =>
'mw-emailuser-recipient',
110 'default' => $target->
getName(),
114 'default' => $this->
msg(
'defemailsubject', $user->getName() )->inContentLanguage()->text(),
115 'label-message' =>
'emailsubject',
121 'type' =>
'textarea',
123 'label-message' =>
'emailmessage',
128 'label-message' =>
'emailccme',
129 'default' => $this->userOptionsLookup->getBoolOption( $user,
'ccmeonemails' ),
140 $out->addModuleStyles(
'mediawiki.special' );
143 $emailUser = $this->emailUserFactory->newEmailUserBC(
147 $emailUser->setEditToken( (
string)$request->getVal(
'wpEditToken' ) );
148 $status = $emailUser->canSend();
150 if ( !$status->isGood() ) {
152 $status->throwErrorPageError();
153 } elseif ( $status->hasMessage(
'mailnologin' ) ) {
155 } elseif ( $status->hasMessage(
'usermaildisabled' ) ) {
156 throw new ErrorPageError(
'usermaildisabled',
'usermaildisabledtext' );
157 } elseif ( $status->getValue() !==
null ) {
160 $error = $status->getErrors()[0];
161 throw new ErrorPageError( $status->getValue(), $error[
'message'], $error[
'params'] );
170 $target = $par ?? $request->getVal(
'wpTarget', $request->getVal(
'target',
'' ) );
185 if ( !$targetObject instanceof
User ) {
190 ->newEmailUser( $sender )
191 ->validateTarget( $targetObject );
192 if ( !$status->isGood() ) {
193 $msg = $status->getErrors()[0][
'message'];
194 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
196 $ret = $targetObject;
207 $htmlForm = HTMLForm::factory(
'ooui', [
212 'label-message' =>
'emailusername',
213 'id' =>
'emailusertarget',
218 'filter-callback' =>
static function ( $value ) use ( $name ) {
219 return str_replace(
'_',
' ',
220 ( $value !==
'' && $value !==
false && $value !==
null ) ? $value : $name );
222 'validation-callback' =>
function ( $value ) {
224 $target = $this->userFactory->newFromName( $value );
225 $statusValue = $this->emailUserFactory
227 ->newEmailUser( $this->
getUser() )->validateTarget( $target );
228 if ( !$statusValue->isGood() ) {
230 return Status::wrap( $statusValue )->getMessage();
240 ->setSubmitCallback( [ $this,
'sendEmailForm' ] )
241 ->setId(
'askusername' )
242 ->setWrapperLegendMsg(
'emailtarget' )
243 ->setSubmitTextMsg(
'emailusernamesubmit' )
255 $target = $this->userFactory->newFromName( $data[
'Target'] );
260 ->addPreHtml( $this->
msg(
'emailpagetext', $target->getName() )->parse() )
261 ->setSubmitTextMsg(
'emailsend' )
262 ->setSubmitCallback( [ $this,
'onFormSubmit' ] )
263 ->setWrapperLegendMsg(
'email-legend' )
266 if ( !$this->
getHookRunner()->onEmailUserForm( $htmlForm ) ) {
270 $result = $htmlForm->show();
272 if ( $result ===
true || ( $result instanceof
Status && $result->
isGood() ) ) {
273 $out->setPageTitleMsg( $this->
msg(
'emailsent' ) );
274 $out->addWikiMsg(
'emailsenttext', $target->getName() );
275 $out->returnToMain(
false, $target->getUserPage() );
277 $out->setPageTitleMsg( $this->
msg(
'emailuser-title-target', $target->getName() ) );
289 $target = $this->userFactory->newFromName( $data[
'Target'] );
291 $emailUser = $this->emailUserFactory->newEmailUser( $this->
getAuthority() );
292 $emailUser->setEditToken( $this->
getRequest()->getVal(
'wpEditToken' ) );
295 $status = $emailUser->authorizeSend();
297 if ( !$status->isOK() ) {
302 $res = $emailUser->sendEmailUnsafe(
309 if ( $res->hasMessage(
'hookaborted' ) ) {
314 $res = Status::wrap( $res );
328 $search = $this->userNameUtils->getCanonical( $search );
334 return $this->userNamePrefixSearch
335 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
351class_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 By default the message key is the canonical name of...
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.