* Small cleanups
[lhc/web/wiklou.git] / includes / specials / SpecialEmailuser.php
index 678119a..58e2514 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 /**
- * @todo document
+ *     Constructor for Special:Emailuser.
  */
 function wfSpecialEmailuser( $par ) {
        global $wgRequest, $wgUser, $wgOut;
@@ -98,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( "
-<form id=\"emailuser\" method=\"post\" action=\"{$action}\">
-<table border='0' id='mailheader'><tr>
-<td align='right'>{$emf}:</td>
-<td align='left'><strong>{$senderLink}</strong></td>
-</tr><tr>
-<td align='right'>{$emt}:</td>
-<td align='left'><strong>{$recipientLink}</strong></td>
-</tr><tr>
-<td align='right'>{$emr}:</td>
-<td align='left'>
-<input type='text' size='60' maxlength='200' name=\"wpSubject\" value=\"{$encSubject}\" />
-</td>
-</tr>
-</table>
-<span id='wpTextLabel'><label for=\"wpText\">{$emm}:</label><br /></span>
-<textarea id=\"wpText\" name=\"wpText\" rows='20' cols='80' style=\"width: 100%;\">" . htmlspecialchars( $this->text ) .
-"</textarea>
-" . wfCheckLabel( $emc, 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) . "<br />
-<input type='submit' name=\"wpSend\" value=\"{$ems}\" accesskey=\"s\" />
-<input type='hidden' name='wpEditToken' value=\"$token\" />
-</form>\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' ) ) .
+                       "<tr>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'emailfrom' ), 'emailfrom' ) .
+                               "</td>
+                               <td class='mw-input' id='mw-emailuser-sender'>" .
+                                       $skin->link( $wgUser->getUserPage(), htmlspecialchars( $wgUser->getName() ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'emailto' ), 'emailto' ) .
+                               "</td>
+                               <td class='mw-input' id='mw-emailuser-recipient'>" .
+                                       $skin->link( $this->target->getUserPage(), htmlspecialchars( $this->target->getName() ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'emailsubject' ), 'wpSubject' ) .
+                               "</td>
+                               <td class='mw-input'>" .
+                                       Xml::input( 'wpSubject', 60, $this->subject, array( 'type' => 'text', 'maxlength' => 200 ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td class='mw-label'>" .
+                                       Xml::label( wfMsg( 'emailmessage' ), 'wpText' ) .
+                               "</td>
+                               <td class='mw-input'>" .
+                                       Xml::textarea( 'wpText', $this->text, 80, 20, array( 'id' => 'wpText' ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'emailccme' ), 'wpCCMe', 'wpCCMe', $wgUser->getBoolOption( 'ccmeonemails' ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td class='mw-submit'>" .
+                                       Xml::submitButton( wfMsg( 'emailsend' ), array( 'name' => 'wpSend', 'accesskey' => 's' ) ) .
+                               "</td>
+                       </tr>" .
+                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Xml::closeElement( 'table' ) .
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'form' )
+               );
        }
 
        /*
@@ -153,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 ) ) ) {
@@ -223,7 +241,7 @@ class EmailUserForm {
                        $user = $this->target;
 
                $wgOut->setPagetitle( wfMsg( "emailsent" ) );
-               $wgOut->addHTML( wfMsg( "emailsenttext" ) );
+               $wgOut->addWikiMsg( 'emailsenttext' );
 
                $wgOut->returnToMain( false, $user->getUserPage() );
        }
@@ -234,7 +252,7 @@ class EmailUserForm {
        
        static function userEmailEnabled() {
                global $wgEnableEmail, $wgEnableUserEmail;
-               return $wgEnableEmail && $wgEnableEmail;
+               return $wgEnableEmail && $wgEnableUserEmail;
                
        }
        static function validateEmailTarget ( $target ) {
@@ -250,9 +268,15 @@ class EmailUserForm {
                }
        
                $nu = User::newFromName( $nt->getText() );
-               if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
-                       wfDebug( "Target is invalid user or can't receive.\n" );
+               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;