Kaldari has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/53501


Change subject: Thank notification for Echo (depends on some new core Hooks)
......................................................................

Thank notification for Echo (depends on some new core Hooks)

Change-Id: Ibe047b4188378a5d2529f0a529244e6e914c88c3
---
M Echo.i18n.php
M Echo.php
M Hooks.php
M controller/NotificationController.php
M modules/icons/icons.css
5 files changed, 146 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/01/53501/1

diff --git a/Echo.i18n.php b/Echo.i18n.php
index e9c71d4..60c2a50 100644
--- a/Echo.i18n.php
+++ b/Echo.i18n.php
@@ -36,6 +36,7 @@
        'echo-dismiss-title-article-linked' => 'Page linked',
        'echo-dismiss-title-reverted' => 'Edit reverted',
        'echo-dismiss-title-mention' => 'Mention',
+       'echo-dismiss-title-thanks' => 'Thanks',
 
        // Errors
        'echo-no-agent' => '[Nobody]',
@@ -110,6 +111,7 @@
 
 $5',
        'notification-mention-email-batch-body' => '$1 {{GENDER:$1|mentioned}} 
you on $2',
+       'notification-thanks' => '$1 {{GENDER:$1|thanked}} you for your edit on 
$2 $3',
        'echo-notification-count' => '$1+',
        // Email notification
        'echo-email-subject-default' => 'New notification at {{SITENAME}}',
@@ -162,6 +164,11 @@
        'echo-email-batch-category-header-mention' => '$1 
{{PLURAL:$1|mention|mentions}}',
        'echo-email-batch-category-header-other' => '$1 uncategorized 
{{PLURAL:$1|notification|notifications}}',
        'echo-email-batch-category-header-system' => '$1 system 
{{PLURAL:$1|notification|notifications}}',
+       
+       // Thank notification
+       'echo-thank' => 'thank',
+       'echo-thanked' => 'thanked',
+       'echo-thank-error' => 'Thank action failed. Please try again.',
 );
 
 /** Message documentation (Message documentation)
@@ -489,6 +496,10 @@
 * {{msg-mw|Echo-email-batch-category-header-reverted}}
 * {{msg-mw|Echo-email-batch-category-header-article-linked}}
 * {{msg-mw|Echo-email-batch-category-header-other}}',
+       // Thank notification
+       'echo-thank' => 'Link to thank another user. This is a verb.',
+       'echo-thanked' => 'Message that replaces the link to thank another user 
after they have been thanked ({{msg-mw|Echo-thank}})',
+       'echo-thank-error' => 'Error message that is displayed when the thank 
action fails',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/Echo.php b/Echo.php
index 0e422b3..7c2cb73 100644
--- a/Echo.php
+++ b/Echo.php
@@ -70,6 +70,8 @@
 // API
 $wgAutoloadClasses['ApiEchoNotifications'] =  $dir . 
'api/ApiEchoNotifications.php';
 $wgAPIMetaModules['notifications'] = 'ApiEchoNotifications';
+$wgAutoloadClasses['ApiEchoThank'] = $dir . 'api/ApiEchoThank.php';
+$wgAPIModules['echothank'] = 'ApiEchoThank';
 
 // Special page
 $wgAutoloadClasses['SpecialNotifications'] = $dir . 
'special/SpecialNotifications.php';
@@ -88,6 +90,12 @@
 $wgHooks['MakeGlobalVariablesScript'][] = 
'EchoHooks::makeGlobalVariablesScript';
 $wgHooks['UnitTestsList'][] = 'EchoHooks::getUnitTests';
 $wgHooks['ResourceLoaderRegisterModules'][] = 
'EchoHooks::onResourceLoaderRegisterModules';
+
+// Thank notification hooks
+$wgHooks['HistoryRevisionTools'][] = 'EchoHooks::onHistoryRevisionTools';
+$wgHooks['DiffRevisionTools'][] = 'EchoHooks::onDiffRevisionTools';
+$wgHooks['PageHistoryBeforeList'][] = 'EchoHooks::onPageHistoryBeforeList';
+$wgHooks['DiffViewHeader'][] = 'EchoHooks::onDiffViewHeader';
 
 // Extension initialization
 $wgExtensionFunctions[] = 'EchoHooks::initEchoExtension';
@@ -151,6 +159,15 @@
        ),
        'ext.echo.icons' => $echoResourceTemplate + array(
                'styles' => 'icons/icons.css',
+       ),
+       'ext.echo.thank' => $echoResourceTemplate + array(
+               'scripts' => array(
+                       'thank/ext.echo.thank.js',
+               ),
+               'messages' => array(
+                       'echo-thanked',
+                       'echo-thank-error',
+               ),
        ),
 );
 
@@ -261,6 +278,9 @@
        'mention' => array(
                'priority' => 4,
        ),
+       'thanks' => array(
+               'priority' => 2,
+       ),
 );
 
 // Definitions of the notification event types built into Echo.
@@ -342,6 +362,15 @@
                'content-message' => 'notification-talkpage-content',
                'content-params' => array( 'commentText' ),
                'icon' => 'chat',
+       ),
+       'thanks' => array(
+               'category' => 'thanks',
+               'group' => 'interactive',
+               'formatter-class' => 'EchoEditFormatter',
+               'title-message' => 'notification-thanks',
+               'title-params' => array( 'agent', 'title', 'difflink' ),
+               'payload' => array( 'summary' ),
+               'icon' => 'gratitude',
        )
 );
 
diff --git a/Hooks.php b/Hooks.php
index ef3ebc9..8950ba2 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -119,15 +119,23 @@
                        case 'welcome':
                                $users[$event->getAgent()->getId()] = 
$event->getAgent();
                                break;
+                       case 'thanks':
+                               $extra = $event->getExtra();
+                               if ( !$extra || !isset( 
$extra['thanked-user-id'] ) ) {
+                                       break;
+                               }
+                               $recipientId = $extra['thanked-user-id'];
+                               $recipient = User::newFromId( $recipientId );
+                               $users[$recipientId] = $recipient;
+                               break;
                        case 'reverted':
                                $extra = $event->getExtra();
-
                                if ( !$extra || !isset( 
$extra['reverted-user-id'] ) ) {
                                        break;
                                }
-                               $victimID = $extra['reverted-user-id'];
-                               $victim = User::newFromId( $victimID );
-                               $users[$victim->getId()] = $victim;
+                               $victimId = $extra['reverted-user-id'];
+                               $victim = User::newFromId( $victimId );
+                               $users[$victimId] = $victim;
                                break;
                        case 'article-linked':
                                $extra = $event->getExtra();
@@ -439,6 +447,96 @@
        }
 
        /**
+        * Handler for HistoryRevisionTools hook.
+        * @param $rev Revision object to add the thank link for
+        * @param &$tools array Links to add to the revision interface
+        * @return bool
+        */
+       public static function onHistoryRevisionTools( $rev, &$links ) {
+               global $wgUser;
+               // Don't let users thank themselves
+               // TODO: exclude bots?
+               if ( $rev->getUser() !== $wgUser->getId() ) {
+                       // Add 'thank' link
+                       $thankLink = Html::element(
+                               'a',
+                               array(
+                                       'class' => 'mw-echo-thank-link',
+                                       'href' => '#',
+                                       'data-revision-id' => $rev->getId(),
+                               ),
+                               wfMessage( 'echo-thank' )->plain()
+                       );
+                       if ( $thankLink ) {
+                               $links[] = $thankLink;
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Handler for DiffRevisionTools hook.
+        * @param $rev Revision object to add the thank link for
+        * @param &$links array Links to add to the revision interface
+        * @return bool
+        */
+       public static function onDiffRevisionTools( $rev, &$links ) {
+               global $wgUser;
+               // Don't let users thank themselves
+               // TODO: exclude bots?
+               if ( $rev->getUser() !== $wgUser->getId() ) {
+                       // Add 'thank' link
+                       $thankLink = Html::element(
+                               'a',
+                               array(
+                                       'class' => 'mw-echo-thank-link',
+                                       'href' => '#',
+                                       'data-revision-id' => $rev->getId(),
+                               ),
+                               wfMessage( 'echo-thank' )->plain()
+                       );
+                       if ( $thankLink ) {
+                               $links[] = $thankLink;
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Handler for PageHistoryBeforeList hook.
+        * @see http://www.mediawiki.org/wiki/Manual:Hooks/PageHistoryBeforeList
+        * @param &$page WikiPage|Article|ImagePage|CategoryPage|Page The page 
that the history is loading for.
+        * @param &$out OutputPage object
+        * @return bool true in all cases
+        */
+       public static function onPageHistoryBeforeList( &$page, &$out ) {
+               $user = $out->getUser();
+               if ( $user->isLoggedIn() ) {
+                       // Load the module for the thank links
+                       $out->addModules( array( 'ext.echo.thank' ) );
+               }
+               return true;
+       }
+
+       /**
+        * Handler for DiffViewHeader hook.
+        * @see http://www.mediawiki.org/wiki/Manual:Hooks/DiffViewHeader
+        * @param $diff WikiPage|Article|ImagePage|CategoryPage|Page The page 
that the history is loading for.
+        * @param $oldRev Revision object of the "old" revision (may be 
null/invalid)
+        * @param $newRev Revision object of the "new" revision
+        * @param &$out OutputPage object
+        * @return bool true in all cases
+        */
+       public static function onDiffViewHeader( $diff, $oldRev, $newRev, &$out 
) {
+               $user = $out->getUser();
+               if ( $user->isLoggedIn() ) {
+                       // Load the module for the thank link
+                       $out->addModules( array( 'ext.echo.thank' ) );
+               }
+               return true;
+       }
+
+       /**
         * Handler for LinksUpdateAfterInsert hook.
         * @see 
http://www.mediawiki.org/wiki/Manual:Hooks/LinksUpdateAfterInsert
         * @param $linksUpdate LinksUpdate
diff --git a/controller/NotificationController.php 
b/controller/NotificationController.php
index eff7a80..856956f 100644
--- a/controller/NotificationController.php
+++ b/controller/NotificationController.php
@@ -201,7 +201,6 @@
                        self::doNotification( $event, $event->getAgent(), 'web' 
);
                } else {
                        $subscriptions = self::getSubscriptionsForEvent( $event 
);
-
                        foreach ( $subscriptions as $subscription ) {
                                $user = $subscription->getUser();
                                $notifyTypes = 
$subscription->getNotificationTypes();
diff --git a/modules/icons/icons.css b/modules/icons/icons.css
index 7a5947b..9da80c5 100644
--- a/modules/icons/icons.css
+++ b/modules/icons/icons.css
@@ -47,3 +47,7 @@
        /* @embed */
        background-image: url(Reviewed.png);
 }
+.mw-echo-icon-gratitude {
+       /* @embed */
+       background-image: url(Gratitude.png);
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/53501
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe047b4188378a5d2529f0a529244e6e914c88c3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to