Note whether a category was added in a machine readable way
authorMark A. Hershberger <mah@nichework.com>
Tue, 5 Sep 2017 18:18:02 +0000 (14:18 -0400)
committerAddshore <addshorewiki@gmail.com>
Wed, 6 Sep 2017 09:03:54 +0000 (09:03 +0000)
CategoryMembershipChange is great, but it doesn't have a
machine-readable way to see if the category has been added or removed
from the page. We could parse the comments, but that would rely on
reading the comments and matching the message against the translated
strings.

This patch adds a couple of parameters and notes whether the change
was an addition or removal in rc_params.

Also, puts the evaluation of the AbortEmailNotification hook before
the check of rc_type in the hopes that the extension CatWatch can send
out emails at the right time.

Bug: T175052
Change-Id: I3e2ac0cc148b9d618e2f8b7853b14bff827ee443

includes/changes/CategoryMembershipChange.php
includes/changes/RecentChange.php

index 5d19961..6fa6907 100644 (file)
@@ -134,7 +134,8 @@ class CategoryMembershipChange {
                        ),
                        $this->pageTitle,
                        $this->getPreviousRevisionTimestamp(),
-                       $this->revision
+                       $this->revision,
+                       $type === self::CATEGORY_ADDITION
                );
        }
 
@@ -146,6 +147,7 @@ class CategoryMembershipChange {
         * @param Title $pageTitle Title of the page that is being added or removed
         * @param string $lastTimestamp Parent revision timestamp of this change in TS_MW format
         * @param Revision|null $revision
+        * @param bool $added true, if the category was added, false for removed
         *
         * @throws MWException
         */
@@ -156,7 +158,8 @@ class CategoryMembershipChange {
                $comment,
                Title $pageTitle,
                $lastTimestamp,
-               $revision
+               $revision,
+               $added
        ) {
                $deleted = $revision ? $revision->getVisibility() & Revision::SUPPRESSED_USER : 0;
                $newRevId = $revision ? $revision->getId() : 0;
@@ -197,7 +200,8 @@ class CategoryMembershipChange {
                                $lastTimestamp,
                                $bot,
                                $ip,
-                               $deleted
+                               $deleted,
+                               $added
                        ]
                );
                $rc->save();
index 1992223..fd789a6 100644 (file)
@@ -361,8 +361,8 @@ class RecentChange {
 
                        // Never send an RC notification email about categorization changes
                        if (
-                               $this->mAttribs['rc_type'] != RC_CATEGORIZE &&
-                               Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
+                               Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) &&
+                               $this->mAttribs['rc_type'] != RC_CATEGORIZE
                        ) {
                                // @FIXME: This would be better as an extension hook
                                // Send emails or email jobs once this row is safely committed
@@ -850,6 +850,7 @@ class RecentChange {
         * @param bool $bot true, if the change was made by a bot
         * @param string $ip IP address of the user, if the change was made anonymously
         * @param int $deleted Indicates whether the change has been deleted
+        * @param bool $added true, if the category was added, false for removed
         *
         * @return RecentChange
         */
@@ -864,8 +865,17 @@ class RecentChange {
                $lastTimestamp,
                $bot,
                $ip = '',
-               $deleted = 0
+               $deleted = 0,
+               $added = null
        ) {
+               // Done in a backwards compatible way.
+               $params = [
+                       'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
+               ];
+               if ( $added !== null ) {
+                       $params['added'] = $added;
+               }
+
                $rc = new RecentChange;
                $rc->mTitle = $categoryTitle;
                $rc->mPerformer = $user;
@@ -894,9 +904,7 @@ class RecentChange {
                        'rc_logid' => 0,
                        'rc_log_type' => null,
                        'rc_log_action' => '',
-                       'rc_params' => serialize( [
-                               'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
-                       ] )
+                       'rc_params' => serialize( $params )
                ];
 
                $rc->mExtra = [