Index: branches/salvatoreingala/Gadgets/Gadgets_body.php |
— | — | @@ -210,13 +210,13 @@ |
211 | 211 | |
212 | 212 | |
213 | 213 | //Mandatory arguments for any kind of preferences |
214 | | - private static $prefs_mandatory_args = array( |
| 214 | + private static $prefsMandatoryArgs = array( |
215 | 215 | 'type', |
216 | 216 | 'default' |
217 | 217 | ); |
218 | 218 | |
219 | 219 | //Other mandatory arguments for specific types |
220 | | - private static $prefs_mandatory_args_by_type = array( |
| 220 | + private static $prefsMandatoryArgsByType = array( |
221 | 221 | 'select' => array( 'options' ), |
222 | 222 | 'selectorother' => array( 'options' ), |
223 | 223 | 'selectandother' => array( 'options' ), |
— | — | @@ -548,26 +548,26 @@ |
549 | 549 | } |
550 | 550 | |
551 | 551 | |
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 ); |
554 | 554 | |
555 | 555 | if ( $prefs === null ) { |
556 | 556 | return false; |
557 | 557 | } |
558 | 558 | |
559 | 559 | //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] ) ) { |
563 | 563 | return false; |
564 | 564 | } |
565 | 565 | } |
566 | 566 | |
567 | 567 | $type = $option['type']; |
568 | 568 | |
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] ) ) { |
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | } |
— | — | @@ -582,26 +582,26 @@ |
583 | 583 | // * '' if the gadget exists but doesn't have any preferences |
584 | 584 | // * the preference description in JSON format, otherwise |
585 | 585 | 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 ) { |
590 | 590 | //Gadget found; are there any prefs? |
591 | 591 | |
592 | | - $prefs_msg = "Gadget-" . $gadget . ".preferences"; |
| 592 | + $prefsMsg = "Gadget-" . $gadget . ".preferences"; |
593 | 593 | |
594 | 594 | //TODO: should we cache? |
595 | 595 | |
596 | | - $prefs_json = wfMsgForContentNoTrans( $prefs_msg ); |
597 | | - if ( wfEmptyMsg( $prefs_msg, $prefs_json ) ) { |
| 596 | + $prefsJson = wfMsgForContentNoTrans( $prefsMsg ); |
| 597 | + if ( wfEmptyMsg( $prefsMsg, $prefsJson ) ) { |
598 | 598 | return null; |
599 | 599 | } |
600 | 600 | |
601 | | - if ( !self::isGadgetPrefsDescriptionValid( $prefs_json ) ){ |
| 601 | + if ( !self::isGadgetPrefsDescriptionValid( $prefsJson ) ){ |
602 | 602 | return ''; |
603 | 603 | } |
604 | 604 | |
605 | | - return $prefs_json; |
| 605 | + return $prefsJson; |
606 | 606 | } |
607 | 607 | } |
608 | 608 | } |
— | — | @@ -612,13 +612,13 @@ |
613 | 613 | public static function getUserPrefs( $user, $gadget ) { |
614 | 614 | //TODO |
615 | 615 | //for now, we just return defaults |
616 | | - $prefs_json = Gadget::getGadgetPrefsDescription( $gadget ); |
| 616 | + $prefsJson = Gadget::getGadgetPrefsDescription( $gadget ); |
617 | 617 | |
618 | | - if ( $prefs_json === null || $prefs_json === '' ) { |
| 618 | + if ( $prefsJson === null || $prefsJson === '' ) { |
619 | 619 | return null; |
620 | 620 | } |
621 | 621 | |
622 | | - $prefs = json_decode( $prefs_json, true ); |
| 622 | + $prefs = FormatJson::decode( $prefsJson, true ); |
623 | 623 | |
624 | 624 | $userPrefs = array(); |
625 | 625 | |
— | — | @@ -684,14 +684,14 @@ |
685 | 685 | public function getScript( ResourceLoaderContext $context ) { |
686 | 686 | global $wgUser; |
687 | 687 | |
688 | | - $configurable_gadgets = array(); |
689 | | - $gadgets_list = Gadget::loadStructuredList(); |
| 688 | + $configurableGadgets = array(); |
| 689 | + $gadgetsList = Gadget::loadStructuredList(); |
690 | 690 | |
691 | | - foreach ( $gadgets_list as $section_name => $gadgets ) { |
| 691 | + foreach ( $gadgetsList as $sectionName => $gadgets ) { |
692 | 692 | foreach ( $gadgets as $gadget => $gadget_data ) { |
693 | 693 | $prefs = Gadget::getGadgetPrefsDescription( $gadget ); |
694 | 694 | if ( $prefs !== null && $prefs !== '' ) { |
695 | | - $configurable_gadgets[] = $gadget; |
| 695 | + $configurableGadgets[] = $gadget; |
696 | 696 | } |
697 | 697 | } |
698 | 698 | } |
— | — | @@ -700,7 +700,7 @@ |
701 | 701 | //create the mw.gadgets object |
702 | 702 | $script = "mw.gadgets = {}\n"; |
703 | 703 | //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"; |
705 | 705 | $script .= parent::getScript( $context ); |
706 | 706 | |
707 | 707 | return $script; |
Index: branches/salvatoreingala/Gadgets/GadgetsAjax.php |
— | — | @@ -32,14 +32,14 @@ |
33 | 33 | return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 'parseinline' ); |
34 | 34 | } |
35 | 35 | |
36 | | - $prefs_json = Gadget::getGadgetPrefsDescription( $gadget ); |
| 36 | + $prefsJson = Gadget::getGadgetPrefsDescription( $gadget ); |
37 | 37 | |
38 | 38 | //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 === '' ) { |
40 | 40 | return '<err#>' . wfMsgExt( 'gadgets-ajax-wrongparams', 'parseinline' ); |
41 | 41 | } |
42 | 42 | |
43 | | - $prefs = json_decode( $prefs_json, true ); |
| 43 | + $prefs = FormatJson::decode( $prefsJson, true ); |
44 | 44 | |
45 | 45 | //If it's not valid JSON, signal an error |
46 | 46 | if ( $prefs === null ) { |
Index: branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js |
— | — | @@ -2,66 +2,66 @@ |
3 | 3 | * JavaScript tweaks for Special:Preferences |
4 | 4 | */ |
5 | 5 | ( 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 ); |
9 | 9 | |
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>' ); |
12 | 12 | |
13 | | - if ( !$( input ).is( ':checked' ) ) { |
14 | | - $span.hide(); |
15 | | - } |
| 13 | + if ( !$( input ).is( ':checked' ) ) { |
| 14 | + $span.hide(); |
| 15 | + } |
16 | 16 | |
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 | + } ); |
55 | 55 | |
56 | | - return false; //prevent event propagation |
57 | | - } ); |
| 56 | + return false; //prevent event propagation |
| 57 | + } ); |
58 | 58 | |
59 | | - $span.append( " · ", $link ); |
60 | | - $( input ).next().append( $span ); |
| 59 | + $span.append( " · ", $link ); |
| 60 | + $( input ).next().append( $span ); |
61 | 61 | |
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 | + } ); |
68 | 68 | } )( jQuery, mediaWiki ); |