Modifying ArticleEditUpdateNewTalk hook so that it passes the recipient
authorkaldari <kaldari@gmail.com>
Sun, 14 Apr 2013 22:30:24 +0000 (15:30 -0700)
committerkaldari <kaldari@gmail.com>
Sun, 14 Apr 2013 22:30:24 +0000 (15:30 -0700)
The recipient is the user who's talk page was edited. Extensions may
want to send or not send the notification based on some aspect of the
user, for example a preference.

Bug: 46550
Change-Id: Ifc8fbaf8fdc96f9c18c2a889d2e854e49b3a7010

docs/hooks.txt
includes/WikiPage.php

index c266dcc..e896a72 100644 (file)
@@ -482,7 +482,8 @@ $logEntry: the ManualLogEntry used to record the deletion
 
 'ArticleEditUpdateNewTalk': Before updating user_newtalk when a user talk page
 was changed.
-$wikiPage: WikiPage (object) of the user talk page
+&$wikiPage: WikiPage (object) of the user talk page
+$recipient: User (object) who's talk page was edited
 
 'ArticleEditUpdates': When edit updates (mainly link tracking) are made when an
 article has been changed.
index 228f295..cb75cf5 100644 (file)
@@ -2121,17 +2121,20 @@ class WikiPage implements Page, IDBAccessObject {
                        && $shortTitle != $user->getTitleKey()
                        && !( $revision->isMinor() && $user->isAllowed( 'nominornewtalk' ) )
                ) {
-                       if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this ) ) ) {
-                               $other = User::newFromName( $shortTitle, false );
-                               if ( !$other ) {
-                                       wfDebug( __METHOD__ . ": invalid username\n" );
-                               } elseif ( User::isIP( $shortTitle ) ) {
-                                       // An anonymous user
-                                       $other->setNewtalk( true, $revision );
-                               } elseif ( $other->isLoggedIn() ) {
-                                       $other->setNewtalk( true, $revision );
-                               } else {
-                                       wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
+                       $recipient = User::newFromName( $shortTitle, false );
+                       if ( !$recipient ) {
+                               wfDebug( __METHOD__ . ": invalid username\n" );
+                       } else {
+                               // Allow extensions to prevent user notification when a new message is added to their talk page
+                               if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
+                                       if ( User::isIP( $shortTitle ) ) {
+                                               // An anonymous user
+                                               $recipient->setNewtalk( true, $revision );
+                                       } elseif ( $recipient->isLoggedIn() ) {
+                                               $recipient->setNewtalk( true, $revision );
+                                       } else {
+                                               wfDebug( __METHOD__ . ": don't need to notify a nonexistent user\n" );
+                                       }
                                }
                        }
                }