r94260 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94259‎ | r94260 | r94261 >
Date:17:24, 11 August 2011
Author:hartman
Status:ok (Comments)
Tags:
Comment:
Remove 'private' version of mediawiki.Uri from MwEmbedSupport.
This may possibly break MwEmbedStandalone ? But who cares, it's about time this stuff gets out the door, let this be the point where we remove all the cruft.
Modified paths:
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/MwEmbedSupport.php (modified) (history)
  • /trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mediawiki/mediawiki.Uri.js (deleted) (history)

Diff [purge]

Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/MwEmbedSupport.php
@@ -36,8 +36,9 @@
3737 ),
3838 'mediawiki.UtilitiesTime' => array( 'scripts' => 'mediawiki/mediawiki.UtilitiesTime.js' ),
3939 'mediawiki.client' => array( 'scripts' => 'mediawiki/mediawiki.client.js' ),
40 - 'mediawiki.Uri' => array( 'scripts' => 'mediawiki/mediawiki.Uri.js' ),
41 - 'mediawiki.absoluteUrl' => array( 'scripts' => 'mediawiki/mediawiki.absoluteUrl.js' ),
 40+ 'mediawiki.absoluteUrl' => array( 'scripts' => 'mediawiki/mediawiki.absoluteUrl.js',
 41+ 'dependancies' => array( 'mediawiki.Uri' ),
 42+ ),
4243
4344 'mediawiki.language.parser' => array(
4445 'scripts'=> 'mediawiki/mediawiki.language.parser.js',
Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mediawiki/mediawiki.Uri.js
@@ -1,250 +0,0 @@
2 -/**
3 - * Library for simple URI parsing and manipulation. Requires jQuery.
4 - *
5 - * Do not expect full RFC 3986 compliance. Intended to be minimal, but featureful.
6 - * The use cases we have in mind are constructing 'next page' or 'previous page' URLs,
7 - * detecting whether we need to use cross-domain proxies for an API, constructing simple
8 - * URL-based API calls, etc.
9 - *
10 - * Intended to compress very well if you use a JS-parsing minifier.
11 - *
12 - * Dependencies: mw, mw.Utilities, jQuery
13 - *
14 - * Example:
15 - *
16 - * var uri = new mw.Uri( 'http://foo.com/mysite/mypage.php?quux=2' );
17 - *
18 - * if ( uri.host == 'foo.com' ) {
19 - * uri.host = 'www.foo.com';
20 - * uri.extend( { bar: 1 } );
21 - *
22 - * $( 'a#id1' ).setAttr( 'href', uri );
23 - * // anchor with id 'id1' now links to http://www.foo.com/mysite/mypage.php?bar=1&quux=2
24 - *
25 - * $( 'a#id2' ).setAttr( 'href', uri.clone().extend( { bar: 3, pif: 'paf' } ) );
26 - * // anchor with id 'id2' now links to http://www.foo.com/mysite/mypage.php?bar=3&quux=2&pif=paf
27 - * }
28 - *
29 - * Parsing here is regex based, so may not work on all URIs, but is good enough for most.
30 - *
31 - * Given a URI like
32 - * 'http://usr:pwd@www.test.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top':
33 - * The returned object will have the following properties:
34 - *
35 - * protocol 'http'
36 - * user 'usr'
37 - * password 'pwd'
38 - * host 'www.test.com'
39 - * port '81'
40 - * path '/dir/dir.2/index.htm'
41 - * query { q1: 0, test1: '', test2: 'value (escaped)' }
42 - * fragment 'top'
43 - *
44 - * n.b. 'password' is not technically allowed for HTTP URIs, but it is possible with other sorts of URIs.
45 - *
46 - * You can modify the properties directly. Then use the toString() method to extract the full URI string again.
47 - *
48 - * parsing based on parseUri 1.2.2 (c) Steven Levithan <stevenlevithan.com> MIT License
49 - * http://stevenlevithan.com/demo/parseuri/js/
50 - *
51 - */
52 -
53 -( function( mw, $ ) {
54 - /**
55 - * Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
56 - * @constructor
57 - * @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.
58 - * @param {Boolean} strict mode (when parsing a string)
59 - */
60 - mw.Uri = function( uri, strictMode ) {
61 - strictMode = !!strictMode;
62 - if ( mw.isFull( uri ) ) {
63 - if ( typeof uri === 'string' ) {
64 - this._parse( uri, strictMode );
65 - } else if ( typeof uri === 'object' ) {
66 - var _this = this;
67 - $.each( this._properties, function( i, property ) {
68 - _this[property] = uri[property];
69 - } );
70 - if ( ! mw.isDefined( this.query ) ) {
71 - this.query = {};
72 - }
73 - }
74 - }
75 - //if ( !( this.protocol && this.host && this.path ) ) {
76 - // throw new Error( "bad constructor arguments for " + uri);
77 - //}
78 - };
79 -
80 - mw.Uri.prototype = {
81 -
82 - /**
83 - * Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more compliant with RFC 3986
84 - * @param {String} string
85 - * @return {String} encoded for URI
86 - */
87 - encode: function( component ) {
88 - return encodeURIComponent( component )
89 - .replace( /!/g, '%21')
90 - .replace( /'/g, '%27')
91 - .replace( /\(/g, '%28')
92 - .replace( /\)/g, '%29')
93 - .replace( /\*/g, '%2A')
94 - .replace( /%20/g, '+' );
95 - },
96 -
97 - /**
98 - * Standard decodeURIComponent, with '+' to space
99 - * @param {String} string encoded for URI
100 - * @return {String} decoded string
101 - */
102 - decode: function( component ) {
103 - return decodeURIComponent( component ).replace( /\+/g, ' ' );
104 - },
105 -
106 - // regular expressions to parse many common URIs.
107 - // @private
108 - _parser: {
109 - strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
110 - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
111 - },
112 -
113 - /* the order here matches the order of captured matches in the above parser regexes */
114 - // @private
115 - _properties: [
116 - "protocol", // http
117 - "user", // usr
118 - "password", // pwd
119 - "host", // www.test.com
120 - "port", // 81
121 - "path", // /dir/dir.2/index.htm
122 - "query", // q1=0&&test1&test2=value (will become { q1: 0, test1: '', test2: 'value' } )
123 - "fragment" // top
124 - ],
125 -
126 - /**
127 - * Parse a string and set our properties accordingly.
128 - * @param {String} URI
129 - * @param {Boolean} strictness
130 - * @return {Boolean} success
131 - */
132 - _parse: function( str, strictMode ) {
133 - var matches = this._parser[ strictMode ? "strict" : "loose" ].exec( str );
134 - var uri = this;
135 - $.each( uri._properties, function( i, property ) {
136 - uri[ property ] = matches[ i+1 ];
137 - } );
138 -
139 - // uri.query starts out as the query string; we will parse it into key-val pairs then make
140 - // that object the "query" property.
141 - // we overwrite query in uri way to make cloning easier, it can use the same list of properties.
142 - var query = {};
143 - // using replace to iterate over a string
144 - // JS 1.3 - function as parameter to replace
145 - // Note: uri does not work with repeated parameter names (e.g. foo=1&foo=2 )
146 - if ( uri.query ) {
147 - uri.query.replace( /(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
148 - if ( $1 ) {
149 - query[ uri.decode( $1 ) ] = uri.decode( $2 );
150 - }
151 - } );
152 - }
153 - this.query = query;
154 - },
155 -
156 - /**
157 - * Returns user and password portion of a URI.
158 - * @return {String}
159 - */
160 - getUserInfo: function() {
161 - var userInfo = '';
162 - if ( mw.isFull( this.user ) ) {
163 - userInfo += this.encode( this.user );
164 - if ( mw.isFull( this.password ) ) {
165 - userInfo += ':' + this.encode( this.password );
166 - }
167 - }
168 - return userInfo;
169 - },
170 -
171 - /**
172 - * Gets host and port portion of a URI.
173 - * @return {String}
174 - */
175 - getHostPort: function() {
176 - return this.host
177 - + ( mw.isFull( this.port ) ? ':' + this.port
178 - : ''
179 - );
180 - },
181 -
182 - /**
183 - * Returns the userInfo and host and port portion of the URI.
184 - * In most real-world URLs, this is simply the hostname, but it is more general.
185 - * @return {String}
186 - */
187 - getAuthority: function() {
188 - var userInfo = this.getUserInfo();
189 - return ( mw.isFull( userInfo ) ? userInfo + '@'
190 - : ''
191 - )
192 - + this.getHostPort();
193 - },
194 -
195 - /**
196 - * Returns the query arguments of the URL, encoded into a string
197 - * Does not preserve the order of arguments passed into the URI. Does handle escaping.
198 - * @return {String}
199 - */
200 - getQueryString: function() {
201 - var pairs = [];
202 - var _this = this;
203 - $.each( this.query, function( key, value ) {
204 - pairs.push( _this.encode( key ) + '=' + _this.encode( value ) );
205 - } );
206 - return pairs.join( '&' );
207 - },
208 -
209 - /**
210 - * Returns everything after the authority section of the URI
211 - * @return {String}
212 - */
213 - getRelativePath: function() {
214 - var queryString = this.getQueryString();
215 - return this.path
216 - + ( mw.isFull( queryString ) ? '?' + queryString
217 - : ''
218 - )
219 - + ( mw.isFull( this.fragment ) ? '#' + this.encode( this.fragment )
220 - : ''
221 - );
222 - },
223 -
224 - /**
225 - * Gets the entire URI string. May not be precisely the same as input due to order of query arguments.
226 - * @return {String} the URI string
227 - */
228 - toString: function() {
229 - return this.protocol + '://' + this.getAuthority() + this.getRelativePath();
230 - },
231 -
232 - /**
233 - * Clone this URI
234 - * @return {Object} new URI object with same properties
235 - */
236 - clone: function() {
237 - return new mw.Uri( this );
238 - },
239 -
240 - /**
241 - * Extend the query -- supply query parameters to override or add to ours
242 - * @param {Object} query parameters in key-val form to override or add
243 - * @return {Object} this URI object
244 - */
245 - extend: function( parameters ) {
246 - $.extend( this.query, parameters );
247 - return this;
248 - }
249 - };
250 -
251 -} )( window.mediaWiki, jQuery );

Comments

#Comment by Mdale (talk | contribs)   15:02, 15 August 2011

thanks, should not have any adverse affects if the api for Mw.Uri did not change.

Status & tagging log