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 {