Matmarex has uploaded a new change for review.

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


Change subject: Fire Echo event when revision is approved
......................................................................

Fire Echo event when revision is approved

This is a little rudimentary, but works and handles 90% of use cases.

Things to maybe do sometime in the future:

* handle various approval levels
  (currently the same text is used for any reviewed revision)
* batching
  (if multiple edits to one page are approved in order)
* notifications for "implicitly" approved revisions
  (if only last edit from a stack of edits to one page is approved)

Bug: 52510
Change-Id: I974402262feafc321fbebd9fc514a483b48ba650
---
M FlaggedRevs.php
M FlaggedRevs.setup.php
M backend/FlaggedRevs.hooks.php
M business/RevisionReviewForm.php
M frontend/language/FlaggedRevs.i18n.php
5 files changed, 109 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs 
refs/changes/75/79775/1

diff --git a/FlaggedRevs.php b/FlaggedRevs.php
index de60e62..6403313 100644
--- a/FlaggedRevs.php
+++ b/FlaggedRevs.php
@@ -66,6 +66,9 @@
 $wgDefaultUserOptions['flaggedrevsstable'] = FR_SHOW_STABLE_DEFAULT;
 $wgDefaultUserOptions['flaggedrevseditdiffs'] = true;
 $wgDefaultUserOptions['flaggedrevsviewdiffs'] = false;
+# Echo integration, same config as for built-in notifications
+$wgDefaultUserOptions['echo-subscriptions-web-flaggedrevs'] = true;
+$wgDefaultUserOptions['echo-subscriptions-email-flaggedrevs'] = false;
 
 # Add review log
 $wgLogTypes[] = 'review';
diff --git a/FlaggedRevs.setup.php b/FlaggedRevs.setup.php
index 2d8ec50..9e63894 100644
--- a/FlaggedRevs.setup.php
+++ b/FlaggedRevs.setup.php
@@ -229,6 +229,10 @@
 
                # Database schema changes
                $wgHooks['LoadExtensionSchemaUpdates'][] = 
'FlaggedRevsUpdaterHooks::addSchemaUpdates';
+               
+               # Echo integration
+               $wgHooks['BeforeCreateEchoEvent'][] = 
'FlaggedRevsHooks::onBeforeCreateEchoEvent';
+               $wgHooks['EchoGetDefaultNotifiedUsers'][] = 
'FlaggedRevsHooks::onEchoGetDefaultNotifiedUsers';
                # ########
        }
 
@@ -250,8 +254,6 @@
                        $wgHooks['ParserGetVariableValueSwitch'][] = 
'FlaggedRevsHooks::onParserGetVariableValueSwitch';
                        $wgHooks['MagicWordwgVariableIDs'][] = 
'FlaggedRevsHooks::onMagicWordwgVariableIDs';
                }
-
-               $wgHooks['EchoGetDefaultNotifiedUsers'][] = 
'FlaggedRevsHooks::onEchoGetDefaultNotifiedUsers';
 
                # ######## User interface #########
                FlaggedRevsUISetup::defineHookHandlers( $wgHooks );
diff --git a/backend/FlaggedRevs.hooks.php b/backend/FlaggedRevs.hooks.php
index 6fb52b4..f2f0a54 100644
--- a/backend/FlaggedRevs.hooks.php
+++ b/backend/FlaggedRevs.hooks.php
@@ -1011,6 +1011,38 @@
        }
 
        /**
+        * Add FlaggedRevs events to Echo
+        *
+        * @param $notifications array a list of enabled Echo events
+        * @param $notificationCategories array details for Echo events
+        * @param $icons array of icon details
+        */
+       public static function onBeforeCreateEchoEvent( &$notifications, 
&$notificationCategories, &$icons ) {
+               $notificationCategories['flaggedrevs'] = array(
+                       'priority' => 3,
+                       'tooltip' => 'echo-pref-tooltip-flaggedrevs',
+               );
+
+               $notifications['flaggedrevs-reviewed'] = array(
+                       'category' => 'flaggedrevs',
+                       'group' => 'neutral',
+                       'formatter-class' => 'EchoEditFormatter',
+                       'title-message' => 'flaggedrevs-reviewed',
+                       'title-params' => array( 'agent', 'difflink', 'title' ),
+                       'primary-link' => array( 'message' => 
'notification-link-text-view-edit', 'destination' => 'diff' ),
+                       'email-subject-message' => 
'flaggedrevs-reviewed-email-subject',
+                       'email-subject-params' => array( 'title' ),
+                       'email-body-message' => 
'flaggedrevs-reviewed-email-body',
+                       'email-body-params' => array( 'agent', 'difflink', 
'title', 'titlelink', 'email-footer' ),
+                       'email-body-batch-message' => 
'flaggedrevs-reviewed-email-batch',
+                       'email-body-batch-params' => array( 'agent', 
'difflink', 'title', 'titlelink' ),
+                       'icon' => 'reviewed',
+               );
+
+               return true;
+       }
+
+       /**
         * Handler for EchoGetDefaultNotifiedUsers hook.
         * @param $event EchoEvent to get implicitly subscribed users for
         * @param &$users Array to append implicitly subscribed users to.
@@ -1018,11 +1050,21 @@
         */
        public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) 
{
                $extra = $event->getExtra();
-               if ( $event->getType() == 'reverted' && $extra['method'] == 
'flaggedrevs-reject' ) {
-                       foreach ( $extra['reverted-users-ids'] as $userId ) {
-                               $users[$userId] = User::newFromId( intval( 
$userId ) );
-                       }
+
+               switch ( $event->getType() ) {
+                       case 'reverted':
+                               if ( $extra['method'] == 'flaggedrevs-reject' ) 
{
+                                       foreach ( $extra['reverted-users-ids'] 
as $userId ) {
+                                               $users[$userId] = 
User::newFromId( intval( $userId ) );
+                                       }
+                               }
+                               break;
+
+                       case 'flaggedrevs-reviewed':
+                               $users[$extra['revuserid']] = User::newFromId( 
intval( $extra['revuserid'] ) );
+                               break;
                }
+
                return true;
        }
 }
diff --git a/business/RevisionReviewForm.php b/business/RevisionReviewForm.php
index fdc99b5..4f02fa2 100644
--- a/business/RevisionReviewForm.php
+++ b/business/RevisionReviewForm.php
@@ -336,6 +336,7 @@
 
                        $status = $editStatus->isOK() ? true : 
'review_cannot_undo';
 
+                       // Echo integration
                        if ( $editStatus->isOK() && class_exists( 'EchoEvent' ) 
&& $editStatus->value['revision'] ) {
                                $affectedRevisions = array(); // revid -> userid
                                $revisions = wfGetDB( DB_SLAVE )->select(
@@ -475,6 +476,21 @@
                # Caller may want to get the change time
                $this->newLastChangeTime = $flaggedRevision->getTimestamp();
 
+               // Echo integration
+               // No notifications for anonymous users
+               if ( class_exists( 'EchoEvent' ) && $rev->getUser() ) {
+                       EchoEvent::create( array(
+                               'type' => 'flaggedrevs-reviewed',
+                               'title' => $this->page,
+                               'extra' => array(
+                                       'revid' => $rev->getId(),
+                                       'revuserid' => $rev->getUser(),
+                                       'quality' => $quality,
+                               ),
+                               'agent' => $this->user,
+                       ) );
+               }
+
                wfProfileOut( __METHOD__ );
                return true;
        }
diff --git a/frontend/language/FlaggedRevs.i18n.php 
b/frontend/language/FlaggedRevs.i18n.php
index dd1efe4..815f50e 100644
--- a/frontend/language/FlaggedRevs.i18n.php
+++ b/frontend/language/FlaggedRevs.i18n.php
@@ -227,6 +227,23 @@
        'log-show-hide-review'         => '$1 review log',
 
        'validationpage'               => '{{ns:help}}:Page validation',
+
+       'flaggedrevs-reviewed' => 'Your edit on page "$3" {{GENDER:$1|has been 
reviewed}} by $1. $2',
+       'flaggedrevs-reviewed-email-subject' => 'Your edit on {{SITENAME}} page 
"$1" has been reviewed',
+       'flaggedrevs-reviewed-email-body' => 'Your edit on {{SITENAME}} page 
"$3" {{GENDER:$1|has been reviewed}} by $1.
+
+See the accepted changes:
+
+$2
+
+See the page:
+
+$4
+
+$5',
+       'flaggedrevs-reviewed-email-batch' => 'Your edit on page "$3" 
{{GENDER:$1|has been reviewed}} by $1. $2',
+       'echo-category-title-flaggedrevs' => 'Flagged Revisions',
+       'echo-pref-tooltip-flaggedrevs' => 'Notify me when one of my edits is 
reviewed.',
 );
 
 /** Message documentation (Message documentation)
@@ -822,6 +839,29 @@
 * $1 is one of {{msg-mw|show}} or {{msg-mw|hide}}',
        'validationpage' => "{{Flagged Revs-small}}
 Link to the general help page. Do ''not'' translate the 
<tt><nowiki>{{ns:help}}:</nowiki></tt> part, including the colon.",
+
+       'flaggedrevs-reviewed' => 'Text on Echo [[Special:Notifications]] page 
and',
+       'flaggedrevs-reviewed-email-subject' => 'E-mail subject.
+
+Parameters:
+* $1 - page title',
+       'flaggedrevs-reviewed-email-body' => 'E-mail body.
+
+Parameters:
+* $1 - reviewer\'s nick
+* $2 - link to the diff
+* $3 - page title
+* $4 - link to the page
+* $5 - e-mail footer',
+       'flaggedrevs-reviewed-email-batch' => 'Batched e-mail contents.
+
+Parameters:
+* $1 - reviewer\'s nick
+* $2 - link to the diff
+* $3 - page title
+* $4 - link to the page (unused by default)',
+       'echo-category-title-flaggedrevs' => 'Label on Special:Preferences',
+       'echo-pref-tooltip-flaggedrevs' => 'Label tooltip on 
Special:Preferences',
 );
 
 /** Afrikaans (Afrikaans)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I974402262feafc321fbebd9fc514a483b48ba650
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Matmarex <matma....@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to