Fix PHP 5.2 compatibility for r77144
[lhc/web/wiklou.git] / includes / UserMailer.php
index f2e92ff..18d876c 100644 (file)
@@ -112,7 +112,7 @@ class UserMailer {
         */
        static function send( $to, $from, $subject, $body, $replyto=null, $contentType=null ) {
                global $wgSMTP, $wgOutputEncoding, $wgEnotifImpersonal;
-               global $wgEnotifMaxRecips;
+               global $wgEnotifMaxRecips, $wgAdditionalMailParams;
 
                if ( is_array( $to ) ) {
                        // This wouldn't be necessary if implode() worked on arrays of
@@ -127,6 +127,17 @@ class UserMailer {
                }
 
                if (is_array( $wgSMTP )) {
+                       $found = false;
+                       $pathArray = explode( PATH_SEPARATOR, get_include_path() );
+                       foreach ( $pathArray as $path ) {
+                               if ( file_exists( $path . DIRECTORY_SEPARATOR . 'Mail.php' ) ) {
+                                       $found = true;
+                                       break;
+                               }
+                       }
+                       if ( !$found ) {
+                               throw new MWException( 'PEAR mail package is not installed' );
+                       }
                        require_once( 'Mail.php' );
 
                        $msgid = str_replace(" ", "_", microtime());
@@ -161,10 +172,13 @@ class UserMailer {
                        $headers['Message-ID'] = "<$msgid@" . $wgSMTP['IDHost'] . '>'; // FIXME
                        $headers['X-Mailer'] = 'MediaWiki mailer';
 
+                       wfSuppressWarnings();
+
                        // Create the mail object using the Mail::factory method
                        $mail_object =& Mail::factory('smtp', $wgSMTP);
                        if( PEAR::isError( $mail_object ) ) {
                                wfDebug( "PEAR::Mail factory failed: " . $mail_object->getMessage() . "\n" );
+                               wfRestoreWarnings();
                                return new WikiError( $mail_object->getMessage() );
                        }
 
@@ -172,9 +186,12 @@ class UserMailer {
                        $chunks = array_chunk( (array)$dest, $wgEnotifMaxRecips );
                        foreach ($chunks as $chunk) {
                                $e = self::sendWithPear($mail_object, $chunk, $headers, $body);
-                               if( WikiError::isError( $e ) )
+                               if( WikiError::isError( $e ) ) {
+                                       wfRestoreWarnings();
                                        return $e;
+                               }
                        }
+                       wfRestoreWarnings();
                } else  {
                        # In the following $headers = expression we removed "Reply-To: {$from}\r\n" , because it is treated differently
                        # (fifth parameter of the PHP mail function, see some lines below)
@@ -208,10 +225,10 @@ class UserMailer {
 
                        if (is_array($to)) {
                                foreach ($to as $recip) {
-                                       $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers );
+                                       $sent = mail( $recip->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
                                }
                        } else {
-                               $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers );
+                               $sent = mail( $to->toString(), wfQuotedPrintable( $subject ), $body, $headers, $wgAdditionalMailParams );
                        }
 
                        restore_error_handler();
@@ -306,7 +323,7 @@ class EmailNotification {
                                        'wl_notificationtimestamp IS NULL',
                                ), __METHOD__
                        );
-                       while ($row = $dbw->fetchObject( $res ) ) {
+                       foreach ( $res as $row ) {
                                $watchers[] = intval( $row->wl_user );
                        }
                        if ($watchers) {
@@ -429,7 +446,7 @@ class EmailNotification {
         * @private
         */
        function composeCommonMailtext() {
-               global $wgPasswordSender, $wgNoReplyAddress;
+               global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress;
                global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress;
                global $wgEnotifImpersonal, $wgEnotifUseRealName;
 
@@ -460,13 +477,14 @@ class EmailNotification {
                        $keys['$CHANGEDORCREATED'] = wfMsgForContent( 'created' );
                }
 
-               if ($wgEnotifImpersonal && $this->oldid)
+               if ($wgEnotifImpersonal && $this->oldid) {
                        /*
                         * For impersonal mail, show a diff link to the last
                         * revision.
                         */
                        $keys['$NEWPAGE'] = wfMsgForContent('enotif_lastdiff',
                                        $this->title->getFullURL("oldid={$this->oldid}&diff=next"));
+        }
 
                $body = strtr( $body, $keys );
                $pagetitle = $this->title->getPrefixedText();
@@ -484,7 +502,7 @@ class EmailNotification {
                # global configuration level.
                $editor = $this->editor;
                $name    = $wgEnotifUseRealName ? $editor->getRealName() : $editor->getName();
-               $adminAddress = new MailAddress( $wgPasswordSender, 'WikiAdmin' );
+               $adminAddress = new MailAddress( $wgPasswordSender, $wgPasswordSenderName );
                $editorAddress = new MailAddress( $editor );
                if( $wgEnotifRevealEditorAddress
                    && ( $editor->getEmail() != '' )
@@ -610,13 +628,18 @@ class EmailNotification {
 
 } # end of class EmailNotification
 
-/**
+/**@{
  * Backwards compatibility functions
+ *
+ * @deprecated Use UserMailer methods; will be removed in 1.19
  */
 function wfRFC822Phrase( $s ) {
+       wfDeprecated( __FUNCTION__ );
        return UserMailer::rfc822Phrase( $s );
 }
 
 function userMailer( $to, $from, $subject, $body, $replyto=null ) {
+       wfDeprecated( __FUNCTION__ );
        return UserMailer::send( $to, $from, $subject, $body, $replyto );
 }
+/**@}*/
\ No newline at end of file