r89482 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89481‎ | r89482 | r89483 >
Date:22:07, 4 June 2011
Author:salvatoreingala
Status:ok
Tags:
Comment:
- Added messages
- Several small fixes and improvements
Modified paths:
  • /branches/salvatoreingala/Gadgets (modified) (history)
  • /branches/salvatoreingala/Gadgets/Gadgets.i18n.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/Gadgets.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/Gadgets_body.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js (modified) (history)
  • /branches/salvatoreingala/Gadgets/modules/jquery.formBuilder.js (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/Gadgets_body.php
@@ -658,7 +658,7 @@
659659 $count = 0; //count of present mandatory members
660660 foreach ( $optionDefinition as $fieldName => $fieldValue ) {
661661
662 - if ( strcmp( $fieldName, 'type' ) == 0) {
 662+ if ( $fieldName == 'type' ) {
663663 continue; //'type' must not be checked
664664 }
665665
Property changes on: branches/salvatoreingala/Gadgets/Gadgets_body.php
___________________________________________________________________
Modified: svn:mergeinfo
666666 Merged /trunk/extensions/Gadgets/Gadgets_body.php:r88718-89450
Index: branches/salvatoreingala/Gadgets/Gadgets.i18n.php
@@ -43,9 +43,17 @@
4444 <pre>$2</pre>
4545 You must have appropriate permissions on destination wiki (including the right to edit system messages) and import from file uploads must be enabled.',
4646 'gadgets-export-download' => 'Download',
 47+ 'gadgets-configure' => 'Configure',
 48+ 'gadgets-configuration-of' => 'Configuration of $1',
 49+ 'gadgets-unexpected-error' => 'An unexpected error occurred. Please check your connection. If the problems persists, please contact the developers.',
 50+ 'gadgets-save-success' => 'Settings saved successfully.',
 51+ 'gadgets-save-failed' => 'Failed to save settings. If the problems persists, please contact the developers.',
4752 'gadgets-ajax-wrongparams' => 'An AJAX request with wrong parameters has been made; this is most likely a bug.',
4853 'gadgets-ajax-wrongsyntax' => 'There was an unexpected error while reading the saved gadget\'s configuration description.',
4954 'gadgets-ajax-unlogged' => 'This action is only allowed to registered, logged in users.',
 55+ 'gadgets-formbuilder-required' => 'This field is required.',
 56+ 'gadgets-formbuilder-minlength' => 'Please enter at least $1 characters.',
 57+ 'gadgets-formbuilder-maxlength' => 'Please enter no more than $1 characters.',
5058 );
5159
5260 /** Message documentation (Message documentation)
@@ -510,10 +518,14 @@
511519 'gadgets-pagetext' => 'Nedenstående er en liste med de specielle gadgets som brugere kan aktivere i deres [[Special:Preferences|indstillinger]], som defineret i [[MediaWiki:Gadgets-definition|definitionerne]].
512520 Denne oversigtsside giver simpel adgang til de beskedsider som definerer hver gadgets beskrivelse og kode.',
513521 'gadgets-uses' => 'Bruger',
 522+ 'gadgets-required-rights' => 'Kræver {{PLURAL:$2|rettigheden $1|følgende rettigheder: $1}}.',
514523 'gadgets-default' => 'Aktiveret for alle som standard.',
515524 'gadgets-export' => 'Eksporter',
516525 'gadgets-export-title' => 'Eksporter gadget',
517526 'gadgets-not-found' => 'Gadget "$1" ikke fundet.',
 527+ 'gadgets-export-text' => 'For at eksportere værktøjet $1, klik på knappen "{{int:gadgets-export-download}}", gem den downloadede fil, gå til Special:Import på destinationswikien og læg den op. Tilføj så følgende til siden MediaWiki:Gadgets-definition:
 528+<pre>$2</pre>
 529+Du skal have de nødvendige rettigheder på destinationswikien (herunder rettigheden til at redigere systemmeddelelser) og importering via oplægning af filer skal være slået til.',
518530 'gadgets-export-download' => 'Download',
519531 );
520532
Index: branches/salvatoreingala/Gadgets/Gadgets.php
@@ -63,7 +63,7 @@
6464 );
6565
6666 $wgResourceModules['jquery.validate'] = array(
67 - 'scripts' => array( 'jquery.validate.js' ), //TODO: include i18n scripts?
 67+ 'scripts' => array( 'jquery.validate.js' ),
6868 'dependencies' => array( 'jquery' ),
6969 'localBasePath' => $dir . 'modules/',
7070 'remoteExtPath' => 'Gadgets/modules'
@@ -72,13 +72,21 @@
7373 $wgResourceModules['jquery.formBuilder'] = array(
7474 'scripts' => array( 'jquery.formBuilder.js' ),
7575 'dependencies' => array( 'jquery', 'jquery.validate' ),
 76+ 'messages' => array( 'gadgets-formbuilder-required', 'gadgets-formbuilder-minlength', 'gadgets-formbuilder-maxlength' ),
7677 'localBasePath' => $dir . 'modules/',
7778 'remoteExtPath' => 'Gadgets/modules'
7879 );
7980
8081 $wgResourceModules['ext.gadgets.preferences'] = array(
8182 'scripts' => array( 'ext.gadgets.preferences.js' ),
82 - 'dependencies' => array( 'jquery', 'jquery.json', 'jquery.ui.dialog', 'jquery.formBuilder', 'mediawiki.htmlform', 'ext.gadgets' ),
 83+ 'dependencies' => array(
 84+ 'jquery', 'jquery.json', 'jquery.ui.dialog', 'jquery.formBuilder',
 85+ 'mediawiki.htmlform', 'ext.gadgets'
 86+ ),
 87+ 'messages' => array(
 88+ 'gadgets-configure', 'gadgets-configuration-of', 'gadgets-unexpected-error',
 89+ 'gadgets-save-success', 'gadgets-save-failed'
 90+ ),
8391 'localBasePath' => $dir . 'modules/',
8492 'remoteExtPath' => 'Gadgets/modules'
8593 );
Index: branches/salvatoreingala/Gadgets/modules/jquery.formBuilder.js
@@ -29,7 +29,7 @@
3030 function EmptyField( name, desc ) {
3131 //Check existence of compulsory fields
3232 if ( typeof name == 'undefined' || !desc.type || !desc.label ) {
33 - throw new Error( "Missing arguments" ); //TODO
 33+ $.error( "Missing arguments" );
3434 }
3535
3636 this.$p = $( '<p/>' );
@@ -80,7 +80,7 @@
8181 LabelField.call( this, name, desc );
8282
8383 if ( typeof desc.value != 'boolean' ) {
84 - throw new Error( "desc.value is invalid" );
 84+ $.error( "desc.value is invalid" );
8585 }
8686
8787 this.$c = $( '<input/>' )
@@ -104,7 +104,7 @@
105105 LabelField.call( this, name, desc );
106106
107107 if ( typeof desc.value != 'string' ) {
108 - throw new Error( "desc.value is invalid" );
 108+ $.error( "desc.value is invalid" );
109109 }
110110
111111 this.$text = $( '<input/>' )
@@ -121,8 +121,6 @@
122122 };
123123
124124 StringField.prototype.getValidationSettings = function() {
125 - //TODO: messages
126 -
127125 var settings = {
128126 rules: {}
129127 },
@@ -136,12 +134,20 @@
137135 fieldRules.required = true;
138136 }
139137
140 - if ( typeof desc.minLength != 'undefined' ) {
141 - fieldRules.minlength = desc.minLength;
 138+ if ( typeof desc.minlength != 'undefined' ) {
 139+ fieldRules.minlength = desc.minlength;
142140 }
143 - if ( typeof desc.maxLength != 'undefined' ) {
144 - fieldRules.maxlength = desc.maxLength;
 141+ if ( typeof desc.maxlength != 'undefined' ) {
 142+ fieldRules.maxlength = desc.maxlength;
145143 }
 144+
 145+ settings.messages = {};
 146+
 147+ settings.messages[fieldId] = {
 148+ "required": mw.msg( 'gadgets-formbuilder-required' ),
 149+ "minlength": mw.msg( 'gadgets-formbuilder-minlength', desc.minlength ),
 150+ "maxlength": mw.msg( 'gadgets-formbuilder-maxlength', desc.maxlength )
 151+ };
146152
147153 return settings;
148154 }
@@ -154,23 +160,17 @@
155161 "string" : StringField
156162 };
157163
158 - function log( message ) {
159 - if ( typeof window.console != 'undefined' ) {
160 - console.warn( message );
161 - }
162 - }
163 -
164164 function buildFormBody() {
165165 var description = this.get(0);
166 - if (typeof description != 'object' ) {
167 - log( "description should be an object, instead of a " + typeof description );
 166+ if ( typeof description != 'object' ) {
 167+ mw.log( "description should be an object, instead of a " + typeof description );
168168 return null;
169169 }
170170
171171 var $form = $( '<form/>' );
172172 var $fieldset = $( '<fieldset/>' ).appendTo( $form );
173173
174 - if (typeof description.label == 'string' ) {
 174+ if ( typeof description.label == 'string' ) {
175175 $( '<legend/>' )
176176 .text( $s( description.label ) )
177177 .appendTo( $fieldset );
@@ -178,8 +178,8 @@
179179
180180 //TODO: manage form params
181181
182 - if (typeof description.fields != 'object' ) {
183 - log( "description.fields should be an object, instead of a " + typeof description.fields );
 182+ if ( typeof description.fields != 'object' ) {
 183+ mw.log( "description.fields should be an object, instead of a " + typeof description.fields );
184184 return null;
185185 }
186186
@@ -197,14 +197,14 @@
198198 var FieldConstructor = validFields[field.type];
199199
200200 if ( typeof FieldConstructor != 'function' ) {
201 - log( "field with invalid type: " + field.type );
 201+ mw.log( "field with invalid type: " + field.type );
202202 return null;
203203 }
204204
205205 try {
206206 var f = new FieldConstructor( fieldName, field );
207207 } catch ( e ) {
208 - log( e );
 208+ mw.log( e );
209209 return null; //constructor failed, wrong syntax in field description
210210 }
211211
@@ -218,9 +218,6 @@
219219 }
220220
221221 fields.push( f );
222 -
223 - //TODO: validation of the field
224 -
225222 }
226223 }
227224
Index: branches/salvatoreingala/Gadgets/modules/ext.gadgets.preferences.js
@@ -18,16 +18,14 @@
1919 dataType: "json",
2020 success: function( response ) {
2121 if ( response === true ) {
22 - alert( 'Configuration saved successfully' );
 22+ alert( mw.msg( 'gadgets-save-success' ) );
2323 $dialog.dialog( 'close' );
2424 } else {
25 - //TODO
26 - alert( 'Something wrong happened' );
 25+ alert( mw.msg( 'gadgets-save-failed' ) );
2726 }
2827 },
2928 error: function( response ) {
30 - //TODO
31 - alert( 'Something wrong happened' );
 29+ alert( mw.msg( 'gadgets-save-failed' ) );
3230 }
3331 } );
3432 }
@@ -44,7 +42,7 @@
4543 }
4644
4745 var $link = $( '<a></a>' )
48 - .text( "Configure" ) //TODO: use a message instead
 46+ .text( mw.msg( 'gadgets-configure' ) )
4947 .click( function() {
5048 var postData = 'action=ajax&rs=GadgetsAjax::getPreferences' +
5149 '&rsargs[]=gadget|' + encodeURIComponent( gadget );
@@ -61,13 +59,16 @@
6260
6361 var dialogBody = $( response ).formBuilder();
6462
65 - //window.validator = $( dialogBody ).validate();
 63+ $( dialogBody ).submit( function() {
 64+ return false; //prevent form submission
 65+ } );
6666
 67+
6768 $( dialogBody ).dialog( {
6869 modal: true,
6970 width: 'auto',
7071 resizable: false,
71 - title: 'Configuration of ' + gadget, //TODO: use messages
 72+ title: mw.msg( 'gadgets-configuration-of', gadget ),
7273 close: function() {
7374 $( this ).dialog( 'destroy' ).empty(); //completely destroy on close
7475 },
@@ -89,8 +90,7 @@
9091 } );
9192 },
9293 error: function( response ) {
93 - //TODO
94 - alert( 'Something wrong happened' );
 94+ alert( mw.msg( 'gadgets-unexpected-error' ) );
9595 }
9696 } );
9797
Property changes on: branches/salvatoreingala/Gadgets
___________________________________________________________________
Modified: svn:mergeinfo
9898 Merged /trunk/extensions/Gadgets:r88718-89450

Status & tagging log