[cleanup] Remove unused configuration $wgPopupsReferencePreviews

This configuration is always enabled, so remaining conditions are dead
code.  Removing the flag in this code base simplifies moving the
remaining Reference Previews settings in a later patch.

Bug: T363162
Change-Id: I2b952f4203b6ffa040daad2aa288eb53d2ffd3b2
This commit is contained in:
Adam Wight 2024-09-04 12:33:07 +02:00 committed by Jdlrobson
parent 5868e55e1e
commit 7a79602208
5 changed files with 17 additions and 92 deletions

View file

@ -78,10 +78,6 @@
"description": "Specify a REST endpoint where summaries should be sourced from. Endpoint must meet the spec at https://www.mediawiki.org/wiki/Specs/Summary/1.2.0", "description": "Specify a REST endpoint where summaries should be sourced from. Endpoint must meet the spec at https://www.mediawiki.org/wiki/Specs/Summary/1.2.0",
"value": "/api/rest_v1/page/summary/" "value": "/api/rest_v1/page/summary/"
}, },
"PopupsReferencePreviews": {
"description": "Feature flag to enable or disable the separate popup type for references created via the Cite extension's <ref> tag.",
"value": true
},
"PopupsStatsvSamplingRate": { "PopupsStatsvSamplingRate": {
"description": "Sampling rate for logging performance data to statsv.", "description": "Sampling rate for logging performance data to statsv.",
"value": 0 "value": 0

View file

@ -150,10 +150,6 @@ class PopupsContext {
* @return bool whether or not to show reference previews * @return bool whether or not to show reference previews
*/ */
public function isReferencePreviewsEnabled( User $user ) { public function isReferencePreviewsEnabled( User $user ) {
if ( !$this->config->get( 'PopupsReferencePreviews' ) ) {
return false;
}
return !$user->isNamed() || $this->userOptionsLookup->getBoolOption( return !$user->isNamed() || $this->userOptionsLookup->getBoolOption(
$user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME $user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME
); );

View file

@ -101,14 +101,10 @@ class PopupsHooks implements
} }
$skinPosition = array_search( 'skin', array_keys( $prefs ) ); $skinPosition = array_search( 'skin', array_keys( $prefs ) );
$readingOptions = $this->getPagePreviewPrefToggle( $user ); $readingOptions = array_merge(
$this->getPagePreviewPrefToggle( $user ),
if ( $this->config->get( 'PopupsReferencePreviews' ) ) { $this->getReferencePreviewPrefToggle( $user )
$readingOptions = array_merge( );
$readingOptions,
$this->getReferencePreviewPrefToggle( $user )
);
}
if ( $skinPosition !== false ) { if ( $skinPosition !== false ) {
$injectIntoIndex = $skinPosition + 1; $injectIntoIndex = $skinPosition + 1;
@ -251,9 +247,6 @@ class PopupsHooks implements
public function onUserGetDefaultOptions( &$defaultOptions ) { public function onUserGetDefaultOptions( &$defaultOptions ) {
$default = $this->config->get( 'PopupsOptInDefaultState' ); $default = $this->config->get( 'PopupsOptInDefaultState' );
$defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default; $defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = '1';
if ( $this->config->get( 'PopupsReferencePreviews' ) ) {
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = '1';
}
} }
} }

View file

@ -22,7 +22,6 @@
use MediaWiki\Config\GlobalVarConfig; use MediaWiki\Config\GlobalVarConfig;
use MediaWiki\MainConfigNames; use MediaWiki\MainConfigNames;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
use MediaWiki\User\Options\UserOptionsLookup;
use MediaWiki\User\User; use MediaWiki\User\User;
use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls; use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls;
use Popups\PopupsContext; use Popups\PopupsContext;
@ -109,45 +108,6 @@ class PopupsContextTest extends MediaWikiIntegrationTestCase {
); );
} }
/**
* Tests #shouldSendModuleToUser when the user is logged in and the reference previews feature
* is disabled.
*
* @covers ::shouldSendModuleToUser
* @dataProvider provideTestDataForShouldSendModuleToUser
* @param bool $optIn
* @param bool $expected
*/
public function testShouldSendModuleToUser( $optIn, $expected ) {
$this->overrideConfigValue( 'PopupsReferencePreviews', false );
$user = $this->createMock( User::class );
$user->method( 'isNamed' )->willReturn( true );
$userOptLookup = $this->createMock( UserOptionsLookup::class );
$userOptLookup->method( 'getBoolOption' )
->with( $user, PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME )
->willReturn( $optIn );
$this->setService( 'UserOptionsLookup', $userOptLookup );
$context = $this->getContext();
$this->assertSame( $expected,
$context->shouldSendModuleToUser( $user ),
( $expected ? 'A' : 'No' ) . ' module is sent to the user.' );
}
public static function provideTestDataForShouldSendModuleToUser() {
return [
[
'optin' => PopupsContext::PREVIEWS_ENABLED,
'expected' => true
],
[
'optin' => PopupsContext::PREVIEWS_DISABLED,
'expected' => false
]
];
}
/** /**
* @covers ::areDependenciesMet * @covers ::areDependenciesMet
* @covers ::__construct * @covers ::__construct

View file

@ -61,16 +61,15 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers ::onGetPreferences * @covers ::onGetPreferences
* @dataProvider provideReferencePreviewsFlag
*/ */
public function testOnGetPreferencesNavPopupGadgetIsOn( bool $enabled ) { public function testOnGetPreferencesNavPopupGadgetIsOn() {
$userMock = $this->createMock( User::class ); $userMock = $this->createMock( User::class );
$contextMock = $this->createMock( PopupsContext::class ); $contextMock = $this->createMock( PopupsContext::class );
$contextMock->expects( $this->once() ) $contextMock->expects( $this->once() )
->method( 'showPreviewsOptInOnPreferencesPage' ) ->method( 'showPreviewsOptInOnPreferencesPage' )
->willReturn( true ); ->willReturn( true );
$contextMock->expects( $this->exactly( $enabled ? 2 : 1 ) ) $contextMock->expects( $this->exactly( 2 ) )
->method( 'conflictsWithNavPopupsGadget' ) ->method( 'conflictsWithNavPopupsGadget' )
->with( $userMock ) ->with( $userMock )
->willReturn( true ); ->willReturn( true );
@ -78,9 +77,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
$prefs = []; $prefs = [];
( new PopupsHooks( ( new PopupsHooks(
new HashConfig( [ new HashConfig(),
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock, $contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ), $this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager() $this->getServiceContainer()->getUserOptionsManager()
@ -101,14 +98,13 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers ::onGetPreferences * @covers ::onGetPreferences
* @dataProvider provideReferencePreviewsFlag
*/ */
public function testOnGetPreferencesPreviewsEnabled( bool $enabled ) { public function testOnGetPreferencesPreviewsEnabled() {
$contextMock = $this->createMock( PopupsContext::class ); $contextMock = $this->createMock( PopupsContext::class );
$contextMock->expects( $this->once() ) $contextMock->expects( $this->once() )
->method( 'showPreviewsOptInOnPreferencesPage' ) ->method( 'showPreviewsOptInOnPreferencesPage' )
->willReturn( true ); ->willReturn( true );
$contextMock->expects( $this->exactly( $enabled ? 2 : 1 ) ) $contextMock->expects( $this->exactly( 2 ) )
->method( 'conflictsWithNavPopupsGadget' ) ->method( 'conflictsWithNavPopupsGadget' )
->willReturn( false ); ->willReturn( false );
@ -119,9 +115,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
]; ];
( new PopupsHooks( ( new PopupsHooks(
new HashConfig( [ new HashConfig(),
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock, $contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ), $this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager() $this->getServiceContainer()->getUserOptionsManager()
@ -142,14 +136,13 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers ::onGetPreferences * @covers ::onGetPreferences
* @dataProvider provideReferencePreviewsFlag
*/ */
public function testOnGetPreferencesPreviewsEnabledWhenSkinIsNotAvailable( bool $enabled ) { public function testOnGetPreferencesPreviewsEnabledWhenSkinIsNotAvailable() {
$contextMock = $this->createMock( PopupsContext::class ); $contextMock = $this->createMock( PopupsContext::class );
$contextMock->expects( $this->once() ) $contextMock->expects( $this->once() )
->method( 'showPreviewsOptInOnPreferencesPage' ) ->method( 'showPreviewsOptInOnPreferencesPage' )
->willReturn( true ); ->willReturn( true );
$contextMock->expects( $this->exactly( $enabled ? 2 : 1 ) ) $contextMock->expects( $this->exactly( 2 ) )
->method( 'conflictsWithNavPopupsGadget' ) ->method( 'conflictsWithNavPopupsGadget' )
->willReturn( false ); ->willReturn( false );
@ -159,9 +152,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
]; ];
( new PopupsHooks( ( new PopupsHooks(
new HashConfig( [ new HashConfig(),
'PopupsReferencePreviews' => $enabled,
] ),
$contextMock, $contextMock,
$this->getServiceContainer()->getService( 'Popups.Logger' ), $this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager() $this->getServiceContainer()->getUserOptionsManager()
@ -317,9 +308,8 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers ::onUserGetDefaultOptions * @covers ::onUserGetDefaultOptions
* @dataProvider provideReferencePreviewsFlag
*/ */
public function testOnUserGetDefaultOptions( bool $enabled ) { public function testOnUserGetDefaultOptions() {
$userOptions = [ $userOptions = [
'test' => 'not_empty' 'test' => 'not_empty'
]; ];
@ -327,25 +317,15 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
( new PopupsHooks( ( new PopupsHooks(
new HashConfig( [ new HashConfig( [
'PopupsOptInDefaultState' => '1', 'PopupsOptInDefaultState' => '1',
'PopupsReferencePreviews' => $enabled,
] ), ] ),
$this->getServiceContainer()->getService( 'Popups.Context' ), $this->getServiceContainer()->getService( 'Popups.Context' ),
$this->getServiceContainer()->getService( 'Popups.Logger' ), $this->getServiceContainer()->getService( 'Popups.Logger' ),
$this->getServiceContainer()->getUserOptionsManager() $this->getServiceContainer()->getUserOptionsManager()
) ) ) )
->onUserGetDefaultOptions( $userOptions ); ->onUserGetDefaultOptions( $userOptions );
$this->assertCount( $enabled ? 3 : 2, $userOptions ); $this->assertCount( 3, $userOptions );
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] ); $this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
if ( $enabled ) { $this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
}
}
public static function provideReferencePreviewsFlag() {
return [
[ false ],
[ true ],
];
} }
} }