mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-27 17:00:37 +00:00
Merge "Restore the original behaviour of Reference Previews"
This commit is contained in:
commit
058c772d52
|
@ -22,6 +22,7 @@
|
|||
"BeforePageDisplay": "PopupsHooks",
|
||||
"ResourceLoaderGetConfigVars": "PopupsHooks",
|
||||
"GetPreferences": "PopupsHooks",
|
||||
"UserGetDefaultOptions": "PopupsHooks",
|
||||
"MakeGlobalVariablesScript": "PopupsHooks"
|
||||
},
|
||||
"HookHandlers": {
|
||||
|
@ -201,21 +202,6 @@
|
|||
"named-user"
|
||||
]
|
||||
]
|
||||
],
|
||||
"popups-reference-previews": [
|
||||
[
|
||||
"1",
|
||||
[
|
||||
"registered-after",
|
||||
"20170816000000"
|
||||
]
|
||||
],
|
||||
[
|
||||
"0",
|
||||
[
|
||||
"named-user"
|
||||
]
|
||||
]
|
||||
]
|
||||
},
|
||||
"manifest_version": 2
|
||||
|
|
|
@ -28,6 +28,7 @@ use MediaWiki\Output\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;
|
||||
|
@ -42,6 +43,7 @@ class PopupsHooks implements
|
|||
GetPreferencesHook,
|
||||
BeforePageDisplayHook,
|
||||
ResourceLoaderGetConfigVarsHook,
|
||||
UserGetDefaultOptionsHook,
|
||||
MakeGlobalVariablesScriptHook
|
||||
{
|
||||
|
||||
|
@ -242,4 +244,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