r58598 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58597‎ | r58598 | r58599 >
Date:18:52, 5 November 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Finished getting everything working with the unified loader - now we can start removing the old stuff.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.js (added) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.php
@@ -46,10 +46,10 @@
4747
4848 // Add Internationalized Messages
4949 $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';
5454
5555 // Register Hooks
5656 $wgHooks['EditPageBeforeEditToolbar'][] = 'WikiEditorHooks::addModules';
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php
@@ -8,6 +8,9 @@
99
1010 class WikiEditorHooks {
1111
 12+ static $scripts = array(
 13+ 'raw' => array( 'src' => 'WikiEditor.js', 'version' => 1 ),
 14+ );
1215 static $modules = array(
1316 'highlight' => array(
1417 'i18n' => 'WikiEditorHighlight',
@@ -22,7 +25,7 @@
2326 ),
2427 ),
2528 'scripts' => array(
26 - 'raw' => array( 'src' => 'Modules/Preview/Preview.js', 'version' => 1 ),
 29+ 'raw' => array( 'src' => 'Modules/Highlight/Highlight.js', 'version' => 1 ),
2730 ),
2831 ),
2932 'preview' => array(
@@ -61,8 +64,8 @@
6265 ),
6366 'variables' => array(
6467 // These are probably only for testing purposes?
65 - 'wgNavigableTOCCollapseEnable' => $wgNavigableTOCCollapseEnable,
66 - 'wgNavigableTOCResizable' => $wgNavigableTOCResizable
 68+ 'wgNavigableTOCCollapseEnable',
 69+ 'wgNavigableTOCResizable'
6770 ),
6871 'scripts' => array(
6972 'raw' => array( 'src' => 'Modules/Toc/Toc.js', 'version' => 1 ),
@@ -282,10 +285,13 @@
283286 * Adds the modules to the edit form
284287 */
285288 public static function addModules( &$toolbar ) {
286 - global $wgUser, $wgWikiEditorStyleVersion, $wgWikiEditorEnable, $wgUsabilityInitiativeResourceMode;
 289+ global $wgOut, $wgUser, $wgJsMimeType, $wgWikiEditorStyleVersion, $wgWikiEditorEnable, $wgUsabilityInitiativeResourceMode;
287290
 291+ // Modules
 292+ $scripts = array();
 293+ $enabled = false;
288294 $preferences = array();
289 - for ( $wgWikiEditorEnable as $module => $enable ) {
 295+ foreach ( $wgWikiEditorEnable as $module => $enable ) {
290296 if (
291297 $enable['global'] || (
292298 $enable['user']
@@ -293,16 +299,14 @@
294300 && $wgUser->getOption( self::$modules[$module]['preferences']['enable']['key'] )
295301 )
296302 ) {
 303+ $enabled = true;
297304 UsabilityInitiativeHooks::initialize();
298305 // Scripts
299306 $mode = $wgUsabilityInitiativeResourceMode;
300307 if ( !isset( self::$modules[$module]['scripts'][$mode] ) ) {
301308 $mode = 'raw';
302309 }
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];
307311 // Messages
308312 if ( isset( self::$modules[$module]['i18n'], self::$modules[$module]['messages'] ) ) {
309313 wfLoadExtensionMessages( self::$modules[$module]['i18n'] );
@@ -310,37 +314,42 @@
311315 }
312316 // Variables
313317 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 );
315324 }
316325 // Preferences
317 - $preferences[$module] = array();
318326 if ( isset( self::$modules[$module]['preferences'] ) ) {
319327 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();
322330 }
 331+ $preferences[$module][$name] = $wgUser->getOption( $preference['key'] );
323332 }
324333 }
325334 }
326335 }
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';
336340 }
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(
338348 Xml::tags(
339349 'script',
340350 array( 'type' => $wgJsMimeType ),
341 - '$.wikiEditor.config = {' . implode( ',', $preferencesList ) . '};'
 351+ 'var wgWikiEditorPreferences = ' . FormatJson::encode( $preferences, true ) . ';'
342352 )
343353 );
344 - */
345354 return true;
346355 }
347356
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
19 + native
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js
@@ -2,8 +2,13 @@
33
44 js2AddOnloadHook( function() {
55 // 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+ }
813
914 if ( $j.wikiEditor != undefined && $j.wikiEditor.isSupported() || !$j.wikiEditor.isSupportKnown() ) {
1015 // Remove the old toolbar
@@ -55,7 +60,7 @@
5661 labelMsg: 'wikieditor-toolbar-tool-xlink',
5762 type: 'button',
5863 icon: 'insert-xlink.png',
59 - filters: [ '#wpTextbox1:not(.withCGD)' ],
 64+ filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ],
6065 action: {
6166 type: 'encapsulate',
6267 options: {
@@ -69,7 +74,7 @@
7075 labelMsg: 'wikieditor-toolbar-tool-ilink',
7176 type: 'button',
7277 icon: 'insert-ilink.png',
73 - filters: [ '#wpTextbox1:not(.withCGD)' ],
 78+ filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ],
7479 action: {
7580 type: 'encapsulate',
7681 options: {
@@ -83,7 +88,7 @@
8489 labelMsg: 'wikieditor-toolbar-tool-link',
8590 type: 'button',
8691 icon: 'insert-link.png',
87 - filters: [ '#wpTextbox1.withCGD' ],
 92+ filters: [ '#wpTextbox1.toolbar-dialogs' ],
8893 action: {
8994 type: 'dialog',
9095 module: 'insert-link'
@@ -329,7 +334,7 @@
330335 labelMsg: 'wikieditor-toolbar-tool-table',
331336 type: 'button',
332337 icon: 'insert-table.png',
333 - filters: [ '#wpTextbox1.withCGD' ],
 338+ filters: [ '#wpTextbox1.toolbar-dialogs' ],
334339 action: {
335340 type: 'dialog',
336341 module: 'insert-table'
@@ -339,7 +344,7 @@
340345 labelMsg: 'wikieditor-toolbar-tool-table',
341346 type: 'button',
342347 icon: 'insert-table.png',
343 - filters: [ '#wpTextbox1:not(.withCGD)' ],
 348+ filters: [ '#wpTextbox1:not(.toolbar-dialogs)' ],
344349 action: {
345350 type: 'encapsulate',
346351 options: {
@@ -369,7 +374,7 @@
370375 labelMsg: 'wikieditor-toolbar-tool-replace',
371376 type: 'button',
372377 icon: 'search-replace.png',
373 - filters: [ '#wpTextbox1.withCGD' ],
 378+ filters: [ '#wpTextbox1.toolbar-dialogs' ],
374379 action: {
375380 type: 'dialog',
376381 module: 'search-and-replace'

Status & tagging log