r88647 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88646‎ | r88647 | r88648 >
Date:16:36, 23 May 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
- Fixed coding style issues in previous commits (r88282 & r88644)
- Using FormatJson::decode instead of decode_json
Modified paths:
  • /branches/salvatoreingala/Gadgets/GadgetsAjax.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/Gadgets_body.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/Gadgets_body.php
@@ -210,13 +210,13 @@
211211
212212
213213 //Mandatory arguments for any kind of preferences
214 - private static $prefs_mandatory_args = array(
 214+ private static $prefsMandatoryArgs = array(
215215 'type',
216216 'default'
217217 );
218218
219219 //Other mandatory arguments for specific types
220 - private static $prefs_mandatory_args_by_type = array(
 220+ private static $prefsMandatoryArgsByType = array(
221221 'select' => array( 'options' ),
222222 'selectorother' => array( 'options' ),
223223 'selectandother' => array( 'options' ),
@@ -548,26 +548,26 @@
549549 }
550550
551551
552 - public static function isGadgetPrefsDescriptionValid( $prefs_json ) {
553 - $prefs = json_decode( $prefs_json, true );
 552+ public static function isGadgetPrefsDescriptionValid( $prefsJson ) {
 553+ $prefs = FormatJson::decode( $prefsJson, true );
554554
555555 if ( $prefs === null ) {
556556 return false;
557557 }
558558
559559 //TODO: improve validation
560 - foreach ( $prefs as $option => $option_definition ) {
561 - foreach ( self::$prefs_mandatory_args as $arg ) {
562 - if ( !isset( $option_definition[$arg] ) ) {
 560+ foreach ( $prefs as $option => $optionDefinition ) {
 561+ foreach ( self::$prefsMandatoryArgs as $arg ) {
 562+ if ( !isset( $optionDefinition[$arg] ) ) {
563563 return false;
564564 }
565565 }
566566
567567 $type = $option['type'];
568568
569 - if ( isset( self::$prefs_mandatory_args_by_type[$type] ) ) {
570 - foreach ( self::$prefs_mandatory_args_by_type[$type] as $arg ) {
571 - if ( !isset( $option_definition[$arg] ) ) {
 569+ if ( isset( self::$prefsMandatoryArgsByType[$type] ) ) {
 570+ foreach ( self::$prefsMandatoryArgsByType[$type] as $arg ) {
 571+ if ( !isset( $optionDefinition[$arg] ) ) {
572572 return false;
573573 }
574574 }
@@ -582,26 +582,26 @@
583583 // * '' if the gadget exists but doesn't have any preferences
584584 // * the preference description in JSON format, otherwise
585585 public static function getGadgetPrefsDescription( $gadget ) {
586 - $gadgets_list = Gadget::loadStructuredList();
587 - foreach ( $gadgets_list as $section_name => $gadgets ) {
588 - foreach ( $gadgets as $gadget_name => $gadget_data ) {
589 - if ( $gadget_name == $gadget ) {
 586+ $gadgetsList = Gadget::loadStructuredList();
 587+ foreach ( $gadgetsList as $sectionName => $gadgets ) {
 588+ foreach ( $gadgets as $gadgetName => $gadgetData ) {
 589+ if ( $gadgetName == $gadget ) {
590590 //Gadget found; are there any prefs?
591591
592 - $prefs_msg = "Gadget-" . $gadget . ".preferences";
 592+ $prefsMsg = "Gadget-" . $gadget . ".preferences";
593593
594594 //TODO: should we cache?
595595
596 - $prefs_json = wfMsgForContentNoTrans( $prefs_msg );
597 - if ( wfEmptyMsg( $prefs_msg, $prefs_json ) ) {
 596+ $prefsJson = wfMsgForContentNoTrans( $prefsMsg );
 597+ if ( wfEmptyMsg( $prefsMsg, $prefsJson ) ) {
598598 return null;
599599 }
600600
601 - if ( !self::isGadgetPrefsDescriptionValid( $prefs_json ) ){
 601+ if ( !self::isGadgetPrefsDescriptionValid( $prefsJson ) ){
602602 return '';
603603 }
604604
605 - return $prefs_json;
 605+ return $prefsJson;
606606 }
607607 }
608608 }
@@ -612,13 +612,13 @@
613613 public static function getUserPrefs( $user, $gadget ) {
614614 //TODO
615615 //for now, we just return defaults
616 - $prefs_json = Gadget::getGadgetPrefsDescription( $gadget );
 616+ $prefsJson = Gadget::getGadgetPrefsDescription( $gadget );
617617
618 - if ( $prefs_json === null || $prefs_json === '' ) {
 618+ if ( $prefsJson === null || $prefsJson === '' ) {
619619 return null;
620620 }
621621
622 - $prefs = json_decode( $prefs_json, true );
 622+ $prefs = FormatJson::decode( $prefsJson, true );
623623
624624 $userPrefs = array();
625625
@@ -684,14 +684,14 @@
685685 public function getScript( ResourceLoaderContext $context ) {
686686 global $wgUser;
687687
688 - $configurable_gadgets = array();
689 - $gadgets_list = Gadget::loadStructuredList();
 688+ $configurableGadgets = array();
 689+ $gadgetsList = Gadget::loadStructuredList();
690690
691 - foreach ( $gadgets_list as $section_name => $gadgets ) {
 691+ foreach ( $gadgetsList as $sectionName => $gadgets ) {
692692 foreach ( $gadgets as $gadget => $gadget_data ) {
693693 $prefs = Gadget::getGadgetPrefsDescription( $gadget );
694694 if ( $prefs !== null && $prefs !== '' ) {
695 - $configurable_gadgets[] = $gadget;
 695+ $configurableGadgets[] = $gadget;
696696 }
697697 }
698698 }
@@ -700,7 +700,7 @@
701701 //create the mw.gadgets object
702702 $script = "mw.gadgets = {}\n";
703703 //needed by ext.gadgets.preferences.js
704 - $script .= "mw.gadgets.configurableGadgets = " . Xml::encodeJsVar( $configurable_gadgets ) . ";\n";
 704+ $script .= "mw.gadgets.configurableGadgets = " . Xml::encodeJsVar( $configurableGadgets ) . ";\n";
705705 $script .= parent::getScript( $context );
706706
707707 return $script;
Index: branches/salvatoreingala/Gadgets/GadgetsAjax.php
@@ -32,14 +32,14 @@
3333 return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 'parseinline' );
3434 }
3535
36 - $prefs_json = Gadget::getGadgetPrefsDescription( $gadget );
 36+ $prefsJson = Gadget::getGadgetPrefsDescription( $gadget );
3737
3838 //If $gadget doesn't exists or it doesn't have preferences, something is wrong
39 - if ( $prefs_json === null || $prefs_json === '' ) {
 39+ if ( $prefsJson === null || $prefsJson === '' ) {
4040 return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 'parseinline' );
4141 }
4242
43 - $prefs = json_decode( $prefs_json, true );
 43+ $prefs = FormatJson::decode( $prefsJson, true );
4444
4545 //If it's not valid JSON, signal an error
4646 if ( $prefs === null ) {
Index: branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js
@@ -2,66 +2,66 @@
33 * JavaScript tweaks for Special:Preferences
44 */
55 ( function( $, mw ) {
6 - $( '#mw-htmlform-gadgets input[name="wpgadgets[]"]' ).each( function( idx, input ) {
7 - var id = input.id;
8 - var gadget = id.substr( "mw-input-wpgadgets-".length );
 6+ $( '#mw-htmlform-gadgets input[name="wpgadgets[]"]' ).each( function( idx, input ) {
 7+ var id = input.id,
 8+ gadget = id.substr( "mw-input-wpgadgets-".length );
99
10 - if ( $.inArray( gadget, mw.gadgets.configurableGadgets ) != -1 ) {
11 - var $span = $( '<span></span>' );
 10+ if ( $.inArray( gadget, mw.gadgets.configurableGadgets ) != -1 ) {
 11+ var $span = $( '<span></span>' );
1212
13 - if ( !$( input ).is( ':checked' ) ) {
14 - $span.hide();
15 - }
 13+ if ( !$( input ).is( ':checked' ) ) {
 14+ $span.hide();
 15+ }
1616
17 - var $link = $( '<a></a>' )
18 - .text( "Configure" ) //TODO: use a message instead
19 - .click( function() {
20 - var post_data = 'action=ajax&rs=GadgetsAjax::getUI' +
21 - '&rsargs[]=gadget|' + encodeURIComponent( gadget );
22 - // Send POST request via AJAX!
23 - $.ajax( {
24 - url : mw.config.get( 'wgScriptPath' ) + '/index.php',
25 - type : "POST",
26 - data : post_data,
27 - dataType: "html", // response type
28 - success : function( response ) {
29 - //Show dialog
30 - $( response ).dialog( {
31 - modal: true,
32 - width: 'auto',
33 - resizable: false,
34 - title: 'Configuration of ' + gadget, //TODO: use messages
35 - close: function() {
36 - $(this).dialog('destroy').empty(); //completely destroy on close
37 - },
38 - buttons: {
39 - //TODO: add "Restore defaults" button
40 - "Save": function() {
41 - //TODO
42 - alert( "I should save changes now, but I don't know how :'(..." );
43 - },
44 - "Cancel": function() {
45 - $( this ).dialog( "close" );
46 - }
47 - }
48 - } );
49 - },
50 - error : function( response ) {
51 - //TODO
52 - alert( 'Something wrong happened' );
53 - },
54 - } );
 17+ var $link = $( '<a></a>' )
 18+ .text( "Configure" ) //TODO: use a message instead
 19+ .click( function() {
 20+ var postData = 'action=ajax&rs=GadgetsAjax::getUI' +
 21+ '&rsargs[]=gadget|' + encodeURIComponent( gadget );
 22+ // Send POST request via AJAX!
 23+ $.ajax( {
 24+ url: mw.config.get( 'wgScriptPath' ) + '/index.php',
 25+ type: "POST",
 26+ data: postData,
 27+ dataType: "html", // response type
 28+ success : function( response ) {
 29+ //Show dialog
 30+ $( response ).dialog( {
 31+ modal: true,
 32+ width: 'auto',
 33+ resizable: false,
 34+ title: 'Configuration of ' + gadget, //TODO: use messages
 35+ close: function() {
 36+ $(this).dialog('destroy').empty(); //completely destroy on close
 37+ },
 38+ buttons: {
 39+ //TODO: add "Restore defaults" button
 40+ "Save": function() {
 41+ //TODO
 42+ alert( "I should save changes now, but I don't know how :'(..." );
 43+ },
 44+ "Cancel": function() {
 45+ $( this ).dialog( "close" );
 46+ }
 47+ }
 48+ } );
 49+ },
 50+ error: function( response ) {
 51+ //TODO
 52+ alert( 'Something wrong happened' );
 53+ },
 54+ } );
5555
56 - return false; //prevent event propagation
57 - } );
 56+ return false; //prevent event propagation
 57+ } );
5858
59 - $span.append( "&nbsp;·&nbsp;", $link );
60 - $( input ).next().append( $span );
 59+ $span.append( "&nbsp;·&nbsp;", $link );
 60+ $( input ).next().append( $span );
6161
62 - //Toggle visibility on click to the input
63 - $( input ).click( function() {
64 - $span.fadeToggle( 'fast' );
65 - } );
66 - }
67 - } );
 62+ //Toggle visibility on click to the input
 63+ $( input ).click( function() {
 64+ $span.fadeToggle( 'fast' );
 65+ } );
 66+ }
 67+ } );
6868 } )( jQuery, mediaWiki );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88644- Added code to get preference descriptions (from MediaWiki:Gadget-<gadgetnam...salvatoreingala15:07, 23 May 2011

Status & tagging log