From 2f4b71fc6cef1c1cc67f2ca9be36aea45d837c65 Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Fri, 3 Jul 2020 00:20:38 +0000 Subject: [PATCH] Replace uses of Revision constants Bug: T257010 Change-Id: Id63123e8b8becd31756d5b68ca11edb238ec8a59 --- includes/EditPage.php | 4 +-- includes/filerepo/file/LocalFile.php | 3 +- includes/page/WikiPage.php | 30 +++++++++---------- tests/parser/ParserTestRunner.php | 3 +- .../phpunit/MediaWikiIntegrationTestCase.php | 7 +++-- .../includes/api/ApiComparePagesTest.php | 14 +++++---- .../phpunit/includes/api/ApiEditPageTest.php | 9 +++--- tests/phpunit/includes/api/ApiParseTest.php | 6 +++- .../changes/CategoryMembershipChangeTest.php | 4 ++- .../phpunit/includes/page/WikiPageDbTest.php | 9 +++--- .../WatchedItemQueryServiceUnitTest.php | 11 +++---- 11 files changed, 57 insertions(+), 43 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 5fb904fe443..d0d8457039e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1444,8 +1444,8 @@ class EditPage implements IEditObject { /** * Get the current content of the page. This is basically similar to - * WikiPage::getContent( Revision::RAW ) except that when the page doesn't exist an empty - * content object is returned instead of null. + * WikiPage::getContent( RevisionRecord::RAW ) except that when the page doesn't + * exist an empty content object is returned instead of null. * * @since 1.21 * @return Content diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 23d2da9d4ba..a5223f08d93 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -24,6 +24,7 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; +use MediaWiki\Revision\RevisionStore; use Wikimedia\AtEase\AtEase; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; @@ -2213,7 +2214,7 @@ class LocalFile extends File { } $store = MediaWikiServices::getInstance()->getRevisionStore(); - $revision = $store->getRevisionByTitle( $this->title, 0, Revision::READ_NORMAL ); + $revision = $store->getRevisionByTitle( $this->title, 0, RevisionStore::READ_NORMAL ); if ( !$revision ) { return false; } diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 476d55a9eb9..522bfdd6bf2 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -791,9 +791,9 @@ class WikiPage implements Page, IDBAccessObject { * Get the content of the current revision. No side-effects... * * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to $wgUser - * Revision::RAW get the text regardless of permissions + * RevisionRecord::FOR_PUBLIC to be displayed to all users + * RevisionRecord::FOR_THIS_USER to be displayed to $wgUser + * RevisionRecord::RAW get the text regardless of permissions * @param User|null $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter * @return Content|null The content of the current revision @@ -831,9 +831,9 @@ class WikiPage implements Page, IDBAccessObject { /** * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions + * RevisionRecord::FOR_PUBLIC to be displayed to all users + * RevisionRecord::FOR_THIS_USER to be displayed to the given user + * RevisionRecord::RAW get the text regardless of permissions * @param User|null $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter (not passing for FOR_THIS_USER is deprecated since 1.35) * @return int User ID for the user that made the last article revision @@ -859,9 +859,9 @@ class WikiPage implements Page, IDBAccessObject { /** * Get the User object of the user who created the page * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions + * RevisionRecord::FOR_PUBLIC to be displayed to all users + * RevisionRecord::FOR_THIS_USER to be displayed to the given user + * RevisionRecord::RAW get the text regardless of permissions * @param User|null $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter (not passing for FOR_THIS_USER is deprecated since 1.35) * @return User|null @@ -885,9 +885,9 @@ class WikiPage implements Page, IDBAccessObject { /** * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions + * RevisionRecord::FOR_PUBLIC to be displayed to all users + * RevisionRecord::FOR_THIS_USER to be displayed to the given user + * RevisionRecord::RAW get the text regardless of permissions * @param User|null $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter (not passing for FOR_THIS_USER is deprecated since 1.35) * @return string Username of the user that made the last article revision @@ -912,9 +912,9 @@ class WikiPage implements Page, IDBAccessObject { /** * @param int $audience One of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions + * RevisionRecord::FOR_PUBLIC to be displayed to all users + * RevisionRecord::FOR_THIS_USER to be displayed to the given user + * RevisionRecord::RAW get the text regardless of permissions * @param User|null $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter (not passing for FOR_THIS_USER is deprecated since 1.35) * @return string|null Comment stored for the last article revision, or null if the specified diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 00c36326043..3f45c7cddc4 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -28,6 +28,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\MutableRevisionRecord; +use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; use Wikimedia\Rdbms\IDatabase; use Wikimedia\ScopedCallback; @@ -1658,7 +1659,7 @@ class ParserTestRunner { $page->loadPageData( 'fromdbmaster' ); if ( $page->exists() ) { - $content = $page->getContent( Revision::RAW ); + $content = $page->getContent( RevisionRecord::RAW ); // Only reject the title, if the content/content model is different. // This makes it easier to create Template:(( or Template:)) in different extensions if ( $newContent->equals( $content ) ) { diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index a9366cb56d7..164a1ad80ab 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -6,6 +6,7 @@ use MediaWiki\Logger\LegacySpi; use MediaWiki\Logger\LogCapturingSpi; use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use MediaWiki\Revision\RevisionRecord; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestResult; use Psr\Log\LoggerInterface; @@ -2380,12 +2381,12 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { * Revision-deletes a revision. * * @param RevisionRecord|int $rev Revision to delete - * @param array $value Keys are Revision::DELETED_* flags. Values are 1 to set the bit, 0 to - * clear, -1 to leave alone. (All other values also clear the bit.) + * @param array $value Keys are RevisionRecord::DELETED_* flags. Values are 1 to set the bit, + * 0 to clear, -1 to leave alone. (All other values also clear the bit.) * @param string $comment Deletion comment */ protected function revisionDelete( - $rev, array $value = [ Revision::DELETED_TEXT => 1 ], $comment = '' + $rev, array $value = [ RevisionRecord::DELETED_TEXT => 1 ], $comment = '' ) { if ( is_int( $rev ) ) { $rev = MediaWikiServices::getInstance() diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php index aff739db3b9..ee7e4c0a8c2 100644 --- a/tests/phpunit/includes/api/ApiComparePagesTest.php +++ b/tests/phpunit/includes/api/ApiComparePagesTest.php @@ -1,5 +1,7 @@ setVisibility( [ 'value' => [ - Revision::DELETED_TEXT => 1, - Revision::DELETED_USER => 1, - Revision::DELETED_COMMENT => 1, + RevisionRecord::DELETED_TEXT => 1, + RevisionRecord::DELETED_USER => 1, + RevisionRecord::DELETED_COMMENT => 1, ], 'comment' => 'Test for ApiComparePages', ] ); @@ -103,9 +105,9 @@ class ApiComparePagesTest extends ApiTestCase { [ self::$repl['revB3'] ] )->setVisibility( [ 'value' => [ - Revision::DELETED_USER => 1, - Revision::DELETED_COMMENT => 1, - Revision::DELETED_RESTRICTED => 1, + RevisionRecord::DELETED_USER => 1, + RevisionRecord::DELETED_COMMENT => 1, + RevisionRecord::DELETED_RESTRICTED => 1, ], 'comment' => 'Test for ApiComparePages', ] ); diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php index e7099af7a9f..7fa6ebfb119 100644 --- a/tests/phpunit/includes/api/ApiEditPageTest.php +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -1,6 +1,7 @@ assertSame( 'Success', $re['edit']['result'] ); $newtext = WikiPage::factory( Title::newFromText( $name ) ) - ->getContent( Revision::RAW ) + ->getContent( RevisionRecord::RAW ) ->getText(); $this->assertSame( "==section 1==\nnew content 1\n\n==section 2==\ncontent2", $newtext ); @@ -217,7 +218,7 @@ class ApiEditPageTest extends ApiTestCase { $this->assertSame( 'Success', $re['edit']['result'] ); // Check the page text is correct $text = WikiPage::factory( Title::newFromText( $name ) ) - ->getContent( Revision::RAW ) + ->getContent( RevisionRecord::RAW ) ->getText(); $this->assertSame( "== header ==\n\ntest", $text ); @@ -233,7 +234,7 @@ class ApiEditPageTest extends ApiTestCase { $this->assertSame( 'Success', $re2['edit']['result'] ); $text = WikiPage::factory( Title::newFromText( $name ) ) - ->getContent( Revision::RAW ) + ->getContent( RevisionRecord::RAW ) ->getText(); $this->assertSame( "== header ==\n\ntest\n\n== header ==\n\ntest", $text ); } @@ -731,7 +732,7 @@ class ApiEditPageTest extends ApiTestCase { $list = RevisionDeleter::createList( 'revision', RequestContext::getMain(), $titleObj, [ $revId1 ] ); $list->setVisibility( [ - 'value' => [ Revision::DELETED_TEXT => 1 ], + 'value' => [ RevisionRecord::DELETED_TEXT => 1 ], 'comment' => 'Bye-bye', ] ); diff --git a/tests/phpunit/includes/api/ApiParseTest.php b/tests/phpunit/includes/api/ApiParseTest.php index 5534e1054cf..61a7d10ea8b 100644 --- a/tests/phpunit/includes/api/ApiParseTest.php +++ b/tests/phpunit/includes/api/ApiParseTest.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\Revision\RevisionRecord; use Psr\Container\ContainerInterface; use Wikimedia\ObjectFactory; @@ -54,7 +55,10 @@ class ApiParseTest extends ApiTestCase { $this->revisionDelete( self::$revIds['revdel'] ); $this->revisionDelete( self::$revIds['suppressed'], - [ Revision::DELETED_TEXT => 1, Revision::DELETED_RESTRICTED => 1 ] + [ + RevisionRecord::DELETED_TEXT => 1, + RevisionRecord::DELETED_RESTRICTED => 1 + ] ); Title::clearCaches(); // Otherwise it has the wrong latest revision for some reason diff --git a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php index bb118b7d060..3e866dd2eff 100644 --- a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php +++ b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php @@ -62,7 +62,9 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { $page = WikiPage::factory( $title ); self::$pageRev = $page->getRevisionRecord(); - self::$revUser = User::newFromIdentity( self::$pageRev->getUser( Revision::RAW ) ); + self::$revUser = User::newFromIdentity( + self::$pageRev->getUser( RevisionRecord::RAW ) + ); } private function newChange( RevisionRecord $revision = null ) { diff --git a/tests/phpunit/includes/page/WikiPageDbTest.php b/tests/phpunit/includes/page/WikiPageDbTest.php index 7fb06fdad7b..b65670c8e18 100644 --- a/tests/phpunit/includes/page/WikiPageDbTest.php +++ b/tests/phpunit/includes/page/WikiPageDbTest.php @@ -3,6 +3,7 @@ use MediaWiki\Edit\PreparedEdit; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\MutableRevisionRecord; +use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; use MediaWiki\Storage\RevisionSlotsUpdate; use PHPUnit\Framework\MockObject\MockObject; @@ -642,17 +643,17 @@ class WikiPageDbTest extends MediaWikiLangTestCase { ); $this->assertNull( - $page->getContent( Revision::FOR_PUBLIC ), + $page->getContent( RevisionRecord::FOR_PUBLIC ), "WikiPage::getContent should return null after the page was suppressed for general users" ); $this->assertNull( - $page->getContent( Revision::FOR_THIS_USER, $this->getTestUser()->getUser() ), + $page->getContent( RevisionRecord::FOR_THIS_USER, $this->getTestUser()->getUser() ), "WikiPage::getContent should return null after the page was suppressed for individual users" ); $this->assertNull( - $page->getContent( Revision::FOR_THIS_USER, $user ), + $page->getContent( RevisionRecord::FOR_THIS_USER, $user ), "WikiPage::getContent should return null after the page was suppressed even for a sysop" ); } @@ -1948,7 +1949,7 @@ more stuff ); $this->assertTrue( $result instanceof Revision ); - $this->assertSame( $expectedComment, $result->getComment( Revision::RAW ) ); + $this->assertSame( $expectedComment, $result->getComment( RevisionRecord::RAW ) ); } /** diff --git a/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php b/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php index 7f12e8a0e53..530cfa16982 100644 --- a/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php +++ b/tests/phpunit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php @@ -1,6 +1,7 @@ 'table' ], [ 'actormigration_conds', - '(rc_deleted & ' . Revision::DELETED_USER . ') != ' . Revision::DELETED_USER, + '(rc_deleted & ' . RevisionRecord::DELETED_USER . ') != ' . RevisionRecord::DELETED_USER, '(rc_type != ' . RC_LOG . ') OR ((rc_deleted & ' . LogPage::DELETED_ACTION . ') != ' . LogPage::DELETED_ACTION . ')' ], @@ -1083,8 +1084,8 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiIntegrationTestCase { [ 'actormigration' => 'table' ], [ 'actormigration_conds', - '(rc_deleted & ' . ( Revision::DELETED_USER | Revision::DELETED_RESTRICTED ) . ') != ' . - ( Revision::DELETED_USER | Revision::DELETED_RESTRICTED ), + '(rc_deleted & ' . ( RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED ) . ') != ' . + ( RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED ), '(rc_type != ' . RC_LOG . ') OR (' . '(rc_deleted & ' . ( LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED ) . ') != ' . ( LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED ) . ')' @@ -1097,8 +1098,8 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiIntegrationTestCase { [ 'actormigration' => 'table' ], [ 'actormigration_conds', - '(rc_deleted & ' . ( Revision::DELETED_USER | Revision::DELETED_RESTRICTED ) . ') != ' . - ( Revision::DELETED_USER | Revision::DELETED_RESTRICTED ), + '(rc_deleted & ' . ( RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED ) . ') != ' . + ( RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED ), '(rc_type != ' . RC_LOG . ') OR (' . '(rc_deleted & ' . ( LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED ) . ') != ' . ( LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED ) . ')'