mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Fix initial preferences for newly created user accounts
It appears like we accidentially copy-pasted the behavior for
PagePreviews and made ReferencePreviews behave the same, not taking
into account that the later feature is in Beta mode.
Bug: T240947
Change-Id: I4d31805ee9b2045c49c7ab4179c5a4adbcba0394
(cherry picked from commit 5752c2538e
)
This commit is contained in:
parent
219c0c208b
commit
24f2f88452
|
@ -20,10 +20,11 @@
|
|||
*/
|
||||
namespace Popups;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use User;
|
||||
use OutputPage;
|
||||
use Skin;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Hooks definitions for Popups extension
|
||||
|
@ -81,7 +82,7 @@ class PopupsHooks {
|
|||
'section' => self::PREVIEWS_PREFERENCES_SECTION,
|
||||
'disabled' => $option['disabled'] ?? false,
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
if ( $skinPosition !== false ) {
|
||||
$injectIntoIndex = $skinPosition + 1;
|
||||
|
@ -131,7 +132,7 @@ class PopupsHooks {
|
|||
* @param string $skin
|
||||
*/
|
||||
public static function onResourceLoaderGetConfigVars( array &$vars, $skin ) {
|
||||
/** @var \Config $config */
|
||||
/** @var Config $config */
|
||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
|
||||
$vars['wgPopupsVirtualPageViews'] = $config->get( 'PopupsVirtualPageViews' );
|
||||
|
@ -171,31 +172,40 @@ class PopupsHooks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Register default preferences for popups
|
||||
* Called whenever a user wants to reset their preferences.
|
||||
*
|
||||
* @param array &$wgDefaultUserOptions Reference to default options array
|
||||
* @param array &$defaultOptions
|
||||
*/
|
||||
public static function onUserGetDefaultOptions( array &$wgDefaultUserOptions ) {
|
||||
$default = MediaWikiServices::getInstance()->getService( 'Popups.Config' )
|
||||
->get( 'PopupsOptInDefaultState' );
|
||||
public static function onUserGetDefaultOptions( array &$defaultOptions ) {
|
||||
/** @var Config $config */
|
||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$default = $config->get( 'PopupsOptInDefaultState' );
|
||||
$defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
|
||||
|
||||
$wgDefaultUserOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
|
||||
$wgDefaultUserOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = $default;
|
||||
if ( $config->get( 'PopupsReferencePreviews' ) &&
|
||||
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
|
||||
) {
|
||||
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the default PagePreviews visibility state for newly created accounts
|
||||
* Called one time when initializing a users preferences for a newly created account.
|
||||
*
|
||||
* @param User $user Newly created user object
|
||||
* @param bool $autocreated Is user autocreated
|
||||
* @param bool $isAutoCreated
|
||||
*/
|
||||
public static function onLocalUserCreated( User $user, $autocreated ) {
|
||||
// ignore the $autocreated flag, we always want to set PagePreviews visibility
|
||||
$default = MediaWikiServices::getInstance()->getService( 'Popups.Config' )
|
||||
->get( 'PopupsOptInStateForNewAccounts' );
|
||||
|
||||
public static function onLocalUserCreated( User $user, $isAutoCreated ) {
|
||||
/** @var Config $config */
|
||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$default = $config->get( 'PopupsOptInStateForNewAccounts' );
|
||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $default );
|
||||
$user->setOption( PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME, $default );
|
||||
|
||||
if ( $config->get( 'PopupsReferencePreviews' ) &&
|
||||
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
|
||||
) {
|
||||
$user->setOption( PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME, $default );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,7 +215,7 @@ class PopupsHooks {
|
|||
* @param array[] &$prefs Array of beta features
|
||||
*/
|
||||
public static function onGetBetaFeaturePreferences( User $user, array &$prefs ) {
|
||||
/** @var \Config $config */
|
||||
/** @var Config $config */
|
||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$extensionAssetsPath = $config->get( 'ExtensionAssetsPath' );
|
||||
|
||||
|
|
|
@ -284,7 +284,9 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
];
|
||||
|
||||
$this->setMwGlobals( [
|
||||
'wgPopupsOptInDefaultState' => '1'
|
||||
'wgPopupsOptInDefaultState' => '1',
|
||||
'wgPopupsReferencePreviews' => true,
|
||||
'wgPopupsReferencePreviewsBetaFeature' => false,
|
||||
] );
|
||||
|
||||
PopupsHooks::onUserGetDefaultOptions( $userOptions );
|
||||
|
@ -301,10 +303,15 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
$userMock = $this->createMock( User::class );
|
||||
$userMock->expects( $this->exactly( 2 ) )
|
||||
->method( 'setOption' )
|
||||
->with( $this->stringStartsWith( 'popups' ), $expectedState );
|
||||
->withConsecutive(
|
||||
[ 'popups', $expectedState ],
|
||||
[ 'popupsreferencepreviews', $expectedState ]
|
||||
);
|
||||
|
||||
$this->setMwGlobals( [
|
||||
'wgPopupsOptInStateForNewAccounts' => $expectedState
|
||||
'wgPopupsOptInStateForNewAccounts' => $expectedState,
|
||||
'wgPopupsReferencePreviews' => true,
|
||||
'wgPopupsReferencePreviewsBetaFeature' => false,
|
||||
] );
|
||||
PopupsHooks::onLocalUserCreated( $userMock, false );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue