Cenarium has uploaded a new change for review. https://gerrit.wikimedia.org/r/316410
Change subject: Notify users of reviews ...................................................................... Notify users of reviews This notifies users when one of their edits is reviewed. Change-Id: I7a9e017773d6b7d7b11bb3d22bcddc6834fdf74d --- M FlaggedRevs.setup.php M backend/FlaggedRevs.hooks.php A backend/FlaggedRevsReviewedPresentationModel.php M business/RevisionReviewForm.php M i18n/flaggedrevs/en.json M i18n/flaggedrevs/qqq.json 6 files changed, 126 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FlaggedRevs refs/changes/10/316410/1 diff --git a/FlaggedRevs.setup.php b/FlaggedRevs.setup.php index 298fae4..e3667bd 100755 --- a/FlaggedRevs.setup.php +++ b/FlaggedRevs.setup.php @@ -174,6 +174,11 @@ $classes['Scribunto_LuaFlaggedRevsLibrary'] = "$scribuntoDir/FlaggedRevs.library.php"; ### End ### + ### Echo classes ### + $classes['EchoFlaggedRevsReviewedPresentationModel'] = + "$backendDir/FlaggedRevsReviewedPresentationModel.php"; + ### End ### + ### Event handler classes ### $classes['FlaggedRevsHooks'] = "$backendDir/FlaggedRevs.hooks.php"; $classes['FlaggedRevsUIHooks'] = "$frontendDir/FlaggedRevsUI.hooks.php"; @@ -289,6 +294,7 @@ } $wgHooks['EchoGetDefaultNotifiedUsers'][] = 'FlaggedRevsHooks::onEchoGetDefaultNotifiedUsers'; + $wgHooks['BeforeCreateEchoEvent'][] = 'FlaggedRevsHooks::onBeforeCreateEchoEvent'; # ######## User interface ######### FlaggedRevsUISetup::defineHookHandlers( $wgHooks ); diff --git a/backend/FlaggedRevs.hooks.php b/backend/FlaggedRevs.hooks.php index a669280..3f9942b 100755 --- a/backend/FlaggedRevs.hooks.php +++ b/backend/FlaggedRevs.hooks.php @@ -1065,6 +1065,39 @@ $users[$userId] = User::newFromId( intval( $userId ) ); } } + if ( $event->getType() == 'flaggedrevs-reviewed' ) { + foreach ( $extra['reviewed-users-ids'] as $userId ) { + $users[$userId] = User::newFromId( intval( $userId ) ); + } + } + return true; + } + /** + * Add Review events to Echo + * + * @param $notifications array of Echo notifications + * @param $notificationCategories array of Echo notification categories + * @param $icons array of icon details + * @return bool + */ + public static function onBeforeCreateEchoEvent( + &$notifications, &$notificationCategories, &$icons + ) { + $notificationCategories['flaggedrevs-review'] = [ + 'priority' => 12, + 'tooltip' => 'echo-pref-tooltip-flaggedrevs-reviewed', + ]; + $notifications['flaggedrevs-reviewed'] = [ + 'category' => 'flaggedrevs-review', + 'group' => 'positive', + 'section' => 'message', + 'presentation-model' => 'EchoFlaggedRevsReviewedPresentationModel', + 'bundle' => [ + 'web' => true, + 'expandable' => true, + ], + ]; + // icon exists in echo return true; } diff --git a/backend/FlaggedRevsReviewedPresentationModel.php b/backend/FlaggedRevsReviewedPresentationModel.php new file mode 100644 index 0000000..9367868 --- /dev/null +++ b/backend/FlaggedRevsReviewedPresentationModel.php @@ -0,0 +1,33 @@ +<?php + +class EchoFlaggedRevsReviewedPresentationModel extends EchoEventPresentationModel { + + public function getIconType() { + return 'reviewed'; + } + + public function canRender() { + return (bool)$this->event->getTitle(); + } + + public function getHeaderMessage() { + $msg = parent::getHeaderMessage(); + $msg->params( $this->event->getTitle()->getPrefixedText() ); + return $msg; + } + + public function getPrimaryLink() { + $url = $this->event->getTitle()->getLocalURL( array( + 'oldid' => $this->event->getExtraParam( 'oldid' ), + 'diff' => $this->event->getExtraParam( 'revid' ) + ) ); + return array( + 'url' => $url, + 'label' => $this->msg( 'notification-link-text-view-changes' )->text() + ); + } + + public function getSecondaryLinks() { + return array( $this->getAgentLink() ); + } +} diff --git a/business/RevisionReviewForm.php b/business/RevisionReviewForm.php index 5235051..d8e5c24 100644 --- a/business/RevisionReviewForm.php +++ b/business/RevisionReviewForm.php @@ -289,7 +289,41 @@ return 'review_conflict_oldid'; } } - $status = $this->approveRevision( $rev, $this->oldFrev ); + $result = $this->approveRevision( $rev, $this->oldFrev ); + $status = $result->isOK(); + + if ( $status && class_exists( 'EchoEvent' ) ) { + // notify reviewed users + $srev = $result->value['oldSv']; + $affectedUsers = array(); + $revisions = wfGetDB( DB_SLAVE )->select( + 'revision', + array( 'rev_user' ), + array( + 'rev_id <= ' . $rev->getId(), + 'rev_timestamp <= ' . $rev->getTimestamp(), + 'rev_id > ' . $srev->getRevId(), + 'rev_timestamp > ' . $srev->getRevTimestamp(), + 'rev_page' => $this->page->getArticleID(), + ), + __METHOD__ + ); + foreach ( $revisions as $row ) { + $affectedUsers[] = $row->rev_user; + } + + EchoEvent::create( array( + 'type' => 'flaggedrevs-reviewed', + 'title' => $this->page, + 'extra' => array( + 'revid' => $rev->getId(), + 'oldid' => $srev->getRevId(), + 'reviewed-users-ids' => $affectedUsers, + ), + 'agent' => $this->user, + ) ); + + } # We can only unapprove approved revisions... } elseif ( $this->getAction() === 'unapprove' ) { # Check for review conflicts... @@ -303,7 +337,7 @@ if ( !$this->oldFrev ) { return 'review_not_flagged'; } - $status = $this->unapproveRevision( $this->oldFrev ); + $status = $this->unapproveRevision( $this->oldFrev )->isOK(); } elseif ( $this->getAction() === 'reject' ) { $newRev = Revision::newFromTitle( $this->page, $this->oldid ); $oldRev = Revision::newFromTitle( $this->page, $this->refid ); @@ -342,6 +376,7 @@ $status = $editStatus->isOK() ? true : 'review_cannot_undo'; if ( $editStatus->isOK() && class_exists( 'EchoEvent' ) && $editStatus->value['revision'] ) { + // notify reverted users $affectedRevisions = array(); // revid -> userid $revisions = wfGetDB( DB_SLAVE )->select( 'revision', @@ -400,7 +435,7 @@ * @param Revision $rev The revision to be accepted * @param FlaggedRevision $oldFrev Currently accepted version of $rev or null * @throws Exception - * @return bool|array true on success, array of errors on failure + * @return Status */ private function approveRevision( Revision $rev, FlaggedRevision $oldFrev = null ) { # Revision rating flags @@ -436,7 +471,9 @@ $oldFrev->getTemplateVersions( FR_MASTER ) == $tmpVersions && $oldFrev->getFileVersions( FR_MASTER ) == $fileVersions ) { - return true; // don't record if the same + $status = Status::newGood(); + $status->value['oldSv'] = $oldSv; + return $status; // don't record if the same } # The new review entry... @@ -481,13 +518,15 @@ # Caller may want to get the change time $this->newLastChangeTime = $flaggedRevision->getTimestamp(); - return true; + $status = Status::newGood(); + $status->value['oldSv'] = $oldSv; + return $status; } /** * @param FlaggedRevision $frev * Removes flagged revision data for this page/id set - * @return bool + * @return Status */ private function unapproveRevision( FlaggedRevision $frev ) { # Get current stable version ID (for logging) @@ -515,7 +554,7 @@ # Caller may want to get the change time $this->newLastChangeTime = ''; - return true; + return Status::newGood(); } /** diff --git a/i18n/flaggedrevs/en.json b/i18n/flaggedrevs/en.json index 7bde05f..5775b11 100644 --- a/i18n/flaggedrevs/en.json +++ b/i18n/flaggedrevs/en.json @@ -195,5 +195,8 @@ "log-action-filter-stable": "Type of configuration change:", "log-action-filter-stable-config": "New configuration", "log-action-filter-stable-modify": "Modified configuration", - "log-action-filter-stable-reset": "Configuration reset" + "log-action-filter-stable-reset": "Configuration reset", + "notification-header-flaggedrevs-reviewed": "Your edits on $3 have been approved by $1.", + "echo-category-title-flaggedrevs-review": "Edit approvals", + "echo-pref-tooltip-flaggedrevs-reviewed": "Notify me when someone approves an edit I made." } \ No newline at end of file diff --git a/i18n/flaggedrevs/qqq.json b/i18n/flaggedrevs/qqq.json index 0a843ec..904b954 100644 --- a/i18n/flaggedrevs/qqq.json +++ b/i18n/flaggedrevs/qqq.json @@ -224,5 +224,8 @@ "log-action-filter-stable": "Which type of action to filter for in this log", "log-action-filter-stable-config": "Action to filter for in this log", "log-action-filter-stable-modify": "Action to filter for in this log", - "log-action-filter-stable-reset": "Action to filter for in this log" + "log-action-filter-stable-reset": "Action to filter for in this log", + "notification-header-flaggedrevs-reviewed": "Flyout-specific format for displaying notifications of a user's edit being reverted.\n\nParameters:\n* $1 - the formatted username of the person who reviewed.\n* $2 - the username for GENDER\n* $3 - the page that was reviewed, formatted", + "echo-category-title-flaggedrevs-review": "This is a short title for notification category.\n\nUsed in a list of options under the heading {{msg-mw|Prefs-echosubscriptions}} in Special:Preferences.\n{{Related|Echo-category-title}}", + "echo-pref-tooltip-flaggedrevs-reviewed": "This is a short description of the reviewed notification category.\n{{Related|Echo-pref-tooltip}}", } -- To view, visit https://gerrit.wikimedia.org/r/316410 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7a9e017773d6b7d7b11bb3d22bcddc6834fdf74d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/FlaggedRevs Gerrit-Branch: master Gerrit-Owner: Cenarium <cenarium.sy...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits