r83537 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83536‎ | r83537 | r83538 >
Date:18:29, 8 March 2011
Author:neilk
Status:deferred
Tags:
Comment:
better isEmpty routine, remove useless isFull
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.Uri.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.Utilities.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.Utilities.js
@@ -3,42 +3,16 @@
44 ( function( mw ) {
55
66 /**
7 - * Check if an object is empty or if its an empty string.
 7+ * Check if a value is null, undefined, or the empty string.
88 *
99 * @param {Object} object Object to be checked
1010 * @return {Boolean}
1111 */
12 - mw.isEmpty = function( obj ) {
13 - if( typeof obj === 'string' ) {
14 - if( obj === '' ) return true;
15 - // Non empty string:
16 - return false;
17 - }
18 -
19 - // If an array check length:
20 - if( Object.prototype.toString.call( obj ) === "[object Array]"
21 - && obj.length === 0 ) {
22 - return true;
23 - }
24 -
25 - // Else check as an obj:
26 - for( var i in obj ) { return false; }
27 -
28 - // Else obj is empty:
29 - return true;
 12+ mw.isEmpty = function( o ) {
 13+ return ! mw.isDefined( o ) || o === null || ( typeof o === 'string' && o === '' );
3014 };
3115
3216 /**
33 - * Opposite of mw.isEmpty
34 - *
35 - * @param {Object} object Object to be checked
36 - * @return {Boolean}
37 - */
38 - mw.isFull = function( obj ) {
39 - return ! mw.isEmpty( obj );
40 - };
41 -
42 - /**
4317 * Check if something is defined
4418 * (inlineable?)
4519 * @param {Object}
Index: trunk/extensions/UploadWizard/resources/mw.Uri.js
@@ -58,7 +58,7 @@
5959 */
6060 mw.Uri = function( uri, strictMode ) {
6161 strictMode = !!strictMode;
62 - if ( mw.isFull( uri ) ) {
 62+ if ( !mw.isEmpty( uri ) ) {
6363 if ( typeof uri === 'string' ) {
6464 this._parse( uri, strictMode );
6565 } else if ( typeof uri === 'object' ) {
@@ -158,9 +158,9 @@
159159 */
160160 getUserInfo: function() {
161161 var userInfo = '';
162 - if ( mw.isFull( this.user ) ) {
 162+ if ( !mw.isEmpty( this.user ) ) {
163163 userInfo += this.encode( this.user );
164 - if ( mw.isFull( this.password ) ) {
 164+ if ( !mw.isEmpty( this.password ) ) {
165165 userInfo += ':' + this.encode( this.password );
166166 }
167167 }
@@ -173,8 +173,8 @@
174174 */
175175 getHostPort: function() {
176176 return this.host
177 - + ( mw.isFull( this.port ) ? ':' + this.port
178 - : ''
 177+ + ( !mw.isEmpty( this.port ) ? ':' + this.port
 178+ : ''
179179 );
180180 },
181181
@@ -185,8 +185,8 @@
186186 */
187187 getAuthority: function() {
188188 var userInfo = this.getUserInfo();
189 - return ( mw.isFull( userInfo ) ? userInfo + '@'
190 - : ''
 189+ return ( !mw.isEmpty( userInfo ) ? userInfo + '@'
 190+ : ''
191191 )
192192 + this.getHostPort();
193193 },
@@ -212,11 +212,11 @@
213213 getRelativePath: function() {
214214 var queryString = this.getQueryString();
215215 return this.path
216 - + ( mw.isFull( queryString ) ? '?' + queryString
217 - : ''
 216+ + ( !mw.isEmpty( queryString ) ? '?' + queryString
 217+ : ''
218218 )
219 - + ( mw.isFull( this.fragment ) ? '#' + this.encode( this.fragment )
220 - : ''
 219+ + ( !mw.isEmpty( this.fragment ) ? '#' + this.encode( this.fragment )
 220+ : ''
221221 );
222222 },
223223

Status & tagging log