Merge "Fix typo (seams => seems)"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.Uri.js
index b871ac7..bd12b21 100644 (file)
                 * @constructor
                 * @param {Object|String} URI string, or an Object with appropriate properties (especially another URI object to clone).
                 * Object must have non-blank 'protocol', 'host', and 'path' properties.
+                * This parameter is optional. If omitted (or set to undefined, null or empty string), then an object will be created
+                * for the default uri of this constructor (e.g. document.location for mw.Uri in MediaWiki core).
                 * @param {Object|Boolean} Object with options, or (backwards compatibility) a boolean for strictMode
                 * - strictMode {Boolean} Trigger strict mode parsing of the url. Default: false
                 * - overrideKeys {Boolean} Wether to let duplicate query parameters override eachother (true) or automagically
                                overrideKeys: false
                        }, options );
 
-                       if ( uri !== undefined && uri !== null || uri !== '' ) {
+                       if ( uri !== undefined && uri !== null && uri !== '' ) {
                                if ( typeof uri === 'string' ) {
                                        this.parse( uri, options );
                                } else if ( typeof uri === 'object' ) {
                                                this.query = {};
                                        }
                                }
+                       } else {
+                               // If we didn't get a URI in the constructor, use the default one.
+                               return defaultUri.clone();
                        }
 
                        // protocol-relative URLs
                                var args = [];
                                $.each( this.query, function ( key, val ) {
                                        var k = Uri.encode( key ),
-                                               vals = val === null ? [ null ] : $.makeArray( val );
+                                               vals = $.isArray( val ) ? val : [ val ];
                                        $.each( vals, function ( i, v ) {
                                                args.push( k + ( v === null ? '' : '=' + Uri.encode( v ) ) );
                                        } );
 
                defaultUri = new Uri( documentLocation );
 
-               return Uri;     
+               return Uri;
        };
 
        // if we are running in a browser, inject the current document location, for relative URLs
-       if ( document && document.location && document.location.href ) { 
+       if ( document && document.location && document.location.href ) {
                mw.Uri = mw.UriRelative( document.location.href );
        }