MediaWiki REL1_28
HttpTest.php
Go to the documentation of this file.
1<?php
2
11 public function testValidateCookieDomain( $expected, $domain, $origin = null ) {
12 if ( $origin ) {
13 $ok = Cookie::validateCookieDomain( $domain, $origin );
14 $msg = "$domain against origin $origin";
15 } else {
16 $ok = Cookie::validateCookieDomain( $domain );
17 $msg = "$domain";
18 }
19 $this->assertEquals( $expected, $ok, $msg );
20 }
21
22 public static function cookieDomains() {
23 return [
24 [ false, "org" ],
25 [ false, ".org" ],
26 [ true, "wikipedia.org" ],
27 [ true, ".wikipedia.org" ],
28 [ false, "co.uk" ],
29 [ false, ".co.uk" ],
30 [ false, "gov.uk" ],
31 [ false, ".gov.uk" ],
32 [ true, "supermarket.uk" ],
33 [ false, "uk" ],
34 [ false, ".uk" ],
35 [ false, "127.0.0." ],
36 [ false, "127." ],
37 [ false, "127.0.0.1." ],
38 [ true, "127.0.0.1" ],
39 [ false, "333.0.0.1" ],
40 [ true, "example.com" ],
41 [ false, "example.com." ],
42 [ true, ".example.com" ],
43
44 [ true, ".example.com", "www.example.com" ],
45 [ false, "example.com", "www.example.com" ],
46 [ true, "127.0.0.1", "127.0.0.1" ],
47 [ false, "127.0.0.1", "localhost" ],
48 ];
49 }
50
57 public function testIsValidUri( $expect, $URI, $message = '' ) {
58 $this->assertEquals(
59 $expect,
60 (bool)Http::isValidURI( $URI ),
61 $message
62 );
63 }
64
68 public function testGetProxy() {
69 $this->setMwGlobals( 'wgHTTPProxy', 'proxy.domain.tld' );
70 $this->assertEquals(
71 'proxy.domain.tld',
72 Http::getProxy()
73 );
74 }
75
79 public static function provideURI() {
81 return [
82 [ false, '¿non sens before!! http://a', 'Allow anything before URI' ],
83
84 # (http|https) - only two schemes allowed
85 [ true, 'http://www.example.org/' ],
86 [ true, 'https://www.example.org/' ],
87 [ true, 'http://www.example.org', 'URI without directory' ],
88 [ true, 'http://a', 'Short name' ],
89 [ true, 'http://étoile', 'Allow UTF-8 in hostname' ], # 'étoile' is french for 'star'
90 [ false, '\\host\directory', 'CIFS share' ],
91 [ false, 'gopher://host/dir', 'Reject gopher scheme' ],
92 [ false, 'telnet://host', 'Reject telnet scheme' ],
93
94 # :\/\/ - double slashes
95 [ false, 'http//example.org', 'Reject missing colon in protocol' ],
96 [ false, 'http:/example.org', 'Reject missing slash in protocol' ],
97 [ false, 'http:example.org', 'Must have two slashes' ],
98 # Following fail since hostname can be made of anything
99 [ false, 'http:///example.org', 'Must have exactly two slashes, not three' ],
100
101 # (\w+:{0,1}\w*@)? - optional user:pass
102 [ true, 'http://user@host', 'Username provided' ],
103 [ true, 'http://user:@host', 'Username provided, no password' ],
104 [ true, 'http://user:pass@host', 'Username and password provided' ],
105
106 # (\S+) - host part is made of anything not whitespaces
107 // commented these out in order to remove @group Broken
108 // @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
109 // [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
110 // [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
111
112 # (:[0-9]+)? - port number
113 [ true, 'http://example.org:80/' ],
114 [ true, 'https://example.org:80/' ],
115 [ true, 'http://example.org:443/' ],
116 [ true, 'https://example.org:443/' ],
117
118 # Part after the hostname is / or / with something else
119 [ true, 'http://example/#' ],
120 [ true, 'http://example/!' ],
121 [ true, 'http://example/:' ],
122 [ true, 'http://example/.' ],
123 [ true, 'http://example/?' ],
124 [ true, 'http://example/+' ],
125 [ true, 'http://example/=' ],
126 [ true, 'http://example/&' ],
127 [ true, 'http://example/%' ],
128 [ true, 'http://example/@' ],
129 [ true, 'http://example/-' ],
130 [ true, 'http://example//' ],
131 [ true, 'http://example/&' ],
132
133 # Fragment
134 [ true, 'http://exam#ple.org', ], # This one is valid, really!
135 [ true, 'http://example.org:80#anchor' ],
136 [ true, 'http://example.org/?id#anchor' ],
137 [ true, 'http://example.org/?#anchor' ],
138
139 [ false, 'http://a ¿non !!sens after', 'Allow anything after URI' ],
140 ];
141 }
142
151 public function testRelativeRedirections() {
152 $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext', [], __METHOD__ );
153
154 # Forge a Location header
155 $h->setRespHeaders( 'location', [
156 'http://newsite/file.ext',
157 '/newfile.ext',
158 ]
159 );
160 # Verify we correctly fix the Location
161 $this->assertEquals(
162 'http://newsite/newfile.ext',
163 $h->getFinalUrl(),
164 "Relative file path Location: interpreted as full URL"
165 );
166
167 $h->setRespHeaders( 'location', [
168 'https://oldsite/file.ext'
169 ]
170 );
171 $this->assertEquals(
172 'https://oldsite/file.ext',
173 $h->getFinalUrl(),
174 "Location to the HTTPS version of the site"
175 );
176
177 $h->setRespHeaders( 'location', [
178 '/anotherfile.ext',
179 'http://anotherfile/hoster.ext',
180 'https://anotherfile/hoster.ext'
181 ]
182 );
183 $this->assertEquals(
184 'https://anotherfile/hoster.ext',
185 $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!" )
186 );
187 }
188
207 public function provideCurlConstants() {
208 return [
209 [ 'CURLAUTH_ANY' ],
210 [ 'CURLAUTH_ANYSAFE' ],
211 [ 'CURLAUTH_BASIC' ],
212 [ 'CURLAUTH_DIGEST' ],
213 [ 'CURLAUTH_GSSNEGOTIATE' ],
214 [ 'CURLAUTH_NTLM' ],
215 // [ 'CURLCLOSEPOLICY_CALLBACK' ], // removed in PHP 5.6.0
216 // [ 'CURLCLOSEPOLICY_LEAST_RECENTLY_USED' ], // removed in PHP 5.6.0
217 // [ 'CURLCLOSEPOLICY_LEAST_TRAFFIC' ], // removed in PHP 5.6.0
218 // [ 'CURLCLOSEPOLICY_OLDEST' ], // removed in PHP 5.6.0
219 // [ 'CURLCLOSEPOLICY_SLOWEST' ], // removed in PHP 5.6.0
220 [ 'CURLE_ABORTED_BY_CALLBACK' ],
221 [ 'CURLE_BAD_CALLING_ORDER' ],
222 [ 'CURLE_BAD_CONTENT_ENCODING' ],
223 [ 'CURLE_BAD_FUNCTION_ARGUMENT' ],
224 [ 'CURLE_BAD_PASSWORD_ENTERED' ],
225 [ 'CURLE_COULDNT_CONNECT' ],
226 [ 'CURLE_COULDNT_RESOLVE_HOST' ],
227 [ 'CURLE_COULDNT_RESOLVE_PROXY' ],
228 [ 'CURLE_FAILED_INIT' ],
229 [ 'CURLE_FILESIZE_EXCEEDED' ],
230 [ 'CURLE_FILE_COULDNT_READ_FILE' ],
231 [ 'CURLE_FTP_ACCESS_DENIED' ],
232 [ 'CURLE_FTP_BAD_DOWNLOAD_RESUME' ],
233 [ 'CURLE_FTP_CANT_GET_HOST' ],
234 [ 'CURLE_FTP_CANT_RECONNECT' ],
235 [ 'CURLE_FTP_COULDNT_GET_SIZE' ],
236 [ 'CURLE_FTP_COULDNT_RETR_FILE' ],
237 [ 'CURLE_FTP_COULDNT_SET_ASCII' ],
238 [ 'CURLE_FTP_COULDNT_SET_BINARY' ],
239 [ 'CURLE_FTP_COULDNT_STOR_FILE' ],
240 [ 'CURLE_FTP_COULDNT_USE_REST' ],
241 [ 'CURLE_FTP_PORT_FAILED' ],
242 [ 'CURLE_FTP_QUOTE_ERROR' ],
243 [ 'CURLE_FTP_SSL_FAILED' ],
244 [ 'CURLE_FTP_USER_PASSWORD_INCORRECT' ],
245 [ 'CURLE_FTP_WEIRD_227_FORMAT' ],
246 [ 'CURLE_FTP_WEIRD_PASS_REPLY' ],
247 [ 'CURLE_FTP_WEIRD_PASV_REPLY' ],
248 [ 'CURLE_FTP_WEIRD_SERVER_REPLY' ],
249 [ 'CURLE_FTP_WEIRD_USER_REPLY' ],
250 [ 'CURLE_FTP_WRITE_ERROR' ],
251 [ 'CURLE_FUNCTION_NOT_FOUND' ],
252 [ 'CURLE_GOT_NOTHING' ],
253 [ 'CURLE_HTTP_NOT_FOUND' ],
254 [ 'CURLE_HTTP_PORT_FAILED' ],
255 [ 'CURLE_HTTP_POST_ERROR' ],
256 [ 'CURLE_HTTP_RANGE_ERROR' ],
257 [ 'CURLE_LDAP_CANNOT_BIND' ],
258 [ 'CURLE_LDAP_INVALID_URL' ],
259 [ 'CURLE_LDAP_SEARCH_FAILED' ],
260 [ 'CURLE_LIBRARY_NOT_FOUND' ],
261 [ 'CURLE_MALFORMAT_USER' ],
262 [ 'CURLE_OBSOLETE' ],
263 [ 'CURLE_OK' ],
264 [ 'CURLE_OPERATION_TIMEOUTED' ],
265 [ 'CURLE_OUT_OF_MEMORY' ],
266 [ 'CURLE_PARTIAL_FILE' ],
267 [ 'CURLE_READ_ERROR' ],
268 [ 'CURLE_RECV_ERROR' ],
269 [ 'CURLE_SEND_ERROR' ],
270 [ 'CURLE_SHARE_IN_USE' ],
271 // [ 'CURLE_SSH' ], // not present in HHVM 3.3.0-dev
272 [ 'CURLE_SSL_CACERT' ],
273 [ 'CURLE_SSL_CERTPROBLEM' ],
274 [ 'CURLE_SSL_CIPHER' ],
275 [ 'CURLE_SSL_CONNECT_ERROR' ],
276 [ 'CURLE_SSL_ENGINE_NOTFOUND' ],
277 [ 'CURLE_SSL_ENGINE_SETFAILED' ],
278 [ 'CURLE_SSL_PEER_CERTIFICATE' ],
279 [ 'CURLE_TELNET_OPTION_SYNTAX' ],
280 [ 'CURLE_TOO_MANY_REDIRECTS' ],
281 [ 'CURLE_UNKNOWN_TELNET_OPTION' ],
282 [ 'CURLE_UNSUPPORTED_PROTOCOL' ],
283 [ 'CURLE_URL_MALFORMAT' ],
284 [ 'CURLE_URL_MALFORMAT_USER' ],
285 [ 'CURLE_WRITE_ERROR' ],
286 [ 'CURLFTPAUTH_DEFAULT' ],
287 [ 'CURLFTPAUTH_SSL' ],
288 [ 'CURLFTPAUTH_TLS' ],
289 // [ 'CURLFTPMETHOD_MULTICWD' ], // not present in HHVM 3.3.0-dev
290 // [ 'CURLFTPMETHOD_NOCWD' ], // not present in HHVM 3.3.0-dev
291 // [ 'CURLFTPMETHOD_SINGLECWD' ], // not present in HHVM 3.3.0-dev
292 [ 'CURLFTPSSL_ALL' ],
293 [ 'CURLFTPSSL_CONTROL' ],
294 [ 'CURLFTPSSL_NONE' ],
295 [ 'CURLFTPSSL_TRY' ],
296 // [ 'CURLINFO_CERTINFO' ], // not present in HHVM 3.3.0-dev
297 [ 'CURLINFO_CONNECT_TIME' ],
298 [ 'CURLINFO_CONTENT_LENGTH_DOWNLOAD' ],
299 [ 'CURLINFO_CONTENT_LENGTH_UPLOAD' ],
300 [ 'CURLINFO_CONTENT_TYPE' ],
301 [ 'CURLINFO_EFFECTIVE_URL' ],
302 [ 'CURLINFO_FILETIME' ],
303 [ 'CURLINFO_HEADER_OUT' ],
304 [ 'CURLINFO_HEADER_SIZE' ],
305 [ 'CURLINFO_HTTP_CODE' ],
306 [ 'CURLINFO_NAMELOOKUP_TIME' ],
307 [ 'CURLINFO_PRETRANSFER_TIME' ],
308 [ 'CURLINFO_PRIVATE' ],
309 [ 'CURLINFO_REDIRECT_COUNT' ],
310 [ 'CURLINFO_REDIRECT_TIME' ],
311 // [ 'CURLINFO_REDIRECT_URL' ], // not present in HHVM 3.3.0-dev
312 [ 'CURLINFO_REQUEST_SIZE' ],
313 [ 'CURLINFO_SIZE_DOWNLOAD' ],
314 [ 'CURLINFO_SIZE_UPLOAD' ],
315 [ 'CURLINFO_SPEED_DOWNLOAD' ],
316 [ 'CURLINFO_SPEED_UPLOAD' ],
317 [ 'CURLINFO_SSL_VERIFYRESULT' ],
318 [ 'CURLINFO_STARTTRANSFER_TIME' ],
319 [ 'CURLINFO_TOTAL_TIME' ],
320 [ 'CURLMSG_DONE' ],
321 [ 'CURLM_BAD_EASY_HANDLE' ],
322 [ 'CURLM_BAD_HANDLE' ],
323 [ 'CURLM_CALL_MULTI_PERFORM' ],
324 [ 'CURLM_INTERNAL_ERROR' ],
325 [ 'CURLM_OK' ],
326 [ 'CURLM_OUT_OF_MEMORY' ],
327 [ 'CURLOPT_AUTOREFERER' ],
328 [ 'CURLOPT_BINARYTRANSFER' ],
329 [ 'CURLOPT_BUFFERSIZE' ],
330 [ 'CURLOPT_CAINFO' ],
331 [ 'CURLOPT_CAPATH' ],
332 // [ 'CURLOPT_CERTINFO' ], // not present in HHVM 3.3.0-dev
333 // [ 'CURLOPT_CLOSEPOLICY' ], // removed in PHP 5.6.0
334 [ 'CURLOPT_CONNECTTIMEOUT' ],
335 [ 'CURLOPT_CONNECTTIMEOUT_MS' ],
336 [ 'CURLOPT_COOKIE' ],
337 [ 'CURLOPT_COOKIEFILE' ],
338 [ 'CURLOPT_COOKIEJAR' ],
339 [ 'CURLOPT_COOKIESESSION' ],
340 [ 'CURLOPT_CRLF' ],
341 [ 'CURLOPT_CUSTOMREQUEST' ],
342 [ 'CURLOPT_DNS_CACHE_TIMEOUT' ],
343 [ 'CURLOPT_DNS_USE_GLOBAL_CACHE' ],
344 [ 'CURLOPT_EGDSOCKET' ],
345 [ 'CURLOPT_ENCODING' ],
346 [ 'CURLOPT_FAILONERROR' ],
347 [ 'CURLOPT_FILE' ],
348 [ 'CURLOPT_FILETIME' ],
349 [ 'CURLOPT_FOLLOWLOCATION' ],
350 [ 'CURLOPT_FORBID_REUSE' ],
351 [ 'CURLOPT_FRESH_CONNECT' ],
352 [ 'CURLOPT_FTPAPPEND' ],
353 [ 'CURLOPT_FTPLISTONLY' ],
354 [ 'CURLOPT_FTPPORT' ],
355 [ 'CURLOPT_FTPSSLAUTH' ],
356 [ 'CURLOPT_FTP_CREATE_MISSING_DIRS' ],
357 // [ 'CURLOPT_FTP_FILEMETHOD' ], // not present in HHVM 3.3.0-dev
358 // [ 'CURLOPT_FTP_SKIP_PASV_IP' ], // not present in HHVM 3.3.0-dev
359 [ 'CURLOPT_FTP_SSL' ],
360 [ 'CURLOPT_FTP_USE_EPRT' ],
361 [ 'CURLOPT_FTP_USE_EPSV' ],
362 [ 'CURLOPT_HEADER' ],
363 [ 'CURLOPT_HEADERFUNCTION' ],
364 [ 'CURLOPT_HTTP200ALIASES' ],
365 [ 'CURLOPT_HTTPAUTH' ],
366 [ 'CURLOPT_HTTPGET' ],
367 [ 'CURLOPT_HTTPHEADER' ],
368 [ 'CURLOPT_HTTPPROXYTUNNEL' ],
369 [ 'CURLOPT_HTTP_VERSION' ],
370 [ 'CURLOPT_INFILE' ],
371 [ 'CURLOPT_INFILESIZE' ],
372 [ 'CURLOPT_INTERFACE' ],
373 [ 'CURLOPT_IPRESOLVE' ],
374 // [ 'CURLOPT_KEYPASSWD' ], // not present in HHVM 3.3.0-dev
375 [ 'CURLOPT_KRB4LEVEL' ],
376 [ 'CURLOPT_LOW_SPEED_LIMIT' ],
377 [ 'CURLOPT_LOW_SPEED_TIME' ],
378 [ 'CURLOPT_MAXCONNECTS' ],
379 [ 'CURLOPT_MAXREDIRS' ],
380 // [ 'CURLOPT_MAX_RECV_SPEED_LARGE' ], // not present in HHVM 3.3.0-dev
381 // [ 'CURLOPT_MAX_SEND_SPEED_LARGE' ], // not present in HHVM 3.3.0-dev
382 [ 'CURLOPT_NETRC' ],
383 [ 'CURLOPT_NOBODY' ],
384 [ 'CURLOPT_NOPROGRESS' ],
385 [ 'CURLOPT_NOSIGNAL' ],
386 [ 'CURLOPT_PORT' ],
387 [ 'CURLOPT_POST' ],
388 [ 'CURLOPT_POSTFIELDS' ],
389 [ 'CURLOPT_POSTQUOTE' ],
390 [ 'CURLOPT_POSTREDIR' ],
391 [ 'CURLOPT_PRIVATE' ],
392 [ 'CURLOPT_PROGRESSFUNCTION' ],
393 // [ 'CURLOPT_PROTOCOLS' ], // not present in HHVM 3.3.0-dev
394 [ 'CURLOPT_PROXY' ],
395 [ 'CURLOPT_PROXYAUTH' ],
396 [ 'CURLOPT_PROXYPORT' ],
397 [ 'CURLOPT_PROXYTYPE' ],
398 [ 'CURLOPT_PROXYUSERPWD' ],
399 [ 'CURLOPT_PUT' ],
400 [ 'CURLOPT_QUOTE' ],
401 [ 'CURLOPT_RANDOM_FILE' ],
402 [ 'CURLOPT_RANGE' ],
403 [ 'CURLOPT_READDATA' ],
404 [ 'CURLOPT_READFUNCTION' ],
405 // [ 'CURLOPT_REDIR_PROTOCOLS' ], // not present in HHVM 3.3.0-dev
406 [ 'CURLOPT_REFERER' ],
407 [ 'CURLOPT_RESUME_FROM' ],
408 [ 'CURLOPT_RETURNTRANSFER' ],
409 // [ 'CURLOPT_SSH_AUTH_TYPES' ], // not present in HHVM 3.3.0-dev
410 // [ 'CURLOPT_SSH_HOST_PUBLIC_KEY_MD5' ], // not present in HHVM 3.3.0-dev
411 // [ 'CURLOPT_SSH_PRIVATE_KEYFILE' ], // not present in HHVM 3.3.0-dev
412 // [ 'CURLOPT_SSH_PUBLIC_KEYFILE' ], // not present in HHVM 3.3.0-dev
413 [ 'CURLOPT_SSLCERT' ],
414 [ 'CURLOPT_SSLCERTPASSWD' ],
415 [ 'CURLOPT_SSLCERTTYPE' ],
416 [ 'CURLOPT_SSLENGINE' ],
417 [ 'CURLOPT_SSLENGINE_DEFAULT' ],
418 [ 'CURLOPT_SSLKEY' ],
419 [ 'CURLOPT_SSLKEYPASSWD' ],
420 [ 'CURLOPT_SSLKEYTYPE' ],
421 [ 'CURLOPT_SSLVERSION' ],
422 [ 'CURLOPT_SSL_CIPHER_LIST' ],
423 [ 'CURLOPT_SSL_VERIFYHOST' ],
424 [ 'CURLOPT_SSL_VERIFYPEER' ],
425 [ 'CURLOPT_STDERR' ],
426 [ 'CURLOPT_TCP_NODELAY' ],
427 [ 'CURLOPT_TIMECONDITION' ],
428 [ 'CURLOPT_TIMEOUT' ],
429 [ 'CURLOPT_TIMEOUT_MS' ],
430 [ 'CURLOPT_TIMEVALUE' ],
431 [ 'CURLOPT_TRANSFERTEXT' ],
432 [ 'CURLOPT_UNRESTRICTED_AUTH' ],
433 [ 'CURLOPT_UPLOAD' ],
434 [ 'CURLOPT_URL' ],
435 [ 'CURLOPT_USERAGENT' ],
436 [ 'CURLOPT_USERPWD' ],
437 [ 'CURLOPT_VERBOSE' ],
438 [ 'CURLOPT_WRITEFUNCTION' ],
439 [ 'CURLOPT_WRITEHEADER' ],
440 // [ 'CURLPROTO_ALL' ], // not present in HHVM 3.3.0-dev
441 // [ 'CURLPROTO_DICT' ], // not present in HHVM 3.3.0-dev
442 // [ 'CURLPROTO_FILE' ], // not present in HHVM 3.3.0-dev
443 // [ 'CURLPROTO_FTP' ], // not present in HHVM 3.3.0-dev
444 // [ 'CURLPROTO_FTPS' ], // not present in HHVM 3.3.0-dev
445 // [ 'CURLPROTO_HTTP' ], // not present in HHVM 3.3.0-dev
446 // [ 'CURLPROTO_HTTPS' ], // not present in HHVM 3.3.0-dev
447 // [ 'CURLPROTO_LDAP' ], // not present in HHVM 3.3.0-dev
448 // [ 'CURLPROTO_LDAPS' ], // not present in HHVM 3.3.0-dev
449 // [ 'CURLPROTO_SCP' ], // not present in HHVM 3.3.0-dev
450 // [ 'CURLPROTO_SFTP' ], // not present in HHVM 3.3.0-dev
451 // [ 'CURLPROTO_TELNET' ], // not present in HHVM 3.3.0-dev
452 // [ 'CURLPROTO_TFTP' ], // not present in HHVM 3.3.0-dev
453 [ 'CURLPROXY_HTTP' ],
454 // [ 'CURLPROXY_SOCKS4' ], // not present in HHVM 3.3.0-dev
455 [ 'CURLPROXY_SOCKS5' ],
456 // [ 'CURLSSH_AUTH_DEFAULT' ], // not present in HHVM 3.3.0-dev
457 // [ 'CURLSSH_AUTH_HOST' ], // not present in HHVM 3.3.0-dev
458 // [ 'CURLSSH_AUTH_KEYBOARD' ], // not present in HHVM 3.3.0-dev
459 // [ 'CURLSSH_AUTH_NONE' ], // not present in HHVM 3.3.0-dev
460 // [ 'CURLSSH_AUTH_PASSWORD' ], // not present in HHVM 3.3.0-dev
461 // [ 'CURLSSH_AUTH_PUBLICKEY' ], // not present in HHVM 3.3.0-dev
462 [ 'CURLVERSION_NOW' ],
463 [ 'CURL_HTTP_VERSION_1_0' ],
464 [ 'CURL_HTTP_VERSION_1_1' ],
465 [ 'CURL_HTTP_VERSION_NONE' ],
466 [ 'CURL_IPRESOLVE_V4' ],
467 [ 'CURL_IPRESOLVE_V6' ],
468 [ 'CURL_IPRESOLVE_WHATEVER' ],
469 [ 'CURL_NETRC_IGNORED' ],
470 [ 'CURL_NETRC_OPTIONAL' ],
471 [ 'CURL_NETRC_REQUIRED' ],
472 [ 'CURL_TIMECOND_IFMODSINCE' ],
473 [ 'CURL_TIMECOND_IFUNMODSINCE' ],
474 [ 'CURL_TIMECOND_LASTMOD' ],
475 [ 'CURL_VERSION_IPV6' ],
476 [ 'CURL_VERSION_KERBEROS4' ],
477 [ 'CURL_VERSION_LIBZ' ],
478 [ 'CURL_VERSION_SSL' ],
479 ];
480 }
481
489 public function testCurlConstants( $value ) {
490 $this->assertTrue( defined( $value ), $value . ' not defined' );
491 }
492}
493
498 // function derived from the MWHttpRequest factory function but
499 // returns appropriate tester class here
500 public static function factory( $url, $options = null, $caller = __METHOD__ ) {
501 if ( !Http::$httpEngine ) {
502 Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
503 } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
504 throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
505 'Http::$httpEngine is set to "curl"' );
506 }
507
508 switch ( Http::$httpEngine ) {
509 case 'curl':
510 return new CurlHttpRequestTester( $url, $options, $caller );
511 case 'php':
512 if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
513 throw new MWException( __METHOD__ .
514 ': allow_url_fopen needs to be enabled for pure PHP HTTP requests to work. '
515 . 'If possible, curl should be used instead. See http://php.net/curl.' );
516 }
517
518 return new PhpHttpRequestTester( $url, $options, $caller );
519 default:
520 }
521 }
522}
523
525 function setRespHeaders( $name, $value ) {
526 $this->respHeaders[$name] = $value;
527 }
528}
529
531 function setRespHeaders( $name, $value ) {
532 $this->respHeaders[$name] = $value;
533 }
534}
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
static validateCookieDomain( $domain, $originDomain=null)
Return the true if the cookie is valid is valid.
Definition Cookie.php:92
setRespHeaders( $name, $value)
Definition HttpTest.php:525
MWHttpRequest implemented using internal curl compiled into PHP.
Http.
Definition HttpTest.php:6
testCurlConstants( $value)
Added this test based on an issue experienced with HHVM 3.3.0-dev where it did not define a cURL cons...
Definition HttpTest.php:489
static provideURI()
Feeds URI to test a long regular expression in Http::isValidURI.
Definition HttpTest.php:79
testRelativeRedirections()
Warning:
Definition HttpTest.php:151
testIsValidUri( $expect, $URI, $message='')
Test Http::isValidURI()
Definition HttpTest.php:57
testValidateCookieDomain( $expected, $domain, $origin=null)
cookieDomains Cookie::validateCookieDomain
Definition HttpTest.php:11
testGetProxy()
Http::getProxy.
Definition HttpTest.php:68
static cookieDomains()
Definition HttpTest.php:22
provideCurlConstants()
Constant values are from PHP 5.3.28 using cURL 7.24.0.
Definition HttpTest.php:207
MediaWiki exception.
Class to let us overwrite MWHttpRequest respHeaders variable.
Definition HttpTest.php:497
static factory( $url, $options=null, $caller=__METHOD__)
Generate a new request object.
Definition HttpTest.php:500
This wrapper class will call out to curl (if available) or fallback to regular PHP if necessary for h...
setMwGlobals( $pairs, $value=null)
setRespHeaders( $name, $value)
Definition HttpTest.php:531
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for except in special pages derived from QueryPage It s a common pitfall for new developers to submit code containing SQL queries which examine huge numbers of rows Remember that COUNT * is(N), counting rows in atable is like counting beans in a bucket.------------------------------------------------------------------------ Replication------------------------------------------------------------------------The largest installation of MediaWiki, Wikimedia, uses a large set ofslave MySQL servers replicating writes made to a master MySQL server. Itis important to understand the issues associated with this setup if youwant to write code destined for Wikipedia.It 's often the case that the best algorithm to use for a given taskdepends on whether or not replication is in use. Due to our unabashedWikipedia-centrism, we often just use the replication-friendly version, but if you like, you can use wfGetLB() ->getServerCount() > 1 tocheck to see if replication is in use.===Lag===Lag primarily occurs when large write queries are sent to the master.Writes on the master are executed in parallel, but they are executed inserial when they are replicated to the slaves. The master writes thequery to the binlog when the transaction is committed. The slaves pollthe binlog and start executing the query as soon as it appears. They canservice reads while they are performing a write query, but will not readanything more from the binlog and thus will perform no more writes. Thismeans that if the write query runs for a long time, the slaves will lagbehind the master for the time it takes for the write query to complete.Lag can be exacerbated by high read load. MediaWiki 's load balancer willstop sending reads to a slave when it is lagged by more than 30 seconds.If the load ratios are set incorrectly, or if there is too much loadgenerally, this may lead to a slave permanently hovering around 30seconds lag.If all slaves are lagged by more than 30 seconds, MediaWiki will stopwriting to the database. All edits and other write operations will berefused, with an error returned to the user. This gives the slaves achance to catch up. Before we had this mechanism, the slaves wouldregularly lag by several minutes, making review of recent editsdifficult.In addition to this, MediaWiki attempts to ensure that the user seesevents occurring on the wiki in chronological order. A few seconds of lagcan be tolerated, as long as the user sees a consistent picture fromsubsequent requests. This is done by saving the master binlog positionin the session, and then at the start of each request, waiting for theslave to catch up to that position before doing any reads from it. Ifthis wait times out, reads are allowed anyway, but the request isconsidered to be in "lagged slave mode". Lagged slave mode can bechecked by calling wfGetLB() ->getLaggedSlaveMode(). The onlypractical consequence at present is a warning displayed in the pagefooter.===Lag avoidance===To avoid excessive lag, queries which write large numbers of rows shouldbe split up, generally to write one row at a time. Multi-row INSERT ...SELECT queries are the worst offenders should be avoided altogether.Instead do the select first and then the insert.===Working with lag===Despite our best efforts, it 's not practical to guarantee a low-lagenvironment. Lag will usually be less than one second, but mayoccasionally be up to 30 seconds. For scalability, it 's very importantto keep load on the master low, so simply sending all your queries tothe master is not the answer. So when you have a genuine need forup-to-date data, the following approach is advised:1) Do a quick query to the master for a sequence number or timestamp 2) Run the full query on the slave and check if it matches the data you gotfrom the master 3) If it doesn 't, run the full query on the masterTo avoid swamping the master every time the slaves lag, use of thisapproach should be kept to a minimum. In most cases you should just readfrom the slave and let the user deal with the delay.------------------------------------------------------------------------ Lock contention------------------------------------------------------------------------Due to the high write rate on Wikipedia(and some other wikis), MediaWiki developers need to be very careful to structure their writesto avoid long-lasting locks. By default, MediaWiki opens a transactionat the first query, and commits it before the output is sent. Locks willbe held from the time when the query is done until the commit. So youcan reduce lock time by doing as much processing as possible before youdo your write queries.Often this approach is not good enough, and it becomes necessary toenclose small groups of queries in their own transaction. Use thefollowing syntax:$dbw=wfGetDB(DB_MASTER
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition hooks.txt:1096
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37