MediaWiki  1.32.0
GlobalTest.php
Go to the documentation of this file.
1 <?php
2 
4 
10  protected function setUp() {
11  parent::setUp();
12 
13  $readOnlyFile = $this->getNewTempFile();
14  unlink( $readOnlyFile );
15 
16  $this->setMwGlobals( [
17  'wgReadOnlyFile' => $readOnlyFile,
18  'wgUrlProtocols' => [
19  'http://',
20  'https://',
21  'mailto:',
22  '//',
23  'file://', # Non-default
24  ],
25  ] );
26  }
27 
32  public function testWfArrayDiff2( $a, $b, $expected ) {
33  $this->assertEquals(
34  wfArrayDiff2( $a, $b ), $expected
35  );
36  }
37 
38  // @todo Provide more tests
39  public static function provideForWfArrayDiff2() {
40  // $a $b $expected
41  return [
42  [
43  [ 'a', 'b' ],
44  [ 'a', 'b' ],
45  [],
46  ],
47  [
48  [ [ 'a' ], [ 'a', 'b', 'c' ] ],
49  [ [ 'a' ], [ 'a', 'b' ] ],
50  [ 1 => [ 'a', 'b', 'c' ] ],
51  ],
52  ];
53  }
54 
55  /*
56  * Test cases for random functions could hypothetically fail,
57  * even though they shouldn't.
58  */
59 
63  public function testRandom() {
64  $this->assertFalse(
65  wfRandom() == wfRandom()
66  );
67  }
68 
72  public function testRandomString() {
73  $this->assertFalse(
75  );
76  $this->assertEquals(
77  strlen( wfRandomString( 10 ) ), 10
78  );
79  $this->assertTrue(
80  preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
81  );
82  }
83 
87  public function testUrlencode() {
88  $this->assertEquals(
89  "%E7%89%B9%E5%88%A5:Contributions/Foobar",
90  wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
91  }
92 
96  public function testExpandIRI() {
97  $this->assertEquals(
98  "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
99  wfExpandIRI( "https://te.wikibooks.org/wiki/"
100  . "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
101  . "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
102  . "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
103  . "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
104  }
105 
110  public function testReadOnlyEmpty() {
111  global $wgReadOnly;
112  $wgReadOnly = null;
113 
114  MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache();
115  $this->assertFalse( wfReadOnly() );
116  $this->assertFalse( wfReadOnly() );
117  }
118 
123  public function testReadOnlySet() {
125 
126  $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
127  $readOnlyMode->clearCache();
128 
129  $f = fopen( $wgReadOnlyFile, "wt" );
130  fwrite( $f, 'Message' );
131  fclose( $f );
132  $wgReadOnly = null; # Check on $wgReadOnlyFile
133 
134  $this->assertTrue( wfReadOnly() );
135  $this->assertTrue( wfReadOnly() ); # Check cached
136 
137  unlink( $wgReadOnlyFile );
138  $readOnlyMode->clearCache();
139  $this->assertFalse( wfReadOnly() );
140  $this->assertFalse( wfReadOnly() );
141  }
142 
147  public function testReadOnlyGlobalChange() {
148  $this->assertFalse( wfReadOnlyReason() );
149  $this->setMwGlobals( [
150  'wgReadOnly' => 'reason'
151  ] );
152  $this->assertSame( 'reason', wfReadOnlyReason() );
153  }
154 
155  public static function provideArrayToCGI() {
156  return [
157  [ [], '' ], // empty
158  [ [ 'foo' => 'bar' ], 'foo=bar' ], // string test
159  [ [ 'foo' => '' ], 'foo=' ], // empty string test
160  [ [ 'foo' => 1 ], 'foo=1' ], // number test
161  [ [ 'foo' => true ], 'foo=1' ], // true test
162  [ [ 'foo' => false ], '' ], // false test
163  [ [ 'foo' => null ], '' ], // null test
164  [ [ 'foo' => 'A&B=5+6@!"\'' ], 'foo=A%26B%3D5%2B6%40%21%22%27' ], // urlencoding test
165  [
166  [ 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ],
167  'foo=bar&baz=is&asdf=qwerty'
168  ], // multi-item test
169  [ [ 'foo' => [ 'bar' => 'baz' ] ], 'foo%5Bbar%5D=baz' ],
170  [
171  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ],
172  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
173  ],
174  [ [ 'foo' => [ 'bar', 'baz' ] ], 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
175  [
176  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ],
177  'foo%5Bbar%5D%5Bbar%5D=baz'
178  ],
179  ];
180  }
181 
186  public function testArrayToCGI( $array, $result ) {
187  $this->assertEquals( $result, wfArrayToCgi( $array ) );
188  }
189 
193  public function testArrayToCGI2() {
194  $this->assertEquals(
195  "baz=bar&foo=bar",
196  wfArrayToCgi(
197  [ 'baz' => 'bar' ],
198  [ 'foo' => 'bar', 'baz' => 'overridden value' ] ) );
199  }
200 
201  public static function provideCgiToArray() {
202  return [
203  [ '', [] ], // empty
204  [ 'foo=bar', [ 'foo' => 'bar' ] ], // string
205  [ 'foo=', [ 'foo' => '' ] ], // empty string
206  [ 'foo', [ 'foo' => '' ] ], // missing =
207  [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
208  [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
209  [ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
210  [
211  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
212  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
213  ],
214  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz', [ 'foo' => [ 0 => 'bar', 1 => 'baz' ] ] ],
215  [
216  'foo%5Bbar%5D%5Bbar%5D=baz',
217  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
218  ],
219  ];
220  }
221 
226  public function testCgiToArray( $cgi, $result ) {
227  $this->assertEquals( $result, wfCgiToArray( $cgi ) );
228  }
229 
230  public static function provideCgiRoundTrip() {
231  return [
232  [ '' ],
233  [ 'foo=bar' ],
234  [ 'foo=' ],
235  [ 'foo=bar&baz=biz' ],
236  [ 'foo=A%26B%3D5%2B6%40%21%22%27' ],
237  [ 'foo%5Bbar%5D=baz' ],
238  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
239  [ 'foo%5Bbar%5D%5Bbar%5D=baz' ],
240  ];
241  }
242 
247  public function testCgiRoundTrip( $cgi ) {
248  $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
249  }
250 
254  public function testMimeTypeMatch() {
255  $this->assertEquals(
256  'text/html',
257  mimeTypeMatch( 'text/html',
258  [ 'application/xhtml+xml' => 1.0,
259  'text/html' => 0.7,
260  'text/plain' => 0.3 ] ) );
261  $this->assertEquals(
262  'text/*',
263  mimeTypeMatch( 'text/html',
264  [ 'image/*' => 1.0,
265  'text/*' => 0.5 ] ) );
266  $this->assertEquals(
267  '*/*',
268  mimeTypeMatch( 'text/html',
269  [ '*/*' => 1.0 ] ) );
270  $this->assertNull(
271  mimeTypeMatch( 'text/html',
272  [ 'image/png' => 1.0,
273  'image/svg+xml' => 0.5 ] ) );
274  }
275 
279  public function testNegotiateType() {
280  $this->assertEquals(
281  'text/html',
283  [ 'application/xhtml+xml' => 1.0,
284  'text/html' => 0.7,
285  'text/plain' => 0.5,
286  'text/*' => 0.2 ],
287  [ 'text/html' => 1.0 ] ) );
288  $this->assertEquals(
289  'application/xhtml+xml',
291  [ 'application/xhtml+xml' => 1.0,
292  'text/html' => 0.7,
293  'text/plain' => 0.5,
294  'text/*' => 0.2 ],
295  [ 'application/xhtml+xml' => 1.0,
296  'text/html' => 0.5 ] ) );
297  $this->assertEquals(
298  'text/html',
300  [ 'text/html' => 1.0,
301  'text/plain' => 0.5,
302  'text/*' => 0.5,
303  'application/xhtml+xml' => 0.2 ],
304  [ 'application/xhtml+xml' => 1.0,
305  'text/html' => 0.5 ] ) );
306  $this->assertEquals(
307  'text/html',
309  [ 'text/*' => 1.0,
310  'image/*' => 0.7,
311  '*/*' => 0.3 ],
312  [ 'application/xhtml+xml' => 1.0,
313  'text/html' => 0.5 ] ) );
314  $this->assertNull(
316  [ 'text/*' => 1.0 ],
317  [ 'application/xhtml+xml' => 1.0 ] ) );
318  }
319 
324  public function testDebugFunctionTest() {
325  $debugLogFile = $this->getNewTempFile();
326 
327  $this->setMwGlobals( [
328  'wgDebugLogFile' => $debugLogFile,
329  #  @todo FIXME: $wgDebugTimestamps should be tested
330  'wgDebugTimestamps' => false,
331  ] );
332  $this->setLogger( 'wfDebug', new LegacyLogger( 'wfDebug' ) );
333 
334  wfDebug( "This is a normal string" );
335  $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
336  unlink( $debugLogFile );
337 
338  wfDebug( "This is nöt an ASCII string" );
339  $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
340  unlink( $debugLogFile );
341 
342  wfDebug( "\00305This has böth UTF and control chars\003" );
343  $this->assertEquals(
344  " 05This has böth UTF and control chars \n",
345  file_get_contents( $debugLogFile )
346  );
347  unlink( $debugLogFile );
348 
349  wfDebugMem();
350  $this->assertGreaterThan(
351  1000,
352  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
353  );
354  unlink( $debugLogFile );
355 
356  wfDebugMem( true );
357  $this->assertGreaterThan(
358  1000000,
359  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
360  );
361  unlink( $debugLogFile );
362  }
363 
367  public function testClientAcceptsGzipTest() {
368  $settings = [
369  'gzip' => true,
370  'bzip' => false,
371  '*' => false,
372  'compress, gzip' => true,
373  'gzip;q=1.0' => true,
374  'foozip' => false,
375  'foo*zip' => false,
376  'gzip;q=abcde' => true, // is this REALLY valid?
377  'gzip;q=12345678.9' => true,
378  ' gzip' => true,
379  ];
380 
381  if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
382  $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
383  }
384 
385  foreach ( $settings as $encoding => $expect ) {
386  $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
387 
388  $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
389  "'$encoding' => " . wfBoolToStr( $expect ) );
390  }
391 
392  if ( isset( $old_server_setting ) ) {
393  $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
394  }
395  }
396 
400  public function testWfPercentTest() {
401  $pcts = [
402  [ 6 / 7, '0.86%', 2, false ],
403  [ 3 / 3, '1%' ],
404  [ 22 / 7, '3.14286%', 5 ],
405  [ 3 / 6, '0.5%' ],
406  [ 1 / 3, '0%', 0 ],
407  [ 10 / 3, '0%', -1 ],
408  [ 3 / 4 / 5, '0.1%', 1 ],
409  [ 6 / 7 * 8, '6.8571428571%', 10 ],
410  ];
411 
412  foreach ( $pcts as $pct ) {
413  if ( !isset( $pct[2] ) ) {
414  $pct[2] = 2;
415  }
416  if ( !isset( $pct[3] ) ) {
417  $pct[3] = true;
418  }
419 
420  $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
421  }
422  }
423 
429  public function testWfShorthandToInteger( $shorthand, $expected ) {
430  $this->assertEquals( $expected,
431  wfShorthandToInteger( $shorthand )
432  );
433  }
434 
435  public static function provideShorthand() {
436  // Syntax: [ shorthand, expected integer ]
437  return [
438  # Null, empty ...
439  [ '', -1 ],
440  [ ' ', -1 ],
441  [ null, -1 ],
442 
443  # Failures returns 0 :(
444  [ 'ABCDEFG', 0 ],
445  [ 'Ak', 0 ],
446 
447  # Int, strings with spaces
448  [ 1, 1 ],
449  [ ' 1 ', 1 ],
450  [ 1023, 1023 ],
451  [ ' 1023 ', 1023 ],
452 
453  # kilo, Mega, Giga
454  [ '1k', 1024 ],
455  [ '1K', 1024 ],
456  [ '1m', 1024 * 1024 ],
457  [ '1M', 1024 * 1024 ],
458  [ '1g', 1024 * 1024 * 1024 ],
459  [ '1G', 1024 * 1024 * 1024 ],
460 
461  # Negatives
462  [ -1, -1 ],
463  [ -500, -500 ],
464  [ '-500', -500 ],
465  [ '-1k', -1024 ],
466 
467  # Zeroes
468  [ '0', 0 ],
469  [ '0k', 0 ],
470  [ '0M', 0 ],
471  [ '0G', 0 ],
472  [ '-0', 0 ],
473  [ '-0k', 0 ],
474  [ '-0M', 0 ],
475  [ '-0G', 0 ],
476  ];
477  }
478 
483  $this->markTestSkippedIfNoDiff3();
484 
485  $mergedText = null;
486  $successfulMerge = wfMerge( "old1\n\nold2", "old1\n\nnew2", "new1\n\nold2", $mergedText );
487 
488  $mergedText = null;
489  $conflictingMerge = wfMerge( 'old', 'old and mine', 'old and yours', $mergedText );
490 
491  $this->assertEquals( true, $successfulMerge );
492  $this->assertEquals( false, $conflictingMerge );
493  }
494 
507  public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
508  $expectedMergeAttemptResult ) {
509  $this->markTestSkippedIfNoDiff3();
510 
511  $mergedText = null;
512  $attemptMergeResult = null;
513  $isMerged = wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
514 
515  $msg = 'Merge should be a ';
516  $msg .= $expectedMergeResult ? 'success' : 'failure';
517  $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
518  $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
519 
520  if ( $isMerged ) {
521  // Verify the merged text
522  $this->assertEquals( $expectedText, $mergedText,
523  'is merged text as expected?' );
524  }
525  }
526 
527  public static function provideMerge() {
528  $EXPECT_MERGE_SUCCESS = true;
529  $EXPECT_MERGE_FAILURE = false;
530 
531  return [
532  // #0: clean merge
533  [
534  // old:
535  "one one one\n" . // trimmed
536  "\n" .
537  "two two two",
538 
539  // mine:
540  "one one one ONE ONE\n" .
541  "\n" .
542  "two two two\n", // with tailing whitespace
543 
544  // yours:
545  "one one one\n" .
546  "\n" .
547  "two two TWO TWO", // trimmed
548 
549  // ok:
550  $EXPECT_MERGE_SUCCESS,
551 
552  // result:
553  "one one one ONE ONE\n" .
554  "\n" .
555  "two two TWO TWO\n", // note: will always end in a newline
556 
557  // mergeAttemptResult:
558  "",
559  ],
560 
561  // #1: conflict, fail
562  [
563  // old:
564  "one one one", // trimmed
565 
566  // mine:
567  "one one one ONE ONE\n" .
568  "\n" .
569  "bla bla\n" .
570  "\n", // with tailing whitespace
571 
572  // yours:
573  "one one one\n" .
574  "\n" .
575  "two two", // trimmed
576 
577  $EXPECT_MERGE_FAILURE,
578 
579  // result:
580  null,
581 
582  // mergeAttemptResult:
583  "1,3c\n" .
584  "one one one\n" .
585  "\n" .
586  "two two\n" .
587  ".\n",
588  ],
589  ];
590  }
591 
596  public function testMakeUrlIndexes( $url, $expected ) {
597  $index = wfMakeUrlIndexes( $url );
598  $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
599  }
600 
601  public static function provideMakeUrlIndexes() {
602  return [
603  // Testcase for T30627
604  [
605  'https://example.org/test.cgi?id=12345',
606  [ 'https://org.example./test.cgi?id=12345' ]
607  ],
608  [
609  // mailtos are handled special
610  // is this really right though? that final . probably belongs earlier?
611  'mailto:wiki@wikimedia.org',
612  [ 'mailto:org.wikimedia@wiki.' ]
613  ],
614 
615  // file URL cases per T30627...
616  [
617  // three slashes: local filesystem path Unix-style
618  'file:///whatever/you/like.txt',
619  [ 'file://./whatever/you/like.txt' ]
620  ],
621  [
622  // three slashes: local filesystem path Windows-style
623  'file:///c:/whatever/you/like.txt',
624  [ 'file://./c:/whatever/you/like.txt' ]
625  ],
626  [
627  // two slashes: UNC filesystem path Windows-style
628  'file://intranet/whatever/you/like.txt',
629  [ 'file://intranet./whatever/you/like.txt' ]
630  ],
631  // Multiple-slash cases that can sorta work on Mozilla
632  // if you hack it just right are kinda pathological,
633  // and unreliable cross-platform or on IE which means they're
634  // unlikely to appear on intranets.
635  // Those will survive the algorithm but with results that
636  // are less consistent.
637 
638  // protocol-relative URL cases per T31854...
639  [
640  '//example.org/test.cgi?id=12345',
641  [
642  'http://org.example./test.cgi?id=12345',
643  'https://org.example./test.cgi?id=12345'
644  ]
645  ],
646  ];
647  }
648 
653  public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
654  $actual = wfMatchesDomainList( $url, $domains );
655  $this->assertEquals( $expected, $actual, $description );
656  }
657 
658  public static function provideWfMatchesDomainList() {
659  $a = [];
660  $protocols = [ 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ];
661  foreach ( $protocols as $pDesc => $p ) {
662  $a = array_merge( $a, [
663  [
664  "$p//www.example.com",
665  [],
666  false,
667  "No matches for empty domains array, $pDesc URL"
668  ],
669  [
670  "$p//www.example.com",
671  [ 'www.example.com' ],
672  true,
673  "Exact match in domains array, $pDesc URL"
674  ],
675  [
676  "$p//www.example.com",
677  [ 'example.com' ],
678  true,
679  "Match without subdomain in domains array, $pDesc URL"
680  ],
681  [
682  "$p//www.example2.com",
683  [ 'www.example.com', 'www.example2.com', 'www.example3.com' ],
684  true,
685  "Exact match with other domains in array, $pDesc URL"
686  ],
687  [
688  "$p//www.example2.com",
689  [ 'example.com', 'example2.com', 'example3,com' ],
690  true,
691  "Match without subdomain with other domains in array, $pDesc URL"
692  ],
693  [
694  "$p//www.example4.com",
695  [ 'example.com', 'example2.com', 'example3,com' ],
696  false,
697  "Domain not in array, $pDesc URL"
698  ],
699  [
700  "$p//nds-nl.wikipedia.org",
701  [ 'nl.wikipedia.org' ],
702  false,
703  "Non-matching substring of domain, $pDesc URL"
704  ],
705  ] );
706  }
707 
708  return $a;
709  }
710 
714  public function testWfMkdirParents() {
715  // Should not return true if file exists instead of directory
716  $fname = $this->getNewTempFile();
717  Wikimedia\suppressWarnings();
718  $ok = wfMkdirParents( $fname );
719  Wikimedia\restoreWarnings();
720  $this->assertFalse( $ok );
721  }
722 
727  public function testWfShellWikiCmd( $script, $parameters, $options,
728  $expected, $description
729  ) {
730  if ( wfIsWindows() ) {
731  // Approximation that's good enough for our purposes just now
732  $expected = str_replace( "'", '"', $expected );
733  }
734  $actual = wfShellWikiCmd( $script, $parameters, $options );
735  $this->assertEquals( $expected, $actual, $description );
736  }
737 
738  public function wfWikiID() {
739  $this->setMwGlobals( [
740  'wgDBname' => 'example',
741  'wgDBprefix' => '',
742  ] );
743  $this->assertEquals(
744  wfWikiID(),
745  'example'
746  );
747 
748  $this->setMwGlobals( [
749  'wgDBname' => 'example',
750  'wgDBprefix' => 'mw_',
751  ] );
752  $this->assertEquals(
753  wfWikiID(),
754  'example-mw_'
755  );
756  }
757 
761  public function testWfMemcKey() {
763  $this->assertEquals(
764  $cache->makeKey( 'foo', 123, 'bar' ),
765  wfMemcKey( 'foo', 123, 'bar' )
766  );
767  }
768 
772  public function testWfForeignMemcKey() {
774  $keyspace = $this->readAttribute( $cache, 'keyspace' );
775  $this->assertEquals(
776  wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
777  $cache->makeKey( 'foo', 'bar' )
778  );
779  }
780 
784  public function testWfGlobalCacheKey() {
786  $this->assertEquals(
787  $cache->makeGlobalKey( 'foo', 123, 'bar' ),
788  wfGlobalCacheKey( 'foo', 123, 'bar' )
789  );
790  }
791 
792  public static function provideWfShellWikiCmdList() {
793  global $wgPhpCli;
794 
795  return [
796  [ 'eval.php', [ '--help', '--test' ], [],
797  "'$wgPhpCli' 'eval.php' '--help' '--test'",
798  "Called eval.php --help --test" ],
799  [ 'eval.php', [ '--help', '--test space' ], [ 'php' => 'php5' ],
800  "'php5' 'eval.php' '--help' '--test space'",
801  "Called eval.php --help --test with php option" ],
802  [ 'eval.php', [ '--help', '--test', 'X' ], [ 'wrapper' => 'MWScript.php' ],
803  "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
804  "Called eval.php --help --test with wrapper option" ],
805  [
806  'eval.php',
807  [ '--help', '--test', 'y' ],
808  [ 'php' => 'php5', 'wrapper' => 'MWScript.php' ],
809  "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
810  "Called eval.php --help --test with wrapper and php option"
811  ],
812  ];
813  }
814  /* @todo many more! */
815 }
$wgPhpCli
$wgPhpCli
Executable path of the PHP cli binary.
Definition: DefaultSettings.php:8344
wfPercent
wfPercent( $nr, $acc=2, $round=true)
Definition: GlobalFunctions.php:2118
GlobalTest\testRandomString
testRandomString()
wfRandomString
Definition: GlobalTest.php:72
GlobalTest\testMimeTypeMatch
testMimeTypeMatch()
mimeTypeMatch
Definition: GlobalTest.php:254
GlobalTest\testReadOnlyGlobalChange
testReadOnlyGlobalChange()
This behaviour could probably be deprecated.
Definition: GlobalTest.php:147
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:365
wfMkdirParents
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Definition: GlobalFunctions.php:2050
GlobalTest\testCgiRoundTrip
testCgiRoundTrip( $cgi)
provideCgiRoundTrip wfArrayToCgi
Definition: GlobalTest.php:247
wfMerge
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
Definition: GlobalFunctions.php:2307
GlobalTest\testWfMemcKey
testWfMemcKey()
wfMemcKey
Definition: GlobalTest.php:761
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:1892
wfMakeUrlIndexes
wfMakeUrlIndexes( $url)
Make URL indexes, appropriate for the el_index field of externallinks.
Definition: GlobalFunctions.php:900
$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. '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 since 1.16! 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 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:2034
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:331
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1237
GlobalTest\testExpandIRI
testExpandIRI()
wfExpandIRI
Definition: GlobalTest.php:96
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:884
GlobalTest\testClientAcceptsGzipTest
testClientAcceptsGzipTest()
wfClientAcceptsGzip
Definition: GlobalTest.php:367
wfShellWikiCmd
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
Definition: GlobalFunctions.php:2282
GlobalTest\testWfArrayDiff2
testWfArrayDiff2( $a, $b, $expected)
provideForWfArrayDiff2 wfArrayDiff2
Definition: GlobalTest.php:32
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:35
GlobalTest\testWfShellWikiCmd
testWfShellWikiCmd( $script, $parameters, $options, $expected, $description)
provideWfShellWikiCmdList wfShellWikiCmd
Definition: GlobalTest.php:727
wfBoolToStr
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
Definition: GlobalFunctions.php:2812
GlobalTest\testRandom
testRandom()
wfRandom
Definition: GlobalTest.php:63
GlobalTest\testWfPercentTest
testWfPercentTest()
wfPercent
Definition: GlobalTest.php:400
mimeTypeMatch
mimeTypeMatch( $type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
Definition: GlobalFunctions.php:1864
GlobalTest\provideArrayToCGI
static provideArrayToCGI()
Definition: GlobalTest.php:155
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:706
MediaWikiTestCase\getNewTempFile
getNewTempFile()
Obtains a new temporary file name.
Definition: MediaWikiTestCase.php:471
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
GlobalTest
Database GlobalFunctions.
Definition: GlobalTest.php:9
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
GlobalTest\testMerge
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText, $expectedMergeAttemptResult)
Definition: GlobalTest.php:507
wfCgiToArray
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
Definition: GlobalFunctions.php:413
GlobalTest\testCgiToArray
testCgiToArray( $cgi, $result)
provideCgiToArray wfCgiToArray
Definition: GlobalTest.php:226
GlobalTest\testReadOnlySet
testReadOnlySet()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
Definition: GlobalTest.php:123
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:988
wfForeignMemcKey
wfForeignMemcKey( $db, $prefix,... $args)
Make a cache key for a foreign DB.
Definition: GlobalFunctions.php:2617
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:121
GlobalTest\testMerge_worksWithLessParameters
testMerge_worksWithLessParameters()
wfMerge
Definition: GlobalTest.php:482
GlobalTest\provideMakeUrlIndexes
static provideMakeUrlIndexes()
Definition: GlobalTest.php:601
$wgDebugTimestamps
$wgDebugTimestamps
Prefix debug messages with relative timestamp.
Definition: DefaultSettings.php:6282
GlobalTest\setUp
setUp()
Definition: GlobalTest.php:10
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:120
wfGlobalCacheKey
wfGlobalCacheKey(... $args)
Make a cache key with database-agnostic prefix.
Definition: GlobalFunctions.php:2634
MediaWikiTestCase\markTestSkippedIfNoDiff3
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
Definition: MediaWikiTestCase.php:2232
wfClientAcceptsGzip
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
Definition: GlobalFunctions.php:1582
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:1993
GlobalTest\testDebugFunctionTest
testDebugFunctionTest()
wfDebug wfDebugMem
Definition: GlobalTest.php:324
$wgReadOnly
$wgReadOnly
Set this to a string to put the wiki into read-only mode.
Definition: DefaultSettings.php:6743
wfDebugMem
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
Definition: GlobalFunctions.php:1047
on
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function 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:77
GlobalTest\provideMerge
static provideMerge()
Definition: GlobalTest.php:527
GlobalTest\testWfMatchesDomainList
testWfMatchesDomainList( $url, $domains, $expected, $description)
provideWfMatchesDomainList wfMatchesDomainList
Definition: GlobalTest.php:653
GlobalTest\provideWfMatchesDomainList
static provideWfMatchesDomainList()
Definition: GlobalTest.php:658
wfShorthandToInteger
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
Definition: GlobalFunctions.php:2973
GlobalTest\testWfShorthandToInteger
testWfShorthandToInteger( $shorthand, $expected)
test
Definition: GlobalTest.php:429
GlobalTest\provideShorthand
static provideShorthand()
Definition: GlobalTest.php:435
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:278
wfReadOnlyReason
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
Definition: GlobalFunctions.php:1250
wfMatchesDomainList
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
Definition: GlobalFunctions.php:954
$cache
$cache
Definition: mcc.php:33
$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:2036
$wgReadOnlyFile
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
Definition: DefaultSettings.php:6759
MediaWikiTestCase\setLogger
setLogger( $channel, LoggerInterface $logger)
Sets the logger for a specified channel, for the duration of the test.
Definition: MediaWikiTestCase.php:1115
GlobalTest\testUrlencode
testUrlencode()
wfUrlencode
Definition: GlobalTest.php:87
GlobalTest\testArrayToCGI2
testArrayToCGI2()
wfArrayToCgi
Definition: GlobalTest.php:193
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:9
GlobalTest\testArrayToCGI
testArrayToCGI( $array, $result)
provideArrayToCGI wfArrayToCgi
Definition: GlobalTest.php:186
GlobalTest\testWfGlobalCacheKey
testWfGlobalCacheKey()
wfGlobalCacheKey
Definition: GlobalTest.php:784
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:2036
GlobalTest\testWfForeignMemcKey
testWfForeignMemcKey()
wfForeignMemcKey
Definition: GlobalTest.php:772
wfMemcKey
wfMemcKey(... $args)
Make a cache key for the local wiki.
Definition: GlobalFunctions.php:2603
GlobalTest\wfWikiID
wfWikiID()
Definition: GlobalTest.php:738
GlobalTest\testReadOnlyEmpty
testReadOnlyEmpty()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
Definition: GlobalTest.php:110
GlobalTest\provideCgiToArray
static provideCgiToArray()
Definition: GlobalTest.php:201
GlobalTest\testMakeUrlIndexes
testMakeUrlIndexes( $url, $expected)
provideMakeUrlIndexes() wfMakeUrlIndexes
Definition: GlobalTest.php:596
GlobalTest\provideForWfArrayDiff2
static provideForWfArrayDiff2()
Definition: GlobalTest.php:39
GlobalTest\testNegotiateType
testNegotiateType()
wfNegotiateType
Definition: GlobalTest.php:279
LegacyLogger
MediaWiki Logger LegacyLogger
Definition: logger.txt:54
GlobalTest\provideCgiRoundTrip
static provideCgiRoundTrip()
Definition: GlobalTest.php:230
GlobalTest\provideWfShellWikiCmdList
static provideWfShellWikiCmdList()
Definition: GlobalTest.php:792
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:368
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:296
GlobalTest\testWfMkdirParents
testWfMkdirParents()
wfMkdirParents
Definition: GlobalTest.php:714