mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-11 16:58:14 +00:00
Restore the original behaviour of Reference Previews
Commita75ddc41
and 33f9e9d3 effectively changed the default user option value of popups-reference-previews for users created before 2017/08/16 without any justification. Please see the task description for full analysis. This partially reverts commita75ddc41
. Bug: T366419 Change-Id: I68d6114384af6d259dbc4541522d52ae9a289e49
This commit is contained in:
parent
96e9c555b1
commit
ff30b0bc2b
|
@ -22,6 +22,7 @@
|
|||
"BeforePageDisplay": "PopupsHooks",
|
||||
"ResourceLoaderGetConfigVars": "PopupsHooks",
|
||||
"GetPreferences": "PopupsHooks",
|
||||
"UserGetDefaultOptions": "PopupsHooks",
|
||||
"MakeGlobalVariablesScript": "PopupsHooks"
|
||||
},
|
||||
"HookHandlers": {
|
||||
|
@ -220,21 +221,6 @@
|
|||
"named-user"
|
||||
]
|
||||
]
|
||||
],
|
||||
"popups-reference-previews": [
|
||||
[
|
||||
"1",
|
||||
[
|
||||
"registered-after",
|
||||
"20170816000000"
|
||||
]
|
||||
],
|
||||
[
|
||||
"0",
|
||||
[
|
||||
"named-user"
|
||||
]
|
||||
]
|
||||
]
|
||||
},
|
||||
"manifest_version": 2
|
||||
|
|
|
@ -27,6 +27,7 @@ use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
|||
use MediaWiki\Output\OutputPage;
|
||||
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
||||
use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
|
||||
use MediaWiki\User\Options\UserOptionsManager;
|
||||
use MediaWiki\User\User;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -41,6 +42,7 @@ class PopupsHooks implements
|
|||
GetPreferencesHook,
|
||||
BeforePageDisplayHook,
|
||||
ResourceLoaderGetConfigVarsHook,
|
||||
UserGetDefaultOptionsHook,
|
||||
MakeGlobalVariablesScriptHook
|
||||
{
|
||||
|
||||
|
@ -241,4 +243,18 @@ class PopupsHooks implements
|
|||
public function onMakeGlobalVariablesScript( &$vars, $out ): void {
|
||||
$vars['wgPopupsFlags'] = $this->popupsContext->getConfigBitmaskFromUser( $out->getUser() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a user wants to reset their preferences.
|
||||
*
|
||||
* @param array &$defaultOptions
|
||||
*/
|
||||
public function onUserGetDefaultOptions( &$defaultOptions ) {
|
||||
$default = $this->config->get( 'PopupsOptInDefaultState' );
|
||||
$defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
|
||||
|
||||
if ( $this->config->get( 'PopupsReferencePreviews' ) ) {
|
||||
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,6 +315,32 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase {
|
|||
'The wgPopupsFlags global is present and 0.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onUserGetDefaultOptions
|
||||
* @dataProvider provideReferencePreviewsFlag
|
||||
*/
|
||||
public function testOnUserGetDefaultOptions( bool $enabled ) {
|
||||
$userOptions = [
|
||||
'test' => 'not_empty'
|
||||
];
|
||||
|
||||
( new PopupsHooks(
|
||||
new HashConfig( [
|
||||
'PopupsOptInDefaultState' => '1',
|
||||
'PopupsReferencePreviews' => $enabled,
|
||||
] ),
|
||||
$this->getServiceContainer()->getService( 'Popups.Context' ),
|
||||
$this->getServiceContainer()->getService( 'Popups.Logger' ),
|
||||
$this->getServiceContainer()->getUserOptionsManager()
|
||||
) )
|
||||
->onUserGetDefaultOptions( $userOptions );
|
||||
$this->assertCount( $enabled ? 3 : 2, $userOptions );
|
||||
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
|
||||
if ( $enabled ) {
|
||||
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
|
||||
}
|
||||
}
|
||||
|
||||
public static function provideReferencePreviewsFlag() {
|
||||
return [
|
||||
[ false ],
|
||||
|
|
Loading…
Reference in a new issue