TheDJ has uploaded a new change for review. https://gerrit.wikimedia.org/r/130068
Change subject: Persistent disabling of CodeEditor ...................................................................... Persistent disabling of CodeEditor This makes it so that if you do not have WikiEditor enabled, you also will not have CodeEditor enabled. In the feedback we have seen so far, this seems to be desirable for those users (bug 45850). Also people were not able with the cookie pref for the editor, because it can easily expire. This introduces a hidden pref, controlled by the enable/disable CodeEditor button, to preserve this value instead (bug 46779). It also gives a more reliable way to detect if the editor is enabled or disabled. mw.user.options.get( 'usebetatoolbar' ) and mw.user.options.get( 'usecodeeditor' ) combined should be able to convey this information to something like WikEd (bug 62250). Bug: 46779 Bug: 62250 Bug: 45850 Change-Id: I4639f68c00a2b9183a6f89b5e00983c07a8592a2 --- M CodeEditor.hooks.php M CodeEditor.php M modules/jquery.codeEditor.js 3 files changed, 24 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeEditor refs/changes/68/130068/1 diff --git a/CodeEditor.hooks.php b/CodeEditor.hooks.php index b094047..d367be2 100644 --- a/CodeEditor.hooks.php +++ b/CodeEditor.hooks.php @@ -24,10 +24,18 @@ return $lang; } + + public static function getPreferences( $user, &$defaultPreferences ) { + $defaultPreferences['usecodeeditor'] = array( + 'type' => 'api', + 'default' => '1', + ); + return true; + } public static function editPageShowEditFormInitial( $editpage, $output ) { $lang = self::getPageLanguage( $editpage->getContextTitle() ); - if ( $lang ) { + if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) { $output->addModules( 'ext.codeEditor' ); } return true; diff --git a/CodeEditor.php b/CodeEditor.php index 6c9a044..421931f 100644 --- a/CodeEditor.php +++ b/CodeEditor.php @@ -27,6 +27,7 @@ $wgHooks['EditPage::showReadOnlyForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial'; $wgHooks['BeforePageDisplay'][] = 'CodeEditorHooks::onBeforePageDisplay'; $wgHooks['MakeGlobalVariablesScript'][] = 'CodeEditorHooks::onMakeGlobalVariablesScript'; +$wgHooks['GetPreferences'][] = 'CodeEditorHooks::getPreferences'; $tpl = array( 'localBasePath' => __DIR__ . '/modules', diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js index 4fee225..bbe500f 100644 --- a/modules/jquery.codeEditor.js +++ b/modules/jquery.codeEditor.js @@ -33,7 +33,7 @@ }; $.wikiEditor.extensions.codeEditor = function ( context ) { - var cookieEnabled, saveAndExtend; + var saveAndExtend; /* * Event Handlers @@ -80,8 +80,7 @@ } } ); - cookieEnabled = $.cookie( 'wikiEditor-' + context.instance + '-codeEditor-enabled' ); - context.codeEditorActive = (cookieEnabled !== '0'); + context.codeEditorActive = mw.user.options.get( 'usecodeeditor' ) !== '0' ? true : false; /** * Internally used functions @@ -106,11 +105,8 @@ } ); var callback = function ( context ) { context.codeEditorActive = !context.codeEditorActive; - $.cookie( - 'wikiEditor-' + context.instance + '-codeEditor-enabled', - context.codeEditorActive ? 1 : 0, - { expires: 30, path: '/' } - ); + + context.fn.setCodeEditorPreference( context.codeEditorActive ); context.fn.toggleCodeEditorToolbar(); if ( context.codeEditorActive ) { @@ -143,6 +139,16 @@ $img = context.modules.toolbar.$toolbar.find( target ); $img.attr( 'src', context.fn.codeEditorToolbarIcon() ); }, + 'setCodeEditorPreference': function ( prefValue ) { + var api = new mw.Api(); + api.postWithToken( 'options', { + action: 'options', + optionname: 'usecodeeditor', + optionvalue: prefValue ? 1 : 0 + } ).fail( function( code, result ) { + mw.log.error( 'Failed to set code editor preference: ' + code + '\n' + result.error ); + } ); + }, /** * Sets up the iframe in place of the textarea to allow more advanced operations */ -- To view, visit https://gerrit.wikimedia.org/r/130068 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4639f68c00a2b9183a6f89b5e00983c07a8592a2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CodeEditor Gerrit-Branch: master Gerrit-Owner: TheDJ <hartman.w...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits