MediaWiki  master
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  $this->setServerVars( $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 
132  protected function mockWebRequest( array $data = [], array $config = [] ) {
133  // Cannot use PHPUnit getMockBuilder() as it does not support
134  // overriding protected properties afterwards
135  $reflection = new ReflectionClass( WebRequest::class );
136  $req = $reflection->newInstanceWithoutConstructor();
137 
138  $prop = $reflection->getProperty( 'data' );
139  $prop->setAccessible( true );
140  $prop->setValue( $req, $data );
141 
142  if ( isset( $config['requestTime'] ) ) {
143  $prop = $reflection->getProperty( 'requestTime' );
144  $prop->setAccessible( true );
145  $prop->setValue( $req, $config['requestTime'] );
146  }
147 
148  return $req;
149  }
150 
154  public function testGetElapsedTime() {
155  $now = microtime( true ) - 10.0;
156  $req = $this->mockWebRequest( [], [ 'requestTime' => $now ] );
157  $this->assertGreaterThanOrEqual( 10.0, $req->getElapsedTime() );
158  // Catch common errors, but don't fail on slow hardware or VMs (T199764).
159  $this->assertEquals( 10.0, $req->getElapsedTime(), '', 60.0 );
160  }
161 
167  public function testGetValNormal() {
168  // Assert that WebRequest normalises GPC data using UtfNormal\Validator
169  $input = "a \x00 null";
170  $normal = "a \xef\xbf\xbd null";
171  $req = $this->mockWebRequest( [ 'x' => $input, 'y' => [ $input, $input ] ] );
172  $this->assertSame( $normal, $req->getVal( 'x' ) );
173  $this->assertNotSame( $input, $req->getVal( 'x' ) );
174  $this->assertSame( [ $normal, $normal ], $req->getArray( 'y' ) );
175  }
176 
181  public function testGetVal() {
182  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a' ], 'crlf' => "A\r\nb" ] );
183  $this->assertSame( 'Value', $req->getVal( 'x' ), 'Simple value' );
184  $this->assertSame( null, $req->getVal( 'z' ), 'Not found' );
185  $this->assertSame( null, $req->getVal( 'y' ), 'Array is ignored' );
186  $this->assertSame( "A\r\nb", $req->getVal( 'crlf' ), 'CRLF' );
187  }
188 
192  public function testGetRawVal() {
193  $req = $this->mockWebRequest( [
194  'x' => 'Value',
195  'y' => [ 'a' ],
196  'crlf' => "A\r\nb"
197  ] );
198  $this->assertSame( 'Value', $req->getRawVal( 'x' ) );
199  $this->assertSame( null, $req->getRawVal( 'z' ), 'Not found' );
200  $this->assertSame( null, $req->getRawVal( 'y' ), 'Array is ignored' );
201  $this->assertSame( "A\r\nb", $req->getRawVal( 'crlf' ), 'CRLF' );
202  }
203 
207  public function testGetArray() {
208  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => [ 'a', 'b' ] ] );
209  $this->assertSame( [ 'Value' ], $req->getArray( 'x' ), 'Value becomes array' );
210  $this->assertSame( null, $req->getArray( 'z' ), 'Not found' );
211  $this->assertSame( [ 'a', 'b' ], $req->getArray( 'y' ) );
212  }
213 
217  public function testGetIntArray() {
218  $req = $this->mockWebRequest( [ 'x' => [ 'Value' ], 'y' => [ '0', '4.2', '-2' ] ] );
219  $this->assertSame( [ 0 ], $req->getIntArray( 'x' ), 'Text becomes 0' );
220  $this->assertSame( null, $req->getIntArray( 'z' ), 'Not found' );
221  $this->assertSame( [ 0, 4, -2 ], $req->getIntArray( 'y' ) );
222  }
223 
227  public function testGetInt() {
228  $req = $this->mockWebRequest( [
229  'x' => 'Value',
230  'y' => [ 'a' ],
231  'zero' => '0',
232  'answer' => '4.2',
233  'neg' => '-2',
234  ] );
235  $this->assertSame( 0, $req->getInt( 'x' ), 'Text' );
236  $this->assertSame( 0, $req->getInt( 'y' ), 'Array' );
237  $this->assertSame( 0, $req->getInt( 'z' ), 'Not found' );
238  $this->assertSame( 0, $req->getInt( 'zero' ) );
239  $this->assertSame( 4, $req->getInt( 'answer' ) );
240  $this->assertSame( -2, $req->getInt( 'neg' ) );
241  }
242 
246  public function testGetIntOrNull() {
247  $req = $this->mockWebRequest( [
248  'x' => 'Value',
249  'y' => [ 'a' ],
250  'zero' => '0',
251  'answer' => '4.2',
252  'neg' => '-2',
253  ] );
254  $this->assertSame( null, $req->getIntOrNull( 'x' ), 'Text' );
255  $this->assertSame( null, $req->getIntOrNull( 'y' ), 'Array' );
256  $this->assertSame( null, $req->getIntOrNull( 'z' ), 'Not found' );
257  $this->assertSame( 0, $req->getIntOrNull( 'zero' ) );
258  $this->assertSame( 4, $req->getIntOrNull( 'answer' ) );
259  $this->assertSame( -2, $req->getIntOrNull( 'neg' ) );
260  }
261 
265  public function testGetFloat() {
266  $req = $this->mockWebRequest( [
267  'x' => 'Value',
268  'y' => [ 'a' ],
269  'zero' => '0',
270  'answer' => '4.2',
271  'neg' => '-2',
272  ] );
273  $this->assertSame( 0.0, $req->getFloat( 'x' ), 'Text' );
274  $this->assertSame( 0.0, $req->getFloat( 'y' ), 'Array' );
275  $this->assertSame( 0.0, $req->getFloat( 'z' ), 'Not found' );
276  $this->assertSame( 0.0, $req->getFloat( 'zero' ) );
277  $this->assertSame( 4.2, $req->getFloat( 'answer' ) );
278  $this->assertSame( -2.0, $req->getFloat( 'neg' ) );
279  }
280 
284  public function testGetBool() {
285  $req = $this->mockWebRequest( [
286  'x' => 'Value',
287  'y' => [ 'a' ],
288  'zero' => '0',
289  'f' => 'false',
290  't' => 'true',
291  ] );
292  $this->assertSame( true, $req->getBool( 'x' ), 'Text' );
293  $this->assertSame( false, $req->getBool( 'y' ), 'Array' );
294  $this->assertSame( false, $req->getBool( 'z' ), 'Not found' );
295  $this->assertSame( false, $req->getBool( 'zero' ) );
296  $this->assertSame( true, $req->getBool( 'f' ) );
297  $this->assertSame( true, $req->getBool( 't' ) );
298  }
299 
300  public static function provideFuzzyBool() {
301  return [
302  [ 'Text', true ],
303  [ '', false, '(empty string)' ],
304  [ '0', false ],
305  [ '1', true ],
306  [ 'false', false ],
307  [ 'true', true ],
308  [ 'False', false ],
309  [ 'True', true ],
310  [ 'FALSE', false ],
311  [ 'TRUE', true ],
312  ];
313  }
314 
319  public function testGetFuzzyBool( $value, $expected, $message = null ) {
320  $req = $this->mockWebRequest( [ 'x' => $value ] );
321  $this->assertSame( $expected, $req->getFuzzyBool( 'x' ), $message ?: "Value: '$value'" );
322  }
323 
327  public function testGetFuzzyBoolDefault() {
328  $req = $this->mockWebRequest();
329  $this->assertSame( false, $req->getFuzzyBool( 'z' ), 'Not found' );
330  }
331 
335  public function testGetCheck() {
336  $req = $this->mockWebRequest( [ 'x' => 'Value', 'zero' => '0' ] );
337  $this->assertSame( false, $req->getCheck( 'z' ), 'Not found' );
338  $this->assertSame( true, $req->getCheck( 'x' ), 'Text' );
339  $this->assertSame( true, $req->getCheck( 'zero' ) );
340  }
341 
345  public function testGetText() {
346  // Avoid FauxRequest (overrides getText)
347  $req = $this->mockWebRequest( [ 'crlf' => "Va\r\nlue" ] );
348  $this->assertSame( "Va\nlue", $req->getText( 'crlf' ), 'CR stripped' );
349  }
350 
354  public function testGetValues() {
355  $values = [ 'x' => 'Value', 'y' => '' ];
356  // Avoid FauxRequest (overrides getValues)
357  $req = $this->mockWebRequest( $values );
358  $this->assertSame( $values, $req->getValues() );
359  $this->assertSame( [ 'x' => 'Value' ], $req->getValues( 'x' ), 'Specific keys' );
360  }
361 
365  public function testGetValueNames() {
366  $req = $this->mockWebRequest( [ 'x' => 'Value', 'y' => '' ] );
367  $this->assertSame( [ 'x', 'y' ], $req->getValueNames() );
368  $this->assertSame( [ 'x' ], $req->getValueNames( [ 'y' ] ), 'Exclude keys' );
369  }
370 
375  public function testGetIP( $expected, $input, $squid, $xffList, $private, $description ) {
376  $this->setServerVars( $input );
377  $this->setMwGlobals( [
378  'wgUsePrivateIPs' => $private,
379  'wgHooks' => [
380  'IsTrustedProxy' => [
381  function ( &$ip, &$trusted ) use ( $xffList ) {
382  $trusted = $trusted || in_array( $ip, $xffList );
383  return true;
384  }
385  ]
386  ]
387  ] );
388 
389  $this->setService( 'ProxyLookup', new ProxyLookup( [], $squid ) );
390 
391  $request = new WebRequest();
392  $result = $request->getIP();
393  $this->assertEquals( $expected, $result, $description );
394  }
395 
396  public static function provideGetIP() {
397  return [
398  [
399  '127.0.0.1',
400  [
401  'REMOTE_ADDR' => '127.0.0.1'
402  ],
403  [],
404  [],
405  false,
406  'Simple IPv4'
407  ],
408  [
409  '::1',
410  [
411  'REMOTE_ADDR' => '::1'
412  ],
413  [],
414  [],
415  false,
416  'Simple IPv6'
417  ],
418  [
419  '12.0.0.1',
420  [
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',
423  ],
424  [ 'ABCD:1:2:3:4:555:6666:7777' ],
425  [],
426  false,
427  'IPv6 normalisation'
428  ],
429  [
430  '12.0.0.3',
431  [
432  'REMOTE_ADDR' => '12.0.0.1',
433  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
434  ],
435  [ '12.0.0.1', '12.0.0.2' ],
436  [],
437  false,
438  'With X-Forwaded-For'
439  ],
440  [
441  '12.0.0.1',
442  [
443  'REMOTE_ADDR' => '12.0.0.1',
444  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
445  ],
446  [],
447  [],
448  false,
449  'With X-Forwaded-For and disallowed server'
450  ],
451  [
452  '12.0.0.2',
453  [
454  'REMOTE_ADDR' => '12.0.0.1',
455  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
456  ],
457  [ '12.0.0.1' ],
458  [],
459  false,
460  'With multiple X-Forwaded-For and only one allowed server'
461  ],
462  [
463  '10.0.0.3',
464  [
465  'REMOTE_ADDR' => '12.0.0.2',
466  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
467  ],
468  [ '12.0.0.1', '12.0.0.2' ],
469  [],
470  false,
471  'With X-Forwaded-For and private IP (from cache proxy)'
472  ],
473  [
474  '10.0.0.4',
475  [
476  'REMOTE_ADDR' => '12.0.0.2',
477  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
478  ],
479  [ '12.0.0.1', '12.0.0.2', '10.0.0.3' ],
480  [],
481  true,
482  'With X-Forwaded-For and private IP (allowed)'
483  ],
484  [
485  '10.0.0.4',
486  [
487  'REMOTE_ADDR' => '12.0.0.2',
488  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
489  ],
490  [ '12.0.0.1', '12.0.0.2' ],
491  [ '10.0.0.3' ],
492  true,
493  'With X-Forwaded-For and private IP (allowed)'
494  ],
495  [
496  '10.0.0.3',
497  [
498  'REMOTE_ADDR' => '12.0.0.2',
499  'HTTP_X_FORWARDED_FOR' => '10.0.0.4, 10.0.0.3, 12.0.0.2'
500  ],
501  [ '12.0.0.1', '12.0.0.2' ],
502  [ '10.0.0.3' ],
503  false,
504  'With X-Forwaded-For and private IP (disallowed)'
505  ],
506  [
507  '12.0.0.3',
508  [
509  'REMOTE_ADDR' => '12.0.0.1',
510  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
511  ],
512  [],
513  [ '12.0.0.1', '12.0.0.2' ],
514  false,
515  'With X-Forwaded-For'
516  ],
517  [
518  '12.0.0.2',
519  [
520  'REMOTE_ADDR' => '12.0.0.1',
521  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
522  ],
523  [],
524  [ '12.0.0.1' ],
525  false,
526  'With multiple X-Forwaded-For and only one allowed server'
527  ],
528  [
529  '12.0.0.2',
530  [
531  'REMOTE_ADDR' => '12.0.0.2',
532  'HTTP_X_FORWARDED_FOR' => '10.0.0.3, 12.0.0.2'
533  ],
534  [],
535  [ '12.0.0.2' ],
536  false,
537  'With X-Forwaded-For and private IP and hook (disallowed)'
538  ],
539  [
540  '12.0.0.1',
541  [
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',
544  ],
545  [ 'ABCD:1:2:3::/64' ],
546  [],
547  false,
548  'IPv6 CIDR'
549  ],
550  [
551  '12.0.0.3',
552  [
553  'REMOTE_ADDR' => '12.0.0.1',
554  'HTTP_X_FORWARDED_FOR' => '12.0.0.3, 12.0.0.2'
555  ],
556  [ '12.0.0.0/24' ],
557  [],
558  false,
559  'IPv4 CIDR'
560  ],
561  ];
562  }
563 
569  // ensure that local install state doesn't interfere with test
570  $this->setMwGlobals( [
571  'wgSquidServersNoPurge' => [],
572  'wgSquidServers' => [],
573  'wgUsePrivateIPs' => false,
574  'wgHooks' => [],
575  ] );
576  $this->setService( 'ProxyLookup', new ProxyLookup( [], [] ) );
577 
578  $request = new WebRequest();
579  # Next call throw an exception about lacking an IP
580  $request->getIP();
581  }
582 
583  public static function provideLanguageData() {
584  return [
585  [ '', [], 'Empty Accept-Language header' ],
586  [ 'en', [ 'en' => 1 ], 'One language' ],
587  [ 'en, ar', [ 'en' => 1, 'ar' => 1 ], 'Two languages listed in appearance order.' ],
588  [
589  'zh-cn,zh-tw',
590  [ 'zh-cn' => 1, 'zh-tw' => 1 ],
591  'Two equally prefered languages, listed in appearance order per rfc3282. Checks c9119'
592  ],
593  [
594  'es, en; q=0.5',
595  [ 'es' => 1, 'en' => '0.5' ],
596  'Spanish as first language and English and second'
597  ],
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" ],
602  [
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'
606  ],
607  [
608  'en-gb, en-us; q=1',
609  [ 'en-gb' => 1, 'en-us' => '1' ],
610  'Two equally prefered English variants'
611  ],
612  [ '_', [], 'Invalid input' ],
613  ];
614  }
615 
620  public function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) {
621  $this->setServerVars( [ 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ] );
622  $request = new WebRequest();
623  $this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description );
624  }
625 
626  protected function setServerVars( $vars ) {
627  // Don't remove vars which should be available in all SAPI.
628  if ( !isset( $vars['REQUEST_TIME_FLOAT'] ) ) {
629  $vars['REQUEST_TIME_FLOAT'] = $_SERVER['REQUEST_TIME_FLOAT'];
630  }
631  if ( !isset( $vars['REQUEST_TIME'] ) ) {
632  $vars['REQUEST_TIME'] = $_SERVER['REQUEST_TIME'];
633  }
634  $_SERVER = $vars;
635  }
636 }
testGetFloat()
WebRequest::getFloat.
testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description)
provideLanguageData WebRequest::getAcceptLang
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))
testGetIpLackOfRemoteAddrThrowAnException()
MWException WebRequest::getIP.
testGetIntArray()
WebRequest::getIntArray.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
if(is_array( $mode)) switch( $mode) $input
testGetInt()
WebRequest::getInt.
testGetIP( $expected, $input, $squid, $xffList, $private, $description)
provideGetIP WebRequest::getIP
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=[])
testGetArray()
WebRequest::getArray.
testGetElapsedTime()
WebRequest::getElapsedTime.
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.
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.