41 parent::__construct(
'Emailuser' );
51 return $this->
msg(
'emailuser-title-notarget' );
61 'default' => $linkRenderer->makeLink(
65 'label-message' =>
'emailfrom',
66 'id' =>
'mw-emailuser-sender',
71 'default' => $linkRenderer->makeLink(
75 'label-message' =>
'emailto',
76 'id' =>
'mw-emailuser-recipient',
80 'default' => $target->
getName(),
84 'default' => $this->
msg(
'defemailsubject', $user->getName() )->inContentLanguage()->text(),
85 'label-message' =>
'emailsubject',
93 'label-message' =>
'emailmessage',
98 'label-message' =>
'emailccme',
99 'default' => $this->userOptionsLookup->getBoolOption( $user,
'ccmeonemails' ),
107 private function handleCanSendEmailStatus(
StatusValue $status ): void {
108 if ( !$status->isGood() ) {
110 $status->throwErrorPageError();
111 } elseif ( $status->
hasMessage(
'mailnologin' ) ) {
112 throw new ErrorPageError(
'mailnologin',
'mailnologintext' );
113 } elseif ( $status->
hasMessage(
'usermaildisabled' ) ) {
114 throw new ErrorPageError(
'usermaildisabled',
'usermaildisabledtext' );
115 } elseif ( $status->
getValue() !==
null ) {
119 throw new ErrorPageError( $status->
getValue(), $msg );
122 throw new ErrorPageError( $this->getDescription(), Status::wrap( $status )->getMessage() );
130 $this->outputHeader();
132 $out = $this->getOutput();
133 $request = $this->getRequest();
134 $out->addModuleStyles(
'mediawiki.special' );
137 $emailUser = $this->emailUserFactory->newEmailUserBC(
141 $emailUser->setEditToken( (
string)$request->getVal(
'wpEditToken' ) );
142 $status = $emailUser->canSend();
148 $this->handleCanSendEmailStatus( $status );
153 $this->requireNamedUser(
'mailnologintext',
'mailnologin' );
155 $this->handleCanSendEmailStatus( $status );
159 $target = $par ?? $request->getVal(
'wpTarget', $request->getVal(
'target',
'' ) );
161 $this->userForm( $target );
173 $targetObject = MediaWikiServices::getInstance()->getUserFactory()->newFromName( $target );
174 if ( !$targetObject instanceof
User ) {
178 $status = MediaWikiServices::getInstance()->getEmailUserFactory()
179 ->newEmailUser( $sender )
180 ->validateTarget( $targetObject );
181 if ( !$status->
isGood() ) {
183 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
185 $ret = $targetObject;
196 $htmlForm = HTMLForm::factory(
'ooui', [
201 'label-message' =>
'emailusername',
202 'id' =>
'emailusertarget',
205 'excludetemp' =>
true,
209 'filter-callback' =>
static function ( $value ) use ( $name ) {
210 return str_replace(
'_',
' ',
211 ( $value !==
'' && $value !==
false && $value !==
null ) ? $value : $name );
213 'validation-callback' =>
function ( $value ) {
215 $target = $this->userFactory->
newFromName( $value );
216 $statusValue = $this->emailUserFactory
218 ->newEmailUser( $this->getUser() )->validateTarget( $target );
219 if ( !$statusValue->isGood() ) {
221 return Status::wrap( $statusValue )->getMessage();
226 ], $this->getContext() );
230 ->setTitle( $this->getPageTitle() )
231 ->setSubmitCallback( $this->sendEmailForm( ... ) )
232 ->setId(
'askusername' )
233 ->setWrapperLegendMsg(
'emailtarget' )
234 ->setSubmitTextMsg(
'emailusernamesubmit' )
242 private function sendEmailForm( array $data ) {
243 $out = $this->getOutput();
246 $target = $this->userFactory->
newFromName( $data[
'Target'] );
248 $htmlForm = HTMLForm::factory(
'ooui', $this->getFormFields( $target ), $this->getContext() );
250 ->setTitle( $this->getPageTitle() )
251 ->addPreHtml( $this->msg(
'emailpagetext', $target->
getName() )->parse() )
252 ->setSubmitTextMsg(
'emailsend' )
253 ->setSubmitCallback( $this->onFormSubmit( ... ) )
254 ->setWrapperLegendMsg(
'email-legend' )
257 if ( !$this->getHookRunner()->onEmailUserForm( $htmlForm ) ) {
261 $result = $htmlForm->show();
263 if ( $result ===
true || ( $result instanceof Status && $result->isGood() ) ) {
264 $out->setPageTitleMsg( $this->msg(
'emailsent' ) );
265 $out->addWikiMsg(
'emailsenttext', $target->
getName() );
266 $out->returnToMain(
false, $target->
getUserPage() );
268 $out->setPageTitleMsg( $this->msg(
'emailuser-title-target', $target->
getName() ) );
277 private function onFormSubmit( array $data ) {
279 $target = $this->userFactory->
newFromName( $data[
'Target'] );
281 $emailUser = $this->emailUserFactory->newEmailUser( $this->
getAuthority() );
282 $emailUser->setEditToken( $this->
getRequest()->getVal(
'wpEditToken' ) );
285 $status = $emailUser->authorizeSend();
287 if ( !$status->
isOK() ) {
292 $res = $emailUser->sendEmailUnsafe(
297 $this->getLanguage()->getCode()
299 if ( $res->hasMessage(
'hookaborted' ) ) {
304 $res = Status::wrap( $res );
318 $search = $this->userNameUtils->getCanonical( $search );
324 return $this->userNamePrefixSearch
325 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
332 return $this->getConfig()->get( MainConfigNames::EnableUserEmail );
342class_alias( SpecialEmailUser::class,
'SpecialEmailUser' );
if(!defined('MW_SETUP_CALLBACK'))
An error page which can definitely be safely rendered using the OutputPage.
A class containing constants representing the names of configuration variables.
Parent class for all special pages.
getUser()
Shortcut to get the User executing this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getMessages(?string $type=null)
Returns a list of error messages, optionally only those of the given type.
hasMessage(string $message)
Returns true if the specified message is present as a warning or error.
isOK()
Returns whether the operation completed.
isGood()
Returns whether the operation completed and didn't have any error or warnings.