From 3a1d030efbfeda29aa2de330b3d7c23750bef700 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Thu, 4 Nov 2021 13:39:04 -0700 Subject: [PATCH] PageUpdater: apply tags even if RC suppressed. Sometimes we apply tag to a revision even if we suppress the RecentChange, for example when leaving redirects after page moves. Bug: T291967 Change-Id: I7330d3b56cd2280dd23ec0ccb4e1c4807c534739 --- includes/Storage/PageUpdater.php | 5 ++++ .../includes/Storage/PageUpdaterTest.php | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/includes/Storage/PageUpdater.php b/includes/Storage/PageUpdater.php index 09d4d06916b..577d4576974 100644 --- a/includes/Storage/PageUpdater.php +++ b/includes/Storage/PageUpdater.php @@ -25,6 +25,7 @@ namespace MediaWiki\Storage; use AtomicSectionUpdate; +use ChangeTags; use CommentStoreComment; use Content; use ContentHandler; @@ -1304,6 +1305,8 @@ class PageUpdater { $tags, $editResult ); + } else { + ChangeTags::addTags( $tags, null, $newRevisionRecord->getId(), null ); } $this->userEditTracker->incrementUserEditCount( $this->author ); @@ -1423,6 +1426,8 @@ class PageUpdater { $this->rcPatrolStatus, $tags ); + } else { + ChangeTags::addTags( $tags, null, $newRevisionRecord->getId(), null ); } $this->userEditTracker->incrementUserEditCount( $this->author ); diff --git a/tests/phpunit/includes/Storage/PageUpdaterTest.php b/tests/phpunit/includes/Storage/PageUpdaterTest.php index cc562e4c004..d1892df0948 100644 --- a/tests/phpunit/includes/Storage/PageUpdaterTest.php +++ b/tests/phpunit/includes/Storage/PageUpdaterTest.php @@ -2,10 +2,12 @@ namespace MediaWiki\Tests\Storage; +use ChangeTags; use CommentStoreComment; use Content; use DeferredUpdates; use FormatJson; +use MediaWiki\Page\PageIdentityValue; use MediaWiki\Revision\RenderedRevision; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; @@ -969,4 +971,30 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertStringContainsString( $expected, $html, 'In HTML' ); } + public function testChangeTagsSuppressRecentChange() { + $page = PageIdentityValue::localIdentity( 0, NS_MAIN, __METHOD__ ); + $revision = $this->getServiceContainer() + ->getPageUpdaterFactory() + ->newPageUpdater( + WikiPage::factory( $page ), + $this->getTestUser()->getUser() + ) + ->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) ) + ->addTag( 'foo' ) + ->setFlags( EDIT_SUPPRESS_RC ) + ->saveRevision( CommentStoreComment::newUnsavedComment( 'Comment' ) ); + $this->assertArrayEquals( [ 'foo' ], ChangeTags::getTags( $this->db, null, $revision->getId() ) ); + + $revision2 = $this->getServiceContainer() + ->getPageUpdaterFactory() + ->newPageUpdater( + WikiPage::factory( $page ), + $this->getTestUser()->getUser() + ) + ->setContent( SlotRecord::MAIN, new TextContent( 'Other content' ) ) + ->addTag( 'bar' ) + ->setFlags( EDIT_SUPPRESS_RC ) + ->saveRevision( CommentStoreComment::newUnsavedComment( 'Comment' ) ); + $this->assertArrayEquals( [ 'bar' ], ChangeTags::getTags( $this->db, null, $revision2->getId() ) ); + } }