From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/specials/SpecialEmailuser.php | 112 ++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 44 deletions(-) (limited to 'includes/specials/SpecialEmailuser.php') diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 61271227..7c2ba570 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -28,20 +28,20 @@ */ class SpecialEmailUser extends UnlistedSpecialPage { protected $mTarget; - - public function __construct(){ + + public function __construct() { parent::__construct( 'Emailuser' ); } - - protected function getFormFields(){ + + protected function getFormFields() { global $wgUser; return array( 'From' => array( 'type' => 'info', 'raw' => 1, - 'default' => $wgUser->getSkin()->link( - $wgUser->getUserPage(), - htmlspecialchars( $wgUser->getName() ) + 'default' => $this->getSkin()->link( + $wgUser->getUserPage(), + htmlspecialchars( $wgUser->getName() ) ), 'label-message' => 'emailfrom', 'id' => 'mw-emailuser-sender', @@ -49,8 +49,8 @@ class SpecialEmailUser extends UnlistedSpecialPage { 'To' => array( 'type' => 'info', 'raw' => 1, - 'default' => $wgUser->getSkin()->link( - $this->mTargetObj->getUserPage(), + 'default' => $this->getSkin()->link( + $this->mTargetObj->getUserPage(), htmlspecialchars( $this->mTargetObj->getName() ) ), 'label-message' => 'emailto', @@ -82,25 +82,17 @@ class SpecialEmailUser extends UnlistedSpecialPage { ), ); } - + public function execute( $par ) { global $wgRequest, $wgOut, $wgUser; $this->setHeaders(); $this->outputHeader(); - + $wgOut->addModuleStyles( 'mediawiki.special' ); $this->mTarget = is_null( $par ) ? $wgRequest->getVal( 'wpTarget', $wgRequest->getVal( 'target', '' ) ) : $par; - - $ret = self::getTarget( $this->mTarget ); - if( $ret instanceof User ){ - $this->mTargetObj = $ret; - } else { - $wgOut->showErrorPage( "{$ret}title", "{$ret}text" ); - return false; - } - + // error out if sending user cannot do this $error = self::getPermissionsError( $wgUser, $wgRequest->getVal( 'wpEditToken' ) ); switch ( $error ) { case null: @@ -125,7 +117,19 @@ class SpecialEmailUser extends UnlistedSpecialPage { $wgOut->showErrorPage( $title, $msg, $params ); return; } - + // Got a valid target user name? Else ask for one. + $ret = self::getTarget( $this->mTarget ); + if( !$ret instanceof User ) { + if( $this->mTarget != '' ) { + $ret = ( $ret == 'notarget' ) ? 'emailnotarget' : ( $ret . 'text' ); + $wgOut->wrapWikiMsg( "

$1

", $ret ); + } + $wgOut->addHTML( self::userForm( $this->mTarget ) ); + return false; + } + + $this->mTargetObj = $ret; + $form = new HTMLForm( $this->getFormFields() ); $form->addPreText( wfMsgExt( 'emailpagetext', 'parseinline' ) ); $form->setSubmitText( wfMsg( 'emailsend' ) ); @@ -133,16 +137,16 @@ class SpecialEmailUser extends UnlistedSpecialPage { $form->setSubmitCallback( array( __CLASS__, 'submit' ) ); $form->setWrapperLegend( wfMsgExt( 'email-legend', 'parsemag' ) ); $form->loadData(); - - if( !wfRunHooks( 'EmailUserForm', array( &$form ) ) ){ + + if( !wfRunHooks( 'EmailUserForm', array( &$form ) ) ) { return false; } - - $wgOut->setPagetitle( wfMsg( 'emailpage' ) ); + + $wgOut->setPageTitle( wfMsg( 'emailpage' ) ); $result = $form->show(); - - if( $result === true || ( $result instanceof Status && $result->isGood() ) ){ - $wgOut->setPagetitle( wfMsg( 'emailsent' ) ); + + if( $result === true || ( $result instanceof Status && $result->isGood() ) ) { + $wgOut->setPageTitle( wfMsg( 'emailsent' ) ); $wgOut->addWikiMsg( 'emailsenttext' ); $wgOut->returnToMain( false, $this->mTargetObj->getUserPage() ); } @@ -159,15 +163,15 @@ class SpecialEmailUser extends UnlistedSpecialPage { wfDebug( "Target is empty.\n" ); return 'notarget'; } - + $nu = User::newFromName( $target ); if( !$nu instanceof User || !$nu->getId() ) { wfDebug( "Target is invalid user.\n" ); return 'notarget'; - } else if ( !$nu->isEmailConfirmed() ) { + } elseif ( !$nu->isEmailConfirmed() ) { wfDebug( "User has no valid email.\n" ); return 'noemail'; - } else if ( !$nu->canReceiveEmail() ) { + } elseif ( !$nu->canReceiveEmail() ) { wfDebug( "User does not allow user emails.\n" ); return 'nowikiemail'; } @@ -184,15 +188,15 @@ class SpecialEmailUser extends UnlistedSpecialPage { */ public static function getPermissionsError( $user, $editToken ) { global $wgEnableEmail, $wgEnableUserEmail; - if( !$wgEnableEmail || !$wgEnableUserEmail ){ + if( !$wgEnableEmail || !$wgEnableUserEmail ) { return 'usermaildisabled'; } - + if( !$user->isAllowed( 'sendemail' ) ) { return 'badaccess'; } - - if( !$user->isEmailConfirmed() ){ + + if( !$user->isEmailConfirmed() ) { return 'mailnologin'; } @@ -216,9 +220,29 @@ class SpecialEmailUser extends UnlistedSpecialPage { return null; } + /** + * Form to ask for target user name. + * + * @param $name String: user name submitted. + * @return String: form asking for user name. + */ + + function userForm( $name ) { + global $wgScript ; + $string = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'askusername' ) ) . + Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . + Xml::openElement( 'fieldset' ) . + Html::rawElement( 'legend', null, wfMessage( 'emailtarget' )->parse() ) . + Xml::inputLabel( wfMessage( 'emailusername' )->text(), 'target', 'emailusertarget', 30, $name ) . ' ' . + Xml::submitButton( wfMessage( 'emailusernamesubmit' )->text() ) . + Xml::closeElement( 'fieldset' ) . + Xml::closeElement( 'form' ) . "\n"; + return $string; + } + /** * Really send a mail. Permissions should have been checked using - * getPermissionsError(). It is probably also a good + * getPermissionsError(). It is probably also a good * idea to check the edit token and ping limiter in advance. * * @return Mixed: Status object, or potentially a String on error @@ -228,7 +252,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { global $wgUser, $wgUserEmailUseReplyTo; $target = self::getTarget( $data['Target'] ); - if( !$target instanceof User ){ + if( !$target instanceof User ) { return wfMsgExt( $target . 'text', 'parse' ); } $to = new MailAddress( $target ); @@ -238,17 +262,17 @@ class SpecialEmailUser extends UnlistedSpecialPage { // Add a standard footer and trim up trailing newlines $text = rtrim( $text ) . "\n\n-- \n"; - $text .= wfMsgExt( + $text .= wfMsgExt( 'emailuserfooter', - array( 'content', 'parsemag' ), - array( $from->name, $to->name ) + array( 'content', 'parsemag' ), + array( $from->name, $to->name ) ); $error = ''; if( !wfRunHooks( 'EmailUser', array( &$to, &$from, &$subject, &$text, &$error ) ) ) { return $error; } - + if( $wgUserEmailUseReplyTo ) { // Put the generic wiki autogenerated address in the From: // header and reserve the user for Reply-To. @@ -283,12 +307,12 @@ class SpecialEmailUser extends UnlistedSpecialPage { return $status; } else { // if the user requested a copy of this mail, do this now, - // unless they are emailing themselves, in which case one + // unless they are emailing themselves, in which case one // copy of the message is sufficient. if ( $data['CCMe'] && $to != $from ) { $cc_subject = wfMsg( - 'emailccsubject', - $target->getName(), + 'emailccsubject', + $target->getName(), $subject ); wfRunHooks( 'EmailUserCC', array( &$from, &$from, &$cc_subject, &$text ) ); -- cgit v1.2.2