Extension:CodeEditor

This extension comes with MediaWiki 1.31 and above. Thus you do not have to download it again. However, you still need to follow the other instructions provided.
Not to be confused with CodeMirror .
MediaWiki extensions manual
CodeEditor
Release status: stable
Description Provides a syntax-highlighting code editor for site & user JS, CSS and Lua pages, integrating with advanced edit toolbar
Author(s)
  • Brooke Vibber
  • Derk-Jan Hartman
  • authors of Ace (ace.c9.io)
Compatibility policy Snapshots releases along with MediaWiki. Master is not backward compatible.
MediaWiki >= 1.42.0
Database changes No
License GPL-2.0-or-later AND BSD-3-Clause
Download
  • $wgCodeEditorEnableCore
Quarterly downloads 162 (Ranked 41st)
Public wikis using 8,385 (Ranked 17th)
Translate the CodeEditor extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

The CodeEditor extension extends the WikiEditor advanced editing toolbar with an embedded Ace editor widget, providing some handy features for user/site JavaScript pages, CSS pages, JSON pages, and when extension Scribunto is also installed, for Lua pages, i.e. pages in the Module namespace. The code editor does not show on regular wiki pages, i.e. wiki pages with the "wikitext" content model. (See Extension:CodeMirror for syntax highlighting of wikitext when using the source editor.)

It provides the following features:

  • syntax highlighting for JavaScript, CSS and Lua
  • auto-indent
  • tab key produces tab indents (since 1.22), soft indents before.
  • indent/unindent selection with Tab ↹/⇧ Shift+Tab ↹ keys
  • syntax validity check for JavaScript
  • Pair-matching for parenthesis, braces and square brackets

Installation edit

The WikiEditor extension needs to be installed for this extension to work. Installing the Scribunto extension is optional.
  • Download and move the extracted CodeEditor folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'CodeEditor' );
    $wgDefaultUserOptions['usebetatoolbar'] = 1; // user option provided by WikiEditor extension
    
  • Configure as required.
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


Vagrant installation:

  • If using Vagrant , install with vagrant roles enable codeeditor --provision

Configuration edit

$wgCodeEditorEnableCore
To disable the editor on JavaScript and CSS pages in the MediaWiki, User and other core namespaces, set $wgCodeEditorEnableCore = false; (default is "true")
$wgScribuntoUseCodeEditor
To disable this extension for Scribunto, i.e. in the module namespace set $wgScribuntoUseCodeEditor = false; (default is "true")
This configuration parameter is provided by the Scribunto extension and must therefore be added after invoking the CodeEditor as well as the Scribunto extension which also needs to be installed for this to work.

JavaScript edit

It is possible to change the configuration of the ACE editor, by hooking into the MediaWiki JS hook (i.e. mw.hook( 'codeEditor.configure' ).add( ... )). The argument passed to your hook will be an ACE EditSession object.

If you need to interact with the contents of a CodeEditor instance, use jQueryPlugins.textSelection().

License edit

While this extension is licensed GNU General Public License v2.0 or later (GPL-2.0+) it makes use of the Ace editor software which is licensed BSD 3-clause "New" or "Revised" License (BSD-3-Clause).

See also edit