9 protected function setUp() {
27 $this->
setMwGlobals(
'wgAssumeProxiesUseDefaultProtocolPorts',
true );
30 $result = WebRequest::detectServer();
49 'Host header with secure'
57 'Default SERVER_PORT',
71 'HTTP_X_FORWARDED_PROTO' =>
'https',
80 'SERVER_PORT' =>
'81',
81 'HTTP_X_FORWARDED_PROTO' =>
'https',
98 'Host server name precedence'
103 'HTTP_HOST' =>
'[::1]',
104 'SERVER_NAME' =>
'::1',
105 'SERVER_PORT' =>
'81',
112 'SERVER_NAME' =>
'[2001'
114 'Kind of like lighttpd per commit message in MW r83847',
117 'http://[2a01:e35:2eb4:1::2]:777',
119 'SERVER_NAME' =>
'[2a01:e35:2eb4:1::2]:777'
121 'Possible lighttpd environment per bug 14977 comment 13',
136 $req = $reflection->newInstanceWithoutConstructor();
138 $prop = $reflection->getProperty(
'data' );
139 $prop->setAccessible(
true );
142 if (
isset( $config[
'requestTime'] ) ) {
143 $prop = $reflection->getProperty(
'requestTime' );
144 $prop->setAccessible(
true );
145 $prop->setValue(
$req, $config[
'requestTime'] );
170 $normal =
"a \xef\xbf\xbd null";
182 $req = $this->
mockWebRequest( [
'x' =>
'Value',
'y' => [
'a' ],
'crlf' =>
"A\r\nb" ] );
183 $this->
assertSame(
'Value',
$req->getVal(
'x' ),
'Simple value' );
185 $this->
assertSame(
null,
$req->getVal(
'y' ),
'Array is ignored' );
200 $this->
assertSame(
null,
$req->getRawVal(
'y' ),
'Array is ignored' );
209 $this->
assertSame( [
'Value' ],
$req->getArray(
'x' ),
'Value becomes array' );
219 $this->
assertSame( [ 0 ],
$req->getIntArray(
'x' ),
'Text becomes 0' );
256 $this->
assertSame(
null,
$req->getIntOrNull(
'z' ),
'Not found' );
303 [
'',
false,
'(empty string)' ],
321 $this->
assertSame( $expected,
$req->getFuzzyBool(
'x' ), $message ?:
"Value: '$value'" );
329 $this->
assertSame(
false,
$req->getFuzzyBool(
'z' ),
'Not found' );
348 $this->
assertSame(
"Va\nlue",
$req->getText(
'crlf' ),
'CR stripped' );
355 $values = [
'x' =>
'Value',
'y' =>
'' ];
359 $this->
assertSame( [
'x' =>
'Value' ],
$req->getValues(
'x' ),
'Specific keys' );
368 $this->
assertSame( [
'x' ],
$req->getValueNames( [
'y' ] ),
'Exclude keys' );
375 public function testGetIP( $expected,
$input, $squid, $xffList, $private, $description ) {
378 'wgUsePrivateIPs' => $private,
380 'IsTrustedProxy' => [
381 function ( &$ip, &$trusted ) use ( $xffList ) {
382 $trusted = $trusted ||
in_array( $ip, $xffList );
393 $this->
assertEquals( $expected, $result, $description );
401 'REMOTE_ADDR' =>
'127.0.0.1'
411 'REMOTE_ADDR' =>
'::1'
421 'REMOTE_ADDR' =>
'abcd:0001:002:03:4:555:6666:7777',
422 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
424 [
'ABCD:1:2:3:4:555:6666:7777' ],
432 'REMOTE_ADDR' =>
'12.0.0.1',
433 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
435 [
'12.0.0.1',
'12.0.0.2' ],
438 'With X-Forwaded-For'
443 'REMOTE_ADDR' =>
'12.0.0.1',
444 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
449 'With X-Forwaded-For and disallowed server'
454 'REMOTE_ADDR' =>
'12.0.0.1',
455 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
460 'With multiple X-Forwaded-For and only one allowed server'
465 'REMOTE_ADDR' =>
'12.0.0.2',
466 'HTTP_X_FORWARDED_FOR' =>
'10.0.0.4, 10.0.0.3, 12.0.0.2'
468 [
'12.0.0.1',
'12.0.0.2' ],
471 'With X-Forwaded-For and private IP (from cache proxy)'
476 'REMOTE_ADDR' =>
'12.0.0.2',
477 'HTTP_X_FORWARDED_FOR' =>
'10.0.0.4, 10.0.0.3, 12.0.0.2'
479 [
'12.0.0.1',
'12.0.0.2',
'10.0.0.3' ],
482 'With X-Forwaded-For and private IP (allowed)'
487 'REMOTE_ADDR' =>
'12.0.0.2',
488 'HTTP_X_FORWARDED_FOR' =>
'10.0.0.4, 10.0.0.3, 12.0.0.2'
490 [
'12.0.0.1',
'12.0.0.2' ],
493 'With X-Forwaded-For and private IP (allowed)'
498 'REMOTE_ADDR' =>
'12.0.0.2',
499 'HTTP_X_FORWARDED_FOR' =>
'10.0.0.4, 10.0.0.3, 12.0.0.2'
501 [
'12.0.0.1',
'12.0.0.2' ],
504 'With X-Forwaded-For and private IP (disallowed)'
509 'REMOTE_ADDR' =>
'12.0.0.1',
510 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
513 [
'12.0.0.1',
'12.0.0.2' ],
515 'With X-Forwaded-For'
520 'REMOTE_ADDR' =>
'12.0.0.1',
521 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
526 'With multiple X-Forwaded-For and only one allowed server'
531 'REMOTE_ADDR' =>
'12.0.0.2',
532 'HTTP_X_FORWARDED_FOR' =>
'10.0.0.3, 12.0.0.2'
537 'With X-Forwaded-For and private IP and hook (disallowed)'
542 'REMOTE_ADDR' =>
'abcd:0001:002:03:4:555:6666:7777',
543 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
545 [
'ABCD:1:2:3::/64' ],
553 'REMOTE_ADDR' =>
'12.0.0.1',
554 'HTTP_X_FORWARDED_FOR' =>
'12.0.0.3, 12.0.0.2'
571 'wgSquidServersNoPurge' => [],
572 'wgSquidServers' => [],
573 'wgUsePrivateIPs' =>
false,
579 # Next call throw an exception about lacking an IP
585 [
'', [],
'Empty Accept-Language header' ],
586 [
'en', [
'en' => 1 ],
'One language' ],
587 [
'en, ar', [
'en' => 1,
'ar' => 1 ],
'Two languages listed in appearance order.' ],
590 [
'zh-cn' => 1,
'zh-tw' => 1 ],
591 'Two equally prefered languages, listed in appearance order per rfc3282. Checks c9119'
595 [
'es' => 1,
'en' =>
'0.5' ],
596 'Spanish as first language and English and second'
598 [
'en; q=0.5, es', [
'es' => 1,
'en' =>
'0.5' ],
'Less prefered language first' ],
599 [
'fr, en; q=0.5, es', [
'fr' => 1,
'es' => 1,
'en' =>
'0.5' ],
'Three languages' ],
600 [
'en; q=0.5, es', [
'es' => 1,
'en' =>
'0.5' ],
'Two languages' ],
601 [
'en, zh;q=0', [
'en' => 1 ],
"It's Chinese to me" ],
603 'es; q=1, pt;q=0.7, it; q=0.6, de; q=0.1, ru;q=0',
604 [
'es' =>
'1',
'pt' =>
'0.7',
'it' =>
'0.6',
'de' =>
'0.1' ],
605 'Preference for Romance languages'
609 [
'en-gb' => 1,
'en-us' =>
'1' ],
610 'Two equally prefered English variants'
612 [
'_', [],
'Invalid input' ],
620 public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
621 $this->
setServerVars( [
'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ] );
628 if ( !
isset(
$vars[
'REQUEST_TIME_FLOAT'] ) ) {
629 $vars[
'REQUEST_TIME_FLOAT'] = $_SERVER[
'REQUEST_TIME_FLOAT'];
632 $vars[
'REQUEST_TIME'] = $_SERVER[
'REQUEST_TIME'];
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testGetText()
WebRequest::getText.
testGetIpLackOfRemoteAddrThrowAnException()
MWException WebRequest::getIP.
testDetectServer( $expected, $input, $description)
provideDetectServer WebRequest::detectServer WebRequest::detectProtocol
static provideLanguageData()
testGetValues()
WebRequest::getValues.
testGetRawVal()
WebRequest::getRawVal.
testGetIntOrNull()
WebRequest::getIntOrNull.
testGetBool()
WebRequest::getBool.
testGetCheck()
WebRequest::getCheck.
static provideFuzzyBool()
testGetValueNames()
WebRequest::getValueNames.
testGetFuzzyBoolDefault()
WebRequest::getFuzzyBool.
testGetFuzzyBool( $value, $expected, $message=null)
provideFuzzyBool WebRequest::getFuzzyBool
mockWebRequest(array $data=[], array $config=[])
testGetElapsedTime()
WebRequest::getElapsedTime.
testGetValNormal()
WebRequest::getVal WebRequest::getGPCVal WebRequest::normalizeUnicode.
static provideDetectServer()
testGetArray()
WebRequest::getArray.
testGetFloat()
WebRequest::getFloat.
testGetIP( $expected, $input, $squid, $xffList, $private, $description)
provideGetIP WebRequest::getIP
testGetInt()
WebRequest::getInt.
testGetIntArray()
WebRequest::getIntArray.
testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description)
provideLanguageData WebRequest::getAcceptLang
testGetVal()
WebRequest::getVal WebRequest::getGPCVal.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
this hook is for auditing only $req
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(is_array($mode)) switch( $mode) $input