r110794 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110793‎ | r110794 | r110795 >
Date:21:59, 6 February 2012
Author:vvv
Status:deferred
Tags:
Comment:
* Update the list of the languages
* Make the language to be used determined on server side
* Allow extension to enable code editor for certain pages
Modified paths:
  • /trunk/extensions/CodeEditor/CodeEditor.hooks.php (modified) (history)
  • /trunk/extensions/CodeEditor/CodeEditor.php (modified) (history)
  • /trunk/extensions/CodeEditor/modules/jquery.codeEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeEditor/CodeEditor.php
@@ -24,6 +24,7 @@
2525
2626 $wgHooks['EditPage::showEditForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial';
2727 $wgHooks['BeforePageDisplay'][] = 'CodeEditorHooks::onBeforePageDisplay';
 28+$wgHooks['MakeGlobalVariablesScript'][] = 'CodeEditorHooks::onMakeGlobalVariablesScript';
2829
2930 $tpl = array(
3031 'localBasePath' => dirname( __FILE__ ) . '/modules',
@@ -56,28 +57,29 @@
5758 'group' => 'ext.codeEditor.ace',
5859 'scripts' => array(
5960 'ace/ace-uncompressed.js',
60 - 'ace/mode-javascript.js',
61 - 'ace/mode-css.js',
 61+ 'ace/mode-javascript-uncompressed.js',
 62+ 'ace/mode-css-uncompressed.js',
 63+ 'ace/mode-lua-uncompressed.js',
6264 ),
6365 ) + $tpl;
6466
65 -// Extra highlighting modes to match some availabel GeSHi highlighting languages
 67+// Extra highlighting modes to match some available GeSHi highlighting languages
6668 $wgResourceModules['ext.codeEditor.ace.modes'] = array(
6769 'group' => 'ext.codeEditor.ace',
6870 'scripts' => array(
69 - 'ace/mode-c_cpp.js',
70 - 'ace/mode-clojure.js',
71 - 'ace/mode-csharp.js',
72 - 'ace/mode-coffee.js',
73 - 'ace/mode-groovy.js',
74 - 'ace/mode-html.js',
75 - 'ace/mode-java.js',
76 - 'ace/mode-ocaml.js',
77 - 'ace/mode-perl.js',
78 - 'ace/mode-php.js',
79 - 'ace/mode-python.js',
80 - 'ace/mode-ruby.js',
81 - 'ace/mode-scala.js',
 71+ 'ace/mode-c_cpp-uncompressed.js',
 72+ 'ace/mode-clojure-uncompressed.js',
 73+ 'ace/mode-csharp-uncompressed.js',
 74+ 'ace/mode-coffee-uncompressed.js',
 75+ 'ace/mode-groovy-uncompressed.js',
 76+ 'ace/mode-html-uncompressed.js',
 77+ 'ace/mode-java-uncompressed.js',
 78+ 'ace/mode-ocaml-uncompressed.js',
 79+ 'ace/mode-perl-uncompressed.js',
 80+ 'ace/mode-php-uncompressed.js',
 81+ 'ace/mode-python-uncompressed.js',
 82+ 'ace/mode-ruby-uncompressed.js',
 83+ 'ace/mode-scala-uncompressed.js',
8284 ),
8385 'dependencies' => 'ext.codeEditor.ace',
8486 ) + $tpl;
Index: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js
@@ -132,12 +132,8 @@
133133 'setupCodeEditor': function() {
134134 var box = context.$textarea;
135135
136 - var matches = /\.(js|css)$/.exec(wgTitle);
137 - if (matches && (wgNamespaceNumber == 2 /* User: */ || wgNamespaceNumber == 8 /* MediaWiki: */)) {
138 - var ext = matches[1];
139 - var map = {js: 'javascript', css: 'css'};
140 - var lang = map[ext];
141 -
 136+ var lang = mw.config.get("wgCodeEditorCurrentLanguage")
 137+ if (lang) {
142138 // Ace doesn't like replacing a textarea directly.
143139 // We'll stub this out to sit on top of it...
144140 // line-height is needed to compensate for oddity in WikiEditor extension, which zeroes the line-height on a parent container
Index: trunk/extensions/CodeEditor/CodeEditor.hooks.php
@@ -1,13 +1,44 @@
22 <?php
33
44 class CodeEditorHooks {
 5+ static function getPageLanguage( $title ) {
 6+ // Try CSS/JS
 7+ if( $title->isCssOrJsPage() ) {
 8+ if( preg_match( '/\.js$/', $title->getText() ) )
 9+ return 'javascript';
 10+ if( preg_match( '/\.js$/', $title->getText() ) )
 11+ return 'css';
 12+ }
 13+
 14+ // Give extensions a chance
 15+ $lang = null;
 16+ wfRunHooks( 'CodeEditorGetPageLanguage', array( $title, &$lang ) );
 17+
 18+ return $lang;
 19+ }
 20+
521 public static function editPageShowEditFormInitial( &$toolbar ) {
622 global $wgOut, $wgTitle;
7 - if ( $wgTitle->isCssOrJsPage() || $wgTitle->isCssJsSubpage() ) {
 23+ $lang = self::getPageLanguage( $wgTitle );
 24+ if ( $lang ) {
825 $wgOut->addModules( 'ext.codeEditor' );
926 }
1027 return true;
1128 }
 29+
 30+ public static function onMakeGlobalVariablesScript( &$vars, $output ) {
 31+ global $wgTitle;
 32+
 33+ // Safeguard
 34+ //if( !$wgTitle )
 35+ // return true;
 36+
 37+ $lang = self::getPageLanguage( $wgTitle );
 38+ if( $lang ) {
 39+ $vars['wgCodeEditorCurrentLanguage'] = $lang;
 40+ }
 41+ return true;
 42+ }
1243
1344 public static function onBeforePageDisplay( $out, $skin ) {
1445 global $wgCodeEditorGeshiIntegration;

Follow-up revisions

RevisionCommit summaryAuthorDate
r110795Remove some commented-out code commited by accident in r110794.vvv22:00, 6 February 2012
r113464Fix a very stupid copy-paste-caused typo.vvv11:16, 9 March 2012

Status & tagging log