Index: trunk/extensions/CodeEditor/CodeEditor.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | |
26 | 26 | $wgHooks['EditPage::showEditForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial'; |
27 | 27 | $wgHooks['BeforePageDisplay'][] = 'CodeEditorHooks::onBeforePageDisplay'; |
| 28 | +$wgHooks['MakeGlobalVariablesScript'][] = 'CodeEditorHooks::onMakeGlobalVariablesScript'; |
28 | 29 | |
29 | 30 | $tpl = array( |
30 | 31 | 'localBasePath' => dirname( __FILE__ ) . '/modules', |
— | — | @@ -56,28 +57,29 @@ |
57 | 58 | 'group' => 'ext.codeEditor.ace', |
58 | 59 | 'scripts' => array( |
59 | 60 | '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', |
62 | 64 | ), |
63 | 65 | ) + $tpl; |
64 | 66 | |
65 | | -// Extra highlighting modes to match some availabel GeSHi highlighting languages |
| 67 | +// Extra highlighting modes to match some available GeSHi highlighting languages |
66 | 68 | $wgResourceModules['ext.codeEditor.ace.modes'] = array( |
67 | 69 | 'group' => 'ext.codeEditor.ace', |
68 | 70 | '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', |
82 | 84 | ), |
83 | 85 | 'dependencies' => 'ext.codeEditor.ace', |
84 | 86 | ) + $tpl; |
Index: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js |
— | — | @@ -132,12 +132,8 @@ |
133 | 133 | 'setupCodeEditor': function() { |
134 | 134 | var box = context.$textarea; |
135 | 135 | |
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) { |
142 | 138 | // Ace doesn't like replacing a textarea directly. |
143 | 139 | // We'll stub this out to sit on top of it... |
144 | 140 | // 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 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | 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 | + |
5 | 21 | public static function editPageShowEditFormInitial( &$toolbar ) { |
6 | 22 | global $wgOut, $wgTitle; |
7 | | - if ( $wgTitle->isCssOrJsPage() || $wgTitle->isCssJsSubpage() ) { |
| 23 | + $lang = self::getPageLanguage( $wgTitle ); |
| 24 | + if ( $lang ) { |
8 | 25 | $wgOut->addModules( 'ext.codeEditor' ); |
9 | 26 | } |
10 | 27 | return true; |
11 | 28 | } |
| 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 | + } |
12 | 43 | |
13 | 44 | public static function onBeforePageDisplay( $out, $skin ) { |
14 | 45 | global $wgCodeEditorGeshiIntegration; |