X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialEmailuser.php;h=23958223bdfd1dbd9bc4b0b6d3e13ca8056ef912;hb=000f346c1b541bd8643d901990a69b6a66847d1e;hp=76add3048684c4ae89b37e04fa9763e5c97344f1;hpb=3ddc44c0aaade0116c99b3da72b308b822fd223d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 76add30486..23958223bd 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -1,61 +1,37 @@ showErrorPage( "nosuchspecialpage", "nospecialpagetext" ); - return; - } - - if( !$wgUser->canSendEmail() ) { - wfDebug( "User can't send.\n" ); - $wgOut->showErrorPage( "mailnologin", "mailnologintext" ); - return; + $target = isset($par) ? $par : $wgRequest->getVal( 'target' ); + $error = EmailUserForm::getPermissionsError( $target ); + if ( $error ) { + if ( $error[0] === "blockedemailuser" ) { + $wgOut->blockedPage(); + return; + } else { + $wgOut->showErrorPage( $error[0], $error[1] ); + return; + } } + $form = EmailUserForm::newFromURL( $target, + $wgRequest->getText( 'wpText' ), + $wgRequest->getText( 'wpSubject' ), + $wgRequest->getBool( 'wpCCMe' ) ); + $action = $wgRequest->getVal( 'action' ); - $target = isset($par) ? $par : $wgRequest->getVal( 'target' ); - if ( "" == $target ) { - wfDebug( "Target is empty.\n" ); - $wgOut->showErrorPage( "notargettitle", "notargettext" ); - return; - } - - $nt = Title::newFromURL( $target ); - if ( is_null( $nt ) ) { - wfDebug( "Target is invalid title.\n" ); - $wgOut->showErrorPage( "notargettitle", "notargettext" ); - return; - } - - $nu = User::newFromName( $nt->getText() ); - if( is_null( $nu ) || !$nu->canReceiveEmail() ) { - wfDebug( "Target is invalid user or can't receive.\n" ); - $wgOut->showErrorPage( "noemailtitle", "noemailtext" ); - return; - } - - if ( $wgUser->isBlockedFromEmailUser() ) { - // User has been blocked from sending e-mail. Show the std blocked form. - wfDebug( "User is blocked from sending e-mail.\n" ); - $wgOut->blockedPage(); - return; - } - - $f = new EmailUserForm( $nu ); - if ( "success" == $action ) { - $f->showSuccess( $nu ); + $form->showSuccess(); } else if ( "submit" == $action && $wgRequest->wasPosted() && - $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) + $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { # Check against the rate limiter if( $wgUser->pingLimiter( 'emailuser' ) ) { @@ -63,15 +39,24 @@ function wfSpecialEmailuser( $par ) { return; } - $f->doSubmit(); + $result = $form->doSubmit(); + + if ( !is_null( $result ) ) { + $wgOut->addHTML( wfMsg( "usermailererror" ) . + ' ' . htmlspecialchars( $result->getMessage() ) ); + } else { + $titleObj = SpecialPage::getTitleFor( "Emailuser" ); + $encTarget = wfUrlencode( $form->getTarget()->getName() ); + $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) ); + } } else { - $f->showForm(); + $form->showForm(); } } /** * Implements the Special:Emailuser web interface, and invokes userMailer for sending the email message. - * @addtogroup SpecialPage + * @ingroup SpecialPage */ class EmailUserForm { @@ -82,28 +67,30 @@ class EmailUserForm { /** * @param User $target */ - function EmailUserForm( $target ) { - global $wgRequest; + function EmailUserForm( $target, $text, $subject, $cc_me ) { $this->target = $target; - $this->text = $wgRequest->getText( 'wpText' ); - $this->subject = $wgRequest->getText( 'wpSubject' ); - $this->cc_me = $wgRequest->getBool( 'wpCCMe' ); + $this->text = $text; + $this->subject = $subject; + $this->cc_me = $cc_me; } function showForm() { global $wgOut, $wgUser; + $skin = $wgUser->getSkin(); $wgOut->setPagetitle( wfMsg( "emailpage" ) ); - $wgOut->addWikiText( wfMsg( "emailpagetext" ) ); + $wgOut->addWikiMsg( "emailpagetext" ); if ( $this->subject === "" ) { - $this->subject = wfMsg( "defemailsubject" ); + $this->subject = wfMsgForContent( "defemailsubject" ); } $emf = wfMsg( "emailfrom" ); - $sender = $wgUser->getName(); + $senderLink = $skin->makeLinkObj( + $wgUser->getUserPage(), htmlspecialchars( $wgUser->getName() ) ); $emt = wfMsg( "emailto" ); - $rcpt = $this->target->getName(); + $recipientLink = $skin->makeLinkObj( + $this->target->getUserPage(), htmlspecialchars( $this->target->getName() ) ); $emr = wfMsg( "emailsubject" ); $emm = wfMsg( "emailmessage" ); $ems = wfMsg( "emailsend" ); @@ -119,10 +106,10 @@ class EmailUserForm {
- + - +
{$emf}:" . htmlspecialchars( $sender ) . "{$senderLink}
{$emt}:" . htmlspecialchars( $rcpt ) . "{$recipientLink}
{$emr}: @@ -140,15 +127,20 @@ class EmailUserForm { } + /* + * Really send a mail. Permissions should have been checked using + * EmailUserForm::getPermissionsError. It is probably also a good idea to + * check the edit token and ping limiter in advance. + */ function doSubmit() { - global $wgOut, $wgUser, $wgUserEmailUseReplyTo; + global $wgUser, $wgUserEmailUseReplyTo; $to = new MailAddress( $this->target ); $from = new MailAddress( $wgUser ); $subject = $this->subject; if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text ) ) ) { - + if( $wgUserEmailUseReplyTo ) { // Put the generic wiki autogenerated address in the From: // header and reserve the user for Reply-To. @@ -176,14 +168,14 @@ class EmailUserForm { $mailFrom = $from; $replyTo = null; } - + $mailResult = UserMailer::send( $to, $mailFrom, $subject, $this->text, $replyTo ); if( WikiError::isError( $mailResult ) ) { - $wgOut->addHTML( wfMsg( "usermailererror" ) . - ' ' . htmlspecialchars( $mailResult->getMessage() ) ); - } else { + return $mailResult; + } else { + // if the user requested a copy of this mail, do this now, // unless they are emailing themselves, in which case one copy of the message is sufficient. if ($this->cc_me && $to != $from) { @@ -191,32 +183,78 @@ class EmailUserForm { if( wfRunHooks( 'EmailUser', array( &$from, &$from, &$cc_subject, &$this->text ) ) ) { $ccResult = UserMailer::send( $from, $from, $cc_subject, $this->text ); if( WikiError::isError( $ccResult ) ) { - // At this stage, the user's CC mail has failed, but their + // At this stage, the user's CC mail has failed, but their // original mail has succeeded. It's unlikely, but still, what to do? // We can either show them an error, or we can say everything was fine, - // or we can say we sort of failed AND sort of succeeded. Of these options, + // or we can say we sort of failed AND sort of succeeded. Of these options, // simply saying there was an error is probably best. - $wgOut->addHTML( wfMsg( "usermailererror" ) . - ' ' . htmlspecialchars( $ccResult->getMessage() ) ); - return; + return $ccResult->getMessage(); } } } - - $titleObj = SpecialPage::getTitleFor( "Emailuser" ); - $encTarget = wfUrlencode( $this->target->getName() ); - $wgOut->redirect( $titleObj->getFullURL( "target={$encTarget}&action=success" ) ); + wfRunHooks( 'EmailUserComplete', array( $to, $from, $subject, $this->text ) ); + return; } } } - function showSuccess( &$user ) { + function showSuccess( &$user = null ) { global $wgOut; + + if ( is_null($user) ) + $user = $this->target; $wgOut->setPagetitle( wfMsg( "emailsent" ) ); $wgOut->addHTML( wfMsg( "emailsenttext" ) ); $wgOut->returnToMain( false, $user->getUserPage() ); } + + function getTarget() { + return $this->target; + } + + static function getPermissionsError ( $target ) { + global $wgUser, $wgRequest, $wgEnableEmail, $wgEnableUserEmail; + + if( !( $wgEnableEmail && $wgEnableUserEmail ) ) + return array( "nosuchspecialpage", "nospecialpagetext" ); + + if( !$wgUser->canSendEmail() ) { + wfDebug( "User can't send.\n" ); + return array( "mailnologin", "mailnologintext" ); + } + + if( $wgUser->isBlockedFromEmailuser() ) { + wfDebug( "User is blocked from sending e-mail.\n" ); + return array( "blockedemailuser", "" ); + } + + if ( "" == $target ) { + wfDebug( "Target is empty.\n" ); + return array( "notargettitle", "notargettext" ); + } + + $nt = Title::newFromURL( $target ); + if ( is_null( $nt ) ) { + wfDebug( "Target is invalid title.\n" ); + return array( "notargettitle", "notargettext" ); + } + + $nu = User::newFromName( $nt->getText() ); + if( is_null( $nu ) || !$nu->canReceiveEmail() ) { + wfDebug( "Target is invalid user or can't receive.\n" ); + return array( "noemailtitle", "noemailtext" ); + } + + return; + } + + static function newFromURL( $target, $text, $subject, $cc_me ) + { + $nt = Title::newFromURL( $target ); + $nu = User::newFromName( $nt->getText() ); + return new EmailUserForm( $nu, $text, $subject, $cc_me ); + } }