Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.php |
— | — | @@ -46,10 +46,10 @@ |
47 | 47 | |
48 | 48 | // Add Internationalized Messages |
49 | 49 | $wgExtensionMessagesFiles['WikiEditor'] = dirname( __FILE__ ) . '/WikiEditor.i18n.php'; |
50 | | -$wgExtensionMessagesFiles['WikiEditorHighlight'] = dirname( __FILE__ ) . '/WikiEditor/Modules/Highlight/Highlight.i18n.php'; |
51 | | -$wgExtensionMessagesFiles['WikiEditorPreview'] = dirname( __FILE__ ) . '/WikiEditor/Modules/Preview/Preview.i18n.php'; |
52 | | -$wgExtensionMessagesFiles['WikiEditorToc'] = dirname( __FILE__ ) . '/WikiEditor/Modules/Toc/Toc.i18n.php'; |
53 | | -$wgExtensionMessagesFiles['WikiEditorToolbar'] = dirname( __FILE__ ) . '/WikiEditor/Modules/Toolbar/Toolbar.i18n.php'; |
| 50 | +$wgExtensionMessagesFiles['WikiEditorHighlight'] = dirname( __FILE__ ) . '/Modules/Highlight/Highlight.i18n.php'; |
| 51 | +$wgExtensionMessagesFiles['WikiEditorPreview'] = dirname( __FILE__ ) . '/Modules/Preview/Preview.i18n.php'; |
| 52 | +$wgExtensionMessagesFiles['WikiEditorToc'] = dirname( __FILE__ ) . '/Modules/Toc/Toc.i18n.php'; |
| 53 | +$wgExtensionMessagesFiles['WikiEditorToolbar'] = dirname( __FILE__ ) . '/Modules/Toolbar/Toolbar.i18n.php'; |
54 | 54 | |
55 | 55 | // Register Hooks |
56 | 56 | $wgHooks['EditPageBeforeEditToolbar'][] = 'WikiEditorHooks::addModules'; |
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php |
— | — | @@ -8,6 +8,9 @@ |
9 | 9 | |
10 | 10 | class WikiEditorHooks { |
11 | 11 | |
| 12 | + static $scripts = array( |
| 13 | + 'raw' => array( 'src' => 'WikiEditor.js', 'version' => 1 ), |
| 14 | + ); |
12 | 15 | static $modules = array( |
13 | 16 | 'highlight' => array( |
14 | 17 | 'i18n' => 'WikiEditorHighlight', |
— | — | @@ -22,7 +25,7 @@ |
23 | 26 | ), |
24 | 27 | ), |
25 | 28 | 'scripts' => array( |
26 | | - 'raw' => array( 'src' => 'Modules/Preview/Preview.js', 'version' => 1 ), |
| 29 | + 'raw' => array( 'src' => 'Modules/Highlight/Highlight.js', 'version' => 1 ), |
27 | 30 | ), |
28 | 31 | ), |
29 | 32 | 'preview' => array( |
— | — | @@ -61,8 +64,8 @@ |
62 | 65 | ), |
63 | 66 | 'variables' => array( |
64 | 67 | // These are probably only for testing purposes? |
65 | | - 'wgNavigableTOCCollapseEnable' => $wgNavigableTOCCollapseEnable, |
66 | | - 'wgNavigableTOCResizable' => $wgNavigableTOCResizable |
| 68 | + 'wgNavigableTOCCollapseEnable', |
| 69 | + 'wgNavigableTOCResizable' |
67 | 70 | ), |
68 | 71 | 'scripts' => array( |
69 | 72 | 'raw' => array( 'src' => 'Modules/Toc/Toc.js', 'version' => 1 ), |
— | — | @@ -282,10 +285,13 @@ |
283 | 286 | * Adds the modules to the edit form |
284 | 287 | */ |
285 | 288 | public static function addModules( &$toolbar ) { |
286 | | - global $wgUser, $wgWikiEditorStyleVersion, $wgWikiEditorEnable, $wgUsabilityInitiativeResourceMode; |
| 289 | + global $wgOut, $wgUser, $wgJsMimeType, $wgWikiEditorStyleVersion, $wgWikiEditorEnable, $wgUsabilityInitiativeResourceMode; |
287 | 290 | |
| 291 | + // Modules |
| 292 | + $scripts = array(); |
| 293 | + $enabled = false; |
288 | 294 | $preferences = array(); |
289 | | - for ( $wgWikiEditorEnable as $module => $enable ) { |
| 295 | + foreach ( $wgWikiEditorEnable as $module => $enable ) { |
290 | 296 | if ( |
291 | 297 | $enable['global'] || ( |
292 | 298 | $enable['user'] |
— | — | @@ -293,16 +299,14 @@ |
294 | 300 | && $wgUser->getOption( self::$modules[$module]['preferences']['enable']['key'] ) |
295 | 301 | ) |
296 | 302 | ) { |
| 303 | + $enabled = true; |
297 | 304 | UsabilityInitiativeHooks::initialize(); |
298 | 305 | // Scripts |
299 | 306 | $mode = $wgUsabilityInitiativeResourceMode; |
300 | 307 | if ( !isset( self::$modules[$module]['scripts'][$mode] ) ) { |
301 | 308 | $mode = 'raw'; |
302 | 309 | } |
303 | | - UsabilityInitiativeHooks::addScript( |
304 | | - self::$modules[$module]['scripts'][$mode]['src'], |
305 | | - self::$modules[$module]['scripts'][$mode]['version'] |
306 | | - ); |
| 310 | + $scripts[] = self::$modules[$module]['scripts'][$mode]; |
307 | 311 | // Messages |
308 | 312 | if ( isset( self::$modules[$module]['i18n'], self::$modules[$module]['messages'] ) ) { |
309 | 313 | wfLoadExtensionMessages( self::$modules[$module]['i18n'] ); |
— | — | @@ -310,37 +314,42 @@ |
311 | 315 | } |
312 | 316 | // Variables |
313 | 317 | if ( isset( self::$modules[$module]['variables'] ) ) { |
314 | | - UsabilityInitiativeHooks::addVariables( self::$modules[$module]['variables'] ); |
| 318 | + $variables = array(); |
| 319 | + foreach ( self::$modules[$module]['variables'] as $variable ) { |
| 320 | + global $$variable; |
| 321 | + $variables[$variable] = $$variable; |
| 322 | + } |
| 323 | + UsabilityInitiativeHooks::addVariables( $variables ); |
315 | 324 | } |
316 | 325 | // Preferences |
317 | | - $preferences[$module] = array(); |
318 | 326 | if ( isset( self::$modules[$module]['preferences'] ) ) { |
319 | 327 | foreach ( self::$modules[$module]['preferences'] as $name => $preference ) { |
320 | | - if ( $name !== 'enable' ) { |
321 | | - $preferences[$module][$name] = $wgUser->getOption( $preference['key'] ); |
| 328 | + if ( !isset( $preferences[$module] ) ) { |
| 329 | + $preferences[$module] = array(); |
322 | 330 | } |
| 331 | + $preferences[$module][$name] = $wgUser->getOption( $preference['key'] ); |
323 | 332 | } |
324 | 333 | } |
325 | 334 | } |
326 | 335 | } |
327 | | - /* Do something with these other preferences that makes them accessible to the wikiEditor code?? |
328 | | - $preferencesList = array(); |
329 | | - foreach ( $preferences as $module => $values ) { |
330 | | - $modulePreferences = array(); |
331 | | - foreach ( $values as $key => $value ) { |
332 | | - $modulePreferences .= "'" . Xml::escapeJsString( $key ) . "':'" . Xml::escapeJsString( $key ) . "'"; |
333 | | - } |
334 | | - $preferencesList[] = |
335 | | - "'" . Xml::escapeJsString( $module ) . "':{" . implode( ',', $modulePreferences ) . '}'; |
| 336 | + // Prepend global script |
| 337 | + $mode = $wgUsabilityInitiativeResourceMode; |
| 338 | + if ( !isset( self::$scripts[$mode] ) ) { |
| 339 | + $mode = 'raw'; |
336 | 340 | } |
337 | | - $out->addScript( |
| 341 | + array_unshift( $scripts, self::$scripts[$mode] ); |
| 342 | + // Add all scripts |
| 343 | + foreach ( $scripts as $script ) { |
| 344 | + UsabilityInitiativeHooks::addScript( 'WikiEditor/' . $script['src'], $script['version'] ); |
| 345 | + } |
| 346 | + // Preferences |
| 347 | + $wgOut->addScript( |
338 | 348 | Xml::tags( |
339 | 349 | 'script', |
340 | 350 | array( 'type' => $wgJsMimeType ), |
341 | | - '$.wikiEditor.config = {' . implode( ',', $preferencesList ) . '};' |
| 351 | + 'var wgWikiEditorPreferences = ' . FormatJson::encode( $preferences, true ) . ';' |
342 | 352 | ) |
343 | 353 | ); |
344 | | - */ |
345 | 354 | return true; |
346 | 355 | } |
347 | 356 | |
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.js |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +/* JavaScript for WikiEditor extension */ |
| 3 | + |
| 4 | +js2AddOnloadHook( function() { |
| 5 | + if ( $j.wikiEditor != undefined && $j.wikiEditor.isSupported() || !$j.wikiEditor.isSupportKnown() ) { |
| 6 | + $j( 'textarea#wpTextbox1' ).wikiEditor(); |
| 7 | + } |
| 8 | +} ); |
Property changes on: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 9 | + native |
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js |
— | — | @@ -2,8 +2,13 @@ |
3 | 3 | |
4 | 4 | js2AddOnloadHook( function() { |
5 | 5 | // Only show content generation dialogs if enabled |
6 | | - if ( typeof wgEditToolbarCGD != 'undefined' && wgEditToolbarCGD ) |
7 | | - $j( '#wpTextbox1' ).addClass( 'withCGD' ); |
| 6 | + if ( |
| 7 | + typeof wgWikiEditorPreferences !== 'undefined' |
| 8 | + && typeof wgWikiEditorPreferences.toolbar.dialogs !== 'undefined' |
| 9 | + && wgWikiEditorPreferences.toolbar.dialogs |
| 10 | + ) { |
| 11 | + $j( '#wpTextbox1' ).addClass( 'toolbar-dialogs' ); |
| 12 | + } |
8 | 13 | |
9 | 14 | if ( $j.wikiEditor != undefined && $j.wikiEditor.isSupported() || !$j.wikiEditor.isSupportKnown() ) { |
10 | 15 | // Remove the old toolbar |
— | — | @@ -55,7 +60,7 @@ |
56 | 61 | labelMsg: 'wikieditor-toolbar-tool-xlink', |
57 | 62 | type: 'button', |
58 | 63 | icon: 'insert-xlink.png', |
59 | | - filters: [ '#wpTextbox1:not(.withCGD)' ], |
| 64 | + filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ], |
60 | 65 | action: { |
61 | 66 | type: 'encapsulate', |
62 | 67 | options: { |
— | — | @@ -69,7 +74,7 @@ |
70 | 75 | labelMsg: 'wikieditor-toolbar-tool-ilink', |
71 | 76 | type: 'button', |
72 | 77 | icon: 'insert-ilink.png', |
73 | | - filters: [ '#wpTextbox1:not(.withCGD)' ], |
| 78 | + filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ], |
74 | 79 | action: { |
75 | 80 | type: 'encapsulate', |
76 | 81 | options: { |
— | — | @@ -83,7 +88,7 @@ |
84 | 89 | labelMsg: 'wikieditor-toolbar-tool-link', |
85 | 90 | type: 'button', |
86 | 91 | icon: 'insert-link.png', |
87 | | - filters: [ '#wpTextbox1.withCGD' ], |
| 92 | + filters: [ '#wpTextbox1.toolbar-dialogs' ], |
88 | 93 | action: { |
89 | 94 | type: 'dialog', |
90 | 95 | module: 'insert-link' |
— | — | @@ -329,7 +334,7 @@ |
330 | 335 | labelMsg: 'wikieditor-toolbar-tool-table', |
331 | 336 | type: 'button', |
332 | 337 | icon: 'insert-table.png', |
333 | | - filters: [ '#wpTextbox1.withCGD' ], |
| 338 | + filters: [ '#wpTextbox1.toolbar-dialogs' ], |
334 | 339 | action: { |
335 | 340 | type: 'dialog', |
336 | 341 | module: 'insert-table' |
— | — | @@ -339,7 +344,7 @@ |
340 | 345 | labelMsg: 'wikieditor-toolbar-tool-table', |
341 | 346 | type: 'button', |
342 | 347 | icon: 'insert-table.png', |
343 | | - filters: [ '#wpTextbox1:not(.withCGD)' ], |
| 348 | + filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ], |
344 | 349 | action: { |
345 | 350 | type: 'encapsulate', |
346 | 351 | options: { |
— | — | @@ -369,7 +374,7 @@ |
370 | 375 | labelMsg: 'wikieditor-toolbar-tool-replace', |
371 | 376 | type: 'button', |
372 | 377 | icon: 'search-replace.png', |
373 | | - filters: [ '#wpTextbox1.withCGD' ], |
| 378 | + filters: [ '#wpTextbox1.toolbar-dialogs' ], |
374 | 379 | action: { |
375 | 380 | type: 'dialog', |
376 | 381 | module: 'search-and-replace' |