mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-11-15 03:23:45 +00:00
Merge "Persistent disabling of CodeEditor"
This commit is contained in:
commit
26973c1fa9
|
@ -24,10 +24,18 @@ class CodeEditorHooks {
|
|||
|
||||
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;
|
||||
|
|
|
@ -27,6 +27,7 @@ $wgHooks['EditPage::showEditForm:initial'][] = 'CodeEditorHooks::editPageShowEdi
|
|||
$wgHooks['EditPage::showReadOnlyForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial';
|
||||
$wgHooks['BeforePageDisplay'][] = 'CodeEditorHooks::onBeforePageDisplay';
|
||||
$wgHooks['MakeGlobalVariablesScript'][] = 'CodeEditorHooks::onMakeGlobalVariablesScript';
|
||||
$wgHooks['GetPreferences'][] = 'CodeEditorHooks::getPreferences';
|
||||
|
||||
$tpl = array(
|
||||
'localBasePath' => __DIR__ . '/modules',
|
||||
|
@ -48,7 +49,9 @@ $wgResourceModules['jquery.codeEditor'] = array(
|
|||
'dependencies' => array(
|
||||
'jquery.wikiEditor',
|
||||
'ext.codeEditor.ace',
|
||||
'jquery.ui.resizable'
|
||||
'jquery.ui.resizable',
|
||||
'mediawiki.api',
|
||||
'user.options',
|
||||
),
|
||||
'messages' => array(
|
||||
'codeeditor-toolbar-toggle',
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
};
|
||||
|
||||
$.wikiEditor.extensions.codeEditor = function ( context ) {
|
||||
var cookieEnabled, saveAndExtend;
|
||||
var saveAndExtend;
|
||||
|
||||
/*
|
||||
* Event Handlers
|
||||
|
@ -86,8 +86,7 @@
|
|||
}
|
||||
} );
|
||||
|
||||
cookieEnabled = $.cookie( 'wikiEditor-' + context.instance + '-codeEditor-enabled' );
|
||||
context.codeEditorActive = (cookieEnabled !== '0');
|
||||
context.codeEditorActive = mw.user.options.get( 'usecodeeditor' ) !== '0';
|
||||
|
||||
/**
|
||||
* Internally used functions
|
||||
|
@ -112,11 +111,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 ) {
|
||||
|
@ -149,6 +145,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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue