MediaWiki  master
WebRequestTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10 
11  $this->oldServer = $_SERVER;
12  $this->oldWgRequest = $GLOBALS['wgRequest'];
13  $this->oldWgServer = $GLOBALS['wgServer'];
14  }
15 
16  protected function tearDown() {
17  $_SERVER = $this->oldServer;
18  $GLOBALS['wgRequest'] = $this->oldWgRequest;
19  $GLOBALS['wgServer'] = $this->oldWgServer;
20 
21  parent::tearDown();
22  }
23 
29  public function testDetectServer( $expected, $input, $description ) {
30  $this->setMwGlobals( 'wgAssumeProxiesUseDefaultProtocolPorts', true );
31 
32  $this->setServerVars( $input );
34  $this->assertEquals( $expected, $result, $description );
35  }
36 
37  public static function provideDetectServer() {
38  return [
39  [
40  'http://x',
41  [
42  'HTTP_HOST' => 'x'
43  ],
44  'Host header'
45  ],
46  [
47  'https://x',
48  [
49  'HTTP_HOST' => 'x',
50  'HTTPS' => 'on',
51  ],
52  'Host header with secure'
53  ],
54  [
55  'http://x',
56  [
57  'HTTP_HOST' => 'x',
58  'SERVER_PORT' => 80,
59  ],
60  'Default SERVER_PORT',
61  ],
62  [
63  'http://x',
64  [
65  'HTTP_HOST' => 'x',
66  'HTTPS' => 'off',
67  ],
68  'Secure off'
69  ],
70  [
71  'https://x',
72  [
73  'HTTP_HOST' => 'x',
74  'HTTP_X_FORWARDED_PROTO' => 'https',
75  ],
76  'Forwarded HTTPS'
77  ],
78  [
79  'https://x',
80  [
81  'HTTP_HOST' => 'x',
82  'HTTPS' => 'off',
83  'SERVER_PORT' => '81',
84  'HTTP_X_FORWARDED_PROTO' => 'https',
85  ],
86  'Forwarded HTTPS'
87  ],
88  [
89  'http://y',
90  [
91  'SERVER_NAME' => 'y',
92  ],
93  'Server name'
94  ],
95  [
96  'http://x',
97  [
98  'HTTP_HOST' => 'x',
99  'SERVER_NAME' => 'y',
100  ],
101  'Host server name precedence'
102  ],
103  [
104  'http://[::1]:81',
105  [
106  'HTTP_HOST' => '[::1]',
107  'SERVER_NAME' => '::1',
108  'SERVER_PORT' => '81',
109  ],
110  'Apache bug 26005'
111  ],
112  [
113  'http://localhost',
114  [
115  'SERVER_NAME' => '[2001'
116  ],
117  'Kind of like lighttpd per commit message in MW r83847',
118  ],
119  [
120  'http://[2a01:e35:2eb4:1::2]:777',
121  [
122  'SERVER_NAME' => '[2a01:e35:2eb4:1::2]:777'
123  ],
124  'Possible lighttpd environment per bug 14977 comment 13',
125  ],
126  ];
127  }
128 
135  protected function mockWebRequest( array $data = [], array $config = [] ) {
136  // Cannot use PHPUnit getMockBuilder() as it does not support
137  // overriding protected properties afterwards
138  $reflection = new ReflectionClass( WebRequest::class );
139  $req = $reflection->newInstanceWithoutConstructor();
140 
141  $prop = $reflection->getProperty( 'data' );
142  $prop->setAccessible( true );
143  $prop->setValue( $req, $data );
144 
145  if ( isset( $config['requestTime'] ) ) {
146  $prop = $reflection->getProperty( 'requestTime' );
147  $prop->setAccessible( true );
148  $prop->setValue( $req, $config['requestTime'] );
149  }
150 
151  return $req;
152  }
153 
157  public function testGetElapsedTime() {
158  $now = microtime( true ) - 10.0;
159  $req = $this->mockWebRequest( [], [ 'requestTime' => $now ] );
160  $this->assertGreaterThanOrEqual( 10.0, $req->getElapsedTime() );
161  // Catch common errors, but don't fail on slow hardware or VMs (T199764).
162  $this->assertEquals( 10.0, $req->getElapsedTime(), '', 60.0 );
163  }
164 
170  public function testGetValNormal() {
171  // Assert that WebRequest normalises GPC data using UtfNormal\Validator
172  $input = "a \x00 null";
173  $normal = "a \xef\xbf\xbd null";
174  $req = $this->mockWebRequest( [ 'x' => $input, 'y' => [ $input, $input ] ] );
175  $this->assertSame( $normal, $req->getVal( 'x' ) );
176  $this->assertNotSame( $input, $req->getVal( 'x' ) );
177  $this->assertSame( [ $normal, $normal ], $req->getArray( 'y' ) );
178  }
179 
184  public function testGetVal() {
185  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a' ], 'crlf' => "A\r\nb" ] );
186  $this->assertSame( 'Value', $req->getVal( 'x' ), 'Simple value' );
187  $this->assertSame( null, $req->getVal( 'z' ), 'Not found' );
188  $this->assertSame( null, $req->getVal( 'y' ), 'Array is ignored' );
189  $this->assertSame( "A\r\nb", $req->getVal( 'crlf' ), 'CRLF' );
190  }
191 
195  public function testGetRawVal() {
196  $req = $this->mockWebRequest( [
197  'x' => 'Value',
198  'y' => [ 'a' ],
199  'crlf' => "A\r\nb"
200  ] );
201  $this->assertSame( 'Value', $req->getRawVal( 'x' ) );
202  $this->assertSame( null, $req->getRawVal( 'z' ), 'Not found' );
203  $this->assertSame( null, $req->getRawVal( 'y' ), 'Array is ignored' );
204  $this->assertSame( "A\r\nb", $req->getRawVal( 'crlf' ), 'CRLF' );
205  }
206 
210  public function testGetArray() {
211  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a', 'b' ] ] );
212  $this->assertSame( [ 'Value' ], $req->getArray( 'x' ), 'Value becomes array' );
213  $this->assertSame( null, $req->getArray( 'z' ), 'Not found' );
214  $this->assertSame( [ 'a', 'b' ], $req->getArray( 'y' ) );
215  }
216 
220  public function testGetIntArray() {
221  $req = $this->mockWebRequest( [ 'x' => [ 'Value' ], 'y' => [ '0', '4.2', '-2' ] ] );
222  $this->assertSame( [ 0 ], $req->getIntArray( 'x' ), 'Text becomes 0' );
223  $this->assertSame( null, $req->getIntArray( 'z' ), 'Not found' );
224  $this->assertSame( [ 0, 4, -2 ], $req->getIntArray( 'y' ) );
225  }
226 
230  public function testGetInt() {
231  $req = $this->mockWebRequest( [
232  'x' => 'Value',
233  'y' => [ 'a' ],
234  'zero' => '0',
235  'answer' => '4.2',
236  'neg' => '-2',
237  ] );
238  $this->assertSame( 0, $req->getInt( 'x' ), 'Text' );
239  $this->assertSame( 0, $req->getInt( 'y' ), 'Array' );
240  $this->assertSame( 0, $req->getInt( 'z' ), 'Not found' );
241  $this->assertSame( 0, $req->getInt( 'zero' ) );
242  $this->assertSame( 4, $req->getInt( 'answer' ) );
243  $this->assertSame( -2, $req->getInt( 'neg' ) );
244  }
245 
249  public function testGetIntOrNull() {
250  $req = $this->mockWebRequest( [
251  'x' => 'Value',
252  'y' => [ 'a' ],
253  'zero' => '0',
254  'answer' => '4.2',
255  'neg' => '-2',
256  ] );
257  $this->assertSame( null, $req->getIntOrNull( 'x' ), 'Text' );
258  $this->assertSame( null, $req->getIntOrNull( 'y' ), 'Array' );
259  $this->assertSame( null, $req->getIntOrNull( 'z' ), 'Not found' );
260  $this->assertSame( 0, $req->getIntOrNull( 'zero' ) );
261  $this->assertSame( 4, $req->getIntOrNull( 'answer' ) );
262  $this->assertSame( -2, $req->getIntOrNull( 'neg' ) );
263  }
264 
268  public function testGetFloat() {
269  $req = $this->mockWebRequest( [
270  'x' => 'Value',
271  'y' => [ 'a' ],
272  'zero' => '0',
273  'answer' => '4.2',
274  'neg' => '-2',
275  ] );
276  $this->assertSame( 0.0, $req->getFloat( 'x' ), 'Text' );
277  $this->assertSame( 0.0, $req->getFloat( 'y' ), 'Array' );
278  $this->assertSame( 0.0, $req->getFloat( 'z' ), 'Not found' );
279  $this->assertSame( 0.0, $req->getFloat( 'zero' ) );
280  $this->assertSame( 4.2, $req->getFloat( 'answer' ) );
281  $this->assertSame( -2.0, $req->getFloat( 'neg' ) );
282  }
283 
287  public function testGetBool() {
288  $req = $this->mockWebRequest( [
289  'x' => 'Value',
290  'y' => [ 'a' ],
291  'zero' => '0',
292  'f' => 'false',
293  't' => 'true',
294  ] );
295  $this->assertSame( true, $req->getBool( 'x' ), 'Text' );
296  $this->assertSame( false, $req->getBool( 'y' ), 'Array' );
297  $this->assertSame( false, $req->getBool( 'z' ), 'Not found' );
298  $this->assertSame( false, $req->getBool( 'zero' ) );
299  $this->assertSame( true, $req->getBool( 'f' ) );
300  $this->assertSame( true, $req->getBool( 't' ) );
301  }
302 
303  public static function provideFuzzyBool() {
304  return [
305  [ 'Text', true ],
306  [ '', false, '(empty string)' ],
307  [ '0', false ],
308  [ '1', true ],
309  [ 'false', false ],
310  [ 'true', true ],
311  [ 'False', false ],
312  [ 'True', true ],
313  [ 'FALSE', false ],
314  [ 'TRUE', true ],
315  ];
316  }
317 
322  public function testGetFuzzyBool( $value, $expected, $message = null ) {
323  $req = $this->mockWebRequest( [ 'x' => $value ] );
324  $this->assertSame( $expected, $req->getFuzzyBool( 'x' ), $message ?: "Value: '$value'" );
325  }
326 
330  public function testGetFuzzyBoolDefault() {
331  $req = $this->mockWebRequest();
332  $this->assertSame( false, $req->getFuzzyBool( 'z' ), 'Not found' );
333  }
334 
338  public function testGetCheck() {
339  $req = $this->mockWebRequest( [ 'x' => 'Value', 'zero' => '0' ] );
340  $this->assertSame( false, $req->getCheck( 'z' ), 'Not found' );
341  $this->assertSame( true, $req->getCheck( 'x' ), 'Text' );
342  $this->assertSame( true, $req->getCheck( 'zero' ) );
343  }
344 
348  public function testGetText() {
349  // Avoid FauxRequest (overrides getText)
350  $req = $this->mockWebRequest( [ 'crlf' => "Va\r\nlue" ] );
351  $this->assertSame( "Va\nlue", $req->getText( 'crlf' ), 'CR stripped' );
352  }
353 
357  public function testGetValues() {
358  $values = [ 'x' => 'Value', 'y' => '' ];
359  // Avoid FauxRequest (overrides getValues)
360  $req = $this->mockWebRequest( $values );
361  $this->assertSame( $values, $req->getValues() );
362  $this->assertSame( [ 'x' => 'Value' ], $req->getValues( 'x' ), 'Specific keys' );
363  }
364 
368  public function testGetValueNames() {
369  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => '' ] );
370  $this->assertSame( [ 'x', 'y' ], $req->getValueNames() );
371  $this->assertSame( [ 'x' ], $req->getValueNames( [ 'y' ] ), 'Exclude keys' );
372  }
373 
377  public function testGetFullRequestURL() {
378  // Stub this for wfGetServerUrl()
379  $GLOBALS['wgServer'] = '//wiki.test';
380  $req = $this->getMock( WebRequest::class, [ 'getRequestURL', 'getProtocol' ] );
381  $req->method( 'getRequestURL' )->willReturn( '/path' );
382  $req->method( 'getProtocol' )->willReturn( 'https' );
383 
384  $this->assertSame(
385  'https://wiki.test/path',
386  $req->getFullRequestURL()
387  );
388  }
389 
394  public function testGetIP( $expected, $input, $cdn, $xffList, $private, $description ) {
395  $this->setServerVars( $input );
396  $this->setMwGlobals( [
397  'wgUsePrivateIPs' => $private,
398  'wgHooks' => [
399  'IsTrustedProxy' => [
400  function ( &$ip, &$trusted ) use ( $xffList ) {
401  $trusted = $trusted || in_array( $ip, $xffList );
402  return true;
403  }
404  ]
405  ]
406  ] );
407 
408  $this->setService( 'ProxyLookup', new ProxyLookup( [], $cdn ) );
409 
410  $request = new WebRequest();
411  $result = $request->getIP();
412  $this->assertEquals( $expected, $result, $description );
413  }
414 
415  public static function provideGetIP() {
416  return [
417  [
418  '127.0.0.1',
419  [
420  'REMOTE_ADDR' => '127.0.0.1'
421  ],
422  [],
423  [],
424  false,
425  'Simple IPv4'
426  ],
427  [
428  '::1',
429  [
430  'REMOTE_ADDR' => '::1'
431  ],
432  [],
433  [],
434  false,
435  'Simple IPv6'
436  ],
437  [
438  '12.0.0.1',
439  [
440  'REMOTE_ADDR' => 'abcd:0001:002:03:4:555:6666:7777',
441  'HTTP_X_FORWARDED_FOR' => '12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
442  ],
443  [ 'ABCD:1:2:3:4:555:6666:7777' ],
444  [],
445  false,
446  'IPv6 normalisation'
447  ],
448  [
449  '12.0.0.3',
450  [
451  'REMOTE_ADDR' => '12.0.0.1',
452  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
453  ],
454  [ '12.0.0.1', '12.0.0.2' ],
455  [],
456  false,
457  'With X-Forwaded-For'
458  ],
459  [
460  '12.0.0.1',
461  [
462  'REMOTE_ADDR' => '12.0.0.1',
463  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
464  ],
465  [],
466  [],
467  false,
468  'With X-Forwaded-For and disallowed server'
469  ],
470  [
471  '12.0.0.2',
472  [
473  'REMOTE_ADDR' => '12.0.0.1',
474  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
475  ],
476  [ '12.0.0.1' ],
477  [],
478  false,
479  'With multiple X-Forwaded-For and only one allowed server'
480  ],
481  [
482  '10.0.0.3',
483  [
484  'REMOTE_ADDR' => '12.0.0.2',
485  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
486  ],
487  [ '12.0.0.1', '12.0.0.2' ],
488  [],
489  false,
490  'With X-Forwaded-For and private IP (from cache proxy)'
491  ],
492  [
493  '10.0.0.4',
494  [
495  'REMOTE_ADDR' => '12.0.0.2',
496  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
497  ],
498  [ '12.0.0.1', '12.0.0.2', '10.0.0.3' ],
499  [],
500  true,
501  'With X-Forwaded-For and private IP (allowed)'
502  ],
503  [
504  '10.0.0.4',
505  [
506  'REMOTE_ADDR' => '12.0.0.2',
507  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
508  ],
509  [ '12.0.0.1', '12.0.0.2' ],
510  [ '10.0.0.3' ],
511  true,
512  'With X-Forwaded-For and private IP (allowed)'
513  ],
514  [
515  '10.0.0.3',
516  [
517  'REMOTE_ADDR' => '12.0.0.2',
518  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
519  ],
520  [ '12.0.0.1', '12.0.0.2' ],
521  [ '10.0.0.3' ],
522  false,
523  'With X-Forwaded-For and private IP (disallowed)'
524  ],
525  [
526  '12.0.0.3',
527  [
528  'REMOTE_ADDR' => '12.0.0.1',
529  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
530  ],
531  [],
532  [ '12.0.0.1', '12.0.0.2' ],
533  false,
534  'With X-Forwaded-For'
535  ],
536  [
537  '12.0.0.2',
538  [
539  'REMOTE_ADDR' => '12.0.0.1',
540  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
541  ],
542  [],
543  [ '12.0.0.1' ],
544  false,
545  'With multiple X-Forwaded-For and only one allowed server'
546  ],
547  [
548  '12.0.0.2',
549  [
550  'REMOTE_ADDR' => '12.0.0.2',
551  'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2'
552  ],
553  [],
554  [ '12.0.0.2' ],
555  false,
556  'With X-Forwaded-For and private IP and hook (disallowed)'
557  ],
558  [
559  '12.0.0.1',
560  [
561  'REMOTE_ADDR' => 'abcd:0001:002:03:4:555:6666:7777',
562  'HTTP_X_FORWARDED_FOR' => '12.0.0.1, abcd:0001:002:03:4:555:6666:7777',
563  ],
564  [ 'ABCD:1:2:3::/64' ],
565  [],
566  false,
567  'IPv6 CIDR'
568  ],
569  [
570  '12.0.0.3',
571  [
572  'REMOTE_ADDR' => '12.0.0.1',
573  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
574  ],
575  [ '12.0.0.0/24' ],
576  [],
577  false,
578  'IPv4 CIDR'
579  ],
580  ];
581  }
582 
588  // ensure that local install state doesn't interfere with test
589  $this->setMwGlobals( [
590  'wgCdnServers' => [],
591  'wgCdnServersNoPurge' => [],
592  'wgUsePrivateIPs' => false,
593  'wgHooks' => [],
594  ] );
595  $this->setService( 'ProxyLookup', new ProxyLookup( [], [] ) );
596 
597  $request = new WebRequest();
598  # Next call throw an exception about lacking an IP
599  $request->getIP();
600  }
601 
602  public static function provideLanguageData() {
603  return [
604  [ '', [], 'Empty Accept-Language header' ],
605  [ 'en', [ 'en' => 1 ], 'One language' ],
606  [ 'en, ar', [ 'en' => 1, 'ar' => 1 ], 'Two languages listed in appearance order.' ],
607  [
608  'zh-cn,zh-tw',
609  [ 'zh-cn' => 1, 'zh-tw' => 1 ],
610  'Two equally prefered languages, listed in appearance order per rfc3282. Checks c9119'
611  ],
612  [
613  'es, en; q=0.5',
614  [ 'es' => 1, 'en' => '0.5' ],
615  'Spanish as first language and English and second'
616  ],
617  [ 'en; q=0.5, es', [ 'es' => 1, 'en' => '0.5' ], 'Less prefered language first' ],
618  [ 'fr, en; q=0.5, es', [ 'fr' => 1, 'es' => 1, 'en' => '0.5' ], 'Three languages' ],
619  [ 'en; q=0.5, es', [ 'es' => 1, 'en' => '0.5' ], 'Two languages' ],
620  [ 'en, zh;q=0', [ 'en' => 1 ], "It's Chinese to me" ],
621  [
622  'es; q=1, pt;q=0.7, it; q=0.6, de; q=0.1, ru;q=0',
623  [ 'es' => '1', 'pt' => '0.7', 'it' => '0.6', 'de' => '0.1' ],
624  'Preference for Romance languages'
625  ],
626  [
627  'en-gb, en-us; q=1',
628  [ 'en-gb' => 1, 'en-us' => '1' ],
629  'Two equally prefered English variants'
630  ],
631  [ '_', [], 'Invalid input' ],
632  ];
633  }
634 
639  public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
640  $this->setServerVars( [ 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ] );
641  $request = new WebRequest();
642  $this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description );
643  }
644 
645  protected function setServerVars( $vars ) {
646  // Don't remove vars which should be available in all SAPI.
647  if ( !isset( $vars['REQUEST_TIME_FLOAT'] ) ) {
648  $vars['REQUEST_TIME_FLOAT'] = $_SERVER['REQUEST_TIME_FLOAT'];
649  }
650  if ( !isset( $vars['REQUEST_TIME'] ) ) {
651  $vars['REQUEST_TIME'] = $_SERVER['REQUEST_TIME'];
652  }
653  $_SERVER = $vars;
654  }
655 }
testGetFloat()
WebRequest::getFloat.
testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description)
provideLanguageData WebRequest::getAcceptLang
testGetIpLackOfRemoteAddrThrowAnException()
MWException WebRequest::getIP.
testGetIntArray()
WebRequest::getIntArray.
if(is_array( $mode)) switch( $mode) $input
testGetInt()
WebRequest::getInt.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
testGetFuzzyBool( $value, $expected, $message=null)
provideFuzzyBool WebRequest::getFuzzyBool
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$value
testGetRawVal()
WebRequest::getRawVal.
static provideGetIP()
testGetValues()
WebRequest::getValues.
testDetectServer( $expected, $input, $description)
provideDetectServer WebRequest::detectServer WebRequest::detectProtocol
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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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. '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 '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:Array with elements of the form "language:title" in the order that they will be output. & $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 since 1.28! 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:1980
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:1982
static detectServer()
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_S...
Definition: WebRequest.php:200
testGetText()
WebRequest::getText.
mockWebRequest(array $data=[], array $config=[])
testGetIP( $expected, $input, $cdn, $xffList, $private, $description)
provideGetIP WebRequest::getIP
testGetArray()
WebRequest::getArray.
testGetElapsedTime()
WebRequest::getElapsedTime.
testGetFullRequestURL()
WebRequest.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
WebRequest.
$GLOBALS['IP']
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
static provideDetectServer()
testGetIntOrNull()
WebRequest::getIntOrNull.
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown...
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:979
testGetCheck()
WebRequest::getCheck.
static provideFuzzyBool()
static provideLanguageData()
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
testGetBool()
WebRequest::getBool.
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
Definition: hooks.txt:2633
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2217
testGetVal()
WebRequest::getVal WebRequest::getGPCVal.