Combine page and reference preview preferences

Update copy and remove unnecessary reference preview preference
in favor of using the default preference. It seems there is no
stable method to link to the subsections on the preference page
for gadgets. So in all cases does the link just point to the
gadgets pref page.

These changes should only be visible when reference previews
are no longer marked as a beta feature.

Bug: T265709
Change-Id: I7b8ab91331092ada04b230315373548673b9272c
This commit is contained in:
Andrew Kostka 2021-02-04 18:04:58 +01:00
parent 229e521fcb
commit 82d54945e4
12 changed files with 82 additions and 67 deletions

View file

@ -193,10 +193,12 @@
],
"messages": [
"popups-settings-title",
"popups-settings-unified-title",
"popups-settings-option-simple",
"popups-settings-option-simple-description",
"popups-settings-option-advanced",
"popups-settings-option-advanced-description",
"popups-settings-option-unified-description",
"popups-settings-option-off",
"popups-settings-save",
"popups-settings-cancel",

View file

@ -5,10 +5,12 @@
"popups-message": "Previews",
"popups-desc": "Displays preview popups when the user hovers over a link",
"popups-settings-title": "Page preview",
"popups-settings-unified-title": "Previews",
"popups-settings-option-simple": "Enable",
"popups-settings-option-simple-description": "Get quick previews of a topic while reading a page.",
"popups-settings-option-advanced": "Advanced",
"popups-settings-option-advanced-description": "See link previews and access editing function menus. This is used by many editors.",
"popups-settings-option-unified-description": "Get quick previews of a topic or reference while reading.",
"popups-settings-option-off": "Disable",
"popups-settings-save": "Save",
"popups-settings-help-ok": "Done",
@ -23,6 +25,10 @@
"popups-prefs-optin": "Enable page previews (quick previews of a topic while reading a page)",
"popups-prefs-disable-nav-gadgets-info": "You have to [[$1 | disable Navigation Popups Gadget]] from Gadgets tab 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 global gadget settings and user scripts.",
"popups-prefs-reftooltips-gadget-conflict-info": "You have the [[$1 | Reference Tooltips]] gadget enabled, so you wont 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 global gadget settings and user scripts.",
"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 gadget may have a slightly different name. If you continue to experience issues, please review your global gadget settings and user scripts.",
"popups-refpreview-reference": "Reference",
"popups-refpreview-book": "Book reference",
"popups-refpreview-journal": "Journal reference",
@ -30,7 +36,6 @@
"popups-refpreview-note": "Note",
"popups-refpreview-web": "Web reference",
"popups-refpreview-collapsible-placeholder": "This reference includes a graphic which does not fit in the preview.",
"popups-refpreview-user-preference-label": "Reference previews (get quick previews of footnotes)",
"popups-refpreview-beta-feature-message": "Reference Previews",
"popups-refpreview-beta-feature-description": "Show a preview of a reference by hovering over its footnote marker.\n\nPlease note: If youre using the [https://en.wikipedia.org/wiki/Wikipedia:Tools/Navigation_popups Navigation popups] gadget or the [[mw:Special:MyLanguage/Reference Tooltips|Reference Tooltips]] gadget, you wont see Reference Previews."
}

View file

@ -15,10 +15,12 @@
"popups-message": "Name shown in user preference for this extension\n{{name}}",
"popups-desc": "{{desc|name=Popups|url=https://www.mediawiki.org/wiki/Extension:Popups}}",
"popups-settings-title": "Title used for the setting's dialog",
"popups-settings-unified-title": "Title used for the setting's dialog enabling page and reference previews",
"popups-settings-option-simple": "Title for the reader popup option\n{{Identical|Enable}}",
"popups-settings-option-simple-description": "Description for the reader popup option",
"popups-settings-option-advanced": "Title for the editor or Navigation Popups gadget option\n{{Identical|Advanced}}",
"popups-settings-option-advanced-description": "Description for the editor or Navigation Popups gadget option",
"popups-settings-option-unified-description": "Description for the reader popup option for page and reference previews",
"popups-settings-option-off": "Title to turn off popups option.\n\nSee also:\n* {{msg-mw|Popups-settings-enable}}\n{{Identical|Disable}}",
"popups-settings-save": "Save button for the setting's dialog\n{{Identical|Save}}",
"popups-settings-help-ok": "Confirmation button after showing how to re-enable page previews.\n{{Identical|Done}}",
@ -33,6 +35,10 @@
"popups-prefs-optin": "Label for Page Previews option (description for Page Previews option)",
"popups-prefs-disable-nav-gadgets-info": "Help message telling to disable Navigation Popups gadget in order to enable page previews.\n\nParameters:\n* $1 Link to the Gadgets tab of 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 Navigation Popups gadget in order to allow page and reference previews.\n\nParameters:\n* $1 Link to the Gadgets tab of Preferences",
"popups-prefs-reftooltips-gadget-conflict-info": "Help message telling to disable Reference Tooltips gadget in order to allow page and reference previews.\n\nParameters:\n* $1 Link to the Gadgets tab of Preferences",
"popups-prefs-reftooltips-and-navpopups-gadget-conflict-info": "Help message telling to disable Navigation Popups and Reference Tooltips gadgets in order to allow page and reference previews.\n\nParameters:\n* $1 Link to the Gadgets tab of Preferences",
"popups-refpreview-reference": "Default heading for popups that show previews of references as provided by the Cite extension's <ref> tags (also known as footnotes).\n{{Identical|Reference}}",
"popups-refpreview-book": "Heading for a popup previewing a citation from a book.\n{{Identical|Book}}",
"popups-refpreview-journal": "Heading for a popup previewing a citation from a journal.\n{{Identical|Journal}}",
@ -40,7 +46,6 @@
"popups-refpreview-note": "Heading for a popup previewing a footnote.\n{{Identical|Note}}",
"popups-refpreview-web": "Heading for a popup previewing a citation from a website.\n{{Identical|Website}}",
"popups-refpreview-collapsible-placeholder": "Placeholder text for collapsible tables, templates, or other large elements inside of a reference.",
"popups-refpreview-user-preference-label": "Label for the user option to enable or disable reference preview popups",
"popups-refpreview-beta-feature-message": "Label for the Reference Previews Beta feature.",
"popups-refpreview-beta-feature-description": "Description for the Reference Previews Beta feature, describing the feature that will be enabled."
}

View file

@ -57,9 +57,9 @@ class PopupsContext {
public const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
/**
* User preference key to enable/disable Reference Previews
* Beta feature key to enable/disable Reference Previews
*/
public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popupsreferencepreviews';
public const REFERENCE_PREVIEWS_BETA_FEATURE_KEY = 'popupsreferencepreviews';
/**
* @var \Config
@ -138,16 +138,22 @@ class PopupsContext {
}
// TODO: Remove when not in Beta any more
if ( $this->config->get( 'PopupsReferencePreviewsBetaFeature' ) &&
\ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' )
) {
if ( $this->isReferencePreviewsInBeta() ) {
return BetaFeatures::isFeatureEnabled(
$user,
self::REFERENCE_PREVIEWS_PREFERENCE_NAME
self::REFERENCE_PREVIEWS_BETA_FEATURE_KEY
);
}
return $user->getBoolOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME );
}
return $user->getBoolOption( self::REFERENCE_PREVIEWS_PREFERENCE_NAME );
/**
* @return bool whether or not reference previews are a beta feature
*/
public function isReferencePreviewsInBeta() {
// TODO: Remove when not in Beta any more
return $this->config->get( 'PopupsReferencePreviewsBetaFeature' ) &&
\ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' );
}
/**

View file

@ -51,14 +51,36 @@ class PopupsHooks {
$option = [
'type' => 'toggle',
'label-message' => 'popups-prefs-optin',
'label-message' => 'popups-prefs-optin-all',
'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' ];
// 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 ) );
@ -66,18 +88,6 @@ class PopupsHooks {
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME => $option,
];
$config = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
if ( $config->get( 'PopupsReferencePreviews' ) &&
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
) {
$readingOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = [
'type' => 'toggle',
'label-message' => 'popups-refpreview-user-preference-label',
'section' => self::PREVIEWS_PREFERENCES_SECTION,
'disabled' => $option['disabled'] ?? false,
];
}
if ( $skinPosition !== false ) {
$injectIntoIndex = $skinPosition + 1;
$prefs = array_slice( $prefs, 0, $injectIntoIndex, true )
@ -165,6 +175,9 @@ class PopupsHooks {
// TODO: Move checks and tests from isReferencePreviewsEnabled.js here
$vars['wgPopupsReferencePreviews'] = $context->isReferencePreviewsEnabled( $user );
// TODO: Remove when not in Beta any more
$vars['wgPopupsReferencePreviewsBeta'] = $context->isReferencePreviewsInBeta( $user );
$vars['wgPopupsConflictsWithNavPopupGadget'] = $context->conflictsWithNavPopupsGadget( $user );
$vars['wgPopupsConflictsWithRefTooltipsGadget'] = $context->conflictsWithRefTooltipsGadget( $user );
}
@ -179,14 +192,6 @@ 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;
}
}
/**
@ -200,14 +205,6 @@ 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 );
}
}
/**
@ -224,7 +221,7 @@ class PopupsHooks {
if ( $config->get( 'PopupsReferencePreviewsBetaFeature' ) &&
$config->get( 'PopupsReferencePreviews' )
) {
$prefs[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = [
$prefs[PopupsContext::REFERENCE_PREVIEWS_BETA_FEATURE_KEY] = [
'label-message' => 'popups-refpreview-beta-feature-message',
'desc-message' => 'popups-refpreview-beta-feature-description',
'screenshot' => [

Binary file not shown.

Binary file not shown.

View file

@ -168,7 +168,7 @@ function registerChangeListeners(
pagePreviewGateway = createPagePreviewGateway( mw.config ),
referenceGateway = createReferenceGateway(),
userSettings = createUserSettings( mw.storage ),
settingsDialog = createSettingsDialogRenderer(),
settingsDialog = createSettingsDialogRenderer( mw.config ),
experiments = createExperiments( mw.experiments ),
statsvTracker = getStatsvTracker( mw.user, mw.config, experiments ),
// Virtual pageviews are always tracked.

View file

@ -8,14 +8,20 @@ import { renderSettingsDialog } from './templates/settingsDialog/settingsDialog'
* Create the settings dialog shown to anonymous users.
*
* @param {boolean} navPopupsEnabled
* @param {boolean} isReferencePreviewsInBeta
* @return {JQuery} settings dialog
*/
export function createSettingsDialog( navPopupsEnabled ) {
export function createSettingsDialog( navPopupsEnabled, isReferencePreviewsInBeta ) {
const choices = [
{
id: 'simple',
name: mw.msg( 'popups-settings-option-simple' ),
description: mw.msg( 'popups-settings-option-simple-description' ),
description: mw.msg(
// TODO: Remove when not in Beta any more
isReferencePreviewsInBeta ?
'popups-settings-option-simple-description' :
'popups-settings-option-unified-description'
),
isChecked: true
},
{
@ -35,7 +41,12 @@ export function createSettingsDialog( navPopupsEnabled ) {
}
return renderSettingsDialog( {
heading: mw.msg( 'popups-settings-title' ),
heading: mw.msg(
// TODO: Remove when not in Beta any more
isReferencePreviewsInBeta ?
'popups-settings-title' :
'popups-settings-unified-title'
),
closeLabel: mw.msg( 'popups-settings-cancel' ),
saveLabel: mw.msg( 'popups-settings-save' ),
helpText: mw.msg( 'popups-settings-help' ),

View file

@ -8,9 +8,10 @@ import { createSettingsDialog } from './settingsDialog';
* Creates a render function that will create the settings dialog and return
* a set of methods to operate on it
*
* @param {mw.Map} config
* @return {Function} render function
*/
export default function createSettingsDialogRenderer() {
export default function createSettingsDialogRenderer( config ) {
/**
* Cached settings dialog
*
@ -32,7 +33,7 @@ export default function createSettingsDialogRenderer() {
*/
return ( boundActions ) => {
if ( !$dialog ) {
$dialog = createSettingsDialog( isNavPopupsEnabled() );
$dialog = createSettingsDialog( isNavPopupsEnabled(), config.get( 'wgPopupsReferencePreviewsBeta' ) );
$overlay = $( '<div>' ).addClass( 'mwe-popups-overlay' );
// Setup event bindings

View file

@ -34,7 +34,7 @@ QUnit.test( '#render', ( assert ) => {
toggleHelp() {},
setEnabled() {}
},
result = createSettingsDialogRenderer()( boundActions );
result = createSettingsDialogRenderer( mw.config )( boundActions );
// Specifically NOT a deep equal. Only structure.
assert.propEqual(

View file

@ -267,16 +267,15 @@ class PopupsHooksTest extends MediaWikiTestCase {
$vars = [];
PopupsHooks::onMakeGlobalVariablesScript( $vars, $outputPage );
$this->assertCount( 3, $vars, 'Number of added variables.' );
$this->assertCount( 4, $vars, 'Number of added variables.' );
$this->assertFalse( $vars[ 'wgPopupsConflictsWithNavPopupGadget' ],
'The PopupsConflictsWithNavPopupGadget global is present and false.' );
}
/**
* @covers ::onUserGetDefaultOptions
* @dataProvider provideReferencePreviewsBetaFlag
*/
public function testOnUserGetDefaultOptions( $beta ) {
public function testOnUserGetDefaultOptions() {
$userOptions = [
'test' => 'not_empty'
];
@ -284,23 +283,20 @@ class PopupsHooksTest extends MediaWikiTestCase {
$this->setMwGlobals( [
'wgPopupsOptInDefaultState' => '1',
'wgPopupsReferencePreviews' => true,
'wgPopupsReferencePreviewsBetaFeature' => $beta,
] );
PopupsHooks::onUserGetDefaultOptions( $userOptions );
$this->assertCount( 3 - $beta, $userOptions );
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
$this->assertCount( 2, $userOptions );
}
/**
* @covers ::onUserGetDefaultOptions
* @dataProvider provideReferencePreviewsBetaFlag
*/
public function testOnLocalUserCreatedForNewlyCreatedUser( $beta ) {
public function testOnLocalUserCreatedForNewlyCreatedUser() {
$expectedState = '1';
$userMock = $this->createMock( User::class );
$userMock->expects( $this->exactly( 2 - $beta ) )
$userMock->expects( $this->exactly( 1 ) )
->method( 'setOption' )
->withConsecutive(
[ 'popups', $expectedState ],
@ -310,16 +306,8 @@ class PopupsHooksTest extends MediaWikiTestCase {
$this->setMwGlobals( [
'wgPopupsOptInStateForNewAccounts' => $expectedState,
'wgPopupsReferencePreviews' => true,
'wgPopupsReferencePreviewsBetaFeature' => $beta,
] );
PopupsHooks::onLocalUserCreated( $userMock, false );
}
public function provideReferencePreviewsBetaFlag() {
return [
[ false ],
[ true ],
];
}
}