http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88647

Revision: 88647
Author:   salvatoreingala
Date:     2011-05-23 16:36:33 +0000 (Mon, 23 May 2011)
Log Message:
-----------
- Fixed coding style issues in previous commits (r88282 & r88644)
- Using FormatJson::decode instead of decode_json

Modified Paths:
--------------
    branches/salvatoreingala/Gadgets/GadgetsAjax.php
    branches/salvatoreingala/Gadgets/Gadgets_body.php
    branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js

Modified: branches/salvatoreingala/Gadgets/GadgetsAjax.php
===================================================================
--- branches/salvatoreingala/Gadgets/GadgetsAjax.php    2011-05-23 16:32:52 UTC 
(rev 88646)
+++ branches/salvatoreingala/Gadgets/GadgetsAjax.php    2011-05-23 16:36:33 UTC 
(rev 88647)
@@ -32,14 +32,14 @@
                        return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 
'parseinline' );
                }
                
-               $prefs_json = Gadget::getGadgetPrefsDescription( $gadget );
+               $prefsJson = Gadget::getGadgetPrefsDescription( $gadget );
                
                //If $gadget doesn't exists or it doesn't have preferences, 
something is wrong
-               if ( $prefs_json === null || $prefs_json === '' ) {
+               if ( $prefsJson === null || $prefsJson === '' ) {
                        return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 
'parseinline' );
                }
                
-               $prefs = json_decode( $prefs_json, true );
+               $prefs = FormatJson::decode( $prefsJson, true );
                
                //If it's not valid JSON, signal an error
                if ( $prefs === null ) {

Modified: branches/salvatoreingala/Gadgets/Gadgets_body.php
===================================================================
--- branches/salvatoreingala/Gadgets/Gadgets_body.php   2011-05-23 16:32:52 UTC 
(rev 88646)
+++ branches/salvatoreingala/Gadgets/Gadgets_body.php   2011-05-23 16:36:33 UTC 
(rev 88647)
@@ -210,13 +210,13 @@
 
 
        //Mandatory arguments for any kind of preferences
-       private static $prefs_mandatory_args = array(
+       private static $prefsMandatoryArgs = array(
                        'type',
                        'default'
                );
 
        //Other mandatory arguments for specific types
-       private static $prefs_mandatory_args_by_type = array(
+       private static $prefsMandatoryArgsByType = array(
                        'select' => array( 'options' ),
                        'selectorother' => array( 'options' ),
                        'selectandother' => array( 'options' ),
@@ -548,26 +548,26 @@
        }
        
        
-       public static function isGadgetPrefsDescriptionValid( $prefs_json ) {
-               $prefs = json_decode( $prefs_json, true );
+       public static function isGadgetPrefsDescriptionValid( $prefsJson ) {
+               $prefs = FormatJson::decode( $prefsJson, true );
                
                if ( $prefs === null ) {
                        return false;
                }
                
                //TODO: improve validation
-               foreach ( $prefs as $option => $option_definition ) {
-                       foreach ( self::$prefs_mandatory_args as $arg ) {
-                               if ( !isset( $option_definition[$arg] ) ) {
+               foreach ( $prefs as $option => $optionDefinition ) {
+                       foreach ( self::$prefsMandatoryArgs as $arg ) {
+                               if ( !isset( $optionDefinition[$arg] ) ) {
                                        return false;
                                }
                        }
                        
                        $type = $option['type'];
                        
-                       if ( isset( self::$prefs_mandatory_args_by_type[$type] 
) ) {
-                               foreach ( 
self::$prefs_mandatory_args_by_type[$type] as $arg ) {
-                                       if ( !isset( $option_definition[$arg] ) 
) {
+                       if ( isset( self::$prefsMandatoryArgsByType[$type] ) ) {
+                               foreach ( 
self::$prefsMandatoryArgsByType[$type] as $arg ) {
+                                       if ( !isset( $optionDefinition[$arg] ) 
) {
                                                return false;
                                        }
                                }
@@ -582,26 +582,26 @@
        //         * '' if the gadget exists but doesn't have any preferences
        //         * the preference description in JSON format, otherwise
        public static function getGadgetPrefsDescription( $gadget ) {
-               $gadgets_list = Gadget::loadStructuredList();
-               foreach ( $gadgets_list as $section_name => $gadgets ) {
-                       foreach ( $gadgets as $gadget_name => $gadget_data ) {
-                               if ( $gadget_name == $gadget ) {
+               $gadgetsList = Gadget::loadStructuredList();
+               foreach ( $gadgetsList as $sectionName => $gadgets ) {
+                       foreach ( $gadgets as $gadgetName => $gadgetData ) {
+                               if ( $gadgetName == $gadget ) {
                                        //Gadget found; are there any prefs?
                                        
-                                       $prefs_msg = "Gadget-" . $gadget . 
".preferences";
+                                       $prefsMsg = "Gadget-" . $gadget . 
".preferences";
                                        
                                        //TODO: should we cache?
                                        
-                                       $prefs_json = wfMsgForContentNoTrans( 
$prefs_msg );
-                                       if ( wfEmptyMsg( $prefs_msg, 
$prefs_json ) ) {
+                                       $prefsJson = wfMsgForContentNoTrans( 
$prefsMsg );
+                                       if ( wfEmptyMsg( $prefsMsg, $prefsJson 
) ) {
                                                return null;
                                        }
                                        
-                                       if ( 
!self::isGadgetPrefsDescriptionValid( $prefs_json ) ){
+                                       if ( 
!self::isGadgetPrefsDescriptionValid( $prefsJson ) ){
                                                return '';
                                        }
                                        
-                                       return $prefs_json;
+                                       return $prefsJson;
                                }
                        }
                }
@@ -612,13 +612,13 @@
        public static function getUserPrefs( $user, $gadget ) {
                //TODO
                //for now, we just return defaults
-               $prefs_json = Gadget::getGadgetPrefsDescription( $gadget );
+               $prefsJson = Gadget::getGadgetPrefsDescription( $gadget );
                
-               if ( $prefs_json === null || $prefs_json === '' ) {
+               if ( $prefsJson === null || $prefsJson === '' ) {
                        return null;
                }
                
-               $prefs = json_decode( $prefs_json, true );
+               $prefs = FormatJson::decode( $prefsJson, true );
                
                $userPrefs = array();
                
@@ -684,14 +684,14 @@
        public function getScript( ResourceLoaderContext $context ) {
                global $wgUser;
                
-               $configurable_gadgets = array();
-               $gadgets_list = Gadget::loadStructuredList();
+               $configurableGadgets = array();
+               $gadgetsList = Gadget::loadStructuredList();
                
-               foreach ( $gadgets_list as $section_name => $gadgets ) {
+               foreach ( $gadgetsList as $sectionName => $gadgets ) {
                        foreach ( $gadgets as $gadget => $gadget_data ) {
                                $prefs = Gadget::getGadgetPrefsDescription( 
$gadget );
                                if ( $prefs !== null && $prefs !== '' ) {
-                                       $configurable_gadgets[] = $gadget;
+                                       $configurableGadgets[] = $gadget;
                                }
                        }
                }
@@ -700,7 +700,7 @@
                //create the mw.gadgets object
                $script = "mw.gadgets = {}\n";
                //needed by ext.gadgets.preferences.js
-               $script .= "mw.gadgets.configurableGadgets = " . 
Xml::encodeJsVar( $configurable_gadgets ) . ";\n";
+               $script .= "mw.gadgets.configurableGadgets = " . 
Xml::encodeJsVar( $configurableGadgets ) . ";\n";
                $script .= parent::getScript( $context );
                
                return $script;

Modified: branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js
===================================================================
--- branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js 
2011-05-23 16:32:52 UTC (rev 88646)
+++ branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js 
2011-05-23 16:36:33 UTC (rev 88647)
@@ -2,66 +2,66 @@
  * JavaScript tweaks for Special:Preferences
  */
 ( function( $, mw ) {
-  $( '#mw-htmlform-gadgets input[name="wpgadgets[]"]' ).each( function( idx, 
input ) {
-    var id = input.id;
-    var gadget = id.substr( "mw-input-wpgadgets-".length );
+       $( '#mw-htmlform-gadgets input[name="wpgadgets[]"]' ).each( function( 
idx, input ) {
+               var     id = input.id,
+                       gadget = id.substr( "mw-input-wpgadgets-".length );
 
-    if ( $.inArray( gadget, mw.gadgets.configurableGadgets ) != -1 ) {
-      var $span = $( '<span></span>' );
+               if ( $.inArray( gadget, mw.gadgets.configurableGadgets ) != -1 
) {
+                       var $span = $( '<span></span>' );
 
-      if ( !$( input ).is( ':checked' ) ) {
-        $span.hide();
-      }
+                       if ( !$( input ).is( ':checked' ) ) {
+                               $span.hide();
+                       }
 
-      var $link = $( '<a></a>' )
-              .text( "Configure" ) //TODO: use a message instead
-              .click( function() {
-                var post_data = 'action=ajax&rs=GadgetsAjax::getUI' +
-                                '&rsargs[]=gadget|' + encodeURIComponent( 
gadget );
-                // Send POST request via AJAX!
-                $.ajax( {
-                  url     : mw.config.get( 'wgScriptPath' ) + '/index.php',
-                  type    : "POST",
-                  data    : post_data,
-                  dataType: "html", // response type
-                  success : function( response ) {
-                    //Show dialog
-                    $( response ).dialog( {
-                      modal: true,
-                      width: 'auto',
-                      resizable: false,
-                      title: 'Configuration of ' + gadget, //TODO: use messages
-                      close: function() {
-                        $(this).dialog('destroy').empty(); //completely 
destroy on close
-                      },
-                      buttons: {
-                        //TODO: add "Restore defaults" button
-                        "Save": function() {
-                          //TODO
-                          alert( "I should save changes now, but I don't know 
how :'(..." );
-                        },
-                        "Cancel": function() {
-                          $( this ).dialog( "close" );
-                        }
-                      }
-                    } );
-                  },
-                  error   : function( response ) {
-                    //TODO
-                    alert( 'Something wrong happened' );
-                  },
-                } );
+                       var $link = $( '<a></a>' )
+                               .text( "Configure" ) //TODO: use a message 
instead
+                               .click( function() {
+                                       var postData = 
'action=ajax&rs=GadgetsAjax::getUI' +
+                                                       '&rsargs[]=gadget|' + 
encodeURIComponent( gadget );
+                                       // Send POST request via AJAX!
+                                       $.ajax( {
+                                               url: mw.config.get( 
'wgScriptPath' ) + '/index.php',
+                                               type: "POST",
+                                               data: postData,
+                                               dataType: "html", // response 
type
+                                               success : function( response ) {
+                                                       //Show dialog
+                                                       $( response ).dialog( {
+                                                               modal: true,
+                                                               width: 'auto',
+                                                               resizable: 
false,
+                                                               title: 
'Configuration of ' + gadget, //TODO: use messages
+                                                               close: 
function() {
+                                                                       
$(this).dialog('destroy').empty(); //completely destroy on close
+                                                               },
+                                                               buttons: {
+                                                                       //TODO: 
add "Restore defaults" button
+                                                                       "Save": 
function() {
+                                                                               
//TODO
+                                                                               
alert( "I should save changes now, but I don't know how :'(..." );
+                                                                       },
+                                                                       
"Cancel": function() {
+                                                                               
$( this ).dialog( "close" );
+                                                                       }
+                                                               }
+                                                       } );
+                                               },
+                                               error: function( response ) {
+                                                       //TODO
+                                                       alert( 'Something wrong 
happened' );
+                                               },
+                                       } );
 
-                return false; //prevent event propagation
-              } );
+                                       return false; //prevent event 
propagation
+                               } );
 
-      $span.append( "&nbsp;·&nbsp;", $link );
-      $( input ).next().append( $span );
+                       $span.append( "&nbsp;·&nbsp;", $link );
+                       $( input ).next().append( $span );
 
-      //Toggle visibility on click to the input
-      $( input ).click( function() {
-        $span.fadeToggle( 'fast' );
-      } );
-    }
-  } );
+                       //Toggle visibility on click to the input
+                       $( input ).click( function() {
+                               $span.fadeToggle( 'fast' );
+                       } );
+               }
+       } );
 } )( jQuery, mediaWiki );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to