mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-09-29 13:17:35 +00:00
Merge "Fix preference DB values"
This commit is contained in:
commit
fb6e8ad1e2
|
@ -164,8 +164,12 @@ class MultimediaViewerHooks {
|
||||||
* @param OutputPage $out
|
* @param OutputPage $out
|
||||||
*/
|
*/
|
||||||
public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) {
|
||||||
|
global $wgDefaultUserOptions;
|
||||||
|
|
||||||
$user = $out->getUser();
|
$user = $out->getUser();
|
||||||
$vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
|
$vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user );
|
||||||
|
// needed because of bug 69942; could be different for anon and logged-in
|
||||||
|
$vars['wgMediaViewerEnabledByDefault'] = !empty( $wgDefaultUserOptions['multimediaviewer-enable'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -140,7 +140,9 @@
|
||||||
* @return {jQuery.Promise} a deferred which resolves/rejects on success/failure respectively
|
* @return {jQuery.Promise} a deferred which resolves/rejects on success/failure respectively
|
||||||
*/
|
*/
|
||||||
CP.setMediaViewerEnabledOnClick = function ( enabled ) {
|
CP.setMediaViewerEnabledOnClick = function ( enabled ) {
|
||||||
var config = this,
|
var newPrefValue,
|
||||||
|
defaultPrefValue = this.mwConfig.get( 'wgMediaViewerEnabledByDefault' ),
|
||||||
|
config = this,
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
if ( this.mwUser.isAnon() ) {
|
if ( this.mwUser.isAnon() ) {
|
||||||
|
@ -150,14 +152,25 @@
|
||||||
success = this.removeFromLocalStorage( 'wgMediaViewerOnClick' );
|
success = this.removeFromLocalStorage( 'wgMediaViewerOnClick' );
|
||||||
}
|
}
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
|
// make the change work without a reload
|
||||||
config.mwConfig.set( 'wgMediaViewerOnClick', enabled );
|
config.mwConfig.set( 'wgMediaViewerOnClick', enabled );
|
||||||
return $.Deferred().resolve();
|
return $.Deferred().resolve();
|
||||||
} else {
|
} else {
|
||||||
return $.Deferred().reject();
|
return $.Deferred().reject();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.setUserPreference( 'multimediaviewer-enable', enabled ? true : '').then( function () { // wow our prefs API sucks
|
// Simulate changing the option in Special:Preferences. Turns out this is quite hard (bug 69942):
|
||||||
// make the change work without a reload
|
// we need to delete the user_properties row if the new setting is the same as the default,
|
||||||
|
// otherwise set '1' for enabled, '' for disabled. In theory the pref API will delete the row
|
||||||
|
// if the new value equals the default, but this does not always work.
|
||||||
|
if ( defaultPrefValue === true ) {
|
||||||
|
newPrefValue = enabled ? '1' : '';
|
||||||
|
} else {
|
||||||
|
// undefined will cause the API call to omit the optionvalue parameter
|
||||||
|
// which in turn will cause the options API to delete the row and revert the pref to default
|
||||||
|
newPrefValue = enabled ? '1' : undefined;
|
||||||
|
}
|
||||||
|
return this.setUserPreference( 'multimediaviewer-enable', newPrefValue ).then( function () {
|
||||||
config.mwConfig.set( 'wgMediaViewerOnClick', enabled );
|
config.mwConfig.set( 'wgMediaViewerOnClick', enabled );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@
|
||||||
QUnit.test( 'setMediaViewerEnabledOnClick sanity check', 3, function ( assert ) {
|
QUnit.test( 'setMediaViewerEnabledOnClick sanity check', 3, function ( assert ) {
|
||||||
var localStorage = { setItem: this.sandbox.stub(), removeItem: this.sandbox.stub() },
|
var localStorage = { setItem: this.sandbox.stub(), removeItem: this.sandbox.stub() },
|
||||||
mwUser = { isAnon: this.sandbox.stub() },
|
mwUser = { isAnon: this.sandbox.stub() },
|
||||||
mwConfig = { set: this.sandbox.stub() },
|
mwConfig = new mw.Map( { wgMediaViewerEnabledByDefault: false } ),
|
||||||
api = { postWithToken: this.sandbox.stub() },
|
api = { postWithToken: this.sandbox.stub() },
|
||||||
config = new mw.mmv.Config( {}, mwConfig, mwUser, api, localStorage );
|
config = new mw.mmv.Config( {}, mwConfig, mwUser, api, localStorage );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue