Avoid using User::getOption
Remove using of User:getOption since this method will be hard-deprecated. Now it is soft-deprecated. Bug: T296083 Change-Id: I3194a9c1c5c70592f88bc4dbedc78846d1141768
This commit is contained in:
parent
8c19f565d1
commit
262a520a2c
|
@ -55,7 +55,8 @@ return [
|
||||||
new SkinVersionLookup(
|
new SkinVersionLookup(
|
||||||
$context->getRequest(),
|
$context->getRequest(),
|
||||||
$context->getUser(),
|
$context->getUser(),
|
||||||
$services->getService( Constants::SERVICE_CONFIG )
|
$services->getService( Constants::SERVICE_CONFIG ),
|
||||||
|
$services->getUserOptionsLookup()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -585,7 +585,9 @@ class SkinVector extends SkinMustache {
|
||||||
private function isSidebarVisible() {
|
private function isSidebarVisible() {
|
||||||
$skin = $this->getSkin();
|
$skin = $this->getSkin();
|
||||||
if ( $skin->getUser()->isRegistered() ) {
|
if ( $skin->getUser()->isRegistered() ) {
|
||||||
$userPrefSidebarState = $skin->getUser()->getOption(
|
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
|
||||||
|
$userPrefSidebarState = $userOptionsLookup->getOption(
|
||||||
|
$skin->getUser(),
|
||||||
Constants::PREF_KEY_SIDEBAR_VISIBLE
|
Constants::PREF_KEY_SIDEBAR_VISIBLE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
namespace Vector;
|
namespace Vector;
|
||||||
|
|
||||||
use Config;
|
use Config;
|
||||||
|
use MediaWiki\User\UserOptionsLookup;
|
||||||
use User;
|
use User;
|
||||||
use WebRequest;
|
use WebRequest;
|
||||||
|
|
||||||
|
@ -61,6 +62,10 @@ final class SkinVersionLookup {
|
||||||
* @var Config
|
* @var Config
|
||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
/**
|
||||||
|
* @var UserOptionsLookup
|
||||||
|
*/
|
||||||
|
private $userOptionsLookup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor accepts all dependencies needed to obtain the skin version. The dependencies
|
* This constructor accepts all dependencies needed to obtain the skin version. The dependencies
|
||||||
|
@ -69,11 +74,18 @@ final class SkinVersionLookup {
|
||||||
* @param WebRequest $request
|
* @param WebRequest $request
|
||||||
* @param User $user
|
* @param User $user
|
||||||
* @param Config $config
|
* @param Config $config
|
||||||
|
* @param UserOptionsLookup $userOptionsLookup
|
||||||
*/
|
*/
|
||||||
public function __construct( WebRequest $request, User $user, Config $config ) {
|
public function __construct(
|
||||||
|
WebRequest $request,
|
||||||
|
User $user,
|
||||||
|
Config $config,
|
||||||
|
UserOptionsLookup $userOptionsLookup
|
||||||
|
) {
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->userOptionsLookup = $userOptionsLookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,11 +114,12 @@ final class SkinVersionLookup {
|
||||||
// sessions are unavailable at that time so it's not possible to determine whether the
|
// sessions are unavailable at that time so it's not possible to determine whether the
|
||||||
// preference is for a logged in user or an anonymous user. Since new users are known to have
|
// preference is for a logged in user or an anonymous user. Since new users are known to have
|
||||||
// had their user preferences initialized in `Hooks::onLocalUserCreated()`, that means all
|
// had their user preferences initialized in `Hooks::onLocalUserCreated()`, that means all
|
||||||
// subsequent requests to `User->getOption()` that do not have a preference set are either
|
// subsequent requests to `UserOptionsLookup->getOption()` that do not have a preference set
|
||||||
// existing accounts or anonymous users. Login state makes the distinction.
|
//are either existing accounts or anonymous users. Login state makes the distinction.
|
||||||
return (string)$this->request->getVal(
|
return (string)$this->request->getVal(
|
||||||
Constants::QUERY_PARAM_SKIN_VERSION,
|
Constants::QUERY_PARAM_SKIN_VERSION,
|
||||||
$this->user->getOption(
|
$this->userOptionsLookup->getOption(
|
||||||
|
$this->user,
|
||||||
Constants::PREF_KEY_SKIN_VERSION,
|
Constants::PREF_KEY_SKIN_VERSION,
|
||||||
$this->config->get(
|
$this->config->get(
|
||||||
$this->user->isRegistered()
|
$this->user->isRegistered()
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* @since 1.35
|
* @since 1.35
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use MediaWiki\User\UserOptionsLookup;
|
||||||
use Vector\SkinVersionLookup;
|
use Vector\SkinVersionLookup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,17 +42,15 @@ class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
||||||
$user
|
$user
|
||||||
->method( 'isRegistered' )
|
->method( 'isRegistered' )
|
||||||
->willReturn( false );
|
->willReturn( false );
|
||||||
$user
|
|
||||||
->method( 'getOption' )
|
|
||||||
->with( $this->anything(), '2' )
|
|
||||||
->willReturn( 'beta' );
|
|
||||||
|
|
||||||
$config = new HashConfig( [
|
$config = new HashConfig( [
|
||||||
'VectorDefaultSkinVersion' => '2',
|
'VectorDefaultSkinVersion' => '2',
|
||||||
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config );
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', 'beta' );
|
||||||
|
|
||||||
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'alpha',
|
'alpha',
|
||||||
|
@ -80,17 +79,15 @@ class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
||||||
$user
|
$user
|
||||||
->method( 'isRegistered' )
|
->method( 'isRegistered' )
|
||||||
->willReturn( false );
|
->willReturn( false );
|
||||||
$user
|
|
||||||
->method( 'getOption' )
|
|
||||||
->with( $this->anything(), '2' )
|
|
||||||
->willReturn( 'beta' );
|
|
||||||
|
|
||||||
$config = new HashConfig( [
|
$config = new HashConfig( [
|
||||||
'VectorDefaultSkinVersion' => '2',
|
'VectorDefaultSkinVersion' => '2',
|
||||||
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config );
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', 'beta' );
|
||||||
|
|
||||||
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'beta',
|
'beta',
|
||||||
|
@ -119,17 +116,15 @@ class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
||||||
$user
|
$user
|
||||||
->method( 'isRegistered' )
|
->method( 'isRegistered' )
|
||||||
->willReturn( true );
|
->willReturn( true );
|
||||||
$user
|
|
||||||
->method( 'getOption' )
|
|
||||||
->with( $this->anything(), '1' )
|
|
||||||
->willReturn( '1' );
|
|
||||||
|
|
||||||
$config = new HashConfig( [
|
$config = new HashConfig( [
|
||||||
'VectorDefaultSkinVersion' => '2',
|
'VectorDefaultSkinVersion' => '2',
|
||||||
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config );
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '1', '1' );
|
||||||
|
|
||||||
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'1',
|
'1',
|
||||||
|
@ -158,17 +153,15 @@ class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
||||||
$user
|
$user
|
||||||
->method( 'isRegistered' )
|
->method( 'isRegistered' )
|
||||||
->willReturn( false );
|
->willReturn( false );
|
||||||
$user
|
|
||||||
->method( 'getOption' )
|
|
||||||
->with( $this->anything(), '2' )
|
|
||||||
->willReturn( '2' );
|
|
||||||
|
|
||||||
$config = new HashConfig( [
|
$config = new HashConfig( [
|
||||||
'VectorDefaultSkinVersion' => '2',
|
'VectorDefaultSkinVersion' => '2',
|
||||||
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
'VectorDefaultSkinVersionForExistingAccounts' => '1'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config );
|
$userOptionsLookup = $this->getUserOptionsLookupMock( $user, '2', '2' );
|
||||||
|
|
||||||
|
$skinVersionLookup = new SkinVersionLookup( $request, $user, $config, $userOptionsLookup );
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'2',
|
'2',
|
||||||
|
@ -181,4 +174,18 @@ class SkinVersionLookupTest extends \MediaWikiIntegrationTestCase {
|
||||||
'Version is non-Legacy.'
|
'Version is non-Legacy.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param User $user
|
||||||
|
* @param mixed|null $defaultOverride
|
||||||
|
* @param mixed|null $returnVal
|
||||||
|
* @return UserOptionsLookup
|
||||||
|
*/
|
||||||
|
private function getUserOptionsLookupMock( $user, $defaultOverride, $returnVal ) {
|
||||||
|
$mock = $this->createMock( UserOptionsLookup::class );
|
||||||
|
$mock->method( 'getOption' )
|
||||||
|
->with( $user, $this->anything(), $defaultOverride )
|
||||||
|
->willReturn( $returnVal );
|
||||||
|
return $mock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
namespace Vector\FeatureManagement\Tests;
|
namespace Vector\FeatureManagement\Tests;
|
||||||
|
|
||||||
use HashConfig;
|
use HashConfig;
|
||||||
|
use MediaWiki\User\UserOptionsLookup;
|
||||||
use User;
|
use User;
|
||||||
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
||||||
use Vector\SkinVersionLookup;
|
use Vector\SkinVersionLookup;
|
||||||
|
@ -48,8 +49,10 @@ class LatestSkinVersionRequirementTest extends \MediaWikiUnitTestCase {
|
||||||
|
|
||||||
$user = $this->createMock( User::class );
|
$user = $this->createMock( User::class );
|
||||||
$user->method( 'isRegistered' )->willReturn( true );
|
$user->method( 'isRegistered' )->willReturn( true );
|
||||||
$user->method( 'getOption' )
|
|
||||||
->will( $this->returnArgument( 1 ) );
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
||||||
|
$userOptionsLookup->method( 'getOption' )
|
||||||
|
->will( $this->returnArgument( 2 ) );
|
||||||
|
|
||||||
$request = $this->createMock( WebRequest::class );
|
$request = $this->createMock( WebRequest::class );
|
||||||
$request->method( 'getVal' )
|
$request->method( 'getVal' )
|
||||||
|
@ -59,7 +62,8 @@ class LatestSkinVersionRequirementTest extends \MediaWikiUnitTestCase {
|
||||||
new SkinVersionLookup(
|
new SkinVersionLookup(
|
||||||
$request,
|
$request,
|
||||||
$user,
|
$user,
|
||||||
$config
|
$config,
|
||||||
|
$userOptionsLookup
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue