(bug 14901) Email notification mistakes log action for new page creation
authorbsitu <bsitu@wikimedia.org>
Fri, 18 May 2012 21:01:12 +0000 (14:01 -0700)
committerAlex Monk <krenair@gmail.com>
Mon, 26 Nov 2012 19:37:01 +0000 (19:37 +0000)
Original patch by Dan Nessett, modified by Benny Situ and Roan Kattouw

Change-Id: Ibb7953741e4189127d1cd6718ac58492f254671e

RELEASE-NOTES-1.21
docs/hooks.txt
includes/RecentChange.php
includes/UserMailer.php
includes/job/jobs/EnotifNotifyJob.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index c6ffa01..dd1c189 100644 (file)
@@ -84,6 +84,7 @@ production.
 * (bug 36053) Log in "returnto" feature forgets query parameters if no
   title parameter was specified.
 * (bug 42410) API action=edit now returns correct timestamp for the new edit.
+* (bug 14901) Email notification mistakes log action for new page creation.
 
 === API changes in 1.21 ===
 * prop=revisions can now report the contentmodel and contentformat, see docs/contenthandler.txt.
index a9a7c10..50cbbe8 100644 (file)
@@ -2221,6 +2221,9 @@ $page: WikiPage object to be removed
 $user: user that watched
 $page: WikiPage object that was watched
 
+'UpdateUserMailerFormattedPageStatus': before notification email gets sent
+$formattedPageStatus: list of valid page states
+
 'UploadForm:initial': before the upload form is generated
 $form: UploadForm object
 You might set the member-variables $uploadFormTextTop and
index 2bdcab4..87fa428 100644 (file)
@@ -55,6 +55,7 @@
  *  lang            the interwiki prefix, automatically set in save()
  *  oldSize         text size before the change
  *  newSize         text size after the change
+ *  pageStatus      status of the page: created, deleted, moved, restored, changed
  *
  * temporary:       not stored in the database
  *      notificationtimestamp
@@ -273,7 +274,8 @@ class RecentChange {
                                        $this->mAttribs['rc_timestamp'],
                                        $this->mAttribs['rc_comment'],
                                        $this->mAttribs['rc_minor'],
-                                       $this->mAttribs['rc_last_oldid'] );
+                                       $this->mAttribs['rc_last_oldid'],
+                                       $this->mExtra['pageStatus'] );
                        }
                }
        }
@@ -461,6 +463,7 @@ class RecentChange {
                        'lastTimestamp' => $lastTimestamp,
                        'oldSize'       => $oldSize,
                        'newSize'       => $newSize,
+                       'pageStatus'   => 'changed'
                );
                $rc->save();
                return $rc;
@@ -518,7 +521,8 @@ class RecentChange {
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'oldSize' => 0,
-                       'newSize' => $size
+                       'newSize' => $size,
+                       'pageStatus' => 'created'
                );
                $rc->save();
                return $rc;
@@ -572,6 +576,27 @@ class RecentChange {
                $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '' ) {
                global $wgRequest;
 
+               ## Get pageStatus for email notification
+               switch ( $type . '-' . $action ) {
+                       case 'delete-delete':
+                               $pageStatus = 'deleted';
+                               break;
+                       case 'move-move':
+                       case 'move-move_redir':
+                               $pageStatus = 'moved';
+                               break;
+                       case 'delete-restore':
+                               $pageStatus = 'restored';
+                               break;
+                       case 'upload-upload':
+                               $pageStatus = 'created';
+                               break;
+                       case 'upload-overwrite':
+                       default:
+                               $pageStatus = 'changed';
+                               break;
+               }
+
                $rc = new RecentChange;
                $rc->mTitle = $target;
                $rc->mPerformer = $user;
@@ -605,6 +630,7 @@ class RecentChange {
                        'prefixedDBkey' => $title->getPrefixedDBkey(),
                        'lastTimestamp' => 0,
                        'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
+                       'pageStatus'    => $pageStatus,
                        'actionCommentIRC' => $actionCommentIRC
                );
                return $rc;
index b9ce9e0..daf7435 100644 (file)
@@ -396,7 +396,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 +421,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 +494,13 @@ class EmailNotification {
                                'summary' => $summary,
                                'minorEdit' => $minorEdit,
                                'oldid' => $oldid,
-                               'watchers' => $watchers
+                               'watchers' => $watchers,
+                               'pageStatus' => $pageStatus
                        );
                        $job = new EnotifNotifyJob( $title, $params );
                        $job->insert();
                } else {
-                       $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
+                       $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers, $pageStatus );
                }
        }
 
@@ -516,7 +518,8 @@ class EmailNotification {
         * @param $oldid int Revision ID
         * @param $watchers array of user IDs
         */
-       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 +539,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 +636,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 +670,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 +683,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 );
index b4c925e..2be05b6 100644 (file)
@@ -49,7 +49,8 @@ class EnotifNotifyJob extends Job {
                        $this->params['summary'],
                        $this->params['minorEdit'],
                        $this->params['oldid'],
-                       $this->params['watchers']
+                       $this->params['watchers'],
+                       $this->params['pageStatus']
                );
                return true;
        }
index 1822237..e0042c8 100644 (file)
@@ -2886,22 +2886,28 @@ Future changes to this page and its associated talk page will be listed there, a
 'unwatching'     => 'Unwatching...',
 'watcherrortext' => 'An error occurred while changing your watchlist settings for "$1".',
 
-'enotif_mailer'                => '{{SITENAME}} notification mailer',
-'enotif_reset'                 => 'Mark all pages visited',
-'enotif_newpagetext'           => 'This is a new page.',
-'enotif_impersonal_salutation' => '{{SITENAME}} user',
-'changed'                      => 'changed',
-'created'                      => 'created',
-'enotif_subject'               => '{{SITENAME}} page $PAGETITLE has been $CHANGEDORCREATED by $PAGEEDITOR',
-'enotif_lastvisited'           => 'See $1 for all changes since your last visit.',
-'enotif_lastdiff'              => 'See $1 to view this change.',
-'enotif_anon_editor'           => 'anonymous user $1',
-'enotif_body'                  => 'Dear $WATCHINGUSERNAME,
-
+'enotif_mailer'                    => '{{SITENAME}} notification mailer',
+'enotif_reset'                     => 'Mark all pages visited',
+'enotif_impersonal_salutation'     => '{{SITENAME}} user',
+
+'enotif_subject_deleted'           => '{{SITENAME}} page $1 has been deleted by {{gender:$2|$2}}',
+'enotif_subject_created'           => '{{SITENAME}} page $1 has been created by {{gender:$2|$2}}',
+'enotif_subject_moved'             => '{{SITENAME}} page $1 has been moved by {{gender:$2|$2}}',
+'enotif_subject_restored'          => '{{SITENAME}} page $1 has been restored by {{gender:$2|$2}}',
+'enotif_subject_changed'           => '{{SITENAME}} page $1 has been changed by {{gender:$2|$2}}',
+'enotif_body_intro_deleted'        =>  'The {{SITENAME}} page $1 has been deleted on $PAGEEDITDATE by {{gender:$2|$2}}, see $3 for the current revision.',
+'enotif_body_intro_created'        =>  'The {{SITENAME}} page $1 has been created on $PAGEEDITDATE by {{gender:$2|$2}}, see $3 for the current revision.',
+'enotif_body_intro_moved'          =>  'The {{SITENAME}} page $1 has been moved on $PAGEEDITDATE by {{gender:$2|$2}}, see $3 for the current revision.',
+'enotif_body_intro_restored'       =>  'The {{SITENAME}} page $1 has been restored on $PAGEEDITDATE by {{gender:$2|$2}}, see $3 for the current revision.',
+'enotif_body_intro_changed'        =>  'The {{SITENAME}} page $1 has been changed on $PAGEEDITDATE by {{gender:$2|$2}}, see $3 for the current revision.',
+
+'enotif_lastvisited'               => 'See $1 for all changes since your last visit.',
+'enotif_lastdiff'                  => 'See $1 to view this change.',
+'enotif_anon_editor'               => 'anonymous user $1',
 
-The {{SITENAME}} page $PAGETITLE has been $CHANGEDORCREATED on $PAGEEDITDATE by $PAGEEDITOR, see $PAGETITLE_URL for the current revision.
+'enotif_body'                  => 'Dear $WATCHINGUSERNAME,
 
-$NEWPAGE
+$PAGEINTRO $NEWPAGE
 
 Editor\'s summary: $PAGESUMMARY $PAGEMINOREDIT
 
@@ -2909,8 +2915,7 @@ Contact the editor:
 mail: $PAGEEDITOR_EMAIL
 wiki: $PAGEEDITOR_WIKI
 
-There will be no other notifications in case of further changes unless you visit this page.
-You could also reset the notification flags for all your watched pages on your watchlist.
+There will be no other notifications in case of further changes unless you visit this page. You could also reset the notification flags for all your watched pages on your watchlist.
 
                         Your friendly {{SITENAME}} notification system
 
index f80b904..6871b1d 100644 (file)
@@ -2779,17 +2779,29 @@ Similar to {{msg-mw|rcnote}} which is used on [[Special:RecentChanges]].
 
 'enotif_reset' => "This should be translated as \"Mark all pages '''as''' visited\".",
 'enotif_newpagetext' => 'Part of text of a notification e-mail sent when a watched page has been created. See [[File:Screenshot_MediaWiki_e-mail_notifier.PNG|150px|right]]',
-'changed' => 'Possible value for $CHANGEDORCREATED in {{msg|enotif_subject}} and {{msg|enotif_body}}.',
-'created' => 'Possible value for $CHANGEDORCREATED in {{msg|enotif_subject}} and {{msg|enotif_body}}.',
-'enotif_subject' => '$CHANGEDORCREATED can be one of {{msg|changed}} and {{msg|created}}. Can also be {{msg-mw|blog-added}} or {{msg-mw|blog-edited}} from Wikia.',
+
+'enotif_subject_deleted' => 'Email notification subject for deleted pages, $1 is page title, $2 is page editor.',
+'enotif_subject_created' => 'Email notification subject for new pages, $1 is page title, $2 is page editor.',
+'enotif_subject_moved' => 'Email notification subject for pages that get moved, $1 is page title, $2 is page editor.',
+'enotif_subject_restored' => 'Email notification subject for pages that get restored, $1 is page title, $2 is page editor.',
+'enotif_subject_changed' => 'Email notification subject for pages that get changed, $1 is page title, $2 is page editor.',
+
+'enotif_body_intro_deleted'        =>  'Email notification body intro text for deleted pages, $1 is the page title, $2 is the page editor, $3 is page url.',
+'enotif_body_intro_created'        =>  'Email notification body intro text for new pages, $1 is the page title, $2 is the page editor, $3 is page url.',
+'enotif_body_intro_moved'          =>  'Email notification body intro for pages that get moved, $1 is the page title, $2 is the page editor, $3 is page url.',
+'enotif_body_intro_restored'       =>  'Email notification body intro for pages that get restored, $1 is the page title, $2 is the page editor, $3 is page url.',
+'enotif_body_intro_changed'        =>  'Email notification body intro for pages that get changed, $1 is the page title, $2 is the page editor, $3 is page url.',
+
 'enotif_lastvisited' => '$1 is a URL address.',
 'enotif_lastdiff' => 'E-mail notification text to the latest page differences. Parameters:
 * $1 is a link to a diff, shown as a plain link.',
 'enotif_anon_editor' => 'User name in an e-mail notification when referring to an anonymous user. Parameters:
 * $1 is the anonymous user name (i.e. an IP address).',
-'enotif_body' => 'Text of a notification e-mail sent when a watched page has been edited or deleted.[[File:Screenshot_MediaWiki_e-mail_notifier.PNG|150px|right]]
 
-* <tt>$CHANGEDORCREATED</tt> can be one of {{msg-mw|changed}}, {{msg-mw|created}}, or {{msg-mw|deleted}}. Can also be {{msg-mw|blog-added}} or {{msg-mw|blog-edited}} from Wikia.',
+'enotif_body'        => 'Text of a notification e-mail sent when a watched page has been created, edited, deleted, moved or restored. [[File:Screenshot_MediaWiki_e-mail_notifier.PNG|150px|right]]
+
+$PAGETITLE_URL is the full URL for the page acted on. $PAGEINTRO has the possible values of {{msg|enotif_body_intro_deleted}}, {{msg|enotif_body_intro_created}}, {{msg|enotif_body_intro_moved}}, {{msg|enotif_body_intro_restored}}, {{msg|enotif_body_intro_changed}}
+$NEWPAGE has the possible values of {{msg|enotif_newpagetext}}, {{msg|enotif_lastvisited}}, or {{msg|enotif_lastdiff}}',
 
 # Delete
 'confirm' => 'Submit button text for protection confirmation
index 14a672e..60232da 100644 (file)
@@ -1950,11 +1950,17 @@ $wgMessageStructure = array(
        'enotif' => array(
                'enotif_mailer',
                'enotif_reset',
-               'enotif_newpagetext',
                'enotif_impersonal_salutation',
-               'changed',
-               'created',
-               'enotif_subject',
+               'enotif_subject_deleted',
+               'enotif_subject_created',
+               'enotif_subject_moved',
+               'enotif_subject_restored',
+               'enotif_subject_changed',
+               'enotif_body_intro_deleted',
+               'enotif_body_intro_created',
+               'enotif_body_intro_moved',
+               'enotif_body_intro_restored',
+               'enotif_body_intro_changed',
                'enotif_lastvisited',
                'enotif_lastdiff',
                'enotif_anon_editor',