Merge "Do correct average year length arithmetic."
[lhc/web/wiklou.git] / includes / UserMailer.php
index 9830f69..b8b6aa8 100644 (file)
@@ -231,12 +231,7 @@ class UserMailer {
                        # PEAR MAILER
                        #
 
-                       if ( function_exists( 'stream_resolve_include_path' ) ) {
-                               $found = stream_resolve_include_path( 'Mail.php' );
-                       } else {
-                               $found = Fallback::stream_resolve_include_path( 'Mail.php' );
-                       }
-                       if ( !$found ) {
+                       if ( ! stream_resolve_include_path( 'Mail.php' ) ) {
                                throw new MWException( 'PEAR mail package is not installed' );
                        }
                        require_once( 'Mail.php' );
@@ -273,7 +268,7 @@ class UserMailer {
                        }
                        wfRestoreWarnings();
                        return Status::newGood();
-               } else  {
+               } else {
                        #
                        # PHP mail()
                        #
@@ -396,7 +391,7 @@ class UserMailer {
  */
 class EmailNotification {
        protected $subject, $body, $replyto, $from;
-       protected $timestamp, $summary, $minorEdit, $oldid, $composed_common;
+       protected $timestamp, $summary, $minorEdit, $oldid, $composed_common, $pageStatus;
        protected $mailTargets = array();
 
        /**
@@ -421,8 +416,9 @@ class EmailNotification {
         * @param $summary
         * @param $minorEdit
         * @param $oldid (default: false)
+        * @param $pageStatus (default: 'changed')
         */
-       public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
+       public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false, $pageStatus = 'changed' ) {
                global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
                        $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
 
@@ -493,12 +489,13 @@ class EmailNotification {
                                'summary' => $summary,
                                'minorEdit' => $minorEdit,
                                'oldid' => $oldid,
-                               'watchers' => $watchers
+                               'watchers' => $watchers,
+                               'pageStatus' => $pageStatus
                        );
                        $job = new EnotifNotifyJob( $title, $params );
-                       $job->insert();
+                       JobQueueGroup::singleton()->push( $job );
                } else {
-                       $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
+                       $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus );
                }
        }
 
@@ -515,8 +512,11 @@ class EmailNotification {
         * @param $minorEdit bool
         * @param $oldid int Revision ID
         * @param $watchers array of user IDs
+        * @param string $pageStatus
+        * @throws MWException
         */
-       public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers ) {
+       public function actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit,
+               $oldid, $watchers, $pageStatus = 'changed' ) {
                # we use $wgPasswordSender as sender's address
                global $wgEnotifWatchlist;
                global $wgEnotifMinorEdits, $wgEnotifUserTalk;
@@ -536,6 +536,14 @@ class EmailNotification {
                $this->oldid = $oldid;
                $this->editor = $editor;
                $this->composed_common = false;
+               $this->pageStatus = $pageStatus;
+
+               $formattedPageStatus = array( 'deleted', 'created', 'moved', 'restored', 'changed' );
+
+               wfRunHooks( 'UpdateUserMailerFormattedPageStatus', array( &$formattedPageStatus ) );
+               if ( !in_array( $this->pageStatus, $formattedPageStatus ) ) {
+                       throw new MWException( 'Not a valid page status!' );
+               }
 
                $userTalkId = false;
 
@@ -625,26 +633,27 @@ class EmailNotification {
 
                $keys = array();
                $postTransformKeys = array();
+               $pageTitleUrl = $this->title->getCanonicalUrl();
+               $pageTitle = $this->title->getPrefixedText();
 
                if ( $this->oldid ) {
                        // Always show a link to the diff which triggered the mail. See bug 32210.
-                       $keys['$NEWPAGE'] = wfMessage( 'enotif_lastdiff',
+                       $keys['$NEWPAGE'] = "\n\n" . wfMessage( 'enotif_lastdiff',
                                $this->title->getCanonicalUrl( 'diff=next&oldid=' . $this->oldid ) )
                                ->inContentLanguage()->text();
+
                        if ( !$wgEnotifImpersonal ) {
                                // For personal mail, also show a link to the diff of all changes
                                // since last visited.
-                               $keys['$NEWPAGE'] .= " \n" . wfMessage( 'enotif_lastvisited',
+                               $keys['$NEWPAGE'] .= "\n\n" .  wfMessage( 'enotif_lastvisited',
                                        $this->title->getCanonicalUrl( 'diff=0&oldid=' . $this->oldid ) )
                                        ->inContentLanguage()->text();
                        }
                        $keys['$OLDID']   = $this->oldid;
-                       $keys['$CHANGEDORCREATED'] = wfMessage( 'changed' )->inContentLanguage()->text();
                } else {
-                       $keys['$NEWPAGE'] = wfMessage( 'enotif_newpagetext' )->inContentLanguage()->text();
                        # clear $OLDID placeholder in the message template
                        $keys['$OLDID']   = '';
-                       $keys['$CHANGEDORCREATED'] = wfMessage( 'created' )->inContentLanguage()->text();
+                       $keys['$NEWPAGE'] = '';
                }
 
                $keys['$PAGETITLE'] = $this->title->getPrefixedText();
@@ -658,6 +667,7 @@ class EmailNotification {
                        $keys['$PAGEEDITOR'] = wfMessage( 'enotif_anon_editor', $this->editor->getName() )
                                ->inContentLanguage()->text();
                        $keys['$PAGEEDITOR_EMAIL'] = wfMessage( 'noemailtitle' )->inContentLanguage()->text();
+
                } else {
                        $keys['$PAGEEDITOR'] = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName();
                        $emailPage = SpecialPage::getSafeTitleFor( 'Emailuser', $this->editor->getName() );
@@ -670,11 +680,12 @@ class EmailNotification {
                $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary;
 
                # Now build message's subject and body
+               $this->subject = wfMessage( 'enotif_subject_' . $this->pageStatus )->inContentLanguage()
+                       ->params( $pageTitle, $keys['$PAGEEDITOR'] )->escaped();
 
-               $subject = wfMessage( 'enotif_subject' )->inContentLanguage()->plain();
-               $subject = strtr( $subject, $keys );
-               $subject = MessageCache::singleton()->transform( $subject, false, null, $this->title );
-               $this->subject = strtr( $subject, $postTransformKeys );
+               $keys['$PAGEINTRO'] = wfMessage( 'enotif_body_intro_' . $this->pageStatus )
+                       ->inContentLanguage()->params( $pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl )
+                       ->escaped();
 
                $body = wfMessage( 'enotif_body' )->inContentLanguage()->plain();
                $body = strtr( $body, $keys );
@@ -766,13 +777,15 @@ class EmailNotification {
        /**
         * Same as sendPersonalised but does impersonal mail suitable for bulk
         * mailing.  Takes an array of MailAddress objects.
-        * @return Status
+        * @param $addresses array
+        * @return Status|null
         */
        function sendImpersonal( $addresses ) {
                global $wgContLang;
 
-               if ( empty( $addresses ) )
-                       return;
+               if ( empty( $addresses ) ) {
+                       return null;
+               }
 
                $body = str_replace(
                                array( '$WATCHINGUSERNAME',