From 04dfdc36539f27b83216b22d42edfb44841808ae Mon Sep 17 00:00:00 2001 From: Alexander Vorwerk Date: Fri, 10 Sep 2021 16:06:51 +0200 Subject: [PATCH] Hard deprecate User::setOption() deprecated since 1.35 Bug: T277818 Change-Id: Ic251d624e5d6fa857aa92f9c5dd3df44714ac610 --- RELEASE-NOTES-1.38 | 1 + .../jobqueue/jobs/UserOptionsUpdateJob.php | 6 +++++- includes/user/User.php | 8 ++++++-- tests/parser/ParserTestRunner.php | 5 +++-- tests/phpunit/includes/LinkerTest.php | 6 +++++- .../Storage/DerivedPageDataUpdaterTest.php | 6 ++++-- .../ApiQueryWatchlistIntegrationTest.php | 8 ++++++-- .../ApiQueryWatchlistRawIntegrationTest.php | 11 +++++++--- .../includes/cache/GenderCacheTest.php | 8 +++++--- .../parser/CoreParserFunctionsTest.php | 4 +++- tests/phpunit/includes/skins/SkinTest.php | 6 +++++- ...AbstractChangesListSpecialPageTestCase.php | 6 +++++- .../includes/specials/SpecialSearchTest.php | 3 ++- .../specials/SpecialWatchlistTest.php | 3 ++- tests/phpunit/includes/user/UserTest.php | 20 ++++++++++++++++--- .../languages/LanguageConverterTest.php | 9 +++++++-- .../includes/htmlform/HTMLCheckMatrixTest.php | 2 +- 17 files changed, 85 insertions(+), 27 deletions(-) diff --git a/RELEASE-NOTES-1.38 b/RELEASE-NOTES-1.38 index 647a8b79730..6627aeea39c 100644 --- a/RELEASE-NOTES-1.38 +++ b/RELEASE-NOTES-1.38 @@ -127,6 +127,7 @@ because of Phabricator reports. deprecated in favor of the ReadOnlyMode service. * PageProps::getInstance() has been deprecated. Use MediaWikiServices::getPageProps() instead. +* User::setOption(), deprecated since 1.35, now emits deprecation warnings. * Skin::getSkinStylePath has been hard deprecated. Direct string path should be used instead. * SkinTemplate::getPersonalToolsList(), deprecated since 1.35, now emits diff --git a/includes/jobqueue/jobs/UserOptionsUpdateJob.php b/includes/jobqueue/jobs/UserOptionsUpdateJob.php index 0e8b19f2da5..5315b82ba40 100644 --- a/includes/jobqueue/jobs/UserOptionsUpdateJob.php +++ b/includes/jobqueue/jobs/UserOptionsUpdateJob.php @@ -21,6 +21,8 @@ * @ingroup JobQueue */ +use MediaWiki\MediaWikiServices; + /** * Job that updates a user's preferences * @@ -47,8 +49,10 @@ class UserOptionsUpdateJob extends Job implements GenericParameterJob { return true; } + $userOptionsManager = MediaWikiServices::getInstance() + ->getUserOptionsManager(); foreach ( $this->params['options'] as $name => $value ) { - $user->setOption( $name, $value ); + $userOptionsManager->setOption( $user, $name, $value ); } $user->saveSettings(); diff --git a/includes/user/User.php b/includes/user/User.php index 85c42785a03..4ea34e9a587 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -2621,9 +2621,11 @@ class User implements Authority, UserIdentity, UserEmailContact { * * @param string $oname The option to set * @param mixed $val New value to set - * @deprecated since 1.35 Use UserOptionsManager::setOption instead + * @deprecated since 1.35, hard deprecated since 1.38 + * Use UserOptionsManager::setOption instead */ public function setOption( $oname, $val ) { + wfDeprecated( __METHOD__, '1.35' ); MediaWikiServices::getInstance() ->getUserOptionsManager() ->setOption( $this, $oname, $val ); @@ -2674,7 +2676,9 @@ class User implements Authority, UserIdentity, UserEmailContact { } $token = MWCryptRand::generateHex( 40 ); - $this->setOption( $oname, $token ); + MediaWikiServices::getInstance() + ->getUserOptionsManager() + ->setOption( $this, $oname, $token ); return $token; } diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 207feb3b579..b19e297a7a7 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -1285,13 +1285,14 @@ class ParserTestRunner { $setup[] = $reset; $teardown[] = $reset; + $userOptionsManager = MediaWikiServices::getInstance()->getUserOptionsManager(); // Make a user object with the same language $user = new User; - $user->setOption( 'language', $langCode ); + $userOptionsManager->setOption( $user, 'language', $langCode ); $setup['wgLang'] = $lang; // We (re)set $wgThumbLimits to a single-element array above. - $user->setOption( 'thumbsize', 0 ); + $userOptionsManager->setOption( $user, 'thumbsize', 0 ); $setup['wgUser'] = $user; diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php index f1e49699f00..6a179107a4f 100644 --- a/tests/phpunit/includes/LinkerTest.php +++ b/tests/phpunit/includes/LinkerTest.php @@ -525,7 +525,11 @@ class LinkerTest extends MediaWikiLangTestCase { $context = RequestContext::getMain(); $user = $context->getUser(); - $user->setOption( 'showrollbackconfirmation', $rollbackEnabled ); + $this->getServiceContainer()->getUserOptionsManager()->setOption( + $user, + 'showrollbackconfirmation', + $rollbackEnabled + ); $this->assertSame( 0, Title::newFromText( $title )->getArticleID() ); $pageData = $this->insertPage( $title ); diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php index 383b0f3048e..cd39948d453 100644 --- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php +++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php @@ -1131,13 +1131,15 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase { // Case where user does not have canonical parser options $user = $this->getMutableTestUser()->getUser(); - $user->setOption( + $services = $this->getServiceContainer(); + $services->getUserOptionsManager()->setOption( + $user, 'thumbsize', $user->getOption( 'thumbsize' ) + 1 ); $content = [ 'main' => new WikitextContent( 'rev ID ver #2: {{REVISIONID}}' ) ]; $rev = $this->createRevision( $page, 'first', $content, $user ); - $pcache = MediaWikiServices::getInstance()->getParserCache(); + $pcache = $services->getParserCache(); $pcache->deleteOptionsKey( $page ); $this->db->startAtomic( __METHOD__ ); // let deferred updates queue up diff --git a/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php index 2084893afe2..5a6bbf5a0e8 100644 --- a/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryWatchlistIntegrationTest.php @@ -1462,8 +1462,10 @@ class ApiQueryWatchlistIntegrationTest extends ApiTestCase { 'Create the page' ); + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $otherUser = $this->getNonLoggedInTestUser(); - $otherUser->setOption( 'watchlisttoken', '1234567890' ); + $userOptionsManager->setOption( $otherUser, 'watchlisttoken', '1234567890' ); $otherUser->saveSettings(); $this->watchPages( $otherUser, [ $target ] ); @@ -1490,8 +1492,10 @@ class ApiQueryWatchlistIntegrationTest extends ApiTestCase { } public function testOwnerAndTokenParams_wrongToken() { + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $otherUser = $this->getNonLoggedInTestUser(); - $otherUser->setOption( 'watchlisttoken', '1234567890' ); + $userOptionsManager->setOption( $otherUser, 'watchlisttoken', '1234567890' ); $otherUser->saveSettings(); $this->expectException( ApiUsageException::class ); diff --git a/tests/phpunit/includes/api/query/ApiQueryWatchlistRawIntegrationTest.php b/tests/phpunit/includes/api/query/ApiQueryWatchlistRawIntegrationTest.php index 6ca01898ba1..501456c55d8 100644 --- a/tests/phpunit/includes/api/query/ApiQueryWatchlistRawIntegrationTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryWatchlistRawIntegrationTest.php @@ -472,8 +472,11 @@ class ApiQueryWatchlistRawIntegrationTest extends ApiTestCase { } public function testOwnerAndTokenParams() { + $services = $this->getServiceContainer(); + $userOptionsManager = $services->getUserOptionsManager(); + $otherUser = $this->getNotLoggedInTestUser(); - $otherUser->setOption( 'watchlisttoken', '1234567890' ); + $userOptionsManager->setOption( $otherUser, 'watchlisttoken', '1234567890' ); $otherUser->saveSettings(); $store = $this->getWatchedItemStore(); @@ -482,7 +485,7 @@ class ApiQueryWatchlistRawIntegrationTest extends ApiTestCase { new TitleValue( 1, 'ApiQueryWatchlistRawIntegrationTestPage1' ), ] ); - MediaWikiServices::getInstance()->getMainWANObjectCache()->clearProcessCache(); + $services->getMainWANObjectCache()->clearProcessCache(); $result = $this->doListWatchlistRawRequest( [ 'wrowner' => $otherUser->getName(), 'wrtoken' => '1234567890', @@ -504,8 +507,10 @@ class ApiQueryWatchlistRawIntegrationTest extends ApiTestCase { } public function testOwnerAndTokenParams_wrongToken() { + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $otherUser = $this->getNotLoggedInTestUser(); - $otherUser->setOption( 'watchlisttoken', '1234567890' ); + $userOptionsManager->setOption( $otherUser, 'watchlisttoken', '1234567890' ); $otherUser->saveSettings(); $this->expectException( ApiUsageException::class ); diff --git a/tests/phpunit/includes/cache/GenderCacheTest.php b/tests/phpunit/includes/cache/GenderCacheTest.php index d75d97763e9..b5bb5cabc7b 100644 --- a/tests/phpunit/includes/cache/GenderCacheTest.php +++ b/tests/phpunit/includes/cache/GenderCacheTest.php @@ -15,16 +15,18 @@ class GenderCacheTest extends MediaWikiLangTestCase { // ensure the correct default gender $this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', [ 'gender' => 'unknown' ] ); + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $male = $this->getMutableTestUser()->getUser(); - $male->setOption( 'gender', 'male' ); + $userOptionsManager->setOption( $male, 'gender', 'male' ); $male->saveSettings(); $female = $this->getMutableTestUser()->getUser(); - $female->setOption( 'gender', 'female' ); + $userOptionsManager->setOption( $female, 'gender', 'female' ); $female->saveSettings(); $default = $this->getMutableTestUser()->getUser(); - $default->setOption( 'gender', null ); + $userOptionsManager->setOption( $default, 'gender', null ); $default->saveSettings(); self::$nameMap = [ diff --git a/tests/phpunit/includes/parser/CoreParserFunctionsTest.php b/tests/phpunit/includes/parser/CoreParserFunctionsTest.php index e42f4af34bc..60305b2c5ea 100644 --- a/tests/phpunit/includes/parser/CoreParserFunctionsTest.php +++ b/tests/phpunit/includes/parser/CoreParserFunctionsTest.php @@ -9,8 +9,10 @@ use MediaWiki\MediaWikiServices; class CoreParserFunctionsTest extends MediaWikiLangTestCase { public function testGender() { + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $user = User::createNew( '*Female' ); - $user->setOption( 'gender', 'female' ); + $userOptionsManager->setOption( $user, 'gender', 'female' ); $user->saveSettings(); $msg = ( new RawMessage( '{{GENDER:*Female|m|f|o}}' ) )->parse(); diff --git a/tests/phpunit/includes/skins/SkinTest.php b/tests/phpunit/includes/skins/SkinTest.php index 2d547d58509..c4c2c2177f3 100644 --- a/tests/phpunit/includes/skins/SkinTest.php +++ b/tests/phpunit/includes/skins/SkinTest.php @@ -143,7 +143,11 @@ class SkinTest extends MediaWikiIntegrationTestCase { */ public function getUser() { $user = TestUserRegistry::getImmutableTestUser( [] )->getUser(); - $user->setOption( 'skin-responsive', $this->options['userPreference'] ); + \MediaWiki\MediaWikiServices::getInstance()->getUserOptionsManager()->setOption( + $user, + 'skin-responsive', + $this->options['userPreference'] + ); return $user; } }; diff --git a/tests/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php b/tests/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php index 01f8513e310..7b79df45b34 100644 --- a/tests/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php +++ b/tests/phpunit/includes/specialpage/AbstractChangesListSpecialPageTestCase.php @@ -118,7 +118,11 @@ abstract class AbstractChangesListSpecialPageTestCase extends MediaWikiIntegrati // Give users patrol permissions so we can test that. $user = $this->getTestSysop()->getUser(); - $user->setOption( 'rcenhancedfilters-disable', $rcfilters ? 0 : 1 ); + $this->getServiceContainer()->getUserOptionsManager()->setOption( + $user, + 'rcenhancedfilters-disable', + $rcfilters ? 0 : 1 + ); $ctx = new RequestContext(); $ctx->setUser( $user ); diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index d0f72ab7222..53adc5d6685 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -164,8 +164,9 @@ class SpecialSearchTest extends MediaWikiIntegrationTestCase { if ( $opt === null ) { return $u; } + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); foreach ( $opt as $name => $value ) { - $u->setOption( $name, $value ); + $userOptionsManager->setOption( $u, $name, $value ); } return $u; diff --git a/tests/phpunit/includes/specials/SpecialWatchlistTest.php b/tests/phpunit/includes/specials/SpecialWatchlistTest.php index a1ccc076619..379910545a6 100644 --- a/tests/phpunit/includes/specials/SpecialWatchlistTest.php +++ b/tests/phpunit/includes/specials/SpecialWatchlistTest.php @@ -114,8 +114,9 @@ class SpecialWatchlistTest extends SpecialPageTestBase { $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false ); $user = $this->getTestUser()->getUser(); + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); foreach ( $preferences as $key => $value ) { - $user->setOption( $key, $value ); + $userOptionsManager->setOption( $user, $key, $value ); } $context->setRequest( $fauxRequest ); diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index 4a76ee785e7..41806ced1c1 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -445,6 +445,7 @@ class UserTest extends MediaWikiIntegrationTestCase { public function testOptions() { $this->hideDeprecated( 'User::getBoolOption' ); $this->hideDeprecated( 'User::getIntOption' ); + $this->hideDeprecated( 'User::setOption' ); $this->setMwGlobals( [ 'wgMaxArticleSize' => 2, ] ); @@ -493,6 +494,7 @@ class UserTest extends MediaWikiIntegrationTestCase { */ public function testAnonOptions() { global $wgDefaultUserOptions; + $this->hideDeprecated( 'User::setOption' ); $this->user->setOption( 'userjs-someoption', 'test' ); $this->assertSame( $wgDefaultUserOptions['rclimit'], $this->user->getOption( 'rclimit' ) ); $this->assertSame( 'test', $this->user->getOption( 'userjs-someoption' ) ); @@ -2243,7 +2245,11 @@ class UserTest extends MediaWikiIntegrationTestCase { ] ); $user = User::newFromName( 'UserWhoMayRequireHTTPS' ); - $user->setOption( 'prefershttps', $preference ); + $this->getServiceContainer()->getUserOptionsManager()->setOption( + $user, + 'prefershttps', + $preference + ); $user->saveSettings(); $user = User::newFromName( $user->getName() ); @@ -2267,7 +2273,11 @@ class UserTest extends MediaWikiIntegrationTestCase { ] ); $user = User::newFromName( 'UserWhoMayRequireHTTP' ); - $user->setOption( 'prefershttps', true ); + $this->getServiceContainer()->getUserOptionsManager()->setOption( + $user, + 'prefershttps', + true + ); $user->saveSettings(); $user = User::newFromName( $user->getName() ); @@ -2287,7 +2297,11 @@ class UserTest extends MediaWikiIntegrationTestCase { ] ); $user = User::newFromName( 'UserWhoMayRequireHTTP' ); - $user->setOption( 'prefershttps', false ); + $this->getServiceContainer()->getUserOptionsManager()->setOption( + $user, + 'prefershttps', + false + ); $user->saveSettings(); $user = User::newFromName( $user->getName() ); diff --git a/tests/phpunit/languages/LanguageConverterTest.php b/tests/phpunit/languages/LanguageConverterTest.php index ff8bab9d565..196a7298ec8 100644 --- a/tests/phpunit/languages/LanguageConverterTest.php +++ b/tests/phpunit/languages/LanguageConverterTest.php @@ -106,11 +106,13 @@ class LanguageConverterTest extends MediaWikiLangTestCase { $optionName = 'variant-tg'; } + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $user = new User; $user->load(); // from 'defaults' $user->mId = 1; $user->mDataLoaded = true; - $user->setOption( $optionName, $optionVal ); + $userOptionsManager->setOption( $user, $optionName, $optionVal ); $this->setContextUser( $user ); @@ -136,11 +138,14 @@ class LanguageConverterTest extends MediaWikiLangTestCase { $this->setContentLang( 'tg-latn' ); $wgRequest->setVal( 'variant', 'tg' ); + + $userOptionsManager = $this->getServiceContainer()->getUserOptionsManager(); + $user = User::newFromId( "admin" ); $user->setId( 1 ); $user->mFrom = 'defaults'; // The user's data is ignored because the variant is set in the URL. - $user->setOption( 'variant', 'tg-latn' ); + $userOptionsManager->setOption( $user, 'variant', 'tg-latn' ); $this->setContextUser( $user ); diff --git a/tests/phpunit/unit/includes/htmlform/HTMLCheckMatrixTest.php b/tests/phpunit/unit/includes/htmlform/HTMLCheckMatrixTest.php index fa5ea982774..a7aee74ea81 100644 --- a/tests/phpunit/unit/includes/htmlform/HTMLCheckMatrixTest.php +++ b/tests/phpunit/unit/includes/htmlform/HTMLCheckMatrixTest.php @@ -67,7 +67,7 @@ class HTMLCheckMatrixTest extends MediaWikiUnitTestCase { * This form object actually has no visibility into what happens later on, but essentially * if the data submitted by the user passes validate the following is run: * foreach ( $field->filterDataForSubmit( $data ) as $k => $v ) { - * $user->setOption( $k, $v ); + * $userOptionsManager->setOption( $user, $k, $v ); * } */ public function testValuesForcedOnRemainOn() {