From b9b85843572bf283f48285001e276ba7e61b63f6 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 22 Feb 2009 13:37:51 +0100 Subject: updated to MediaWiki 1.14.0 --- includes/specials/SpecialEmailuser.php | 142 ++++++++++++++++++++------------- 1 file changed, 85 insertions(+), 57 deletions(-) (limited to 'includes/specials/SpecialEmailuser.php') diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 3874c6a1..cf90f94d 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -5,17 +5,22 @@ */ /** - * @todo document + * Constructor for Special:Emailuser. */ function wfSpecialEmailuser( $par ) { global $wgRequest, $wgUser, $wgOut; + if ( !EmailUserForm::userEmailEnabled() ) { + $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' ); + return; + } + $action = $wgRequest->getVal( 'action' ); $target = isset($par) ? $par : $wgRequest->getVal( 'target' ); $targetUser = EmailUserForm::validateEmailTarget( $target ); if ( !( $targetUser instanceof User ) ) { - $wgOut->showErrorPage( $targetUser[0], $targetUser[1] ); + $wgOut->showErrorPage( $targetUser.'title', $targetUser.'text' ); return; } @@ -30,7 +35,7 @@ function wfSpecialEmailuser( $par ) { $error = EmailUserForm::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) ); if ( $error ) { - switch ( $error[0] ) { + switch ( $error ) { case 'blockedemailuser': $wgOut->blockedPage(); return; @@ -40,12 +45,11 @@ function wfSpecialEmailuser( $par ) { case 'sessionfailure': $form->showForm(); return; - default: - $wgOut->showErrorPage( $error[0], $error[1] ); + case 'mailnologin': + $wgOut->showErrorPage( 'mailnologin', 'mailnologintext' ); return; } } - if ( "submit" == $action && $wgRequest->wasPosted() ) { $result = $form->doSubmit(); @@ -94,46 +98,64 @@ class EmailUserForm { $this->subject = wfMsgExt( 'defemailsubject', array( 'content', 'parsemag' ) ); } - $emf = wfMsg( "emailfrom" ); - $senderLink = $skin->makeLinkObj( - $wgUser->getUserPage(), htmlspecialchars( $wgUser->getName() ) ); - $emt = wfMsg( "emailto" ); - $recipientLink = $skin->makeLinkObj( - $this->target->getUserPage(), htmlspecialchars( $this->target->getName() ) ); - $emr = wfMsg( "emailsubject" ); - $emm = wfMsg( "emailmessage" ); - $ems = wfMsg( "emailsend" ); - $emc = wfMsg( "emailccme" ); - $encSubject = htmlspecialchars( $this->subject ); - $titleObj = SpecialPage::getTitleFor( "Emailuser" ); - $action = $titleObj->escapeLocalURL( "target=" . + $action = $titleObj->getLocalURL( "target=" . urlencode( $this->target->getName() ) . "&action=submit" ); - $token = htmlspecialchars( $wgUser->editToken() ); - - $wgOut->addHTML( " -
- - - - - - - - - - -
{$emf}:{$senderLink}
{$emt}:{$recipientLink}
{$emr}: - -
-
- -" . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "
- - -
\n" ); + $wgOut->addHTML( + Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'emailuser' ) ) . + Xml::openElement( 'fieldset' ) . + Xml::element( 'legend', null, wfMsgExt( 'email-legend', 'parsemag' ) ) . + Xml::openElement( 'table', array( 'class' => 'mw-emailuser-table' ) ) . + " + " . + Xml::label( wfMsg( 'emailfrom' ), 'emailfrom' ) . + " + " . + $skin->link( $wgUser->getUserPage(), htmlspecialchars( $wgUser->getName() ) ) . + " + + + " . + Xml::label( wfMsg( 'emailto' ), 'emailto' ) . + " + " . + $skin->link( $this->target->getUserPage(), htmlspecialchars( $this->target->getName() ) ) . + " + + + " . + Xml::label( wfMsg( 'emailsubject' ), 'wpSubject' ) . + " + " . + Xml::input( 'wpSubject', 60, $this->subject, array( 'type' => 'text', 'maxlength' => 200 ) ) . + " + + + " . + Xml::label( wfMsg( 'emailmessage' ), 'wpText' ) . + " + " . + Xml::textarea( 'wpText', $this->text, 80, 20, array( 'id' => 'wpText' ) ) . + " + + + + " . + Xml::checkLabel( wfMsg( 'emailccme' ), 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . + " + + + + " . + Xml::submitButton( wfMsg( 'emailsend' ), array( 'name' => 'wpSend', 'accesskey' => 's' ) ) . + " + " . + Xml::hidden( 'wpEditToken', $wgUser->editToken() ) . + Xml::closeElement( 'table' ) . + Xml::closeElement( 'fieldset' ) . + Xml::closeElement( 'form' ) + ); } /* @@ -149,7 +171,7 @@ class EmailUserForm { $subject = $this->subject; // Add a standard footer and trim up trailing newlines - $this->text = rtrim($this->text) . "\n\n---\n" . wfMsgExt( 'emailuserfooter', + $this->text = rtrim($this->text) . "\n\n-- \n" . wfMsgExt( 'emailuserfooter', array( 'content', 'parsemag' ), array( $from->name, $to->name ) ); if( wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$this->text ) ) ) { @@ -228,27 +250,33 @@ class EmailUserForm { return $this->target; } - static function validateEmailTarget ( $target ) { + static function userEmailEnabled() { global $wgEnableEmail, $wgEnableUserEmail; - - if( !( $wgEnableEmail && $wgEnableUserEmail ) ) - return array( "nosuchspecialpage", "nospecialpagetext" ); + return $wgEnableEmail && $wgEnableUserEmail; + } + static function validateEmailTarget ( $target ) { if ( "" == $target ) { wfDebug( "Target is empty.\n" ); - return array( "notargettitle", "notargettext" ); + return "notarget"; } $nt = Title::newFromURL( $target ); if ( is_null( $nt ) ) { wfDebug( "Target is invalid title.\n" ); - return array( "notargettitle", "notargettext" ); + return "notarget"; } $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" ); + if( is_null( $nu ) || !$nu->getId() ) { + wfDebug( "Target is invalid user.\n" ); + return "notarget"; + } else if ( !$nu->isEmailConfirmed() ) { + wfDebug( "User has no valid email.\n" ); + return "noemail"; + } else if ( !$nu->canReceiveEmail() ) { + wfDebug( "User does not allow user emails.\n" ); + return "nowikiemail"; } return $nu; @@ -256,22 +284,22 @@ class EmailUserForm { static function getPermissionsError ( $user, $editToken ) { if( !$user->canSendEmail() ) { wfDebug( "User can't send.\n" ); - return array( "mailnologin", "mailnologintext" ); + return "mailnologin"; } if( $user->isBlockedFromEmailuser() ) { wfDebug( "User is blocked from sending e-mail.\n" ); - return array( "blockedemailuser", "" ); + return "blockedemailuser"; } if( $user->pingLimiter( 'emailuser' ) ) { wfDebug( "Ping limiter triggered.\n" ); - return array( 'actionthrottledtext', '' ); + return 'actionthrottledtext'; } if( !$user->matchEditToken( $editToken ) ) { wfDebug( "Matching edit token failed.\n" ); - return array( 'sessionfailure', '' ); + return 'sessionfailure'; } return; -- cgit v1.2.2