mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-30 19:04:19 +00:00
Merge "IP masking update"
This commit is contained in:
commit
a4151f7d21
|
@ -28,7 +28,6 @@ use ExtensionRegistry;
|
|||
use MediaWiki\Category\Category;
|
||||
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
use OutputPage;
|
||||
use Skin;
|
||||
|
@ -74,14 +73,14 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
|
||||
/**
|
||||
* Checks the context for whether to load the viewer.
|
||||
* @param UserIdentity $performer
|
||||
* @param User $performer
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldHandleClicks( UserIdentity $performer ) {
|
||||
protected function shouldHandleClicks( User $performer ): bool {
|
||||
global $wgMediaViewerEnableByDefaultForAnonymous,
|
||||
$wgMediaViewerEnableByDefault;
|
||||
|
||||
if ( $performer->isRegistered() ) {
|
||||
if ( $performer->isNamed() ) {
|
||||
return (bool)$this->userOptionsLookup->getOption( $performer, 'multimediaviewer-enable' );
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
// IMPORTANT: mmv.head.js uses the same logic but does not use this class to be lightweight. Make sure to keep it in sync.
|
||||
return this.mwConfig.get( 'wgMediaViewer' ) && // global opt-out switch, can be set in user JS
|
||||
this.mwConfig.get( 'wgMediaViewerOnClick' ) && // thumbnail opt-out, can be set in preferences
|
||||
( !this.mwUser.isAnon() || this.getFromLocalStorage( 'wgMediaViewerOnClick', '1' ) === '1' ); // thumbnail opt-out for anons
|
||||
( this.mwUser.isNamed() || this.getFromLocalStorage( 'wgMediaViewerOnClick', '1' ) === '1' ); // thumbnail opt-out for anons
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,7 +157,7 @@
|
|||
let newPrefValue;
|
||||
let success = true;
|
||||
|
||||
if ( this.mwUser.isAnon() ) {
|
||||
if ( !this.mwUser.isNamed() ) {
|
||||
if ( !enabled ) {
|
||||
success = this.setInLocalStorage( 'wgMediaViewerOnClick', '0' ); // localStorage stringifies everything, best use strings in the first place
|
||||
} else {
|
||||
|
|
|
@ -26,7 +26,7 @@ module.exports = base;
|
|||
// This is loaded before user JS so we cannot check wgMediaViewer.
|
||||
if (
|
||||
mw.config.get( 'wgMediaViewerOnClick' ) !== true ||
|
||||
mw.user.isAnon() && mw.storage.get( 'wgMediaViewerOnClick', '1' ) !== '1'
|
||||
!mw.user.isNamed() && mw.storage.get( 'wgMediaViewerOnClick', '1' ) !== '1'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -91,41 +91,41 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
QUnit.test( 'isMediaViewerEnabledOnClick', function ( assert ) {
|
||||
var localStorage = createLocalStorage( { getItem: this.sandbox.stub() } ),
|
||||
mwConfig = { get: this.sandbox.stub() },
|
||||
mwUser = { isAnon: this.sandbox.stub() },
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
config = new Config( {}, mwConfig, mwUser, {}, localStorage );
|
||||
|
||||
mwUser.isAnon.returns( false );
|
||||
mwUser.isNamed.returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( true );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), true, 'Returns true for logged-in with standard settings' );
|
||||
|
||||
mwUser.isAnon.returns( false );
|
||||
mwUser.isNamed.returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( true );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), false, 'Returns false if opted out via user JS flag' );
|
||||
|
||||
mwUser.isAnon.returns( false );
|
||||
mwUser.isNamed.returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( false );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), false, 'Returns false if opted out via preferences' );
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( true );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), false, 'Returns false if anon user opted out via user JS flag' );
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( false );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), false, 'Returns false if anon user opted out in some weird way' ); // apparently someone created a browser extension to do this
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( true );
|
||||
localStorage.store.getItem.withArgs( 'wgMediaViewerOnClick' ).returns( null );
|
||||
assert.strictEqual( config.isMediaViewerEnabledOnClick(), true, 'Returns true for anon with standard settings' );
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
mwConfig.get.withArgs( 'wgMediaViewer' ).returns( true );
|
||||
mwConfig.get.withArgs( 'wgMediaViewerOnClick' ).returns( true );
|
||||
localStorage.store.getItem.withArgs( 'wgMediaViewerOnClick' ).returns( '0' );
|
||||
|
@ -138,22 +138,22 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
setItem: this.sandbox.stub(),
|
||||
removeItem: this.sandbox.stub()
|
||||
} ),
|
||||
mwUser = { isAnon: this.sandbox.stub() },
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
mwConfig = new mw.Map(),
|
||||
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) },
|
||||
config = new Config( {}, mwConfig, mwUser, api, localStorage );
|
||||
mwConfig.set( 'wgMediaViewerEnabledByDefault', false );
|
||||
|
||||
mwUser.isAnon.returns( false );
|
||||
mwUser.isNamed.returns( true );
|
||||
api.saveOption.returns( $.Deferred().resolve() );
|
||||
config.setMediaViewerEnabledOnClick( false );
|
||||
assert.true( api.saveOption.called, 'For logged-in users, pref change is via API' );
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
config.setMediaViewerEnabledOnClick( false );
|
||||
assert.true( localStorage.store.setItem.called, 'For anons, opt-out is set in localStorage' );
|
||||
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
config.setMediaViewerEnabledOnClick( true );
|
||||
assert.true( localStorage.store.removeItem.called, 'For anons, opt-in means clearing localStorage' );
|
||||
} );
|
||||
|
@ -162,7 +162,7 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
var config,
|
||||
mwConfig = new mw.Map(),
|
||||
fakeLocalStorage = getFakeLocalStorage(),
|
||||
mwUser = { isAnon: this.sandbox.stub() },
|
||||
mwUser = { isNamed: this.sandbox.stub() },
|
||||
api = { saveOption: this.sandbox.stub().returns( $.Deferred().resolve() ) };
|
||||
|
||||
mwConfig.set( {
|
||||
|
@ -171,7 +171,7 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
wgMediaViewerEnabledByDefault: true
|
||||
} );
|
||||
config = new Config( {}, mwConfig, mwUser, api, fakeLocalStorage );
|
||||
mwUser.isAnon.returns( false );
|
||||
mwUser.isNamed.returns( true );
|
||||
|
||||
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown by default' );
|
||||
config.setMediaViewerEnabledOnClick( false );
|
||||
|
@ -189,7 +189,7 @@ const { createLocalStorage, getDisabledLocalStorage, getFakeLocalStorage, getUns
|
|||
|
||||
// make sure disabling calls maybeEnableStatusInfo() for logged-in as well
|
||||
config.localStorage = getFakeLocalStorage();
|
||||
mwUser.isAnon.returns( true );
|
||||
mwUser.isNamed.returns( false );
|
||||
assert.strictEqual( config.shouldShowStatusInfo(), false, 'Status info is not shown by default for logged-in users' );
|
||||
config.setMediaViewerEnabledOnClick( false );
|
||||
assert.strictEqual( config.shouldShowStatusInfo(), true, 'Status info is shown after MMV is disabled the first time for logged-in users' );
|
||||
|
|
Loading…
Reference in a new issue