mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 23:24:39 +00:00
Separate page and reference preview preferences
Bug: T277638 Change-Id: I8144625e0d3a2626511f35d4e92d082b6fa44bb4
This commit is contained in:
parent
6144e315ee
commit
e4e07e509a
|
@ -25,7 +25,6 @@
|
|||
"popups-prefs-optin": "Enable page previews (get quick previews of a topic while reading a page)",
|
||||
"popups-prefs-disable-nav-gadgets-info": "You have to [[$1|disable the Navigation popups gadget]] in your Gadgets preferences to enable page previews.",
|
||||
"popups-prefs-conflicting-gadgets-info": "Certain gadgets and other customizations may affect the performance of this feature. If you experience problems please review your gadgets and user scripts, including global ones.",
|
||||
"popups-prefs-optin-all": "Enable previews (get quick previews of a topic or a reference while reading a page)",
|
||||
"popups-prefs-navpopups-gadget-conflict-info": "You have the [[$1|Navigation popups]] gadget enabled, so you won't see previews provided by this feature. Depending on your wiki, the gadget may have a slightly different name. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
||||
"popups-prefs-reftooltips-gadget-conflict-info": "You have the [[$1|Reference Tooltips]] gadget enabled, so you won't see reference previews but will still see page previews. Depending on your wiki, the gadget may have a slightly different name. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
||||
"popups-prefs-reftooltips-and-navpopups-gadget-conflict-info": "You have the [[$1|Navigation popups]] and [[$1|Reference Tooltips]] gadgets enabled, so you won't see previews provided by this feature. Depending on your wiki, the gadgets may have slightly different names. If you continue to experience issues, please review your gadgets and user scripts, including global ones.",
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
"popups-prefs-optin": "Label for Page Previews option (description for Page Previews option)",
|
||||
"popups-prefs-disable-nav-gadgets-info": "Help message telling to disable the \"Navigation popups\" gadget in order to enable page previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
||||
"popups-prefs-conflicting-gadgets-info": "Help message informing about possible conflicts with other gadgets/customizations",
|
||||
"popups-prefs-optin-all": "Label for the merged Page and Reference Previews option (description for Page and Reference Previews option)",
|
||||
"popups-prefs-navpopups-gadget-conflict-info": "Help message telling to disable the \"Navigation popups\" gadget in order to allow page and reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
||||
"popups-prefs-reftooltips-gadget-conflict-info": "Help message telling to disable the \"Reference Tooltips\" gadget in order to allow reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
||||
"popups-prefs-reftooltips-and-navpopups-gadget-conflict-info": "Help message telling to disable the \"Navigation popups\" and \"Reference Tooltips\" gadgets in order to allow page and reference previews. The word \"Gadgets\" should be based on {{msg-mw|prefs-gadgets}}.\n\nParameters:\n* $1 – Link to the Gadgets tab in the user's preferences",
|
||||
|
|
|
@ -57,9 +57,9 @@ class PopupsContext {
|
|||
public const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
||||
|
||||
/**
|
||||
* Beta feature key to enable/disable Reference Previews
|
||||
* User preference key to enable/disable Reference Previews
|
||||
*/
|
||||
public const REFERENCE_PREVIEWS_BETA_FEATURE_KEY = 'popupsreferencepreviews';
|
||||
public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popupsreferencepreviews';
|
||||
|
||||
/**
|
||||
* Flags passed on to JS representing preferences
|
||||
|
@ -149,10 +149,10 @@ class PopupsContext {
|
|||
if ( $this->isReferencePreviewsInBeta() ) {
|
||||
return BetaFeatures::isFeatureEnabled(
|
||||
$user,
|
||||
self::REFERENCE_PREVIEWS_BETA_FEATURE_KEY
|
||||
self::REFERENCE_PREVIEWS_PREFERENCE_NAME
|
||||
);
|
||||
}
|
||||
return $user->getBoolOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME );
|
||||
return $user->getBoolOption( self::REFERENCE_PREVIEWS_PREFERENCE_NAME );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,7 @@ class PopupsHooks {
|
|||
private const PREVIEWS_PREFERENCES_SECTION = 'rendering/reading';
|
||||
|
||||
/**
|
||||
* Add Page Previews options to user Preferences page
|
||||
* Add options to user Preferences page
|
||||
*
|
||||
* @param User $user User whose preferences are being modified
|
||||
* @param array[] &$prefs Preferences description array, to be fed to a HTMLForm object
|
||||
|
@ -49,44 +49,18 @@ class PopupsHooks {
|
|||
return;
|
||||
}
|
||||
|
||||
$option = [
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'popups-prefs-optin-all',
|
||||
'help-message' => 'popups-prefs-conflicting-gadgets-info',
|
||||
'section' => self::PREVIEWS_PREFERENCES_SECTION
|
||||
];
|
||||
|
||||
// TODO: Remove when not in Beta any more
|
||||
if ( $context->isReferencePreviewsInBeta() ) {
|
||||
$option[ 'label-message' ] = 'popups-prefs-optin';
|
||||
|
||||
if ( $context->conflictsWithNavPopupsGadget( $user ) ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-disable-nav-gadgets-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
}
|
||||
} else {
|
||||
$isNavPopupsGadgetEnabled = $context->conflictsWithNavPopupsGadget( $user );
|
||||
$isRefTooltipsGadgetEnabled = $context->conflictsWithRefTooltipsGadget( $user );
|
||||
|
||||
if ( $isNavPopupsGadgetEnabled && $isRefTooltipsGadgetEnabled ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-and-navpopups-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
} elseif ( $isNavPopupsGadgetEnabled ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-navpopups-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
} elseif ( $isRefTooltipsGadgetEnabled ) {
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
}
|
||||
}
|
||||
|
||||
$skinPosition = array_search( 'skin', array_keys( $prefs ) );
|
||||
$readingOptions = [
|
||||
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME => $option,
|
||||
];
|
||||
$readingOptions = self::getPagePreviewPrefToggle( $user, $context );
|
||||
|
||||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
if ( $config->get( 'PopupsReferencePreviews' ) &&
|
||||
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
|
||||
) {
|
||||
$readingOptions = array_merge(
|
||||
$readingOptions,
|
||||
self::getReferencePreviewPrefToggle( $user, $context )
|
||||
);
|
||||
}
|
||||
|
||||
if ( $skinPosition !== false ) {
|
||||
$injectIntoIndex = $skinPosition + 1;
|
||||
|
@ -98,6 +72,69 @@ class PopupsHooks {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Page Preview option
|
||||
*
|
||||
* @param User $user User whose preferences are being modified
|
||||
* @param PopupsContext $context
|
||||
* @return array[]
|
||||
*/
|
||||
private static function getPagePreviewPrefToggle( User $user, PopupsContext $context ) {
|
||||
$option = [
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'popups-prefs-optin',
|
||||
'help-message' => 'popups-prefs-conflicting-gadgets-info',
|
||||
'section' => self::PREVIEWS_PREFERENCES_SECTION
|
||||
];
|
||||
|
||||
if ( $context->conflictsWithNavPopupsGadget( $user ) ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-disable-nav-gadgets-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
}
|
||||
|
||||
return [
|
||||
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME => $option
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Reference Preview option
|
||||
*
|
||||
* @param User $user User whose preferences are being modified
|
||||
* @param PopupsContext $context
|
||||
* @return array[]
|
||||
*/
|
||||
private static function getReferencePreviewPrefToggle( User $user, PopupsContext $context ) {
|
||||
$option = [
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'popups-refpreview-user-preference-label',
|
||||
'help-message' => 'popups-prefs-conflicting-gadgets-info',
|
||||
'section' => self::PREVIEWS_PREFERENCES_SECTION
|
||||
];
|
||||
|
||||
$isNavPopupsGadgetEnabled = $context->conflictsWithNavPopupsGadget( $user );
|
||||
$isRefTooltipsGadgetEnabled = $context->conflictsWithRefTooltipsGadget( $user );
|
||||
|
||||
if ( $isNavPopupsGadgetEnabled && $isRefTooltipsGadgetEnabled ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-and-navpopups-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
} elseif ( $isNavPopupsGadgetEnabled ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-navpopups-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
} elseif ( $isRefTooltipsGadgetEnabled ) {
|
||||
$option[ 'disabled' ] = true;
|
||||
$option[ 'help-message' ] = [ 'popups-prefs-reftooltips-gadget-conflict-info',
|
||||
'Special:Preferences#mw-prefsection-gadgets' ];
|
||||
}
|
||||
|
||||
return [
|
||||
PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME => $option
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows last minute changes to the output page, e.g. adding of CSS or JavaScript by extensions.
|
||||
*
|
||||
|
@ -183,6 +220,14 @@ class PopupsHooks {
|
|||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$default = $config->get( 'PopupsOptInDefaultState' );
|
||||
$defaultOptions[PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME] = $default;
|
||||
|
||||
// As long as in Beta, don't set a default for Reference Previews. Rely on it either being
|
||||
// null (= disabled), or follow what the "betafeatures-auto-enroll" flag says.
|
||||
if ( $config->get( 'PopupsReferencePreviews' ) &&
|
||||
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
|
||||
) {
|
||||
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,6 +241,14 @@ class PopupsHooks {
|
|||
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||
$default = $config->get( 'PopupsOptInStateForNewAccounts' );
|
||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $default );
|
||||
|
||||
// As long as in Beta, don't set a default for Reference Previews. Rely on it either being
|
||||
// null (= disabled), or follow what the "betafeatures-auto-enroll" flag says.
|
||||
if ( $config->get( 'PopupsReferencePreviews' ) &&
|
||||
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
|
||||
) {
|
||||
$user->setOption( PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME, $default );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +265,7 @@ class PopupsHooks {
|
|||
if ( $config->get( 'PopupsReferencePreviewsBetaFeature' ) &&
|
||||
$config->get( 'PopupsReferencePreviews' )
|
||||
) {
|
||||
$prefs[PopupsContext::REFERENCE_PREVIEWS_BETA_FEATURE_KEY] = [
|
||||
$prefs[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = [
|
||||
'label-message' => 'popups-refpreview-beta-feature-message',
|
||||
'desc-message' => 'popups-refpreview-beta-feature-description',
|
||||
'screenshot' => [
|
||||
|
|
|
@ -271,8 +271,9 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
|
||||
/**
|
||||
* @covers ::onUserGetDefaultOptions
|
||||
* @dataProvider provideReferencePreviewsBetaFlag
|
||||
*/
|
||||
public function testOnUserGetDefaultOptions() {
|
||||
public function testOnUserGetDefaultOptions( $beta ) {
|
||||
$userOptions = [
|
||||
'test' => 'not_empty'
|
||||
];
|
||||
|
@ -280,20 +281,26 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
$this->setMwGlobals( [
|
||||
'wgPopupsOptInDefaultState' => '1',
|
||||
'wgPopupsReferencePreviews' => true,
|
||||
'wgPopupsReferencePreviewsBetaFeature' => $beta,
|
||||
] );
|
||||
|
||||
PopupsHooks::onUserGetDefaultOptions( $userOptions );
|
||||
$this->assertCount( 2, $userOptions );
|
||||
$this->assertCount( 3 - $beta, $userOptions );
|
||||
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
|
||||
if ( $beta === false ) {
|
||||
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::onUserGetDefaultOptions
|
||||
* @dataProvider provideReferencePreviewsBetaFlag
|
||||
*/
|
||||
public function testOnLocalUserCreatedForNewlyCreatedUser() {
|
||||
public function testOnLocalUserCreatedForNewlyCreatedUser( $beta ) {
|
||||
$expectedState = '1';
|
||||
|
||||
$userMock = $this->createMock( User::class );
|
||||
$userMock->expects( $this->exactly( 1 ) )
|
||||
$userMock->expects( $this->exactly( 2 - $beta ) )
|
||||
->method( 'setOption' )
|
||||
->withConsecutive(
|
||||
[ 'popups', $expectedState ],
|
||||
|
@ -303,8 +310,16 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
|||
$this->setMwGlobals( [
|
||||
'wgPopupsOptInStateForNewAccounts' => $expectedState,
|
||||
'wgPopupsReferencePreviews' => true,
|
||||
'wgPopupsReferencePreviewsBetaFeature' => $beta,
|
||||
] );
|
||||
PopupsHooks::onLocalUserCreated( $userMock, false );
|
||||
}
|
||||
|
||||
public function provideReferencePreviewsBetaFlag() {
|
||||
return [
|
||||
[ false ],
|
||||
[ true ],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue