From: Mark A. Hershberger Date: Tue, 5 Sep 2017 18:18:02 +0000 (-0400) Subject: Note whether a category was added in a machine readable way X-Git-Tag: 1.31.0-rc.0~2200 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=4fd44dcd26417265e61029d43d61c522505b96fd Note whether a category was added in a machine readable way 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 --- diff --git a/includes/changes/CategoryMembershipChange.php b/includes/changes/CategoryMembershipChange.php index 5d199612df..6fa6907007 100644 --- a/includes/changes/CategoryMembershipChange.php +++ b/includes/changes/CategoryMembershipChange.php @@ -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(); diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 199222307c..fd789a6421 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -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 = [