MediaWiki  1.28.1
WebRequestTest.php
Go to the documentation of this file.
1 <?php
2 
7  protected $oldServer;
8 
9  protected function setUp() {
10  parent::setUp();
11 
12  $this->oldServer = $_SERVER;
13  }
14 
15  protected function tearDown() {
16  $_SERVER = $this->oldServer;
17 
18  parent::tearDown();
19  }
20 
26  public function testDetectServer( $expected, $input, $description ) {
27  $this->setMwGlobals( 'wgAssumeProxiesUseDefaultProtocolPorts', true );
28 
29  $_SERVER = $input;
31  $this->assertEquals( $expected, $result, $description );
32  }
33 
34  public static function provideDetectServer() {
35  return [
36  [
37  'http://x',
38  [
39  'HTTP_HOST' => 'x'
40  ],
41  'Host header'
42  ],
43  [
44  'https://x',
45  [
46  'HTTP_HOST' => 'x',
47  'HTTPS' => 'on',
48  ],
49  'Host header with secure'
50  ],
51  [
52  'http://x',
53  [
54  'HTTP_HOST' => 'x',
55  'SERVER_PORT' => 80,
56  ],
57  'Default SERVER_PORT',
58  ],
59  [
60  'http://x',
61  [
62  'HTTP_HOST' => 'x',
63  'HTTPS' => 'off',
64  ],
65  'Secure off'
66  ],
67  [
68  'https://x',
69  [
70  'HTTP_HOST' => 'x',
71  'HTTP_X_FORWARDED_PROTO' => 'https',
72  ],
73  'Forwarded HTTPS'
74  ],
75  [
76  'https://x',
77  [
78  'HTTP_HOST' => 'x',
79  'HTTPS' => 'off',
80  'SERVER_PORT' => '81',
81  'HTTP_X_FORWARDED_PROTO' => 'https',
82  ],
83  'Forwarded HTTPS'
84  ],
85  [
86  'http://y',
87  [
88  'SERVER_NAME' => 'y',
89  ],
90  'Server name'
91  ],
92  [
93  'http://x',
94  [
95  'HTTP_HOST' => 'x',
96  'SERVER_NAME' => 'y',
97  ],
98  'Host server name precedence'
99  ],
100  [
101  'http://[::1]:81',
102  [
103  'HTTP_HOST' => '[::1]',
104  'SERVER_NAME' => '::1',
105  'SERVER_PORT' => '81',
106  ],
107  'Apache bug 26005'
108  ],
109  [
110  'http://localhost',
111  [
112  'SERVER_NAME' => '[2001'
113  ],
114  'Kind of like lighttpd per commit message in MW r83847',
115  ],
116  [
117  'http://[2a01:e35:2eb4:1::2]:777',
118  [
119  'SERVER_NAME' => '[2a01:e35:2eb4:1::2]:777'
120  ],
121  'Possible lighttpd environment per bug 14977 comment 13',
122  ],
123  ];
124  }
125 
126  protected function mockWebRequest( $data = [] ) {
127  // Cannot use PHPUnit getMockBuilder() as it does not support
128  // overriding protected properties afterwards
129  $reflection = new ReflectionClass( 'WebRequest' );
130  $req = $reflection->newInstanceWithoutConstructor();
131 
132  $prop = $reflection->getProperty( 'data' );
133  $prop->setAccessible( true );
134  $prop->setValue( $req, $data );
135 
136  $prop = $reflection->getProperty( 'requestTime' );
137  $prop->setAccessible( true );
138  $prop->setValue( $req, microtime( true ) );
139 
140  return $req;
141  }
142 
146  public function testGetElapsedTime() {
147  $req = $this->mockWebRequest();
148  $this->assertGreaterThanOrEqual( 0.0, $req->getElapsedTime() );
149  $this->assertEquals( 0.0, $req->getElapsedTime(), '', /*delta*/ 0.2 );
150  }
151 
157  public function testGetValNormal() {
158  // Assert that WebRequest normalises GPC data using UtfNormal\Validator
159  $input = "a \x00 null";
160  $normal = "a \xef\xbf\xbd null";
161  $req = $this->mockWebRequest( [ 'x' => $input, 'y' => [ $input, $input ] ] );
162  $this->assertSame( $normal, $req->getVal( 'x' ) );
163  $this->assertNotSame( $input, $req->getVal( 'x' ) );
164  $this->assertSame( [ $normal, $normal ], $req->getArray( 'y' ) );
165  }
166 
171  public function testGetVal() {
172  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a' ], 'crlf' => "A\r\nb" ] );
173  $this->assertSame( 'Value', $req->getVal( 'x' ), 'Simple value' );
174  $this->assertSame( null, $req->getVal( 'z' ), 'Not found' );
175  $this->assertSame( null, $req->getVal( 'y' ), 'Array is ignored' );
176  $this->assertSame( "A\r\nb", $req->getVal( 'crlf' ), 'CRLF' );
177  }
178 
182  public function testGetRawVal() {
183  $req = $this->mockWebRequest( [
184  'x' => 'Value',
185  'y' => [ 'a' ],
186  'crlf' => "A\r\nb"
187  ] );
188  $this->assertSame( 'Value', $req->getRawVal( 'x' ) );
189  $this->assertSame( null, $req->getRawVal( 'z' ), 'Not found' );
190  $this->assertSame( null, $req->getRawVal( 'y' ), 'Array is ignored' );
191  $this->assertSame( "A\r\nb", $req->getRawVal( 'crlf' ), 'CRLF' );
192  }
193 
197  public function testGetArray() {
198  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a', 'b' ] ] );
199  $this->assertSame( [ 'Value' ], $req->getArray( 'x' ), 'Value becomes array' );
200  $this->assertSame( null, $req->getArray( 'z' ), 'Not found' );
201  $this->assertSame( [ 'a', 'b' ], $req->getArray( 'y' ) );
202  }
203 
207  public function testGetIntArray() {
208  $req = $this->mockWebRequest( [ 'x' => [ 'Value' ], 'y' => [ '0', '4.2', '-2' ] ] );
209  $this->assertSame( [ 0 ], $req->getIntArray( 'x' ), 'Text becomes 0' );
210  $this->assertSame( null, $req->getIntArray( 'z' ), 'Not found' );
211  $this->assertSame( [ 0, 4, -2 ], $req->getIntArray( 'y' ) );
212  }
213 
217  public function testGetInt() {
218  $req = $this->mockWebRequest( [
219  'x' => 'Value',
220  'y' => [ 'a' ],
221  'zero' => '0',
222  'answer' => '4.2',
223  'neg' => '-2',
224  ] );
225  $this->assertSame( 0, $req->getInt( 'x' ), 'Text' );
226  $this->assertSame( 0, $req->getInt( 'y' ), 'Array' );
227  $this->assertSame( 0, $req->getInt( 'z' ), 'Not found' );
228  $this->assertSame( 0, $req->getInt( 'zero' ) );
229  $this->assertSame( 4, $req->getInt( 'answer' ) );
230  $this->assertSame( -2, $req->getInt( 'neg' ) );
231  }
232 
236  public function testGetIntOrNull() {
237  $req = $this->mockWebRequest( [
238  'x' => 'Value',
239  'y' => [ 'a' ],
240  'zero' => '0',
241  'answer' => '4.2',
242  'neg' => '-2',
243  ] );
244  $this->assertSame( null, $req->getIntOrNull( 'x' ), 'Text' );
245  $this->assertSame( null, $req->getIntOrNull( 'y' ), 'Array' );
246  $this->assertSame( null, $req->getIntOrNull( 'z' ), 'Not found' );
247  $this->assertSame( 0, $req->getIntOrNull( 'zero' ) );
248  $this->assertSame( 4, $req->getIntOrNull( 'answer' ) );
249  $this->assertSame( -2, $req->getIntOrNull( 'neg' ) );
250  }
251 
255  public function testGetFloat() {
256  $req = $this->mockWebRequest( [
257  'x' => 'Value',
258  'y' => [ 'a' ],
259  'zero' => '0',
260  'answer' => '4.2',
261  'neg' => '-2',
262  ] );
263  $this->assertSame( 0.0, $req->getFloat( 'x' ), 'Text' );
264  $this->assertSame( 0.0, $req->getFloat( 'y' ), 'Array' );
265  $this->assertSame( 0.0, $req->getFloat( 'z' ), 'Not found' );
266  $this->assertSame( 0.0, $req->getFloat( 'zero' ) );
267  $this->assertSame( 4.2, $req->getFloat( 'answer' ) );
268  $this->assertSame( -2.0, $req->getFloat( 'neg' ) );
269  }
270 
274  public function testGetBool() {
275  $req = $this->mockWebRequest( [
276  'x' => 'Value',
277  'y' => [ 'a' ],
278  'zero' => '0',
279  'f' => 'false',
280  't' => 'true',
281  ] );
282  $this->assertSame( true, $req->getBool( 'x' ), 'Text' );
283  $this->assertSame( false, $req->getBool( 'y' ), 'Array' );
284  $this->assertSame( false, $req->getBool( 'z' ), 'Not found' );
285  $this->assertSame( false, $req->getBool( 'zero' ) );
286  $this->assertSame( true, $req->getBool( 'f' ) );
287  $this->assertSame( true, $req->getBool( 't' ) );
288  }
289 
290  public static function provideFuzzyBool() {
291  return [
292  [ 'Text', true ],
293  [ '', false, '(empty string)' ],
294  [ '0', false ],
295  [ '1', true ],
296  [ 'false', false ],
297  [ 'true', true ],
298  [ 'False', false ],
299  [ 'True', true ],
300  [ 'FALSE', false ],
301  [ 'TRUE', true ],
302  ];
303  }
304 
309  public function testGetFuzzyBool( $value, $expected, $message = null ) {
310  $req = $this->mockWebRequest( [ 'x' => $value ] );
311  $this->assertSame( $expected, $req->getFuzzyBool( 'x' ), $message ?: "Value: '$value'" );
312  }
313 
317  public function testGetFuzzyBoolDefault() {
318  $req = $this->mockWebRequest();
319  $this->assertSame( false, $req->getFuzzyBool( 'z' ), 'Not found' );
320  }
321 
325  public function testGetCheck() {
326  $req = $this->mockWebRequest( [ 'x' => 'Value', 'zero' => '0' ] );
327  $this->assertSame( false, $req->getCheck( 'z' ), 'Not found' );
328  $this->assertSame( true, $req->getCheck( 'x' ), 'Text' );
329  $this->assertSame( true, $req->getCheck( 'zero' ) );
330  }
331 
335  public function testGetText() {
336  // Avoid FauxRequest (overrides getText)
337  $req = $this->mockWebRequest( [ 'crlf' => "Va\r\nlue" ] );
338  $this->assertSame( "Va\nlue", $req->getText( 'crlf' ), 'CR stripped' );
339  }
340 
344  public function testGetValues() {
345  $values = [ 'x' => 'Value', 'y' => '' ];
346  // Avoid FauxRequest (overrides getValues)
347  $req = $this->mockWebRequest( $values );
348  $this->assertSame( $values, $req->getValues() );
349  $this->assertSame( [ 'x' => 'Value' ], $req->getValues( 'x' ), 'Specific keys' );
350  }
351 
355  public function testGetValueNames() {
356  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => '' ] );
357  $this->assertSame( [ 'x', 'y' ], $req->getValueNames() );
358  $this->assertSame( [ 'x' ], $req->getValueNames( [ 'y' ] ), 'Exclude keys' );
359  }
360 
365  public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) {
366  $_SERVER = $input;
367  $this->setMwGlobals( [
368  'wgUsePrivateIPs' => $private,
369  'wgHooks' => [
370  'IsTrustedProxy' => [
371  function ( &$ip, &$trusted ) use ( $xffList ) {
372  $trusted = $trusted || in_array( $ip, $xffList );
373  return true;
374  }
375  ]
376  ]
377  ] );
378 
379  $this->setService( 'ProxyLookup', new ProxyLookup( [], $squid ) );
380 
381  $request = new WebRequest();
382  $result = $request->getIP();
383  $this->assertEquals( $expected, $result, $description );
384  }
385 
386  public static function provideGetIP() {
387  return [
388  [
389  '127.0.0.1',
390  [
391  'REMOTE_ADDR' => '127.0.0.1'
392  ],
393  [],
394  [],
395  false,
396  'Simple IPv4'
397  ],
398  [
399  '::1',
400  [
401  'REMOTE_ADDR' => '::1'
402  ],
403  [],
404  [],
405  false,
406  'Simple IPv6'
407  ],
408  [
409  '12.0.0.1',
410  [
411  'REMOTE_ADDR' => 'abcd:0001:002:03:4:555:6666:7777',
412  'HTTP_X_FORWARDED_FOR' => '12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
413  ],
414  [ 'ABCD:1:2:3:4:555:6666:7777' ],
415  [],
416  false,
417  'IPv6 normalisation'
418  ],
419  [
420  '12.0.0.3',
421  [
422  'REMOTE_ADDR' => '12.0.0.1',
423  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
424  ],
425  [ '12.0.0.1', '12.0.0.2' ],
426  [],
427  false,
428  'With X-Forwaded-For'
429  ],
430  [
431  '12.0.0.1',
432  [
433  'REMOTE_ADDR' => '12.0.0.1',
434  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
435  ],
436  [],
437  [],
438  false,
439  'With X-Forwaded-For and disallowed server'
440  ],
441  [
442  '12.0.0.2',
443  [
444  'REMOTE_ADDR' => '12.0.0.1',
445  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
446  ],
447  [ '12.0.0.1' ],
448  [],
449  false,
450  'With multiple X-Forwaded-For and only one allowed server'
451  ],
452  [
453  '10.0.0.3',
454  [
455  'REMOTE_ADDR' => '12.0.0.2',
456  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
457  ],
458  [ '12.0.0.1', '12.0.0.2' ],
459  [],
460  false,
461  'With X-Forwaded-For and private IP (from cache proxy)'
462  ],
463  [
464  '10.0.0.4',
465  [
466  'REMOTE_ADDR' => '12.0.0.2',
467  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
468  ],
469  [ '12.0.0.1', '12.0.0.2', '10.0.0.3' ],
470  [],
471  true,
472  'With X-Forwaded-For and private IP (allowed)'
473  ],
474  [
475  '10.0.0.4',
476  [
477  'REMOTE_ADDR' => '12.0.0.2',
478  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
479  ],
480  [ '12.0.0.1', '12.0.0.2' ],
481  [ '10.0.0.3' ],
482  true,
483  'With X-Forwaded-For and private IP (allowed)'
484  ],
485  [
486  '10.0.0.3',
487  [
488  'REMOTE_ADDR' => '12.0.0.2',
489  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
490  ],
491  [ '12.0.0.1', '12.0.0.2' ],
492  [ '10.0.0.3' ],
493  false,
494  'With X-Forwaded-For and private IP (disallowed)'
495  ],
496  [
497  '12.0.0.3',
498  [
499  'REMOTE_ADDR' => '12.0.0.1',
500  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
501  ],
502  [],
503  [ '12.0.0.1', '12.0.0.2' ],
504  false,
505  'With X-Forwaded-For'
506  ],
507  [
508  '12.0.0.2',
509  [
510  'REMOTE_ADDR' => '12.0.0.1',
511  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
512  ],
513  [],
514  [ '12.0.0.1' ],
515  false,
516  'With multiple X-Forwaded-For and only one allowed server'
517  ],
518  [
519  '12.0.0.2',
520  [
521  'REMOTE_ADDR' => '12.0.0.2',
522  'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2'
523  ],
524  [],
525  [ '12.0.0.2' ],
526  false,
527  'With X-Forwaded-For and private IP and hook (disallowed)'
528  ],
529  [
530  '12.0.0.1',
531  [
532  'REMOTE_ADDR' => 'abcd:0001:002:03:4:555:6666:7777',
533  'HTTP_X_FORWARDED_FOR' => '12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
534  ],
535  [ 'ABCD:1:2:3::/64' ],
536  [],
537  false,
538  'IPv6 CIDR'
539  ],
540  [
541  '12.0.0.3',
542  [
543  'REMOTE_ADDR' => '12.0.0.1',
544  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
545  ],
546  [ '12.0.0.0/24' ],
547  [],
548  false,
549  'IPv4 CIDR'
550  ],
551  ];
552  }
553 
559  // ensure that local install state doesn't interfere with test
560  $this->setMwGlobals( [
561  'wgSquidServersNoPurge' => [],
562  'wgSquidServers' => [],
563  'wgUsePrivateIPs' => false,
564  'wgHooks' => [],
565  ] );
566  $this->setService( 'ProxyLookup', new ProxyLookup( [], [] ) );
567 
568  $request = new WebRequest();
569  # Next call throw an exception about lacking an IP
570  $request->getIP();
571  }
572 
573  public static function provideLanguageData() {
574  return [
575  [ '', [], 'Empty Accept-Language header' ],
576  [ 'en', [ 'en' => 1 ], 'One language' ],
577  [ 'en, ar', [ 'en' => 1, 'ar' => 1 ], 'Two languages listed in appearance order.' ],
578  [
579  'zh-cn,zh-tw',
580  [ 'zh-cn' => 1, 'zh-tw' => 1 ],
581  'Two equally prefered languages, listed in appearance order per rfc3282. Checks c9119'
582  ],
583  [
584  'es, en; q=0.5',
585  [ 'es' => 1, 'en' => '0.5' ],
586  'Spanish as first language and English and second'
587  ],
588  [ 'en; q=0.5, es', [ 'es' => 1, 'en' => '0.5' ], 'Less prefered language first' ],
589  [ 'fr, en; q=0.5, es', [ 'fr' => 1, 'es' => 1, 'en' => '0.5' ], 'Three languages' ],
590  [ 'en; q=0.5, es', [ 'es' => 1, 'en' => '0.5' ], 'Two languages' ],
591  [ 'en, zh;q=0', [ 'en' => 1 ], "It's Chinese to me" ],
592  [
593  'es; q=1, pt;q=0.7, it; q=0.6, de; q=0.1, ru;q=0',
594  [ 'es' => '1', 'pt' => '0.7', 'it' => '0.6', 'de' => '0.1' ],
595  'Preference for Romance languages'
596  ],
597  [
598  'en-gb, en-us; q=1',
599  [ 'en-gb' => 1, 'en-us' => '1' ],
600  'Two equally prefered English variants'
601  ],
602  [ '_', [], 'Invalid input' ],
603  ];
604  }
605 
610  public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
611  $_SERVER = [ 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ];
612  $request = new WebRequest();
613  $this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description );
614  }
615 }
testGetFloat()
WebRequest::getFloat.
testGetIpLackOfRemoteAddrThrowAnException()
MWException WebRequest::getIP.
testGetIntArray()
WebRequest::getIntArray.
testGetInt()
WebRequest::getInt.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
testAcceptLang($acceptLanguageHeader, $expectedLanguages, $description)
provideLanguageData WebRequest::getAcceptLang
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$value
testGetRawVal()
WebRequest::getRawVal.
static provideGetIP()
testGetValues()
WebRequest::getValues.
testGetFuzzyBool($value, $expected, $message=null)
provideFuzzyBool WebRequest::getFuzzyBool
setService($name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown...
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1934
testGetFuzzyBoolDefault()
WebRequest::getFuzzyBool.
testGetValNormal()
WebRequest::getVal WebRequest::getGPCVal WebRequest::normalizeUnicode.
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
Definition: hooks.txt:1936
static detectServer()
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_S...
Definition: WebRequest.php:197
testGetText()
WebRequest::getText.
testDetectServer($expected, $input, $description)
provideDetectServer WebRequest::detectServer WebRequest::detectProtocol
testGetArray()
WebRequest::getArray.
testGetElapsedTime()
WebRequest::getElapsedTime.
WebRequest.
mockWebRequest($data=[])
static provideDetectServer()
testGetIntOrNull()
WebRequest::getIntOrNull.
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:35
testGetValueNames()
WebRequest::getValueNames.
this hook is for auditing only $req
Definition: hooks.txt:1007
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
testGetCheck()
WebRequest::getCheck.
static provideFuzzyBool()
static provideLanguageData()
testGetBool()
WebRequest::getBool.
testGetIP($expected, $input, $squid, $xffList, $private, $description)
provideGetIP WebRequest::getIP
setMwGlobals($pairs, $value=null)
testGetVal()
WebRequest::getVal WebRequest::getGPCVal.