mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Remove BetaFeature code
Popups is out of beta feature and this code is no longer needed. Removing code is the happiest activity a developer can do. Other changes: * Remove redundant type field on extension.json (If not set, the extension will default to the "other" section.) * Repurpose `name` with `namemsg` and make use of existing i18n messages Bug: T193053 Change-Id: Iea832cd1f37b0e7df6ff95efd66e4a1ff2a9004e
This commit is contained in:
parent
d7871bb9c4
commit
4e3282e5ff
|
@ -1,4 +1,4 @@
|
||||||
![Popups](images/popups-ltr.svg)
|
![Popups](images/popups.svg)
|
||||||
|
|
||||||
# mediawiki/extensions/Popups
|
# mediawiki/extensions/Popups
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Popups",
|
"name": "Popups",
|
||||||
|
"namemsg": "popups-message",
|
||||||
"author": [
|
"author": [
|
||||||
"Prateek Saxena",
|
"Prateek Saxena",
|
||||||
"Yair Rand"
|
"Yair Rand"
|
||||||
|
@ -7,7 +8,6 @@
|
||||||
"url": "https://www.mediawiki.org/wiki/Extension:Popups",
|
"url": "https://www.mediawiki.org/wiki/Extension:Popups",
|
||||||
"descriptionmsg": "popups-desc",
|
"descriptionmsg": "popups-desc",
|
||||||
"license-name": "GPL-2.0-or-later",
|
"license-name": "GPL-2.0-or-later",
|
||||||
"type": "betafeatures",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"MediaWiki": ">= 1.30.0"
|
"MediaWiki": ">= 1.30.0"
|
||||||
},
|
},
|
||||||
|
@ -25,9 +25,6 @@
|
||||||
"popups": "GlobalVarConfig::newInstance"
|
"popups": "GlobalVarConfig::newInstance"
|
||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"GetBetaFeaturePreferences": [
|
|
||||||
"Popups\\PopupsHooks::onGetBetaPreferences"
|
|
||||||
],
|
|
||||||
"BeforePageDisplay": [
|
"BeforePageDisplay": [
|
||||||
"Popups\\PopupsHooks::onBeforePageDisplay"
|
"Popups\\PopupsHooks::onBeforePageDisplay"
|
||||||
],
|
],
|
||||||
|
@ -59,9 +56,7 @@
|
||||||
"config": {
|
"config": {
|
||||||
"@PopupsVirtualPageViews": "@var bool: Whether the extension should log virtual pageviews.",
|
"@PopupsVirtualPageViews": "@var bool: Whether the extension should log virtual pageviews.",
|
||||||
"PopupsVirtualPageViews": false,
|
"PopupsVirtualPageViews": false,
|
||||||
"@PopupsBetaFeature": "@var bool: Whether the extension should be enabled as an opt-in beta feature. If true, the BetaFeatures extension must be installed. False by default.",
|
"@PopupsHideOptInOnPreferencesPage": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. False by default",
|
||||||
"PopupsBetaFeature": false,
|
|
||||||
"@PopupsHideOptInOnPreferencesPage": "@var bool: Whether the option to enable/disable Page Previews should be hidden on Preferences page. Please note if PopupsBetaFeature is set to true this option will be always hidden. False by default",
|
|
||||||
"PopupsHideOptInOnPreferencesPage": false,
|
"PopupsHideOptInOnPreferencesPage": false,
|
||||||
"@PopupsOptInDefaultState": "@var string:['1'|'0'] Default Page Previews visibility. Has to be a string as a compatibility with beta feature settings",
|
"@PopupsOptInDefaultState": "@var string:['1'|'0'] Default Page Previews visibility. Has to be a string as a compatibility with beta feature settings",
|
||||||
"PopupsOptInDefaultState": "0",
|
"PopupsOptInDefaultState": "0",
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="264" height="162" viewBox="0 0 264 162">
|
|
||||||
<defs>
|
|
||||||
<clipPath id="jagged-edge">
|
|
||||||
<path d="M0 0v152l12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10 12 10 12-10V0z"/>
|
|
||||||
</clipPath>
|
|
||||||
</defs>
|
|
||||||
<g fill="#eaecf0" clip-path="url(#jagged-edge)" transform="matrix(-1 0 0 1 264 0)">
|
|
||||||
<path id="background" fill="#fff" d="M0 0h264v162H0"/>
|
|
||||||
<path id="logo" d="M11 22c0-8 6-14 14-14s14 6 14 14-6 14-14 14-14-6-14-14M38 45v-5H13v5h25"/>
|
|
||||||
<path id="sidebar" d="M38 163V58H13v106h25"/>
|
|
||||||
<path id="personal-tools" d="M233 5h26v6h-26V5zM209 5h22v6h-22zM185 5h22v6h-22zM162 5h13v6h-13zM177 5h6v6h-6zM154 5h6v6h-6z"/>
|
|
||||||
<g id="search">
|
|
||||||
<path id="input" d="M258 16v4h-92v-4h92m1-1h-94v6h94v-6z"/>
|
|
||||||
<path id="icon" d="M168 17h2v2h-2z"/>
|
|
||||||
</g>
|
|
||||||
<path id="article" d="M252 162V29H48v133z"/>
|
|
||||||
<path id="border" d="M0 0v162h264V0zm1 1h262v150.533l-11 9.166-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-12-10-12 10-11-9z"/>
|
|
||||||
<path id="article-copy" fill="#72777d" d="M143.756 56h-38.14v7.782h38.14V56zm56.732 35.02v-8.755h-50.814v8.755h50.814zm-89.725-22.374H89.93v8.633h20.832v-8.636zm98.535 7.782v-7.782h-37.695v7.782h37.695zm-88.645 5.716H94.955v7.782h25.698v-7.782zM195.233 56h-46.207v7.782h46.207V56z"/>
|
|
||||||
<path id="article-link" fill="#36c" d="M114.735 68.646v9.2h51.558v-9.2h-51.558z"/>
|
|
||||||
<g id="popup">
|
|
||||||
<path fill="#fff" d="M114 82h75v44h-75z"/>
|
|
||||||
<path fill="#36c" d="M189 82h-31v44h31V82zm-18.167 24.13l5.904 9.652 3.206-2.958 4.83 6.05-21.137.03 6.244-12.775h.953z"/>
|
|
||||||
<g id="copy" fill="#c8ccd1" transform="translate(284 -12)">
|
|
||||||
<rect width="20" height="1" x="-163" y="100" rx="1"/>
|
|
||||||
<rect width="20" height="1" x="-163" y="104" rx="1"/>
|
|
||||||
<rect width="20" height="1" x="-163" y="108" rx="1"/>
|
|
||||||
<rect width="28" height="1" x="-163" y="112" rx="1"/>
|
|
||||||
<rect width="28" height="1" x="-163" y="116" rx="1"/>
|
|
||||||
<rect width="28" height="1" x="-163" y="120" rx="1"/>
|
|
||||||
<rect width="28" height="1" x="-163" y="124" rx="1"/>
|
|
||||||
<rect width="28" height="1" x="-163" y="128" rx="1"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 2.2 KiB |
|
@ -45,30 +45,22 @@ class PopupsContext {
|
||||||
const LOGGER_CHANNEL = 'popups';
|
const LOGGER_CHANNEL = 'popups';
|
||||||
/**
|
/**
|
||||||
* User preference value for enabled Page Previews
|
* User preference value for enabled Page Previews
|
||||||
* Identical to \HTMLFeatureField::OPTION_ENABLED in BetaFeatures
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const PREVIEWS_ENABLED = '1';
|
const PREVIEWS_ENABLED = '1';
|
||||||
/**
|
/**
|
||||||
* User preference value for disabled Page Previews
|
* User preference value for disabled Page Previews
|
||||||
* Identical to \HTMLFeatureField::OPTION_DISABLED in BetaFeatures
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const PREVIEWS_DISABLED = '0';
|
const PREVIEWS_DISABLED = '0';
|
||||||
/**
|
/**
|
||||||
* User preference to enable/disable Page Previews
|
* User preference key to enable/disable Page Previews
|
||||||
* Currently for BETA and regular opt in we use same preference name
|
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
|
||||||
/**
|
|
||||||
* User preference to enable/disable Page Preivews as a beta feature
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const PREVIEWS_BETA_PREFERENCE_NAME = 'popups';
|
|
||||||
/**
|
/**
|
||||||
* @var \Config
|
* @var \Config
|
||||||
*/
|
*/
|
||||||
|
@ -102,14 +94,6 @@ class PopupsContext {
|
||||||
public function conflictsWithNavPopupsGadget( \User $user ) {
|
public function conflictsWithNavPopupsGadget( \User $user ) {
|
||||||
return $this->gadgetsIntegration->conflictsWithNavPopupsGadget( $user );
|
return $this->gadgetsIntegration->conflictsWithNavPopupsGadget( $user );
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Is Beta Feature mode enabled
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isBetaFeatureEnabled() {
|
|
||||||
return $this->config->get( 'PopupsBetaFeature' ) === true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default Page previews state
|
* Get default Page previews state
|
||||||
|
@ -127,8 +111,7 @@ class PopupsContext {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function showPreviewsOptInOnPreferencesPage() {
|
public function showPreviewsOptInOnPreferencesPage() {
|
||||||
return !$this->isBetaFeatureEnabled()
|
return $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
||||||
&& $this->config->get( 'PopupsHideOptInOnPreferencesPage' ) === false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,10 +119,6 @@ class PopupsContext {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function shouldSendModuleToUser( \User $user ) {
|
public function shouldSendModuleToUser( \User $user ) {
|
||||||
if ( $this->isBetaFeatureEnabled() ) {
|
|
||||||
return $user->isAnon() ? false :
|
|
||||||
\BetaFeatures::isFeatureEnabled( $user, self::PREVIEWS_BETA_PREFERENCE_NAME );
|
|
||||||
}
|
|
||||||
return $user->isAnon() ? true :
|
return $user->isAnon() ? true :
|
||||||
$user->getOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME ) === self::PREVIEWS_ENABLED;
|
$user->getOption( self::PREVIEWS_OPTIN_PREFERENCE_NAME ) === self::PREVIEWS_ENABLED;
|
||||||
}
|
}
|
||||||
|
@ -155,10 +134,6 @@ class PopupsContext {
|
||||||
&& $this->extensionRegistry->isLoaded( 'PageImages' );
|
&& $this->extensionRegistry->isLoaded( 'PageImages' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->isBetaFeatureEnabled() ) {
|
|
||||||
$areMet = $areMet && $this->extensionRegistry->isLoaded( 'BetaFeatures' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $areMet;
|
return $areMet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,33 +33,6 @@ use Skin;
|
||||||
class PopupsHooks {
|
class PopupsHooks {
|
||||||
const PREVIEWS_PREFERENCES_SECTION = 'rendering/reading';
|
const PREVIEWS_PREFERENCES_SECTION = 'rendering/reading';
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook executed on retrieving User beta preferences
|
|
||||||
* @param User $user User whose beta preferences are retrieved
|
|
||||||
* @param array &$prefs An associative array of all beta preferences
|
|
||||||
*/
|
|
||||||
static function onGetBetaPreferences( User $user, array &$prefs ) {
|
|
||||||
global $wgExtensionAssetsPath;
|
|
||||||
/** @var PopupsContext $context */
|
|
||||||
$context = MediaWikiServices::getInstance()->getService( 'Popups.Context' );
|
|
||||||
if ( $context->isBetaFeatureEnabled() !== true ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$prefs[PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME] = [
|
|
||||||
'label-message' => 'popups-message',
|
|
||||||
'desc-message' => 'popups-desc',
|
|
||||||
'screenshot' => [
|
|
||||||
'ltr' => "$wgExtensionAssetsPath/Popups/images/popups-ltr.svg",
|
|
||||||
'rtl' => "$wgExtensionAssetsPath/Popups/images/popups-rtl.svg",
|
|
||||||
],
|
|
||||||
'info-link' => 'https://www.mediawiki.org/wiki/Special:MyLanguage/Beta_Features/Hovercards',
|
|
||||||
'discussion-link' => 'https://www.mediawiki.org/wiki/Talk:Beta_Features/Hovercards',
|
|
||||||
'requirements' => [
|
|
||||||
'javascript' => true,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Page Previews options to user Preferences page
|
* Add Page Previews options to user Preferences page
|
||||||
*
|
*
|
||||||
|
@ -116,13 +89,13 @@ class PopupsHooks {
|
||||||
|
|
||||||
if ( !$context->areDependenciesMet() ) {
|
if ( !$context->areDependenciesMet() ) {
|
||||||
$logger = $context->getLogger();
|
$logger = $context->getLogger();
|
||||||
$logger->error( 'Popups requires the PageImages and TextExtracts extensions. '
|
$logger->error( 'Popups requires the PageImages extensions.
|
||||||
. 'If Beta mode is on it requires also BetaFeatures extension' );
|
TextExtracts extension is required when using mwApiPlain gateway.' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $out->getUser();
|
$user = $out->getUser();
|
||||||
if ( !$context->isBetaFeatureEnabled() || $context->shouldSendModuleToUser( $user ) ) {
|
if ( $context->shouldSendModuleToUser( $user ) ) {
|
||||||
$out->addModules( [ 'ext.popups' ] );
|
$out->addModules( [ 'ext.popups' ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +105,6 @@ class PopupsHooks {
|
||||||
*/
|
*/
|
||||||
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
||||||
$conf = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
$conf = MediaWikiServices::getInstance()->getService( 'Popups.Config' );
|
||||||
$vars['wgPopupsBetaFeature'] = $conf->get( 'PopupsBetaFeature' );
|
|
||||||
$vars['wgPopupsVirtualPageViews'] = $conf->get( 'PopupsVirtualPageViews' );
|
$vars['wgPopupsVirtualPageViews'] = $conf->get( 'PopupsVirtualPageViews' );
|
||||||
$vars['wgPopupsGateway'] = $conf->get( 'PopupsGateway' );
|
$vars['wgPopupsGateway'] = $conf->get( 'PopupsGateway' );
|
||||||
$vars['wgPopupsEventLogging'] = $conf->get( 'PopupsEventLogging' );
|
$vars['wgPopupsEventLogging'] = $conf->get( 'PopupsEventLogging' );
|
||||||
|
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.json
vendored
BIN
resources/dist/index.js.json
vendored
Binary file not shown.
|
@ -203,7 +203,7 @@ function registerChangeListeners(
|
||||||
);
|
);
|
||||||
const boundActions = Redux.bindActionCreators( actions, store.dispatch );
|
const boundActions = Redux.bindActionCreators( actions, store.dispatch );
|
||||||
const previewBehavior = createPreviewBehavior(
|
const previewBehavior = createPreviewBehavior(
|
||||||
mw.config, mw.user, boundActions
|
mw.user, boundActions
|
||||||
);
|
);
|
||||||
|
|
||||||
registerChangeListeners(
|
registerChangeListeners(
|
||||||
|
|
|
@ -9,11 +9,6 @@ import { BUCKETS } from './constants';
|
||||||
*
|
*
|
||||||
* Page Previews is disabled when the Navigation Popups gadget is enabled.
|
* Page Previews is disabled when the Navigation Popups gadget is enabled.
|
||||||
*
|
*
|
||||||
* If Page Previews is configured as a beta feature (see
|
|
||||||
* `$wgPopupsBetaFeature`), the user must be logged in and have enabled the
|
|
||||||
* beta feature in order to see previews. Logged out users won't be able
|
|
||||||
* to see the feature.
|
|
||||||
*
|
|
||||||
* If Page Previews is configured as a user preference, then the user must
|
* If Page Previews is configured as a user preference, then the user must
|
||||||
* either be logged in and have enabled the preference or be logged out and have
|
* either be logged in and have enabled the preference or be logged out and have
|
||||||
* not disabled previews via the settings modal. Logged out users who have not
|
* not disabled previews via the settings modal. Logged out users who have not
|
||||||
|
@ -36,10 +31,6 @@ export default function isEnabled( user, userSettings, config, bucket ) {
|
||||||
return config.get( 'wgPopupsShouldSendModuleToUser' );
|
return config.get( 'wgPopupsShouldSendModuleToUser' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( config.get( 'wgPopupsBetaFeature' ) ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !userSettings.hasIsEnabled() ) {
|
if ( !userSettings.hasIsEnabled() ) {
|
||||||
return bucket === BUCKETS.on;
|
return bucket === BUCKETS.on;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,13 @@ const mw = window.mediaWiki,
|
||||||
* modal.
|
* modal.
|
||||||
*
|
*
|
||||||
* If the user is logged in, then clicking the cog should send them to the
|
* If the user is logged in, then clicking the cog should send them to the
|
||||||
* Special:Preferences page with the "Beta features" tab open if Page Previews
|
* the "Appearance" tab otherwise.
|
||||||
* is enabled as a beta feature, or the "Appearance" tab otherwise.
|
|
||||||
*
|
*
|
||||||
* @param {mw.Map} config
|
|
||||||
* @param {mw.User} user
|
* @param {mw.User} user
|
||||||
* @param {Object} actions The action creators bound to the Redux store
|
* @param {Object} actions The action creators bound to the Redux store
|
||||||
* @return {ext.popups.PreviewBehavior}
|
* @return {ext.popups.PreviewBehavior}
|
||||||
*/
|
*/
|
||||||
export default function createPreviewBehavior( config, user, actions ) {
|
export default function createPreviewBehavior( user, actions ) {
|
||||||
const isBetaFeature = config.get( 'wgPopupsBetaFeature' );
|
|
||||||
let settingsUrl, showSettings = $.noop;
|
let settingsUrl, showSettings = $.noop;
|
||||||
|
|
||||||
if ( user.isAnon() ) {
|
if ( user.isAnon() ) {
|
||||||
|
@ -45,8 +42,7 @@ export default function createPreviewBehavior( config, user, actions ) {
|
||||||
actions.showSettings();
|
actions.showSettings();
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
let rawTitle = 'Special:Preferences#mw-prefsection-';
|
const rawTitle = 'Special:Preferences#mw-prefsection-rendering';
|
||||||
rawTitle += isBetaFeature ? 'betafeatures' : 'rendering';
|
|
||||||
|
|
||||||
settingsUrl = mw.Title.newFromText( rawTitle )
|
settingsUrl = mw.Title.newFromText( rawTitle )
|
||||||
.getUrl();
|
.getUrl();
|
||||||
|
|
|
@ -56,28 +56,6 @@ QUnit.test( 'is should handle logged out users', ( assert ) => {
|
||||||
testCase[ 3 ]
|
testCase[ 3 ]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
|
||||||
|
|
||||||
config.set( 'wgPopupsBetaFeature', true );
|
|
||||||
|
|
||||||
assert.notOk(
|
|
||||||
isEnabled( user, userSettings, config, BUCKETS.on ),
|
|
||||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
||||||
' enabled for logged out users when they are in the on group.'
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.notOk(
|
|
||||||
isEnabled( user, userSettings, config, BUCKETS.control ),
|
|
||||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
||||||
' enabled for logged out users when they are not in the control group.'
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.notOk(
|
|
||||||
isEnabled( user, userSettings, config, BUCKETS.off ),
|
|
||||||
'When Page Previews is enabled as a beta feature, then it\'s not' +
|
|
||||||
' enabled for logged out users when they are in the off group.'
|
|
||||||
);
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
QUnit.test( 'it should handle logged in users', ( assert ) => {
|
||||||
|
|
|
@ -15,31 +15,22 @@ QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( assert ) {
|
QUnit.test( 'it should set the settingsUrl', function ( assert ) {
|
||||||
const user = createStubUser( /* isAnon = */ false ),
|
const user = createStubUser( /* isAnon = */ false ),
|
||||||
actions = {};
|
actions = {};
|
||||||
|
|
||||||
const cases = [
|
const behavior = createPreviewBehavior( user, actions );
|
||||||
[ true, 'Special:Preferences#mw-prefsection-betafeatures' ],
|
|
||||||
[ false, 'Special:Preferences#mw-prefsection-rendering' ]
|
|
||||||
];
|
|
||||||
|
|
||||||
cases.forEach( ( testCase ) => {
|
|
||||||
this.config.set( 'wgPopupsBetaFeature', testCase[ 0 ] );
|
|
||||||
|
|
||||||
const behavior = createPreviewBehavior( this.config, user, actions );
|
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
behavior.settingsUrl,
|
behavior.settingsUrl,
|
||||||
`url/${ testCase[ 1 ] }`
|
'url/Special:Preferences#mw-prefsection-rendering'
|
||||||
);
|
);
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
||||||
const user = createStubUser( /* isAnon = */ true ),
|
const user = createStubUser( /* isAnon = */ true ),
|
||||||
actions = {},
|
actions = {},
|
||||||
behavior = createPreviewBehavior( this.config, user, actions );
|
behavior = createPreviewBehavior( user, actions );
|
||||||
|
|
||||||
assert.strictEqual( behavior.settingsUrl, undefined );
|
assert.strictEqual( behavior.settingsUrl, undefined );
|
||||||
} );
|
} );
|
||||||
|
@ -47,7 +38,7 @@ QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', funct
|
||||||
QUnit.test( 'it shouldn\'t set a showSettings handler if the user is logged in', function ( assert ) {
|
QUnit.test( 'it shouldn\'t set a showSettings handler if the user is logged in', function ( assert ) {
|
||||||
const user = createStubUser( /* isAnon = */ false ),
|
const user = createStubUser( /* isAnon = */ false ),
|
||||||
actions = {},
|
actions = {},
|
||||||
behavior = createPreviewBehavior( this.config, user, actions );
|
behavior = createPreviewBehavior( user, actions );
|
||||||
|
|
||||||
assert.strictEqual( behavior.showSettings, $.noop );
|
assert.strictEqual( behavior.showSettings, $.noop );
|
||||||
} );
|
} );
|
||||||
|
@ -60,7 +51,7 @@ QUnit.test( 'it should set a showSettings handler if the user is logged out', fu
|
||||||
actions = {
|
actions = {
|
||||||
showSettings: this.sandbox.spy()
|
showSettings: this.sandbox.spy()
|
||||||
},
|
},
|
||||||
behavior = createPreviewBehavior( this.config, user, actions );
|
behavior = createPreviewBehavior( user, actions );
|
||||||
|
|
||||||
behavior.showSettings( event );
|
behavior.showSettings( event );
|
||||||
|
|
||||||
|
@ -84,7 +75,7 @@ QUnit.test( 'it should mix in default actions', function ( assert ) {
|
||||||
actions.previewShow = () => {};
|
actions.previewShow = () => {};
|
||||||
actions.linkClick = () => {};
|
actions.linkClick = () => {};
|
||||||
|
|
||||||
const behavior = createPreviewBehavior( this.config, user, actions );
|
const behavior = createPreviewBehavior( user, actions );
|
||||||
|
|
||||||
assert.strictEqual( behavior.previewDwell, actions.previewDwell );
|
assert.strictEqual( behavior.previewDwell, actions.previewDwell );
|
||||||
assert.strictEqual( behavior.previewAbandon, actions.abandon );
|
assert.strictEqual( behavior.previewAbandon, actions.abandon );
|
||||||
|
|
|
@ -76,38 +76,27 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
public function provideConfigForShowPreviewsInOptIn() {
|
public function provideConfigForShowPreviewsInOptIn() {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
"options" => [
|
[
|
||||||
"wgPopupsBetaFeature" => false,
|
|
||||||
"wgPopupsHideOptInOnPreferencesPage" => false
|
"wgPopupsHideOptInOnPreferencesPage" => false
|
||||||
],
|
],
|
||||||
"expected" => true
|
true
|
||||||
], [
|
|
||||||
"options" => [
|
|
||||||
"wgPopupsBetaFeature" => true,
|
|
||||||
"wgPopupsHideOptInOnPreferencesPage" => false
|
|
||||||
],
|
],
|
||||||
"expected" => false
|
[
|
||||||
], [
|
[
|
||||||
"options" => [
|
|
||||||
"wgPopupsBetaFeature" => false,
|
|
||||||
"wgPopupsHideOptInOnPreferencesPage" => true
|
"wgPopupsHideOptInOnPreferencesPage" => true
|
||||||
],
|
],
|
||||||
"expected" => false
|
false
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::shouldSendModuleToUser
|
* @covers ::shouldSendModuleToUser
|
||||||
* @covers ::isBetaFeatureEnabled
|
|
||||||
* @dataProvider provideTestDataForShouldSendModuleToUser
|
* @dataProvider provideTestDataForShouldSendModuleToUser
|
||||||
* @param bool $optIn
|
* @param bool $optIn
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testShouldSendModuleToUser( $optIn, $expected ) {
|
public function testShouldSendModuleToUser( $optIn, $expected ) {
|
||||||
$this->setMwGlobals( [
|
|
||||||
"wgPopupsBetaFeature" => false
|
|
||||||
] );
|
|
||||||
$context = $this->getContext();
|
$context = $this->getContext();
|
||||||
$user = $this->getMutableTestUser()->getUser();
|
$user = $this->getMutableTestUser()->getUser();
|
||||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $optIn );
|
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $optIn );
|
||||||
|
@ -130,41 +119,16 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers ::shouldSendModuleToUser
|
|
||||||
* @covers ::isBetaFeatureEnabled
|
|
||||||
* @dataProvider provideTestDataForShouldSendModuleToUserWhenBetaEnabled
|
|
||||||
* @param bool $optIn
|
|
||||||
* @param bool $expected
|
|
||||||
*/
|
|
||||||
public function testShouldSendModuleToUserWhenBetaEnabled( $optIn, $expected ) {
|
|
||||||
if ( !class_exists( 'BetaFeatures' ) ) {
|
|
||||||
$this->markTestSkipped( 'Skipped as BetaFeatures is not available' );
|
|
||||||
}
|
|
||||||
$this->setMwGlobals( [
|
|
||||||
"wgPopupsBetaFeature" => true
|
|
||||||
] );
|
|
||||||
|
|
||||||
$context = $this->getContext();
|
|
||||||
$user = $this->getMutableTestUser()->getUser();
|
|
||||||
$user->setOption( PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME, $optIn );
|
|
||||||
$this->assertEquals( $context->shouldSendModuleToUser( $user ), $expected );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check tst Page Previews are disabled for anonymous user
|
* Check tst Page Previews are disabled for anonymous user
|
||||||
* @covers ::shouldSendModuleToUser
|
* @covers ::shouldSendModuleToUser
|
||||||
* @covers ::isBetaFeatureEnabled
|
|
||||||
* @dataProvider providerAnonUserHasDisabledPagePreviews
|
* @dataProvider providerAnonUserHasDisabledPagePreviews
|
||||||
*/
|
*/
|
||||||
public function testAnonUserHasDisabledPagePreviews( $betaFeatureEnabled, $expected ) {
|
public function testAnonUserHasDisabledPagePreviews( $expected ) {
|
||||||
$user = $this->getMutableTestUser()->getUser();
|
$user = $this->getMutableTestUser()->getUser();
|
||||||
$user->setId( self::ANONYMOUS_USER );
|
$user->setId( self::ANONYMOUS_USER );
|
||||||
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
$user->setOption( PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME,
|
||||||
PopupsContext::PREVIEWS_DISABLED );
|
PopupsContext::PREVIEWS_DISABLED );
|
||||||
$this->setMwGlobals( [
|
|
||||||
"wgPopupsBetaFeature" => $betaFeatureEnabled,
|
|
||||||
] );
|
|
||||||
|
|
||||||
$context = $this->getContext();
|
$context = $this->getContext();
|
||||||
$this->assertEquals( $expected, $context->shouldSendModuleToUser( $user ) );
|
$this->assertEquals( $expected, $context->shouldSendModuleToUser( $user ) );
|
||||||
|
@ -172,43 +136,24 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
public static function providerAnonUserHasDisabledPagePreviews() {
|
public static function providerAnonUserHasDisabledPagePreviews() {
|
||||||
return [
|
return [
|
||||||
// If beta feature is enabled we can assume it's opt in only.
|
// Anons see this by default
|
||||||
[ true, false ],
|
[ true ],
|
||||||
// If beta feature is disabled we can assume it's rolled out to everyone.
|
|
||||||
[ false, true ],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @return array/
|
|
||||||
*/
|
|
||||||
public function provideTestDataForShouldSendModuleToUserWhenBetaEnabled() {
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
"optin" => PopupsContext::PREVIEWS_ENABLED,
|
|
||||||
'expected' => true
|
|
||||||
], [
|
|
||||||
"optin" => PopupsContext::PREVIEWS_DISABLED,
|
|
||||||
'expected' => false
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::areDependenciesMet
|
* @covers ::areDependenciesMet
|
||||||
* @dataProvider provideTestDataForTestAreDependenciesMet
|
* @dataProvider provideTestDataForTestAreDependenciesMet
|
||||||
* @param bool $betaOn
|
|
||||||
* @param bool $textExtracts
|
* @param bool $textExtracts
|
||||||
* @param bool $pageImages
|
* @param bool $pageImages
|
||||||
* @param bool $betaFeatures
|
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testAreDependenciesMet( $betaOn, $textExtracts, $pageImages,
|
public function testAreDependenciesMet( $textExtracts, $pageImages,
|
||||||
$betaFeatures, $gateway, $expected ) {
|
$gateway, $expected ) {
|
||||||
$this->setMwGlobals( [
|
$this->setMwGlobals( [
|
||||||
"wgPopupsBetaFeature" => $betaOn,
|
|
||||||
"wgPopupsGateway" => $gateway,
|
"wgPopupsGateway" => $gateway,
|
||||||
] );
|
] );
|
||||||
$returnValues = [ $textExtracts, $pageImages, $betaFeatures ];
|
$returnValues = [ $textExtracts, $pageImages ];
|
||||||
|
|
||||||
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
$mock = $this->getMock( ExtensionRegistry::class, [ 'isLoaded' ] );
|
||||||
$mock->expects( $this->any() )
|
$mock->expects( $this->any() )
|
||||||
|
@ -223,57 +168,31 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
*/
|
*/
|
||||||
public function provideTestDataForTestAreDependenciesMet() {
|
public function provideTestDataForTestAreDependenciesMet() {
|
||||||
return [
|
return [
|
||||||
// Beta is off, dependencies are met even BetaFeatures ext is not available
|
// Dependencies are met
|
||||||
[
|
[
|
||||||
"betaOn" => false,
|
|
||||||
"textExtracts" => true,
|
"textExtracts" => true,
|
||||||
"pageImages" => true,
|
"pageImages" => true,
|
||||||
"betaFeatures" => false,
|
|
||||||
"gateway" => "mwApiPlain",
|
"gateway" => "mwApiPlain",
|
||||||
"expected" => true
|
"expected" => true
|
||||||
],
|
],
|
||||||
// textExtracts dep is missing
|
// textExtracts dep is missing
|
||||||
[
|
[
|
||||||
"betaOn" => false,
|
|
||||||
"textExtracts" => false,
|
"textExtracts" => false,
|
||||||
"pageImages" => true,
|
"pageImages" => true,
|
||||||
"betaFeatures" => false,
|
|
||||||
"gateway" => "mwApiPlain",
|
"gateway" => "mwApiPlain",
|
||||||
"expected" => false
|
"expected" => false
|
||||||
],
|
],
|
||||||
// PageImages dep is missing
|
// PageImages dep is missing
|
||||||
[
|
[
|
||||||
"betaOn" => false,
|
|
||||||
"textExtracts" => true,
|
"textExtracts" => true,
|
||||||
"pageImages" => false,
|
"pageImages" => false,
|
||||||
"betaFeatures" => false,
|
|
||||||
"gateway" => "mwApiPlain",
|
"gateway" => "mwApiPlain",
|
||||||
"expected" => false
|
"expected" => false
|
||||||
],
|
],
|
||||||
// Beta is on but BetaFeatures dep is missing
|
|
||||||
[
|
|
||||||
"betaOn" => true,
|
|
||||||
"textExtracts" => true,
|
|
||||||
"pageImages" => true,
|
|
||||||
"betaFeatures" => false,
|
|
||||||
"gateway" => "mwApiPlain",
|
|
||||||
"expected" => false
|
|
||||||
],
|
|
||||||
// beta is on and all deps are available
|
|
||||||
[
|
|
||||||
"betaOn" => true,
|
|
||||||
"textExtracts" => true,
|
|
||||||
"pageImages" => true,
|
|
||||||
"betaFeatures" => true,
|
|
||||||
"gateway" => "mwApiPlain",
|
|
||||||
"expected" => true
|
|
||||||
],
|
|
||||||
// when Popups uses gateway!=mwApiPlain we don't require PageImages nor TextExtracts
|
// when Popups uses gateway!=mwApiPlain we don't require PageImages nor TextExtracts
|
||||||
[
|
[
|
||||||
"betaOn" => false,
|
|
||||||
"textExtracts" => false,
|
"textExtracts" => false,
|
||||||
"pageImages" => false,
|
"pageImages" => false,
|
||||||
"betaFeatures" => false,
|
|
||||||
"gateway" => "restbaseHTML",
|
"gateway" => "restbaseHTML",
|
||||||
"expected" => true
|
"expected" => true
|
||||||
],
|
],
|
||||||
|
@ -285,7 +204,7 @@ class PopupsContextTest extends MediaWikiTestCase {
|
||||||
* @dataProvider provideTestIsTitleBLacklisted
|
* @dataProvider provideTestIsTitleBLacklisted
|
||||||
* @param array $blacklist
|
* @param array $blacklist
|
||||||
* @param Title $title
|
* @param Title $title
|
||||||
$ @param bool $expected
|
* @param bool $expected
|
||||||
*/
|
*/
|
||||||
public function testIsTitleBlacklisted( $blacklist, Title $title, $expected ) {
|
public function testIsTitleBlacklisted( $blacklist, Title $title, $expected ) {
|
||||||
$this->setMwGlobals( [ "wgPopupsPageBlacklist" => $blacklist ] );
|
$this->setMwGlobals( [ "wgPopupsPageBlacklist" => $blacklist ] );
|
||||||
|
|
|
@ -33,30 +33,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers ::onGetBetaPreferences
|
|
||||||
*/
|
|
||||||
public function testOnGetBetaPreferencesBetaDisabled() {
|
|
||||||
$prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
|
|
||||||
$this->setMwGlobals( [ 'wgPopupsBetaFeature' => false ] );
|
|
||||||
|
|
||||||
PopupsHooks::onGetBetaPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
||||||
$this->assertCount( 1, $prefs );
|
|
||||||
$this->assertEquals( 'notEmpty', $prefs[ 'someNotEmptyValue'] );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers ::onGetBetaPreferences
|
|
||||||
*/
|
|
||||||
public function testOnGetBetaPreferencesBetaEnabled() {
|
|
||||||
$prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
|
|
||||||
$this->setMwGlobals( [ 'wgPopupsBetaFeature' => true ] );
|
|
||||||
|
|
||||||
PopupsHooks::onGetBetaPreferences( $this->getTestUser()->getUser(), $prefs );
|
|
||||||
$this->assertCount( 2, $prefs );
|
|
||||||
$this->assertArrayHasKey( PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME, $prefs );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::onGetPreferences
|
* @covers ::onGetPreferences
|
||||||
*/
|
*/
|
||||||
|
@ -176,7 +152,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
$config = [
|
$config = [
|
||||||
'wgPopupsAnonsExperimentalGroupSize' => 0.1,
|
'wgPopupsAnonsExperimentalGroupSize' => 0.1,
|
||||||
'wgPopupsEventLogging' => false,
|
'wgPopupsEventLogging' => false,
|
||||||
'wgPopupsBetaFeature' => true,
|
|
||||||
'wgPopupsRestGatewayEndpoint' => '/api',
|
'wgPopupsRestGatewayEndpoint' => '/api',
|
||||||
'wgPopupsVirtualPageViews' => true,
|
'wgPopupsVirtualPageViews' => true,
|
||||||
'wgPopupsGateway' => 'mwApiPlain',
|
'wgPopupsGateway' => 'mwApiPlain',
|
||||||
|
@ -184,7 +159,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
];
|
];
|
||||||
$this->setMwGlobals( $config );
|
$this->setMwGlobals( $config );
|
||||||
PopupsHooks::onResourceLoaderGetConfigVars( $vars );
|
PopupsHooks::onResourceLoaderGetConfigVars( $vars );
|
||||||
$this->assertCount( 8, $vars );
|
$this->assertCount( 7, $vars );
|
||||||
|
|
||||||
foreach ( $config as $key => $value ) {
|
foreach ( $config as $key => $value ) {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -251,15 +226,12 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
|
|
||||||
public function providerOnBeforePageDisplay() {
|
public function providerOnBeforePageDisplay() {
|
||||||
return [
|
return [
|
||||||
[ false, true, false, false ],
|
[ false, false, false ],
|
||||||
[ true, true, true, false ],
|
[ true, true, false ],
|
||||||
// if the user doesnt have the feature but the beta feature is disabled
|
// Code not sent if title blacklisted
|
||||||
// we can assume the user has it (as its rolled out to everyone)
|
[ true, false, true ],
|
||||||
[ false, false, true, false ],
|
// Code not sent if title blacklisted
|
||||||
// If the user has enabled it and the beta feature is disabled
|
[ false, false, true ]
|
||||||
// we can assume the code will be loaded.
|
|
||||||
[ true, false, true, false ],
|
|
||||||
[ false, false, false, true ]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +240,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
* @dataProvider providerOnBeforePageDisplay
|
* @dataProvider providerOnBeforePageDisplay
|
||||||
*/
|
*/
|
||||||
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
public function testOnBeforePageDisplay( $shouldSendModuleToUser,
|
||||||
$isBetaFeatureEnabled, $isCodeLoaded, $isTitleBlacklisted ) {
|
$isCodeLoaded, $isTitleBlacklisted ) {
|
||||||
$skinMock = $this->getMock( Skin::class );
|
$skinMock = $this->getMock( Skin::class );
|
||||||
|
|
||||||
$outPageMock = $this->getMock(
|
$outPageMock = $this->getMock(
|
||||||
|
@ -284,7 +256,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
->with( [ 'ext.popups' ] );
|
->with( [ 'ext.popups' ] );
|
||||||
|
|
||||||
$contextMock = $this->getMockBuilder( PopupsContext::class )
|
$contextMock = $this->getMockBuilder( PopupsContext::class )
|
||||||
->setMethods( [ 'areDependenciesMet', 'isBetaFeatureEnabled',
|
->setMethods( [ 'areDependenciesMet',
|
||||||
'shouldSendModuleToUser', 'isTitleBlacklisted' ] )
|
'shouldSendModuleToUser', 'isTitleBlacklisted' ] )
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -295,10 +267,6 @@ class PopupsHooksTest extends MediaWikiTestCase {
|
||||||
->will( $this->returnValue( true ) );
|
->will( $this->returnValue( true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$contextMock->expects( $this->any() )
|
|
||||||
->method( 'isBetaFeatureEnabled' )
|
|
||||||
->will( $this->returnValue( $isBetaFeatureEnabled ) );
|
|
||||||
|
|
||||||
$contextMock->expects( $this->any() )
|
$contextMock->expects( $this->any() )
|
||||||
->method( 'shouldSendModuleToUser' )
|
->method( 'shouldSendModuleToUser' )
|
||||||
->will( $this->returnValue( $shouldSendModuleToUser ) );
|
->will( $this->returnValue( $shouldSendModuleToUser ) );
|
||||||
|
|
Loading…
Reference in a new issue