Gergő Tisza has uploaded a new change for review. https://gerrit.wikimedia.org/r/156004
Change subject: Fix preference DB values ...................................................................... Fix preference DB values Ensure that changing the preference via the quick link and Special:Preferences is stored identically in the DB. Change-Id: Ia37da1c6bfbb3edf0eba56f01105e4a5f3a5e4ba --- M MultimediaViewerHooks.php M resources/mmv/mmv.Config.js 2 files changed, 15 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer refs/changes/04/156004/1 diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 6ac204a..9d40dee 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -164,8 +164,12 @@ * @param OutputPage $out */ public static function makeGlobalVariablesScript( &$vars, OutputPage $out ) { + global $wgDefaultUserOptions; + $user = $out->getUser(); $vars['wgMediaViewerOnClick'] = self::shouldHandleClicks( $user ); + // needed because of bug 69942; could be different for anon and logged-in + $vars['wgMediaViewerEnabledByDefault'] = !empty( $wgDefaultUserOptions['multimediaviewer-enable'] ); } /** diff --git a/resources/mmv/mmv.Config.js b/resources/mmv/mmv.Config.js index 341cdeb..38107bf 100644 --- a/resources/mmv/mmv.Config.js +++ b/resources/mmv/mmv.Config.js @@ -140,7 +140,9 @@ * @return {jQuery.Promise} a deferred which resolves/rejects on success/failure respectively */ CP.setMediaViewerEnabledOnClick = function ( enabled ) { - var config = this, + var newPrefValue, + defaultPrefValue = this.mwConfig.get( 'wgMediaViewerEnabledByDefault'), + config = this, success = true; if ( this.mwUser.isAnon() ) { @@ -150,14 +152,20 @@ success = this.removeFromLocalStorage( 'wgMediaViewerOnClick' ); } if ( success ) { + // make the change work without a reload config.mwConfig.set( 'wgMediaViewerOnClick', enabled ); return $.Deferred().resolve(); } else { return $.Deferred().reject(); } } else { - return this.setUserPreference( 'multimediaviewer-enable', enabled ? true : '').then( function () { // wow our prefs API sucks - // make the change work without a reload + // bug 69942 + if ( defaultPrefValue === true ) { + newPrefValue = enabled ? '1' : ''; + } else { + newPrefValue = enabled ? '1' : undefined; + } + return this.setUserPreference( 'multimediaviewer-enable', newPrefValue ).then( function () { // wow our prefs API sucks config.mwConfig.set( 'wgMediaViewerOnClick', enabled ); } ); } -- To view, visit https://gerrit.wikimedia.org/r/156004 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia37da1c6bfbb3edf0eba56f01105e4a5f3a5e4ba Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits