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();
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 );
176 $targetObject = MediaWikiServices::getInstance()->getUserFactory()->newFromName( $target );
177 if ( !$targetObject instanceof
User ) {
181 $status = MediaWikiServices::getInstance()->getEmailUserFactory()
182 ->newEmailUser( $sender )
183 ->validateTarget( $targetObject );
184 if ( !$status->
isGood() ) {
186 $ret = $msg ===
'emailnotarget' ?
'notarget' : preg_replace(
'/text$/',
'', $msg );
188 $ret = $targetObject;
199 $htmlForm = HTMLForm::factory(
'ooui', [
204 'label-message' =>
'emailusername',
205 'id' =>
'emailusertarget',
208 'excludetemp' =>
true,
212 'filter-callback' =>
static function ( $value ) use ( $name ) {
213 return str_replace(
'_',
' ',
214 ( $value !==
'' && $value !==
false && $value !==
null ) ? $value : $name );
216 'validation-callback' =>
function ( $value ) {
218 $target = $this->userFactory->
newFromName( $value );
219 $statusValue = $this->emailUserFactory
221 ->newEmailUser( $this->getUser() )->validateTarget( $target );
222 if ( !$statusValue->isGood() ) {
224 return Status::wrap( $statusValue )->getMessage();
229 ], $this->getContext() );
233 ->setTitle( $this->getPageTitle() )
234 ->setSubmitCallback( $this->sendEmailForm( ... ) )
235 ->setId(
'askusername' )
236 ->setWrapperLegendMsg(
'emailtarget' )
237 ->setSubmitTextMsg(
'emailusernamesubmit' )
245 private function sendEmailForm( array $data ) {
246 $out = $this->getOutput();
249 $target = $this->userFactory->
newFromName( $data[
'Target'] );
251 $htmlForm = HTMLForm::factory(
'ooui', $this->getFormFields( $target ), $this->getContext() );
253 ->setTitle( $this->getPageTitle() )
254 ->addPreHtml( $this->msg(
'emailpagetext', $target->
getName() )->parse() )
255 ->setSubmitTextMsg(
'emailsend' )
256 ->setSubmitCallback( $this->onFormSubmit( ... ) )
257 ->setWrapperLegendMsg(
'email-legend' )
260 if ( !$this->getHookRunner()->onEmailUserForm( $htmlForm ) ) {
264 $result = $htmlForm->show();
266 if ( $result ===
true || ( $result instanceof Status && $result->isGood() ) ) {
267 $out->setPageTitleMsg( $this->msg(
'emailsent' ) );
268 $out->addWikiMsg(
'emailsenttext', $target->
getName() );
269 $out->returnToMain(
false, $target->
getUserPage() );
271 $out->setPageTitleMsg( $this->msg(
'emailuser-title-target', $target->
getName() ) );
280 private function onFormSubmit( array $data ) {
282 $target = $this->userFactory->
newFromName( $data[
'Target'] );
284 $emailUser = $this->emailUserFactory->newEmailUser( $this->
getAuthority() );
285 $emailUser->setEditToken( $this->
getRequest()->getVal(
'wpEditToken' ) );
288 $status = $emailUser->authorizeSend();
290 if ( !$status->
isOK() ) {
295 $res = $emailUser->sendEmailUnsafe(
302 if ( $res->hasMessage(
'hookaborted' ) ) {
307 $res = Status::wrap( $res );
321 $search = $this->userNameUtils->getCanonical( $search );
327 return $this->userNamePrefixSearch
328 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
335 return $this->getConfig()->get( MainConfigNames::EnableUserEmail );
346class_alias( SpecialEmailUser::class,
'SpecialEmailUser' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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.