r94230 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94229‎ | r94230 | r94231 >
Date:04:09, 11 August 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Rename mw.uri to mw.Uri + minor fixes:

* Renaming mw.uri to mw.Uri (since it's a constructor)
* Leaked global variable 'g' in _parse() fixed
* Removing unused local variable '_this' in getQueryString()
* Fix documentation (jQuery 'setAttr' should be 'attar')
* Making non-private variables with '@private' comment, private (or "local").
* Using strict undefined comparison (shorter and faster, [[JSPERF]])
* Moving Resources definition from MediaWiki Page section to MediaWiki main section (to reflect directory structure)
* Coding style conventions (mixed spaces and tabs, line wrapping, double/single quotes)
* Remove passing mediaWiki to mw argument (mw is a global alias)
* Passes JSHint

* Removing 404 errors from UploadWizard/test/jasmine/SpecRunner.html

(Follows-up r93781 's move)
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.Api.js (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html (modified) (history)
  • /trunk/extensions/UploadWizard/test/jasmine/spec/mw.Api.edit.spec.js (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.Uri.js (added) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.uri.js (deleted) (history)
  • /trunk/phase3/tests/jasmine/SpecRunner.html (modified) (history)
  • /trunk/phase3/tests/jasmine/spec/mediawiki.Uri.spec.js (added) (history)
  • /trunk/phase3/tests/jasmine/spec/mediawiki.uri.spec.js (deleted) (history)

Diff [purge]

Index: trunk/phase3/tests/jasmine/SpecRunner.html
@@ -10,10 +10,10 @@
1111 <!-- include source files here... -->
1212 <script type="text/javascript" src="../../load.php?debug=true&lang=en&modules=jquery%7Cmediawiki&only=scripts&skin=vector"></script>
1313
14 - <script type="text/javascript" src="../../resources/mediawiki/mediawiki.uri.js"></script>
 14+ <script type="text/javascript" src="../../resources/mediawiki/mediawiki.Uri.js"></script>
1515
1616 <!-- include spec files here... -->
17 - <script type="text/javascript" src="spec/mediawiki.uri.spec.js"></script>
 17+ <script type="text/javascript" src="spec/mediawiki.Uri.spec.js"></script>
1818
1919 </head>
2020 <body>
Index: trunk/phase3/tests/jasmine/spec/mediawiki.uri.spec.js
@@ -1,274 +0,0 @@
2 -( function( mw ) {
3 -
4 - describe( "mw.uri", function() {
5 -
6 - describe( "should work well in loose and strict mode", function() {
7 -
8 - function basicTests( strict ) {
9 -
10 - describe( "should parse a simple HTTP URI correctly", function() {
11 -
12 - var uriString = 'http://www.ietf.org/rfc/rfc2396.txt';
13 - var uri;
14 - if ( strict ) {
15 - uri = new mw.uri( uriString, strict );
16 - } else {
17 - uri = new mw.uri( uriString );
18 - }
19 -
20 - it( "should have basic object properties", function() {
21 - expect( uri.protocol ).toEqual( 'http' );
22 - expect( uri.host ).toEqual( 'www.ietf.org' );
23 - expect( uri.port ).not.toBeDefined();
24 - expect( uri.path ).toEqual( '/rfc/rfc2396.txt' );
25 - expect( uri.query ).toEqual( {} );
26 - expect( uri.fragment ).not.toBeDefined();
27 - } );
28 -
29 - describe( "should construct composite components of URI on request", function() {
30 - it( "should have empty userinfo", function() {
31 - expect( uri.getUserInfo() ).toEqual( '' );
32 - } );
33 -
34 - it( "should have authority equal to host", function() {
35 - expect( uri.getAuthority() ).toEqual( 'www.ietf.org' );
36 - } );
37 -
38 - it( "should have hostport equal to host", function() {
39 - expect( uri.getHostPort() ).toEqual( 'www.ietf.org' );
40 - } );
41 -
42 - it( "should have empty string as query string", function() {
43 - expect( uri.getQueryString() ).toEqual( '' );
44 - } );
45 -
46 - it( "should have path as relative path", function() {
47 - expect( uri.getRelativePath() ).toEqual( '/rfc/rfc2396.txt' );
48 - } );
49 -
50 - it( "should return a uri string equivalent to original", function() {
51 - expect( uri.toString() ).toEqual( uriString );
52 - } );
53 - } );
54 - } );
55 - }
56 -
57 - describe( "should work in loose mode", function() {
58 - basicTests( false );
59 - } );
60 -
61 - describe( "should work in strict mode", function() {
62 - basicTests( true );
63 - } );
64 -
65 - } );
66 -
67 - it( "should parse a simple ftp URI correctly with user and password", function() {
68 - var uri = new mw.uri( 'ftp://usr:pwd@192.0.2.16/' );
69 - expect( uri.protocol ).toEqual( 'ftp' );
70 - expect( uri.user ).toEqual( 'usr' );
71 - expect( uri.password ).toEqual( 'pwd' );
72 - expect( uri.host ).toEqual( '192.0.2.16' );
73 - expect( uri.port ).not.toBeDefined();
74 - expect( uri.path ).toEqual( '/' );
75 - expect( uri.query ).toEqual( {} );
76 - expect( uri.fragment ).not.toBeDefined();
77 - } );
78 -
79 - it( "should parse a simple querystring", function() {
80 - var uri = new mw.uri( 'http://www.google.com/?q=uri' );
81 - expect( uri.protocol ).toEqual( 'http' );
82 - expect( uri.host ).toEqual( 'www.google.com' );
83 - expect( uri.port ).not.toBeDefined();
84 - expect( uri.path ).toEqual( '/' );
85 - expect( uri.query ).toBeDefined();
86 - expect( uri.query ).toEqual( { q: 'uri' } );
87 - expect( uri.fragment ).not.toBeDefined();
88 - expect( uri.getQueryString() ).toEqual( 'q=uri' );
89 - } );
90 -
91 - describe( "should handle multiple value query args", function() {
92 - var uri = new mw.uri( 'http://www.sample.com/dir/?m=foo&m=bar&n=1' );
93 - it ( "should parse with multiple values", function() {
94 - expect( uri.query.m.length ).toEqual( 2 );
95 - expect( uri.query.m[0] ).toEqual( 'foo' );
96 - expect( uri.query.m[1] ).toEqual( 'bar' );
97 - expect( uri.query.n ).toEqual( '1' );
98 - } );
99 - it ( "should accept multiple values", function() {
100 - uri.query.n = [ "x", "y", "z" ];
101 - expect( uri.toString() ).toContain( 'm=foo&m=bar' );
102 - expect( uri.toString() ).toContain( 'n=x&n=y&n=z' );
103 - expect( uri.toString().length ).toEqual( 'http://www.sample.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length );
104 - } );
105 - it ( "should be okay with removing values", function() {
106 - uri.query.m.splice( 0, 1 );
107 - delete uri.query.n;
108 - expect( uri.toString() ).toEqual( 'http://www.sample.com/dir/?m=bar' );
109 - uri.query.m.splice( 0, 1 );
110 - expect( uri.toString() ).toEqual( 'http://www.sample.com/dir/' );
111 - } );
112 - } );
113 -
114 - describe( "should deal with an all-dressed URI with everything", function() {
115 - var uri = new mw.uri( 'http://auth@www.sample.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top' );
116 -
117 - it( "should have basic object properties", function() {
118 - expect( uri.protocol ).toEqual( 'http' );
119 - expect( uri.user ).toEqual( 'auth' );
120 - expect( uri.password ).not.toBeDefined();
121 - expect( uri.host ).toEqual( 'www.sample.com' );
122 - expect( uri.port ).toEqual( '81' );
123 - expect( uri.path ).toEqual( '/dir/dir.2/index.htm' );
124 - expect( uri.query ).toEqual( { q1: '0', test1: null, test2: 'value (escaped)' } );
125 - expect( uri.fragment ).toEqual( 'top' );
126 - } );
127 -
128 - describe( "should construct composite components of URI on request", function() {
129 - it( "should have userinfo", function() {
130 - expect( uri.getUserInfo() ).toEqual( 'auth' );
131 - } );
132 -
133 - it( "should have authority equal to auth@hostport", function() {
134 - expect( uri.getAuthority() ).toEqual( 'auth@www.sample.com:81' );
135 - } );
136 -
137 - it( "should have hostport equal to host:port", function() {
138 - expect( uri.getHostPort() ).toEqual( 'www.sample.com:81' );
139 - } );
140 -
141 - it( "should have query string which contains all components", function() {
142 - var queryString = uri.getQueryString();
143 - expect( queryString ).toContain( 'q1=0' );
144 - expect( queryString ).toContain( 'test1' );
145 - expect( queryString ).not.toContain( 'test1=' );
146 - expect( queryString ).toContain( 'test2=value+%28escaped%29' );
147 - } );
148 -
149 - it( "should have path as relative path", function() {
150 - expect( uri.getRelativePath() ).toContain( uri.path );
151 - expect( uri.getRelativePath() ).toContain( uri.getQueryString() );
152 - expect( uri.getRelativePath() ).toContain( uri.fragment );
153 - } );
154 -
155 - } );
156 - } );
157 -
158 - describe( "should be able to clone itself", function() {
159 - var original = new mw.uri( 'http://en.wiki.local/w/api.php?action=query&foo=bar' );
160 - var clone = original.clone();
161 -
162 - it( "should make clones equivalent", function() {
163 - expect( original ).toEqual( clone );
164 - expect( original.toString() ).toEqual( clone.toString() );
165 - } );
166 -
167 - it( "should be able to manipulate clones independently", function() {
168 - // but they are still different objects
169 - expect( original ).not.toBe( clone );
170 - // and can diverge
171 - clone.host = 'fr.wiki.local';
172 - expect( original.host ).not.toEqual( clone.host );
173 - expect( original.toString() ).not.toEqual( clone.toString() );
174 - } );
175 - } );
176 -
177 - describe( "should be able to construct URL from object", function() {
178 - it ( "should construct given basic arguments", function() {
179 - var uri = new mw.uri( { protocol: 'http', host: 'www.foo.local', path: '/this' } );
180 - expect( uri.toString() ).toEqual( 'http://www.foo.local/this' );
181 - } );
182 -
183 - it ( "should construct given more complex arguments", function() {
184 - var uri = new mw.uri( {
185 - protocol: 'http',
186 - host: 'www.foo.local',
187 - path: '/this',
188 - query: { hi: 'there' },
189 - fragment: 'blah'
190 - } );
191 - expect( uri.toString() ).toEqual( 'http://www.foo.local/this?hi=there#blah' );
192 - } );
193 -
194 - it ( "should fail to construct without required properties", function() {
195 - expect( function() {
196 - var uri = new mw.uri( { protocol: 'http', host: 'www.foo.local' } );
197 - } ).toThrow( "bad constructor arguments" );
198 - } );
199 - } );
200 -
201 - describe( "should be able to manipulate properties", function() {
202 - var uri;
203 -
204 - beforeEach( function() {
205 - uri = new mw.uri( 'http://en.wiki.local/w/api.php' );
206 - } );
207 -
208 - it( "can add a fragment", function() {
209 - uri.fragment = 'frag';
210 - expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php#frag' );
211 - } );
212 -
213 - it( "can change host and port", function() {
214 - uri.host = 'fr.wiki.local';
215 - uri.port = '8080';
216 - expect( uri.toString() ).toEqual( 'http://fr.wiki.local:8080/w/api.php' );
217 - } );
218 -
219 - it ( "can add query arguments", function() {
220 - uri.query.foo = 'bar';
221 - expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
222 - } );
223 -
224 - it ( "can extend query arguments", function() {
225 - uri.query.foo = 'bar';
226 - expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
227 - uri.extend( { foo: 'quux', pif: 'paf' } );
228 - expect( uri.toString() ).toContain( 'foo=quux' );
229 - expect( uri.toString() ).not.toContain( 'foo=bar' );
230 - expect( uri.toString() ).toContain( 'pif=paf' );
231 - } );
232 -
233 - it ( "can remove query arguments", function() {
234 - uri.query.foo = 'bar';
235 - expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
236 - delete( uri.query.foo );
237 - expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php' );
238 - } );
239 -
240 - } );
241 -
242 - it( "should throw error on no arguments to constructor", function() {
243 - expect( function() {
244 - uri = new mw.uri();
245 - } ).toThrow( "bad constructor arguments" );
246 - } );
247 -
248 - it( "should throw error on empty string as argument to constructor", function() {
249 - expect( function() {
250 - uri = new mw.uri( '' );
251 - } ).toThrow( "bad constructor arguments" );
252 - } );
253 -
254 - it( "should throw error on non-URI as argument to constructor", function() {
255 - expect( function() {
256 - uri = new mw.uri( 'glaswegian penguins' );
257 - } ).toThrow( "bad constructor arguments" );
258 - } );
259 -
260 - it( "should throw error on improper URI as argument to constructor", function() {
261 - expect( function() {
262 - uri = new mw.uri( 'http:/foo.com' );
263 - } ).toThrow( "bad constructor arguments" );
264 - } );
265 -
266 - it( "should throw error on URI without protocol as argument to constructor", function() {
267 - expect( function() {
268 - uri = new mw.uri( 'foo.com/bar/baz' );
269 - } ).toThrow( "bad constructor arguments" );
270 - } );
271 -
272 -
273 - } );
274 -
275 -} )( mediaWiki );
Index: trunk/phase3/tests/jasmine/spec/mediawiki.Uri.spec.js
@@ -0,0 +1,274 @@
 2+( function() {
 3+
 4+ describe( "mw.Uri", function() {
 5+
 6+ describe( "should work well in loose and strict mode", function() {
 7+
 8+ function basicTests( strict ) {
 9+
 10+ describe( "should parse a simple HTTP URI correctly", function() {
 11+
 12+ var uriString = 'http://www.ietf.org/rfc/rfc2396.txt';
 13+ var uri;
 14+ if ( strict ) {
 15+ uri = new mw.Uri( uriString, strict );
 16+ } else {
 17+ uri = new mw.Uri( uriString );
 18+ }
 19+
 20+ it( "should have basic object properties", function() {
 21+ expect( uri.protocol ).toEqual( 'http' );
 22+ expect( uri.host ).toEqual( 'www.ietf.org' );
 23+ expect( uri.port ).not.toBeDefined();
 24+ expect( uri.path ).toEqual( '/rfc/rfc2396.txt' );
 25+ expect( uri.query ).toEqual( {} );
 26+ expect( uri.fragment ).not.toBeDefined();
 27+ } );
 28+
 29+ describe( "should construct composite components of URI on request", function() {
 30+ it( "should have empty userinfo", function() {
 31+ expect( uri.getUserInfo() ).toEqual( '' );
 32+ } );
 33+
 34+ it( "should have authority equal to host", function() {
 35+ expect( uri.getAuthority() ).toEqual( 'www.ietf.org' );
 36+ } );
 37+
 38+ it( "should have hostport equal to host", function() {
 39+ expect( uri.getHostPort() ).toEqual( 'www.ietf.org' );
 40+ } );
 41+
 42+ it( "should have empty string as query string", function() {
 43+ expect( uri.getQueryString() ).toEqual( '' );
 44+ } );
 45+
 46+ it( "should have path as relative path", function() {
 47+ expect( uri.getRelativePath() ).toEqual( '/rfc/rfc2396.txt' );
 48+ } );
 49+
 50+ it( "should return a uri string equivalent to original", function() {
 51+ expect( uri.toString() ).toEqual( uriString );
 52+ } );
 53+ } );
 54+ } );
 55+ }
 56+
 57+ describe( "should work in loose mode", function() {
 58+ basicTests( false );
 59+ } );
 60+
 61+ describe( "should work in strict mode", function() {
 62+ basicTests( true );
 63+ } );
 64+
 65+ } );
 66+
 67+ it( "should parse a simple ftp URI correctly with user and password", function() {
 68+ var uri = new mw.Uri( 'ftp://usr:pwd@192.0.2.16/' );
 69+ expect( uri.protocol ).toEqual( 'ftp' );
 70+ expect( uri.user ).toEqual( 'usr' );
 71+ expect( uri.password ).toEqual( 'pwd' );
 72+ expect( uri.host ).toEqual( '192.0.2.16' );
 73+ expect( uri.port ).not.toBeDefined();
 74+ expect( uri.path ).toEqual( '/' );
 75+ expect( uri.query ).toEqual( {} );
 76+ expect( uri.fragment ).not.toBeDefined();
 77+ } );
 78+
 79+ it( "should parse a simple querystring", function() {
 80+ var uri = new mw.Uri( 'http://www.google.com/?q=uri' );
 81+ expect( uri.protocol ).toEqual( 'http' );
 82+ expect( uri.host ).toEqual( 'www.google.com' );
 83+ expect( uri.port ).not.toBeDefined();
 84+ expect( uri.path ).toEqual( '/' );
 85+ expect( uri.query ).toBeDefined();
 86+ expect( uri.query ).toEqual( { q: 'uri' } );
 87+ expect( uri.fragment ).not.toBeDefined();
 88+ expect( uri.getQueryString() ).toEqual( 'q=uri' );
 89+ } );
 90+
 91+ describe( "should handle multiple value query args", function() {
 92+ var uri = new mw.Uri( 'http://www.sample.com/dir/?m=foo&m=bar&n=1' );
 93+ it ( "should parse with multiple values", function() {
 94+ expect( uri.query.m.length ).toEqual( 2 );
 95+ expect( uri.query.m[0] ).toEqual( 'foo' );
 96+ expect( uri.query.m[1] ).toEqual( 'bar' );
 97+ expect( uri.query.n ).toEqual( '1' );
 98+ } );
 99+ it ( "should accept multiple values", function() {
 100+ uri.query.n = [ "x", "y", "z" ];
 101+ expect( uri.toString() ).toContain( 'm=foo&m=bar' );
 102+ expect( uri.toString() ).toContain( 'n=x&n=y&n=z' );
 103+ expect( uri.toString().length ).toEqual( 'http://www.sample.com/dir/?m=foo&m=bar&n=x&n=y&n=z'.length );
 104+ } );
 105+ it ( "should be okay with removing values", function() {
 106+ uri.query.m.splice( 0, 1 );
 107+ delete uri.query.n;
 108+ expect( uri.toString() ).toEqual( 'http://www.sample.com/dir/?m=bar' );
 109+ uri.query.m.splice( 0, 1 );
 110+ expect( uri.toString() ).toEqual( 'http://www.sample.com/dir/' );
 111+ } );
 112+ } );
 113+
 114+ describe( "should deal with an all-dressed URI with everything", function() {
 115+ var uri = new mw.Uri( 'http://auth@www.sample.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top' );
 116+
 117+ it( "should have basic object properties", function() {
 118+ expect( uri.protocol ).toEqual( 'http' );
 119+ expect( uri.user ).toEqual( 'auth' );
 120+ expect( uri.password ).not.toBeDefined();
 121+ expect( uri.host ).toEqual( 'www.sample.com' );
 122+ expect( uri.port ).toEqual( '81' );
 123+ expect( uri.path ).toEqual( '/dir/dir.2/index.htm' );
 124+ expect( uri.query ).toEqual( { q1: '0', test1: null, test2: 'value (escaped)' } );
 125+ expect( uri.fragment ).toEqual( 'top' );
 126+ } );
 127+
 128+ describe( "should construct composite components of URI on request", function() {
 129+ it( "should have userinfo", function() {
 130+ expect( uri.getUserInfo() ).toEqual( 'auth' );
 131+ } );
 132+
 133+ it( "should have authority equal to auth@hostport", function() {
 134+ expect( uri.getAuthority() ).toEqual( 'auth@www.sample.com:81' );
 135+ } );
 136+
 137+ it( "should have hostport equal to host:port", function() {
 138+ expect( uri.getHostPort() ).toEqual( 'www.sample.com:81' );
 139+ } );
 140+
 141+ it( "should have query string which contains all components", function() {
 142+ var queryString = uri.getQueryString();
 143+ expect( queryString ).toContain( 'q1=0' );
 144+ expect( queryString ).toContain( 'test1' );
 145+ expect( queryString ).not.toContain( 'test1=' );
 146+ expect( queryString ).toContain( 'test2=value+%28escaped%29' );
 147+ } );
 148+
 149+ it( "should have path as relative path", function() {
 150+ expect( uri.getRelativePath() ).toContain( uri.path );
 151+ expect( uri.getRelativePath() ).toContain( uri.getQueryString() );
 152+ expect( uri.getRelativePath() ).toContain( uri.fragment );
 153+ } );
 154+
 155+ } );
 156+ } );
 157+
 158+ describe( "should be able to clone itself", function() {
 159+ var original = new mw.Uri( 'http://en.wiki.local/w/api.php?action=query&foo=bar' );
 160+ var clone = original.clone();
 161+
 162+ it( "should make clones equivalent", function() {
 163+ expect( original ).toEqual( clone );
 164+ expect( original.toString() ).toEqual( clone.toString() );
 165+ } );
 166+
 167+ it( "should be able to manipulate clones independently", function() {
 168+ // but they are still different objects
 169+ expect( original ).not.toBe( clone );
 170+ // and can diverge
 171+ clone.host = 'fr.wiki.local';
 172+ expect( original.host ).not.toEqual( clone.host );
 173+ expect( original.toString() ).not.toEqual( clone.toString() );
 174+ } );
 175+ } );
 176+
 177+ describe( "should be able to construct URL from object", function() {
 178+ it ( "should construct given basic arguments", function() {
 179+ var uri = new mw.Uri( { protocol: 'http', host: 'www.foo.local', path: '/this' } );
 180+ expect( uri.toString() ).toEqual( 'http://www.foo.local/this' );
 181+ } );
 182+
 183+ it ( "should construct given more complex arguments", function() {
 184+ var uri = new mw.Uri( {
 185+ protocol: 'http',
 186+ host: 'www.foo.local',
 187+ path: '/this',
 188+ query: { hi: 'there' },
 189+ fragment: 'blah'
 190+ } );
 191+ expect( uri.toString() ).toEqual( 'http://www.foo.local/this?hi=there#blah' );
 192+ } );
 193+
 194+ it ( "should fail to construct without required properties", function() {
 195+ expect( function() {
 196+ var uri = new mw.Uri( { protocol: 'http', host: 'www.foo.local' } );
 197+ } ).toThrow( "Bad constructor arguments" );
 198+ } );
 199+ } );
 200+
 201+ describe( "should be able to manipulate properties", function() {
 202+ var uri;
 203+
 204+ beforeEach( function() {
 205+ uri = new mw.Uri( 'http://en.wiki.local/w/api.php' );
 206+ } );
 207+
 208+ it( "can add a fragment", function() {
 209+ uri.fragment = 'frag';
 210+ expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php#frag' );
 211+ } );
 212+
 213+ it( "can change host and port", function() {
 214+ uri.host = 'fr.wiki.local';
 215+ uri.port = '8080';
 216+ expect( uri.toString() ).toEqual( 'http://fr.wiki.local:8080/w/api.php' );
 217+ } );
 218+
 219+ it ( "can add query arguments", function() {
 220+ uri.query.foo = 'bar';
 221+ expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
 222+ } );
 223+
 224+ it ( "can extend query arguments", function() {
 225+ uri.query.foo = 'bar';
 226+ expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
 227+ uri.extend( { foo: 'quux', pif: 'paf' } );
 228+ expect( uri.toString() ).toContain( 'foo=quux' );
 229+ expect( uri.toString() ).not.toContain( 'foo=bar' );
 230+ expect( uri.toString() ).toContain( 'pif=paf' );
 231+ } );
 232+
 233+ it ( "can remove query arguments", function() {
 234+ uri.query.foo = 'bar';
 235+ expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' );
 236+ delete( uri.query.foo );
 237+ expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php' );
 238+ } );
 239+
 240+ } );
 241+
 242+ it( "should throw error on no arguments to constructor", function() {
 243+ expect( function() {
 244+ uri = new mw.Uri();
 245+ } ).toThrow( "Bad constructor arguments" );
 246+ } );
 247+
 248+ it( "should throw error on empty string as argument to constructor", function() {
 249+ expect( function() {
 250+ uri = new mw.Uri( '' );
 251+ } ).toThrow( "Bad constructor arguments" );
 252+ } );
 253+
 254+ it( "should throw error on non-URI as argument to constructor", function() {
 255+ expect( function() {
 256+ uri = new mw.Uri( 'glaswegian penguins' );
 257+ } ).toThrow( "Bad constructor arguments" );
 258+ } );
 259+
 260+ it( "should throw error on improper URI as argument to constructor", function() {
 261+ expect( function() {
 262+ uri = new mw.Uri( 'http:/foo.com' );
 263+ } ).toThrow( "Bad constructor arguments" );
 264+ } );
 265+
 266+ it( "should throw error on URI without protocol as argument to constructor", function() {
 267+ expect( function() {
 268+ uri = new mw.Uri( 'foo.com/bar/baz' );
 269+ } ).toThrow( "Bad constructor arguments" );
 270+ } );
 271+
 272+
 273+ } );
 274+
 275+} )();
Property changes on: trunk/phase3/tests/jasmine/spec/mediawiki.Uri.spec.js
___________________________________________________________________
Added: svn:eol-style
1276 + native
Index: trunk/phase3/resources/Resources.php
@@ -460,6 +460,9 @@
461461 'mediawiki.Title' => array(
462462 'scripts' => 'resources/mediawiki/mediawiki.Title.js',
463463 ),
 464+ 'mediawiki.Uri' => array(
 465+ 'scripts' => 'resources/mediawiki/mediawiki.Uri.js',
 466+ ),
464467 'mediawiki.user' => array(
465468 'scripts' => 'resources/mediawiki/mediawiki.user.js',
466469 'dependencies' => array(
@@ -582,9 +585,6 @@
583586 'jquery.mwExtension',
584587 ),
585588 ),
586 - 'mediawiki.uri' => array(
587 - 'scripts' => 'resources/mediawiki/mediawiki.uri.js',
588 - ),
589589 'mediawiki.page.mwsuggest' => array(
590590 'scripts' => 'resources/mediawiki.page/mediawiki.page.mwsuggest.js',
591591 'dependencies' => array(
Index: trunk/phase3/resources/mediawiki/mediawiki.uri.js
@@ -1,261 +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, 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=&test3=value+%28escaped%29&r=1&r=2#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 {
42 - * q1: 0,
43 - * test1: null,
44 - * test2: '',
45 - * test3: 'value (escaped)'
46 - * r: [1, 2]
47 - * }
48 - * fragment 'top'
49 - *
50 - * n.b. 'password' is not technically allowed for HTTP URIs, but it is possible with other sorts of URIs.
51 - *
52 - * You can modify the properties directly. Then use the toString() method to extract the full URI string again.
53 - *
54 - * parsing based on parseUri 1.2.2 (c) Steven Levithan <stevenlevithan.com> MIT License
55 - * http://stevenlevithan.com/demo/parseuri/js/
56 - *
57 - */
58 -
59 -( function( mw, $ ) {
60 - /**
61 - * Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
62 - * @constructor
63 - * @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.
64 - * @param {Boolean} strict mode (when parsing a string)
65 - */
66 - mw.uri = function( uri, strictMode ) {
67 - strictMode = !!strictMode;
68 - if ( typeof uri !== 'undefined' && uri !== null || uri !== '' ) {
69 - if ( typeof uri === 'string' ) {
70 - this._parse( uri, strictMode );
71 - } else if ( typeof uri === 'object' ) {
72 - var _this = this;
73 - $.each( this._properties, function( i, property ) {
74 - _this[property] = uri[property];
75 - } );
76 - if ( typeof this.query === 'undefined' ) {
77 - this.query = {};
78 - }
79 - }
80 - }
81 - if ( !( this.protocol && this.host && this.path ) ) {
82 - throw new Error( "bad constructor arguments" );
83 - }
84 - };
85 -
86 - /**
87 - * Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more compliant with RFC 3986
88 - * Similar to rawurlencode from PHP and our JS library mw.util.rawurlencode, but we also replace space with a +
89 - * @param {String} string
90 - * @return {String} encoded for URI
91 - */
92 - mw.uri.encode = function( s ) {
93 - return encodeURIComponent( s )
94 - .replace( /!/g, '%21').replace( /'/g, '%27').replace( /\(/g, '%28')
95 - .replace( /\)/g, '%29').replace( /\*/g, '%2A')
96 - .replace( /%20/g, '+' );
97 - };
98 -
99 - /**
100 - * Standard decodeURIComponent, with '+' to space
101 - * @param {String} string encoded for URI
102 - * @return {String} decoded string
103 - */
104 - mw.uri.decode = function( s ) {
105 - return decodeURIComponent( s ).replace( /\+/g, ' ' );
106 - };
107 -
108 - /**
109 - * Function that's useful when constructing the URI string -- we frequently encounter the pattern of
110 - * having to add something to the URI as we go, but only if it's present, and to include a character before or after if so.
111 - * @param {String} to prepend, if value not empty
112 - * @param {String} value to include, if not empty
113 - * @param {String} to append, if value not empty
114 - * @param {Boolean} raw -- if true, do not URI encode
115 - * @return {String}
116 - */
117 - function _cat( pre, val, post, raw ) {
118 - if ( typeof val === 'undefined' || val === null || val === '' ) {
119 - return '';
120 - } else {
121 - return pre + ( raw ? val : mw.uri.encode( val ) ) + post;
122 - }
123 - }
124 -
125 - mw.uri.prototype = {
126 -
127 - // regular expressions to parse many common URIs.
128 - // @private
129 - _parser: {
130 - strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
131 - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
132 - },
133 -
134 - /* the order here matches the order of captured matches in the above parser regexes */
135 - // @private
136 - _properties: [
137 - "protocol", // http
138 - "user", // usr
139 - "password", // pwd
140 - "host", // www.test.com
141 - "port", // 81
142 - "path", // /dir/dir.2/index.htm
143 - "query", // q1=0&&test1&test2=value (will become { q1: 0, test1: '', test2: 'value' } )
144 - "fragment" // top
145 - ],
146 -
147 - /**
148 - * Parse a string and set our properties accordingly.
149 - * @param {String} URI
150 - * @param {Boolean} strictness
151 - * @return {Boolean} success
152 - */
153 - _parse: function( str, strictMode ) {
154 - var matches = this._parser[ strictMode ? "strict" : "loose" ].exec( str );
155 - var uri = this;
156 - $.each( uri._properties, function( i, property ) {
157 - uri[ property ] = matches[ i+1 ];
158 - } );
159 -
160 - // uri.query starts out as the query string; we will parse it into key-val pairs then make
161 - // that object the "query" property.
162 - // we overwrite query in uri way to make cloning easier, it can use the same list of properties.
163 - q = {};
164 - // using replace to iterate over a string
165 - if ( uri.query ) {
166 - uri.query.replace( /(?:^|&)([^&=]*)(?:(=)([^&]*))?/g, function ($0, $1, $2, $3) {
167 - if ( $1 ) {
168 - var k = mw.uri.decode( $1 );
169 - var v = ( $2 === '' || typeof $2 === 'undefined' ) ? null : mw.uri.decode( $3 );
170 - if ( typeof q[ k ] === 'string' ) {
171 - q[ k ] = [ q[ k ] ];
172 - }
173 - if ( typeof q[ k ] === 'object' ) {
174 - q[ k ].push( v );
175 - } else {
176 - q[ k ] = v;
177 - }
178 - }
179 - } );
180 - }
181 - this.query = q;
182 - },
183 -
184 - /**
185 - * Returns user and password portion of a URI.
186 - * @return {String}
187 - */
188 - getUserInfo: function() {
189 - return _cat( '', this.user, _cat( ':', this.password, '' ) );
190 - },
191 -
192 - /**
193 - * Gets host and port portion of a URI.
194 - * @return {String}
195 - */
196 - getHostPort: function() {
197 - return this.host + _cat( ':', this.port, '' );
198 - },
199 -
200 - /**
201 - * Returns the userInfo and host and port portion of the URI.
202 - * In most real-world URLs, this is simply the hostname, but it is more general.
203 - * @return {String}
204 - */
205 - getAuthority: function() {
206 - return _cat( '', this.getUserInfo(), '@' ) + this.getHostPort();
207 - },
208 -
209 - /**
210 - * Returns the query arguments of the URL, encoded into a string
211 - * Does not preserve the order of arguments passed into the URI. Does handle escaping.
212 - * @return {String}
213 - */
214 - getQueryString: function() {
215 - var args = [];
216 - var _this = this;
217 - $.each( this.query, function( key, val ) {
218 - var k = mw.uri.encode( key );
219 - var vals = val === null ? [ null ] : $.makeArray( val );
220 - $.each( vals, function( i, v ) {
221 - args.push( k + ( v === null ? '' : '=' + mw.uri.encode( v ) ) );
222 - } );
223 - } );
224 - return args.join( '&' );
225 - },
226 -
227 - /**
228 - * Returns everything after the authority section of the URI
229 - * @return {String}
230 - */
231 - getRelativePath: function() {
232 - return this.path + _cat( '?', this.getQueryString(), '', true ) + _cat( '#', this.fragment, '' );
233 - },
234 -
235 - /**
236 - * Gets the entire URI string. May not be precisely the same as input due to order of query arguments.
237 - * @return {String} the URI string
238 - */
239 - toString: function() {
240 - return this.protocol + '://' + this.getAuthority() + this.getRelativePath();
241 - },
242 -
243 - /**
244 - * Clone this URI
245 - * @return {Object} new URI object with same properties
246 - */
247 - clone: function() {
248 - return new mw.uri( this );
249 - },
250 -
251 - /**
252 - * Extend the query -- supply query parameters to override or add to ours
253 - * @param {Object} query parameters in key-val form to override or add
254 - * @return {Object} this URI object
255 - */
256 - extend: function( parameters ) {
257 - $.extend( this.query, parameters );
258 - return this;
259 - }
260 - };
261 -
262 -} )( window.mediaWiki, jQuery );
Index: trunk/phase3/resources/mediawiki/mediawiki.Uri.js
@@ -0,0 +1,260 @@
 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
 8+ * simple URL-based API calls, etc.
 9+ *
 10+ * Intended to compress very well if you use a JS-parsing minifier.
 11+ *
 12+ * Dependencies: mw, 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' ).attr( 'href', uri );
 23+ * // anchor with id 'id1' now links to http://foo.com/mysite/mypage.php?bar=1&quux=2
 24+ *
 25+ * $( 'a#id2' ).attr( 'href', uri.clone().extend( { bar: 3, pif: 'paf' } ) );
 26+ * // anchor with id 'id2' now links to http://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=&test3=value+%28escaped%29&r=1&r=2#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 {
 42+ * q1: 0,
 43+ * test1: null,
 44+ * test2: '',
 45+ * test3: 'value (escaped)'
 46+ * r: [1, 2]
 47+ * }
 48+ * fragment 'top'
 49+ *
 50+ * n.b. 'password' is not technically allowed for HTTP URIs, but it is possible with other
 51+ * sorts of URIs.
 52+ * You can modify the properties directly. Then use the toString() method to extract the
 53+ * full URI string again.
 54+ *
 55+ * Parsing based on parseUri 1.2.2 (c) Steven Levithan <stevenlevithan.com> MIT License
 56+ * http://stevenlevithan.com/demo/parseuri/js/
 57+ *
 58+ */
 59+
 60+( function( $ ) {
 61+
 62+ /**
 63+ * Function that's useful when constructing the URI string -- we frequently encounter the pattern of
 64+ * having to add something to the URI as we go, but only if it's present, and to include a character before or after if so.
 65+ * @param {String} to prepend, if value not empty
 66+ * @param {String} value to include, if not empty
 67+ * @param {String} to append, if value not empty
 68+ * @param {Boolean} raw -- if true, do not URI encode
 69+ * @return {String}
 70+ */
 71+ function cat( pre, val, post, raw ) {
 72+ if ( val === undefined || val === null || val === '' ) {
 73+ return '';
 74+ } else {
 75+ return pre + ( raw ? val : mw.Uri.encode( val ) ) + post;
 76+ }
 77+ }
 78+
 79+ // Regular expressions to parse many common URIs.
 80+ var parser = {
 81+ strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
 82+ loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
 83+ },
 84+
 85+ // The order here matches the order of captured matches in the above parser regexes.
 86+ properties = [
 87+ 'protocol', // http
 88+ 'user', // usr
 89+ 'password', // pwd
 90+ 'host', // www.test.com
 91+ 'port', // 81
 92+ 'path', // /dir/dir.2/index.htm
 93+ 'query', // q1=0&&test1&test2=value (will become { q1: 0, test1: '', test2: 'value' } )
 94+ 'fragment' // top
 95+ ];
 96+
 97+ /**
 98+ * Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
 99+ * @constructor
 100+ * @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.
 101+ * @param {Boolean} strict mode (when parsing a string)
 102+ */
 103+ mw.Uri = function( uri, strictMode ) {
 104+ strictMode = !!strictMode;
 105+ if ( uri !== undefined && uri !== null || uri !== '' ) {
 106+ if ( typeof uri === 'string' ) {
 107+ this._parse( uri, strictMode );
 108+ } else if ( typeof uri === 'object' ) {
 109+ var _this = this;
 110+ $.each( properties, function( i, property ) {
 111+ _this[property] = uri[property];
 112+ } );
 113+ if ( this.query === undefined ) {
 114+ this.query = {};
 115+ }
 116+ }
 117+ }
 118+ if ( !( this.protocol && this.host && this.path ) ) {
 119+ throw new Error( 'Bad constructor arguments' );
 120+ }
 121+ };
 122+
 123+ /**
 124+ * Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more compliant with RFC 3986
 125+ * Similar to rawurlencode from PHP and our JS library mw.util.rawurlencode, but we also replace space with a +
 126+ * @param {String} string
 127+ * @return {String} encoded for URI
 128+ */
 129+ mw.Uri.encode = function( s ) {
 130+ return encodeURIComponent( s )
 131+ .replace( /!/g, '%21').replace( /'/g, '%27').replace( /\(/g, '%28')
 132+ .replace( /\)/g, '%29').replace( /\*/g, '%2A')
 133+ .replace( /%20/g, '+' );
 134+ };
 135+
 136+ /**
 137+ * Standard decodeURIComponent, with '+' to space
 138+ * @param {String} string encoded for URI
 139+ * @return {String} decoded string
 140+ */
 141+ mw.Uri.decode = function( s ) {
 142+ return decodeURIComponent( s ).replace( /\+/g, ' ' );
 143+ };
 144+
 145+ mw.Uri.prototype = {
 146+
 147+ /**
 148+ * Parse a string and set our properties accordingly.
 149+ * @param {String} URI
 150+ * @param {Boolean} strictness
 151+ * @return {Boolean} success
 152+ */
 153+ _parse: function( str, strictMode ) {
 154+ var matches = parser[ strictMode ? 'strict' : 'loose' ].exec( str );
 155+ var uri = this;
 156+ $.each( properties, function( i, property ) {
 157+ uri[ property ] = matches[ i+1 ];
 158+ } );
 159+
 160+ // uri.query starts out as the query string; we will parse it into key-val pairs then make
 161+ // that object the "query" property.
 162+ // we overwrite query in uri way to make cloning easier, it can use the same list of properties.
 163+ var q = {};
 164+ // using replace to iterate over a string
 165+ if ( uri.query ) {
 166+ uri.query.replace( /(?:^|&)([^&=]*)(?:(=)([^&]*))?/g, function ($0, $1, $2, $3) {
 167+ if ( $1 ) {
 168+ var k = mw.Uri.decode( $1 );
 169+ var v = ( $2 === '' || $2 === undefined ) ? null : mw.Uri.decode( $3 );
 170+ if ( typeof q[ k ] === 'string' ) {
 171+ q[ k ] = [ q[ k ] ];
 172+ }
 173+ if ( typeof q[ k ] === 'object' ) {
 174+ q[ k ].push( v );
 175+ } else {
 176+ q[ k ] = v;
 177+ }
 178+ }
 179+ } );
 180+ }
 181+ this.query = q;
 182+ },
 183+
 184+ /**
 185+ * Returns user and password portion of a URI.
 186+ * @return {String}
 187+ */
 188+ getUserInfo: function() {
 189+ return cat( '', this.user, cat( ':', this.password, '' ) );
 190+ },
 191+
 192+ /**
 193+ * Gets host and port portion of a URI.
 194+ * @return {String}
 195+ */
 196+ getHostPort: function() {
 197+ return this.host + cat( ':', this.port, '' );
 198+ },
 199+
 200+ /**
 201+ * Returns the userInfo and host and port portion of the URI.
 202+ * In most real-world URLs, this is simply the hostname, but it is more general.
 203+ * @return {String}
 204+ */
 205+ getAuthority: function() {
 206+ return cat( '', this.getUserInfo(), '@' ) + this.getHostPort();
 207+ },
 208+
 209+ /**
 210+ * Returns the query arguments of the URL, encoded into a string
 211+ * Does not preserve the order of arguments passed into the URI. Does handle escaping.
 212+ * @return {String}
 213+ */
 214+ getQueryString: function() {
 215+ var args = [];
 216+ $.each( this.query, function( key, val ) {
 217+ var k = mw.Uri.encode( key );
 218+ var vals = val === null ? [ null ] : $.makeArray( val );
 219+ $.each( vals, function( i, v ) {
 220+ args.push( k + ( v === null ? '' : '=' + mw.Uri.encode( v ) ) );
 221+ } );
 222+ } );
 223+ return args.join( '&' );
 224+ },
 225+
 226+ /**
 227+ * Returns everything after the authority section of the URI
 228+ * @return {String}
 229+ */
 230+ getRelativePath: function() {
 231+ return this.path + cat( '?', this.getQueryString(), '', true ) + cat( '#', this.fragment, '' );
 232+ },
 233+
 234+ /**
 235+ * Gets the entire URI string. May not be precisely the same as input due to order of query arguments.
 236+ * @return {String} the URI string
 237+ */
 238+ toString: function() {
 239+ return this.protocol + '://' + this.getAuthority() + this.getRelativePath();
 240+ },
 241+
 242+ /**
 243+ * Clone this URI
 244+ * @return {Object} new URI object with same properties
 245+ */
 246+ clone: function() {
 247+ return new mw.Uri( this );
 248+ },
 249+
 250+ /**
 251+ * Extend the query -- supply query parameters to override or add to ours
 252+ * @param {Object} query parameters in key-val form to override or add
 253+ * @return {Object} this URI object
 254+ */
 255+ extend: function( parameters ) {
 256+ $.extend( this.query, parameters );
 257+ return this;
 258+ }
 259+ };
 260+
 261+} )( jQuery );
Property changes on: trunk/phase3/resources/mediawiki/mediawiki.Uri.js
___________________________________________________________________
Added: svn:eol-style
1262 + native
Index: trunk/extensions/UploadWizard/test/jasmine/SpecRunner.html
@@ -12,9 +12,9 @@
1313
1414 <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.js"></script>
1515 <script type="text/javascript" src="../../../../resources/mediawiki.language/mediawiki.language.js"></script>
 16+ <script type="text/javascript" src="../../../../resources/mediawiki/mediawiki.Uri.js"></script>
1617 <script type="text/javascript" src="../../resources/mediawiki.language.parser.js"></script>
1718 <script type="text/javascript" src="../../resources/mw.Utilities.js"></script>
18 - <script type="text/javascript" src="../../resources/mw.Uri.js"></script>
1919 <script type="text/javascript" src="../../resources/mw.Api.js"></script>
2020 <script type="text/javascript" src="../../resources/mw.Api.edit.js"></script>
2121 <script type="text/javascript" src="../../resources/mw.Title.js"></script>
@@ -25,7 +25,6 @@
2626
2727
2828 <!-- include spec files here... -->
29 - <script type="text/javascript" src="spec/mw.Uri.spec.js"></script>
3029 <script type="text/javascript" src="spec/mw.Api.spec.js"></script>
3130 <script type="text/javascript" src="spec/mw.Api.edit.spec.js"></script>
3231
Index: trunk/extensions/UploadWizard/test/jasmine/spec/mw.Api.edit.spec.js
@@ -17,9 +17,9 @@
1818 // TODO this only works for me (NeilK)
1919 var wgScriptPath = '/w';
2020
21 - var pageUri = new mw.uri( window.location );
 21+ var pageUri = new mw.Uri( window.location );
2222
23 - var apiUrl = new mw.uri( {
 23+ var apiUrl = new mw.Uri( {
2424 protocol: pageUri.protocol,
2525 host: pageUri.host,
2626 path: wgScriptPath + '/api.php'
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -24,7 +24,7 @@
2525 'jquery.suggestions',
2626 'jquery.ui.widget',
2727 'mediawiki.language',
28 - 'mediawiki.uri',
 28+ 'mediawiki.Uri',
2929 'mediawiki.util',
3030 'mediawiki.libs.jpegmeta',
3131 'ext.uploadwizard.mediawiki.language.parser',
Index: trunk/extensions/UploadWizard/resources/mw.Api.js
@@ -37,7 +37,7 @@
3838 },
3939
4040 ajax: {
41 - // force toString if we got a mw.uri object
 41+ // force toString if we got a mw.Uri object
4242 url: new String( this.url ),
4343
4444 /* default function for success and no API error */

Follow-up revisions

RevisionCommit summaryAuthorDate
r94325Apply lowerCamelCase to files for constructors as well....krinkle06:41, 12 August 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93781moving URI library to main resourcesneilk20:33, 2 August 2011

Comments

#Comment by TheDJ (talk | contribs)   17:10, 11 August 2011

mw.Uri from Core now conflicts with mw.Uri from extensions/MwEmbedSupport

#Comment by TheDJ (talk | contribs)   17:58, 11 August 2011

Fixed MwEmbed in r94260

#Comment by NeilK (talk | contribs)   19:37, 11 August 2011

We don't have a convention of capitalizing library names -- they are all lowerCamelCase. (I went out of my way to fix this before I committed it... :) Just checked with Trevor, he agrees. Can you change it back?

As for all the coding style conventions, so you renamed these files and made changes to them in the same commit? :( :( :(

Ah, you mean you fixed 'q' not 'g'...

Testing undefined: unfortunately it is possible to redefine undefined. () This can be be fixed if you fix the wrapper code:

(function($, undefined) {

   ...

} )(jQuery);

#Comment by NeilK (talk | contribs)   19:41, 11 August 2011

Just to be clear, I don't have a strong opinion on whether constructors have to start with a capital letter, it's just the filename of the library.

#Comment by Krinkle (talk | contribs)   06:22, 12 August 2011

Regarding constructors, right now in core we have mw.Map, mw.Title in public and User, Map and Message locally, so I just made it fit to that.

As for filenames I dont have a strong opinion, I think mediawiki.Title is currently the only one in our javascript tree that is a constructor and has it's own file. I kinda went with the way we did the PHP backend (classname inside filename), but lowerCamelCase makes sense as well.

So you mean that mediaWiki.FooBarBaz = function(){} would be defined in mediawiki.fooBarBaz.js ?

#Comment by Krinkle (talk | contribs)   06:46, 12 August 2011

We don't have a convention of capitalizing library names

Thanks, indeed not for filenames. The javascript constructor functions themselfs are all capitalized though.

I've renamed the files in r94325.

Testing undefined: I know undefined can be defined, and I'm okay with adding to the conventions that modules using undefined checks should be wrapped in that (just like jQuery does all the time). However since we haven't been doing that until now, I didn't make sense to start doing so in this commit. If we decide to do so, we'll have to change other modules as well.

#Comment by NeilK (talk | contribs)   13:51, 22 August 2011

ok with followups

Status & tagging log