MediaWiki  REL1_31
GlobalTest.php
Go to the documentation of this file.
1 <?php
2 
8  protected function setUp() {
9  parent::setUp();
10 
11  $readOnlyFile = $this->getNewTempFile();
12  unlink( $readOnlyFile );
13 
14  $this->setMwGlobals( [
15  'wgReadOnlyFile' => $readOnlyFile,
16  'wgUrlProtocols' => [
17  'http://',
18  'https://',
19  'mailto:',
20  '//',
21  'file://', # Non-default
22  ],
23  ] );
24  }
25 
30  public function testWfArrayDiff2( $a, $b, $expected ) {
31  $this->assertEquals(
32  wfArrayDiff2( $a, $b ), $expected
33  );
34  }
35 
36  // @todo Provide more tests
37  public static function provideForWfArrayDiff2() {
38  // $a $b $expected
39  return [
40  [
41  [ 'a', 'b' ],
42  [ 'a', 'b' ],
43  [],
44  ],
45  [
46  [ [ 'a' ], [ 'a', 'b', 'c' ] ],
47  [ [ 'a' ], [ 'a', 'b' ] ],
48  [ 1 => [ 'a', 'b', 'c' ] ],
49  ],
50  ];
51  }
52 
53  /*
54  * Test cases for random functions could hypothetically fail,
55  * even though they shouldn't.
56  */
57 
61  public function testRandom() {
62  $this->assertFalse(
63  wfRandom() == wfRandom()
64  );
65  }
66 
70  public function testRandomString() {
71  $this->assertFalse(
73  );
74  $this->assertEquals(
75  strlen( wfRandomString( 10 ) ), 10
76  );
77  $this->assertTrue(
78  preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
79  );
80  }
81 
85  public function testUrlencode() {
86  $this->assertEquals(
87  "%E7%89%B9%E5%88%A5:Contributions/Foobar",
88  wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
89  }
90 
94  public function testExpandIRI() {
95  $this->assertEquals(
96  "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
97  wfExpandIRI( "https://te.wikibooks.org/wiki/"
98  . "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
99  . "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
100  . "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
101  . "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
102  }
103 
108  public function testReadOnlyEmpty() {
110  $wgReadOnly = null;
111 
112  MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache();
113  $this->assertFalse( wfReadOnly() );
114  $this->assertFalse( wfReadOnly() );
115  }
116 
121  public function testReadOnlySet() {
123 
124  $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
125  $readOnlyMode->clearCache();
126 
127  $f = fopen( $wgReadOnlyFile, "wt" );
128  fwrite( $f, 'Message' );
129  fclose( $f );
130  $wgReadOnly = null; # Check on $wgReadOnlyFile
131 
132  $this->assertTrue( wfReadOnly() );
133  $this->assertTrue( wfReadOnly() ); # Check cached
134 
135  unlink( $wgReadOnlyFile );
136  $readOnlyMode->clearCache();
137  $this->assertFalse( wfReadOnly() );
138  $this->assertFalse( wfReadOnly() );
139  }
140 
145  public function testReadOnlyGlobalChange() {
146  $this->assertFalse( wfReadOnlyReason() );
147  $this->setMwGlobals( [
148  'wgReadOnly' => 'reason'
149  ] );
150  $this->assertSame( 'reason', wfReadOnlyReason() );
151  }
152 
153  public static function provideArrayToCGI() {
154  return [
155  [ [], '' ], // empty
156  [ [ 'foo' => 'bar' ], 'foo=bar' ], // string test
157  [ [ 'foo' => '' ], 'foo=' ], // empty string test
158  [ [ 'foo' => 1 ], 'foo=1' ], // number test
159  [ [ 'foo' => true ], 'foo=1' ], // true test
160  [ [ 'foo' => false ], '' ], // false test
161  [ [ 'foo' => null ], '' ], // null test
162  [ [ 'foo' => 'A&B=5+6@!"\'' ], 'foo=A%26B%3D5%2B6%40%21%22%27' ], // urlencoding test
163  [
164  [ 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ],
165  'foo=bar&baz=is&asdf=qwerty'
166  ], // multi-item test
167  [ [ 'foo' => [ 'bar' => 'baz' ] ], 'foo%5Bbar%5D=baz' ],
168  [
169  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ],
170  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
171  ],
172  [ [ 'foo' => [ 'bar', 'baz' ] ], 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
173  [
174  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ],
175  'foo%5Bbar%5D%5Bbar%5D=baz'
176  ],
177  ];
178  }
179 
184  public function testArrayToCGI( $array, $result ) {
185  $this->assertEquals( $result, wfArrayToCgi( $array ) );
186  }
187 
191  public function testArrayToCGI2() {
192  $this->assertEquals(
193  "baz=bar&foo=bar",
194  wfArrayToCgi(
195  [ 'baz' => 'bar' ],
196  [ 'foo' => 'bar', 'baz' => 'overridden value' ] ) );
197  }
198 
199  public static function provideCgiToArray() {
200  return [
201  [ '', [] ], // empty
202  [ 'foo=bar', [ 'foo' => 'bar' ] ], // string
203  [ 'foo=', [ 'foo' => '' ] ], // empty string
204  [ 'foo', [ 'foo' => '' ] ], // missing =
205  [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
206  [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
207  [ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
208  [
209  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
210  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
211  ],
212  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz', [ 'foo' => [ 0 => 'bar', 1 => 'baz' ] ] ],
213  [
214  'foo%5Bbar%5D%5Bbar%5D=baz',
215  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
216  ],
217  ];
218  }
219 
224  public function testCgiToArray( $cgi, $result ) {
225  $this->assertEquals( $result, wfCgiToArray( $cgi ) );
226  }
227 
228  public static function provideCgiRoundTrip() {
229  return [
230  [ '' ],
231  [ 'foo=bar' ],
232  [ 'foo=' ],
233  [ 'foo=bar&baz=biz' ],
234  [ 'foo=A%26B%3D5%2B6%40%21%22%27' ],
235  [ 'foo%5Bbar%5D=baz' ],
236  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
237  [ 'foo%5Bbar%5D%5Bbar%5D=baz' ],
238  ];
239  }
240 
245  public function testCgiRoundTrip( $cgi ) {
246  $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
247  }
248 
252  public function testMimeTypeMatch() {
253  $this->assertEquals(
254  'text/html',
255  mimeTypeMatch( 'text/html',
256  [ 'application/xhtml+xml' => 1.0,
257  'text/html' => 0.7,
258  'text/plain' => 0.3 ] ) );
259  $this->assertEquals(
260  'text/*',
261  mimeTypeMatch( 'text/html',
262  [ 'image/*' => 1.0,
263  'text/*' => 0.5 ] ) );
264  $this->assertEquals(
265  '*/*',
266  mimeTypeMatch( 'text/html',
267  [ '*/*' => 1.0 ] ) );
268  $this->assertNull(
269  mimeTypeMatch( 'text/html',
270  [ 'image/png' => 1.0,
271  'image/svg+xml' => 0.5 ] ) );
272  }
273 
277  public function testNegotiateType() {
278  $this->assertEquals(
279  'text/html',
281  [ 'application/xhtml+xml' => 1.0,
282  'text/html' => 0.7,
283  'text/plain' => 0.5,
284  'text/*' => 0.2 ],
285  [ 'text/html' => 1.0 ] ) );
286  $this->assertEquals(
287  'application/xhtml+xml',
289  [ 'application/xhtml+xml' => 1.0,
290  'text/html' => 0.7,
291  'text/plain' => 0.5,
292  'text/*' => 0.2 ],
293  [ 'application/xhtml+xml' => 1.0,
294  'text/html' => 0.5 ] ) );
295  $this->assertEquals(
296  'text/html',
298  [ 'text/html' => 1.0,
299  'text/plain' => 0.5,
300  'text/*' => 0.5,
301  'application/xhtml+xml' => 0.2 ],
302  [ 'application/xhtml+xml' => 1.0,
303  'text/html' => 0.5 ] ) );
304  $this->assertEquals(
305  'text/html',
307  [ 'text/*' => 1.0,
308  'image/*' => 0.7,
309  '*/*' => 0.3 ],
310  [ 'application/xhtml+xml' => 1.0,
311  'text/html' => 0.5 ] ) );
312  $this->assertNull(
314  [ 'text/*' => 1.0 ],
315  [ 'application/xhtml+xml' => 1.0 ] ) );
316  }
317 
322  public function testDebugFunctionTest() {
323  $debugLogFile = $this->getNewTempFile();
324 
325  $this->setMwGlobals( [
326  'wgDebugLogFile' => $debugLogFile,
327  #  @todo FIXME: $wgDebugTimestamps should be tested
328  'wgDebugTimestamps' => false
329  ] );
330 
331  wfDebug( "This is a normal string" );
332  $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
333  unlink( $debugLogFile );
334 
335  wfDebug( "This is nöt an ASCII string" );
336  $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
337  unlink( $debugLogFile );
338 
339  wfDebug( "\00305This has böth UTF and control chars\003" );
340  $this->assertEquals(
341  " 05This has böth UTF and control chars \n",
342  file_get_contents( $debugLogFile )
343  );
344  unlink( $debugLogFile );
345 
346  wfDebugMem();
347  $this->assertGreaterThan(
348  1000,
349  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
350  );
351  unlink( $debugLogFile );
352 
353  wfDebugMem( true );
354  $this->assertGreaterThan(
355  1000000,
356  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
357  );
358  unlink( $debugLogFile );
359  }
360 
364  public function testClientAcceptsGzipTest() {
365  $settings = [
366  'gzip' => true,
367  'bzip' => false,
368  '*' => false,
369  'compress, gzip' => true,
370  'gzip;q=1.0' => true,
371  'foozip' => false,
372  'foo*zip' => false,
373  'gzip;q=abcde' => true, // is this REALLY valid?
374  'gzip;q=12345678.9' => true,
375  ' gzip' => true,
376  ];
377 
378  if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
379  $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
380  }
381 
382  foreach ( $settings as $encoding => $expect ) {
383  $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
384 
385  $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
386  "'$encoding' => " . wfBoolToStr( $expect ) );
387  }
388 
389  if ( isset( $old_server_setting ) ) {
390  $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
391  }
392  }
393 
397  public function testWfPercentTest() {
398  $pcts = [
399  [ 6 / 7, '0.86%', 2, false ],
400  [ 3 / 3, '1%' ],
401  [ 22 / 7, '3.14286%', 5 ],
402  [ 3 / 6, '0.5%' ],
403  [ 1 / 3, '0%', 0 ],
404  [ 10 / 3, '0%', -1 ],
405  [ 3 / 4 / 5, '0.1%', 1 ],
406  [ 6 / 7 * 8, '6.8571428571%', 10 ],
407  ];
408 
409  foreach ( $pcts as $pct ) {
410  if ( !isset( $pct[2] ) ) {
411  $pct[2] = 2;
412  }
413  if ( !isset( $pct[3] ) ) {
414  $pct[3] = true;
415  }
416 
417  $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
418  }
419  }
420 
426  public function testWfShorthandToInteger( $shorthand, $expected ) {
427  $this->assertEquals( $expected,
428  wfShorthandToInteger( $shorthand )
429  );
430  }
431 
432  public static function provideShorthand() {
433  // Syntax: [ shorthand, expected integer ]
434  return [
435  # Null, empty ...
436  [ '', -1 ],
437  [ ' ', -1 ],
438  [ null, -1 ],
439 
440  # Failures returns 0 :(
441  [ 'ABCDEFG', 0 ],
442  [ 'Ak', 0 ],
443 
444  # Int, strings with spaces
445  [ 1, 1 ],
446  [ ' 1 ', 1 ],
447  [ 1023, 1023 ],
448  [ ' 1023 ', 1023 ],
449 
450  # kilo, Mega, Giga
451  [ '1k', 1024 ],
452  [ '1K', 1024 ],
453  [ '1m', 1024 * 1024 ],
454  [ '1M', 1024 * 1024 ],
455  [ '1g', 1024 * 1024 * 1024 ],
456  [ '1G', 1024 * 1024 * 1024 ],
457 
458  # Negatives
459  [ -1, -1 ],
460  [ -500, -500 ],
461  [ '-500', -500 ],
462  [ '-1k', -1024 ],
463 
464  # Zeroes
465  [ '0', 0 ],
466  [ '0k', 0 ],
467  [ '0M', 0 ],
468  [ '0G', 0 ],
469  [ '-0', 0 ],
470  [ '-0k', 0 ],
471  [ '-0M', 0 ],
472  [ '-0G', 0 ],
473  ];
474  }
475 
480  $this->markTestSkippedIfNoDiff3();
481 
482  $mergedText = null;
483  $successfulMerge = wfMerge( "old1\n\nold2", "old1\n\nnew2", "new1\n\nold2", $mergedText );
484 
485  $mergedText = null;
486  $conflictingMerge = wfMerge( 'old', 'old and mine', 'old and yours', $mergedText );
487 
488  $this->assertEquals( true, $successfulMerge );
489  $this->assertEquals( false, $conflictingMerge );
490  }
491 
504  public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
505  $expectedMergeAttemptResult ) {
506  $this->markTestSkippedIfNoDiff3();
507 
508  $mergedText = null;
509  $attemptMergeResult = null;
510  $isMerged = wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
511 
512  $msg = 'Merge should be a ';
513  $msg .= $expectedMergeResult ? 'success' : 'failure';
514  $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
515  $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
516 
517  if ( $isMerged ) {
518  // Verify the merged text
519  $this->assertEquals( $expectedText, $mergedText,
520  'is merged text as expected?' );
521  }
522  }
523 
524  public static function provideMerge() {
525  $EXPECT_MERGE_SUCCESS = true;
526  $EXPECT_MERGE_FAILURE = false;
527 
528  return [
529  // #0: clean merge
530  [
531  // old:
532  "one one one\n" . // trimmed
533  "\n" .
534  "two two two",
535 
536  // mine:
537  "one one one ONE ONE\n" .
538  "\n" .
539  "two two two\n", // with tailing whitespace
540 
541  // yours:
542  "one one one\n" .
543  "\n" .
544  "two two TWO TWO", // trimmed
545 
546  // ok:
547  $EXPECT_MERGE_SUCCESS,
548 
549  // result:
550  "one one one ONE ONE\n" .
551  "\n" .
552  "two two TWO TWO\n", // note: will always end in a newline
553 
554  // mergeAttemptResult:
555  "",
556  ],
557 
558  // #1: conflict, fail
559  [
560  // old:
561  "one one one", // trimmed
562 
563  // mine:
564  "one one one ONE ONE\n" .
565  "\n" .
566  "bla bla\n" .
567  "\n", // with tailing whitespace
568 
569  // yours:
570  "one one one\n" .
571  "\n" .
572  "two two", // trimmed
573 
574  $EXPECT_MERGE_FAILURE,
575 
576  // result:
577  null,
578 
579  // mergeAttemptResult:
580  "1,3c\n" .
581  "one one one\n" .
582  "\n" .
583  "two two\n" .
584  ".\n",
585  ],
586  ];
587  }
588 
593  public function testMakeUrlIndexes( $url, $expected ) {
594  $index = wfMakeUrlIndexes( $url );
595  $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
596  }
597 
598  public static function provideMakeUrlIndexes() {
599  return [
600  // Testcase for T30627
601  [
602  'https://example.org/test.cgi?id=12345',
603  [ 'https://org.example./test.cgi?id=12345' ]
604  ],
605  [
606  // mailtos are handled special
607  // is this really right though? that final . probably belongs earlier?
608  'mailto:wiki@wikimedia.org',
609  [ 'mailto:org.wikimedia@wiki.' ]
610  ],
611 
612  // file URL cases per T30627...
613  [
614  // three slashes: local filesystem path Unix-style
615  'file:///whatever/you/like.txt',
616  [ 'file://./whatever/you/like.txt' ]
617  ],
618  [
619  // three slashes: local filesystem path Windows-style
620  'file:///c:/whatever/you/like.txt',
621  [ 'file://./c:/whatever/you/like.txt' ]
622  ],
623  [
624  // two slashes: UNC filesystem path Windows-style
625  'file://intranet/whatever/you/like.txt',
626  [ 'file://intranet./whatever/you/like.txt' ]
627  ],
628  // Multiple-slash cases that can sorta work on Mozilla
629  // if you hack it just right are kinda pathological,
630  // and unreliable cross-platform or on IE which means they're
631  // unlikely to appear on intranets.
632  // Those will survive the algorithm but with results that
633  // are less consistent.
634 
635  // protocol-relative URL cases per T31854...
636  [
637  '//example.org/test.cgi?id=12345',
638  [
639  'http://org.example./test.cgi?id=12345',
640  'https://org.example./test.cgi?id=12345'
641  ]
642  ],
643  ];
644  }
645 
650  public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
651  $actual = wfMatchesDomainList( $url, $domains );
652  $this->assertEquals( $expected, $actual, $description );
653  }
654 
655  public static function provideWfMatchesDomainList() {
656  $a = [];
657  $protocols = [ 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ];
658  foreach ( $protocols as $pDesc => $p ) {
659  $a = array_merge( $a, [
660  [
661  "$p//www.example.com",
662  [],
663  false,
664  "No matches for empty domains array, $pDesc URL"
665  ],
666  [
667  "$p//www.example.com",
668  [ 'www.example.com' ],
669  true,
670  "Exact match in domains array, $pDesc URL"
671  ],
672  [
673  "$p//www.example.com",
674  [ 'example.com' ],
675  true,
676  "Match without subdomain in domains array, $pDesc URL"
677  ],
678  [
679  "$p//www.example2.com",
680  [ 'www.example.com', 'www.example2.com', 'www.example3.com' ],
681  true,
682  "Exact match with other domains in array, $pDesc URL"
683  ],
684  [
685  "$p//www.example2.com",
686  [ 'example.com', 'example2.com', 'example3,com' ],
687  true,
688  "Match without subdomain with other domains in array, $pDesc URL"
689  ],
690  [
691  "$p//www.example4.com",
692  [ 'example.com', 'example2.com', 'example3,com' ],
693  false,
694  "Domain not in array, $pDesc URL"
695  ],
696  [
697  "$p//nds-nl.wikipedia.org",
698  [ 'nl.wikipedia.org' ],
699  false,
700  "Non-matching substring of domain, $pDesc URL"
701  ],
702  ] );
703  }
704 
705  return $a;
706  }
707 
711  public function testWfMkdirParents() {
712  // Should not return true if file exists instead of directory
713  $fname = $this->getNewTempFile();
714  Wikimedia\suppressWarnings();
715  $ok = wfMkdirParents( $fname );
716  Wikimedia\restoreWarnings();
717  $this->assertFalse( $ok );
718  }
719 
724  public function testWfShellWikiCmd( $script, $parameters, $options,
725  $expected, $description
726  ) {
727  if ( wfIsWindows() ) {
728  // Approximation that's good enough for our purposes just now
729  $expected = str_replace( "'", '"', $expected );
730  }
731  $actual = wfShellWikiCmd( $script, $parameters, $options );
732  $this->assertEquals( $expected, $actual, $description );
733  }
734 
735  public function wfWikiID() {
736  $this->setMwGlobals( [
737  'wgDBname' => 'example',
738  'wgDBprefix' => '',
739  ] );
740  $this->assertEquals(
741  wfWikiID(),
742  'example'
743  );
744 
745  $this->setMwGlobals( [
746  'wgDBname' => 'example',
747  'wgDBprefix' => 'mw_',
748  ] );
749  $this->assertEquals(
750  wfWikiID(),
751  'example-mw_'
752  );
753  }
754 
758  public function testWfMemcKey() {
760  $this->assertEquals(
761  $cache->makeKey( 'foo', 123, 'bar' ),
762  wfMemcKey( 'foo', 123, 'bar' )
763  );
764  }
765 
769  public function testWfForeignMemcKey() {
771  $keyspace = $this->readAttribute( $cache, 'keyspace' );
772  $this->assertEquals(
773  wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
774  $cache->makeKey( 'foo', 'bar' )
775  );
776  }
777 
781  public function testWfGlobalCacheKey() {
783  $this->assertEquals(
784  $cache->makeGlobalKey( 'foo', 123, 'bar' ),
785  wfGlobalCacheKey( 'foo', 123, 'bar' )
786  );
787  }
788 
789  public static function provideWfShellWikiCmdList() {
791 
792  return [
793  [ 'eval.php', [ '--help', '--test' ], [],
794  "'$wgPhpCli' 'eval.php' '--help' '--test'",
795  "Called eval.php --help --test" ],
796  [ 'eval.php', [ '--help', '--test space' ], [ 'php' => 'php5' ],
797  "'php5' 'eval.php' '--help' '--test space'",
798  "Called eval.php --help --test with php option" ],
799  [ 'eval.php', [ '--help', '--test', 'X' ], [ 'wrapper' => 'MWScript.php' ],
800  "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
801  "Called eval.php --help --test with wrapper option" ],
802  [
803  'eval.php',
804  [ '--help', '--test', 'y' ],
805  [ 'php' => 'php5', 'wrapper' => 'MWScript.php' ],
806  "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
807  "Called eval.php --help --test with wrapper and php option"
808  ],
809  ];
810  }
811  /* @todo many more! */
812 }
$wgPhpCli
$wgPhpCli
Executable path of the PHP cli binary.
Definition: DefaultSettings.php:8300
wfPercent
wfPercent( $nr, $acc=2, $round=true)
Definition: GlobalFunctions.php:2144
GlobalTest\testRandomString
testRandomString()
wfRandomString
Definition: GlobalTest.php:70
GlobalTest\testMimeTypeMatch
testMimeTypeMatch()
mimeTypeMatch
Definition: GlobalTest.php:252
GlobalTest\testReadOnlyGlobalChange
testReadOnlyGlobalChange()
This behaviour could probably be deprecated.
Definition: GlobalTest.php:145
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:367
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2076
GlobalTest\testCgiRoundTrip
testCgiRoundTrip( $cgi)
provideCgiRoundTrip wfArrayToCgi
Definition: GlobalTest.php:245
wfMerge
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
Definition: GlobalFunctions.php:2359
GlobalTest\testWfMemcKey
testWfMemcKey()
wfMemcKey
Definition: GlobalTest.php:758
wfNegotiateType
wfNegotiateType( $cprefs, $sprefs)
Returns the 'best' match between a client's requested internet media types and the server's list of a...
Definition: GlobalFunctions.php:1918
wfMakeUrlIndexes
wfMakeUrlIndexes( $url)
Make URL indexes, appropriate for the el_index field of externallinks.
Definition: GlobalFunctions.php:906
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:340
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1262
GlobalTest\testExpandIRI
testExpandIRI()
wfExpandIRI
Definition: GlobalTest.php:94
$result
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. 'ImgAuthModifyHeaders':Executed just before a file is streamed to a user via img_auth.php, allowing headers to be modified beforehand. $title:LinkTarget object & $headers:HTTP headers(name=> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. '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. '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: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! 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:1993
wfExpandIRI
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
Definition: GlobalFunctions.php:883
true
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:2006
GlobalTest\testClientAcceptsGzipTest
testClientAcceptsGzipTest()
wfClientAcceptsGzip
Definition: GlobalTest.php:364
wfShellWikiCmd
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
Definition: GlobalFunctions.php:2334
GlobalTest\testWfArrayDiff2
testWfArrayDiff2( $a, $b, $expected)
provideForWfArrayDiff2 wfArrayDiff2
Definition: GlobalTest.php:30
php
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
GlobalTest\testWfShellWikiCmd
testWfShellWikiCmd( $script, $parameters, $options, $expected, $description)
provideWfShellWikiCmdList wfShellWikiCmd
Definition: GlobalTest.php:724
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Definition: GlobalFunctions.php:2931
GlobalTest\testRandom
testRandom()
wfRandom
Definition: GlobalTest.php:61
GlobalTest\testWfPercentTest
testWfPercentTest()
wfPercent
Definition: GlobalTest.php:397
wfMemcKey
wfMemcKey()
Make a cache key for the local wiki.
Definition: GlobalFunctions.php:2712
mimeTypeMatch
mimeTypeMatch( $type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
Definition: GlobalFunctions.php:1890
wfGlobalCacheKey
wfGlobalCacheKey()
Make a cache key with database-agnostic prefix.
Definition: GlobalFunctions.php:2750
GlobalTest\provideArrayToCGI
static provideArrayToCGI()
Definition: GlobalTest.php:153
wfArrayDiff2
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
Definition: GlobalFunctions.php:111
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:678
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:462
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
GlobalTest
Database GlobalFunctions.
Definition: GlobalTest.php:7
GlobalTest\testMerge
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText, $expectedMergeAttemptResult)
Definition: GlobalTest.php:504
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:422
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
wfForeignMemcKey
wfForeignMemcKey( $db, $prefix)
Make a cache key for a foreign DB.
Definition: GlobalFunctions.php:2729
GlobalTest\testCgiToArray
testCgiToArray( $cgi, $result)
provideCgiToArray wfCgiToArray
Definition: GlobalTest.php:224
GlobalTest\testReadOnlySet
testReadOnlySet()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
Definition: GlobalTest.php:121
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:994
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:112
$options
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 & $options
Definition: hooks.txt:2001
GlobalTest\testMerge_worksWithLessParameters
testMerge_worksWithLessParameters()
wfMerge
Definition: GlobalTest.php:479
GlobalTest\provideMakeUrlIndexes
static provideMakeUrlIndexes()
Definition: GlobalTest.php:598
$wgDebugTimestamps
$wgDebugTimestamps
Prefix debug messages with relative timestamp.
Definition: DefaultSettings.php:6278
GlobalTest\setUp
setUp()
Definition: GlobalTest.php:8
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:109
MediaWikiTestCase\markTestSkippedIfNoDiff3
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Definition: MediaWikiTestCase.php:1967
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
Definition: GlobalFunctions.php:1609
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:2019
GlobalTest\testDebugFunctionTest
testDebugFunctionTest()
wfDebug wfDebugMem
Definition: GlobalTest.php:322
$wgReadOnly
$wgReadOnly
Set this to a string to put the wiki into read-only mode.
Definition: DefaultSettings.php:6669
wfDebugMem
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
Definition: GlobalFunctions.php:1052
GlobalTest\provideMerge
static provideMerge()
Definition: GlobalTest.php:524
GlobalTest\testWfMatchesDomainList
testWfMatchesDomainList( $url, $domains, $expected, $description)
provideWfMatchesDomainList wfMatchesDomainList
Definition: GlobalTest.php:650
GlobalTest\provideWfMatchesDomainList
static provideWfMatchesDomainList()
Definition: GlobalTest.php:655
wfShorthandToInteger
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
Definition: GlobalFunctions.php:3094
GlobalTest\testWfShorthandToInteger
testWfShorthandToInteger( $shorthand, $expected)
test
Definition: GlobalTest.php:426
GlobalTest\provideShorthand
static provideShorthand()
Definition: GlobalTest.php:432
wfRandom
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
Definition: GlobalFunctions.php:287
wfReadOnlyReason
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
Definition: GlobalFunctions.php:1275
wfMatchesDomainList
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
Definition: GlobalFunctions.php:960
$cache
$cache
Definition: mcc.php:33
$wgReadOnlyFile
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
Definition: DefaultSettings.php:6685
GlobalTest\testUrlencode
testUrlencode()
wfUrlencode
Definition: GlobalTest.php:85
GlobalTest\testArrayToCGI2
testArrayToCGI2()
wfArrayToCgi
Definition: GlobalTest.php:191
on
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
Definition: hooks.txt:86
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
GlobalTest\testArrayToCGI
testArrayToCGI( $array, $result)
provideArrayToCGI wfArrayToCgi
Definition: GlobalTest.php:184
GlobalTest\testWfGlobalCacheKey
testWfGlobalCacheKey()
wfGlobalCacheKey
Definition: GlobalTest.php:781
GlobalTest\testWfForeignMemcKey
testWfForeignMemcKey()
wfForeignMemcKey
Definition: GlobalTest.php:769
GlobalTest\wfWikiID
wfWikiID()
Definition: GlobalTest.php:735
GlobalTest\testReadOnlyEmpty
testReadOnlyEmpty()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
Definition: GlobalTest.php:108
GlobalTest\provideCgiToArray
static provideCgiToArray()
Definition: GlobalTest.php:199
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
GlobalTest\testMakeUrlIndexes
testMakeUrlIndexes( $url, $expected)
provideMakeUrlIndexes() wfMakeUrlIndexes
Definition: GlobalTest.php:593
GlobalTest\provideForWfArrayDiff2
static provideForWfArrayDiff2()
Definition: GlobalTest.php:37
GlobalTest\testNegotiateType
testNegotiateType()
wfNegotiateType
Definition: GlobalTest.php:277
GlobalTest\provideCgiRoundTrip
static provideCgiRoundTrip()
Definition: GlobalTest.php:228
GlobalTest\provideWfShellWikiCmdList
static provideWfShellWikiCmdList()
Definition: GlobalTest.php:789
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:377
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:305
GlobalTest\testWfMkdirParents
testWfMkdirParents()
wfMkdirParents
Definition: GlobalTest.php:711