MediaWiki  1.27.2
GlobalTest.php
Go to the documentation of this file.
1 <?php
2 
7  protected function setUp() {
8  parent::setUp();
9 
10  $readOnlyFile = $this->getNewTempFile();
11  unlink( $readOnlyFile );
12 
13  $this->setMwGlobals( [
14  'wgReadOnlyFile' => $readOnlyFile,
15  'wgUrlProtocols' => [
16  'http://',
17  'https://',
18  'mailto:',
19  '//',
20  'file://', # Non-default
21  ],
22  ] );
23  }
24 
29  public function testWfArrayDiff2( $a, $b, $expected ) {
30  $this->assertEquals(
31  wfArrayDiff2( $a, $b ), $expected
32  );
33  }
34 
35  // @todo Provide more tests
36  public static function provideForWfArrayDiff2() {
37  // $a $b $expected
38  return [
39  [
40  [ 'a', 'b' ],
41  [ 'a', 'b' ],
42  [],
43  ],
44  [
45  [ [ 'a' ], [ 'a', 'b', 'c' ] ],
46  [ [ 'a' ], [ 'a', 'b' ] ],
47  [ 1 => [ 'a', 'b', 'c' ] ],
48  ],
49  ];
50  }
51 
52  /*
53  * Test cases for random functions could hypothetically fail,
54  * even though they shouldn't.
55  */
56 
60  public function testRandom() {
61  $this->assertFalse(
62  wfRandom() == wfRandom()
63  );
64  }
65 
69  public function testRandomString() {
70  $this->assertFalse(
72  );
73  $this->assertEquals(
74  strlen( wfRandomString( 10 ) ), 10
75  );
76  $this->assertTrue(
77  preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
78  );
79  }
80 
84  public function testUrlencode() {
85  $this->assertEquals(
86  "%E7%89%B9%E5%88%A5:Contributions/Foobar",
87  wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
88  }
89 
93  public function testExpandIRI() {
94  $this->assertEquals(
95  "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
96  wfExpandIRI( "https://te.wikibooks.org/wiki/"
97  . "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
98  . "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
99  . "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
100  . "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
101  }
102 
106  public function testReadOnlyEmpty() {
107  global $wgReadOnly;
108  $wgReadOnly = null;
109 
110  $this->assertFalse( wfReadOnly() );
111  $this->assertFalse( wfReadOnly() );
112  }
113 
117  public function testReadOnlySet() {
118  global $wgReadOnly, $wgReadOnlyFile;
119 
120  $f = fopen( $wgReadOnlyFile, "wt" );
121  fwrite( $f, 'Message' );
122  fclose( $f );
123  $wgReadOnly = null; # Check on $wgReadOnlyFile
124 
125  $this->assertTrue( wfReadOnly() );
126  $this->assertTrue( wfReadOnly() ); # Check cached
127 
128  unlink( $wgReadOnlyFile );
129  $wgReadOnly = null; # Clean cache
130 
131  $this->assertFalse( wfReadOnly() );
132  $this->assertFalse( wfReadOnly() );
133  }
134 
135  public static function provideArrayToCGI() {
136  return [
137  [ [], '' ], // empty
138  [ [ 'foo' => 'bar' ], 'foo=bar' ], // string test
139  [ [ 'foo' => '' ], 'foo=' ], // empty string test
140  [ [ 'foo' => 1 ], 'foo=1' ], // number test
141  [ [ 'foo' => true ], 'foo=1' ], // true test
142  [ [ 'foo' => false ], '' ], // false test
143  [ [ 'foo' => null ], '' ], // null test
144  [ [ 'foo' => 'A&B=5+6@!"\'' ], 'foo=A%26B%3D5%2B6%40%21%22%27' ], // urlencoding test
145  [
146  [ 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ],
147  'foo=bar&baz=is&asdf=qwerty'
148  ], // multi-item test
149  [ [ 'foo' => [ 'bar' => 'baz' ] ], 'foo%5Bbar%5D=baz' ],
150  [
151  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ],
152  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
153  ],
154  [ [ 'foo' => [ 'bar', 'baz' ] ], 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
155  [
156  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ],
157  'foo%5Bbar%5D%5Bbar%5D=baz'
158  ],
159  ];
160  }
161 
166  public function testArrayToCGI( $array, $result ) {
167  $this->assertEquals( $result, wfArrayToCgi( $array ) );
168  }
169 
173  public function testArrayToCGI2() {
174  $this->assertEquals(
175  "baz=bar&foo=bar",
176  wfArrayToCgi(
177  [ 'baz' => 'bar' ],
178  [ 'foo' => 'bar', 'baz' => 'overridden value' ] ) );
179  }
180 
181  public static function provideCgiToArray() {
182  return [
183  [ '', [] ], // empty
184  [ 'foo=bar', [ 'foo' => 'bar' ] ], // string
185  [ 'foo=', [ 'foo' => '' ] ], // empty string
186  [ 'foo', [ 'foo' => '' ] ], // missing =
187  [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
188  [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
189  [ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
190  [
191  'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
192  [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
193  ],
194  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz', [ 'foo' => [ 0 => 'bar', 1 => 'baz' ] ] ],
195  [
196  'foo%5Bbar%5D%5Bbar%5D=baz',
197  [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
198  ],
199  ];
200  }
201 
206  public function testCgiToArray( $cgi, $result ) {
207  $this->assertEquals( $result, wfCgiToArray( $cgi ) );
208  }
209 
210  public static function provideCgiRoundTrip() {
211  return [
212  [ '' ],
213  [ 'foo=bar' ],
214  [ 'foo=' ],
215  [ 'foo=bar&baz=biz' ],
216  [ 'foo=A%26B%3D5%2B6%40%21%22%27' ],
217  [ 'foo%5Bbar%5D=baz' ],
218  [ 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
219  [ 'foo%5Bbar%5D%5Bbar%5D=baz' ],
220  ];
221  }
222 
227  public function testCgiRoundTrip( $cgi ) {
228  $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
229  }
230 
234  public function testMimeTypeMatch() {
235  $this->assertEquals(
236  'text/html',
237  mimeTypeMatch( 'text/html',
238  [ 'application/xhtml+xml' => 1.0,
239  'text/html' => 0.7,
240  'text/plain' => 0.3 ] ) );
241  $this->assertEquals(
242  'text/*',
243  mimeTypeMatch( 'text/html',
244  [ 'image/*' => 1.0,
245  'text/*' => 0.5 ] ) );
246  $this->assertEquals(
247  '*/*',
248  mimeTypeMatch( 'text/html',
249  [ '*/*' => 1.0 ] ) );
250  $this->assertNull(
251  mimeTypeMatch( 'text/html',
252  [ 'image/png' => 1.0,
253  'image/svg+xml' => 0.5 ] ) );
254  }
255 
259  public function testNegotiateType() {
260  $this->assertEquals(
261  'text/html',
263  [ 'application/xhtml+xml' => 1.0,
264  'text/html' => 0.7,
265  'text/plain' => 0.5,
266  'text/*' => 0.2 ],
267  [ 'text/html' => 1.0 ] ) );
268  $this->assertEquals(
269  'application/xhtml+xml',
271  [ 'application/xhtml+xml' => 1.0,
272  'text/html' => 0.7,
273  'text/plain' => 0.5,
274  'text/*' => 0.2 ],
275  [ 'application/xhtml+xml' => 1.0,
276  'text/html' => 0.5 ] ) );
277  $this->assertEquals(
278  'text/html',
280  [ 'text/html' => 1.0,
281  'text/plain' => 0.5,
282  'text/*' => 0.5,
283  'application/xhtml+xml' => 0.2 ],
284  [ 'application/xhtml+xml' => 1.0,
285  'text/html' => 0.5 ] ) );
286  $this->assertEquals(
287  'text/html',
289  [ 'text/*' => 1.0,
290  'image/*' => 0.7,
291  '*/*' => 0.3 ],
292  [ 'application/xhtml+xml' => 1.0,
293  'text/html' => 0.5 ] ) );
294  $this->assertNull(
296  [ 'text/*' => 1.0 ],
297  [ 'application/xhtml+xml' => 1.0 ] ) );
298  }
299 
304  public function testDebugFunctionTest() {
305  $debugLogFile = $this->getNewTempFile();
306 
307  $this->setMwGlobals( [
308  'wgDebugLogFile' => $debugLogFile,
309  #  @todo FIXME: $wgDebugTimestamps should be tested
310  'wgDebugTimestamps' => false
311  ] );
312 
313  wfDebug( "This is a normal string" );
314  $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
315  unlink( $debugLogFile );
316 
317  wfDebug( "This is nöt an ASCII string" );
318  $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
319  unlink( $debugLogFile );
320 
321  wfDebug( "\00305This has böth UTF and control chars\003" );
322  $this->assertEquals(
323  " 05This has böth UTF and control chars \n",
324  file_get_contents( $debugLogFile )
325  );
326  unlink( $debugLogFile );
327 
328  wfDebugMem();
329  $this->assertGreaterThan(
330  1000,
331  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
332  );
333  unlink( $debugLogFile );
334 
335  wfDebugMem( true );
336  $this->assertGreaterThan(
337  1000000,
338  preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
339  );
340  unlink( $debugLogFile );
341  }
342 
346  public function testClientAcceptsGzipTest() {
347 
348  $settings = [
349  'gzip' => true,
350  'bzip' => false,
351  '*' => false,
352  'compress, gzip' => true,
353  'gzip;q=1.0' => true,
354  'foozip' => false,
355  'foo*zip' => false,
356  'gzip;q=abcde' => true, // is this REALLY valid?
357  'gzip;q=12345678.9' => true,
358  ' gzip' => true,
359  ];
360 
361  if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
362  $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
363  }
364 
365  foreach ( $settings as $encoding => $expect ) {
366  $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
367 
368  $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
369  "'$encoding' => " . wfBoolToStr( $expect ) );
370  }
371 
372  if ( isset( $old_server_setting ) ) {
373  $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
374  }
375  }
376 
380  public function testWfPercentTest() {
381 
382  $pcts = [
383  [ 6 / 7, '0.86%', 2, false ],
384  [ 3 / 3, '1%' ],
385  [ 22 / 7, '3.14286%', 5 ],
386  [ 3 / 6, '0.5%' ],
387  [ 1 / 3, '0%', 0 ],
388  [ 10 / 3, '0%', -1 ],
389  [ 3 / 4 / 5, '0.1%', 1 ],
390  [ 6 / 7 * 8, '6.8571428571%', 10 ],
391  ];
392 
393  foreach ( $pcts as $pct ) {
394  if ( !isset( $pct[2] ) ) {
395  $pct[2] = 2;
396  }
397  if ( !isset( $pct[3] ) ) {
398  $pct[3] = true;
399  }
400 
401  $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
402  }
403  }
404 
410  public function testWfShorthandToInteger( $shorthand, $expected ) {
411  $this->assertEquals( $expected,
412  wfShorthandToInteger( $shorthand )
413  );
414  }
415 
417  public static function provideShorthand() {
418  return [
419  # Null, empty ...
420  [ '', -1 ],
421  [ ' ', -1 ],
422  [ null, -1 ],
423 
424  # Failures returns 0 :(
425  [ 'ABCDEFG', 0 ],
426  [ 'Ak', 0 ],
427 
428  # Int, strings with spaces
429  [ 1, 1 ],
430  [ ' 1 ', 1 ],
431  [ 1023, 1023 ],
432  [ ' 1023 ', 1023 ],
433 
434  # kilo, Mega, Giga
435  [ '1k', 1024 ],
436  [ '1K', 1024 ],
437  [ '1m', 1024 * 1024 ],
438  [ '1M', 1024 * 1024 ],
439  [ '1g', 1024 * 1024 * 1024 ],
440  [ '1G', 1024 * 1024 * 1024 ],
441 
442  # Negatives
443  [ -1, -1 ],
444  [ -500, -500 ],
445  [ '-500', -500 ],
446  [ '-1k', -1024 ],
447 
448  # Zeroes
449  [ '0', 0 ],
450  [ '0k', 0 ],
451  [ '0M', 0 ],
452  [ '0G', 0 ],
453  [ '-0', 0 ],
454  [ '-0k', 0 ],
455  [ '-0M', 0 ],
456  [ '-0G', 0 ],
457  ];
458  }
459 
471  public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
472  $this->markTestSkippedIfNoDiff3();
473 
474  $mergedText = null;
475  $isMerged = wfMerge( $old, $mine, $yours, $mergedText );
476 
477  $msg = 'Merge should be a ';
478  $msg .= $expectedMergeResult ? 'success' : 'failure';
479  $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
480 
481  if ( $isMerged ) {
482  // Verify the merged text
483  $this->assertEquals( $expectedText, $mergedText,
484  'is merged text as expected?' );
485  }
486  }
487 
488  public static function provideMerge() {
489  $EXPECT_MERGE_SUCCESS = true;
490  $EXPECT_MERGE_FAILURE = false;
491 
492  return [
493  // #0: clean merge
494  [
495  // old:
496  "one one one\n" . // trimmed
497  "\n" .
498  "two two two",
499 
500  // mine:
501  "one one one ONE ONE\n" .
502  "\n" .
503  "two two two\n", // with tailing whitespace
504 
505  // yours:
506  "one one one\n" .
507  "\n" .
508  "two two TWO TWO", // trimmed
509 
510  // ok:
511  $EXPECT_MERGE_SUCCESS,
512 
513  // result:
514  "one one one ONE ONE\n" .
515  "\n" .
516  "two two TWO TWO\n", // note: will always end in a newline
517  ],
518 
519  // #1: conflict, fail
520  [
521  // old:
522  "one one one", // trimmed
523 
524  // mine:
525  "one one one ONE ONE\n" .
526  "\n" .
527  "bla bla\n" .
528  "\n", // with tailing whitespace
529 
530  // yours:
531  "one one one\n" .
532  "\n" .
533  "two two", // trimmed
534 
535  $EXPECT_MERGE_FAILURE,
536 
537  // result:
538  null,
539  ],
540  ];
541  }
542 
547  public function testMakeUrlIndexes( $url, $expected ) {
548  $index = wfMakeUrlIndexes( $url );
549  $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
550  }
551 
552  public static function provideMakeUrlIndexes() {
553  return [
554  // Testcase for T30627
555  [
556  'https://example.org/test.cgi?id=12345',
557  [ 'https://org.example./test.cgi?id=12345' ]
558  ],
559  [
560  // mailtos are handled special
561  // is this really right though? that final . probably belongs earlier?
562  'mailto:wiki@wikimedia.org',
563  [ 'mailto:org.wikimedia@wiki.' ]
564  ],
565 
566  // file URL cases per T30627...
567  [
568  // three slashes: local filesystem path Unix-style
569  'file:///whatever/you/like.txt',
570  [ 'file://./whatever/you/like.txt' ]
571  ],
572  [
573  // three slashes: local filesystem path Windows-style
574  'file:///c:/whatever/you/like.txt',
575  [ 'file://./c:/whatever/you/like.txt' ]
576  ],
577  [
578  // two slashes: UNC filesystem path Windows-style
579  'file://intranet/whatever/you/like.txt',
580  [ 'file://intranet./whatever/you/like.txt' ]
581  ],
582  // Multiple-slash cases that can sorta work on Mozilla
583  // if you hack it just right are kinda pathological,
584  // and unreliable cross-platform or on IE which means they're
585  // unlikely to appear on intranets.
586  // Those will survive the algorithm but with results that
587  // are less consistent.
588 
589  // protocol-relative URL cases per T31854...
590  [
591  '//example.org/test.cgi?id=12345',
592  [
593  'http://org.example./test.cgi?id=12345',
594  'https://org.example./test.cgi?id=12345'
595  ]
596  ],
597  ];
598  }
599 
604  public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
605  $actual = wfMatchesDomainList( $url, $domains );
606  $this->assertEquals( $expected, $actual, $description );
607  }
608 
609  public static function provideWfMatchesDomainList() {
610  $a = [];
611  $protocols = [ 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ];
612  foreach ( $protocols as $pDesc => $p ) {
613  $a = array_merge( $a, [
614  [
615  "$p//www.example.com",
616  [],
617  false,
618  "No matches for empty domains array, $pDesc URL"
619  ],
620  [
621  "$p//www.example.com",
622  [ 'www.example.com' ],
623  true,
624  "Exact match in domains array, $pDesc URL"
625  ],
626  [
627  "$p//www.example.com",
628  [ 'example.com' ],
629  true,
630  "Match without subdomain in domains array, $pDesc URL"
631  ],
632  [
633  "$p//www.example2.com",
634  [ 'www.example.com', 'www.example2.com', 'www.example3.com' ],
635  true,
636  "Exact match with other domains in array, $pDesc URL"
637  ],
638  [
639  "$p//www.example2.com",
640  [ 'example.com', 'example2.com', 'example3,com' ],
641  true,
642  "Match without subdomain with other domains in array, $pDesc URL"
643  ],
644  [
645  "$p//www.example4.com",
646  [ 'example.com', 'example2.com', 'example3,com' ],
647  false,
648  "Domain not in array, $pDesc URL"
649  ],
650  [
651  "$p//nds-nl.wikipedia.org",
652  [ 'nl.wikipedia.org' ],
653  false,
654  "Non-matching substring of domain, $pDesc URL"
655  ],
656  ] );
657  }
658 
659  return $a;
660  }
661 
665  public function testWfMkdirParents() {
666  // Should not return true if file exists instead of directory
667  $fname = $this->getNewTempFile();
668  MediaWiki\suppressWarnings();
669  $ok = wfMkdirParents( $fname );
670  MediaWiki\restoreWarnings();
671  $this->assertFalse( $ok );
672  }
673 
678  public function testWfShellWikiCmd( $script, $parameters, $options,
679  $expected, $description
680  ) {
681  if ( wfIsWindows() ) {
682  // Approximation that's good enough for our purposes just now
683  $expected = str_replace( "'", '"', $expected );
684  }
685  $actual = wfShellWikiCmd( $script, $parameters, $options );
686  $this->assertEquals( $expected, $actual, $description );
687  }
688 
689  public function wfWikiID() {
690  $this->setMwGlobals( [
691  'wgDBname' => 'example',
692  'wgDBprefix' => '',
693  ] );
694  $this->assertEquals(
695  wfWikiID(),
696  'example'
697  );
698 
699  $this->setMwGlobals( [
700  'wgDBname' => 'example',
701  'wgDBprefix' => 'mw_',
702  ] );
703  $this->assertEquals(
704  wfWikiID(),
705  'example-mw_'
706  );
707  }
708 
709  public function testWfMemcKey() {
711  $this->assertEquals(
712  $cache->makeKey( 'foo', 123, 'bar' ),
713  wfMemcKey( 'foo', 123, 'bar' )
714  );
715  }
716 
717  public function testWfForeignMemcKey() {
719  $keyspace = $this->readAttribute( $cache, 'keyspace' );
720  $this->assertEquals(
721  wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
722  $cache->makeKey( 'foo', 'bar' )
723  );
724  }
725 
726  public function testWfGlobalCacheKey() {
728  $this->assertEquals(
729  $cache->makeGlobalKey( 'foo', 123, 'bar' ),
730  wfGlobalCacheKey( 'foo', 123, 'bar' )
731  );
732  }
733 
734  public static function provideWfShellWikiCmdList() {
735  global $wgPhpCli;
736 
737  return [
738  [ 'eval.php', [ '--help', '--test' ], [],
739  "'$wgPhpCli' 'eval.php' '--help' '--test'",
740  "Called eval.php --help --test" ],
741  [ 'eval.php', [ '--help', '--test space' ], [ 'php' => 'php5' ],
742  "'php5' 'eval.php' '--help' '--test space'",
743  "Called eval.php --help --test with php option" ],
744  [ 'eval.php', [ '--help', '--test', 'X' ], [ 'wrapper' => 'MWScript.php' ],
745  "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
746  "Called eval.php --help --test with wrapper option" ],
747  [
748  'eval.php',
749  [ '--help', '--test', 'y' ],
750  [ 'php' => 'php5', 'wrapper' => 'MWScript.php' ],
751  "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
752  "Called eval.php --help --test with wrapper and php option"
753  ],
754  ];
755  }
756  /* @todo many more! */
757 }
GlobalFunctions.
Definition: GlobalTest.php:6
wfPercent($nr, $acc=2, $round=true)
wfForeignMemcKey($db, $prefix)
Make a cache key for a foreign DB.
testDebugFunctionTest()
wfDebug wfDebugMem
Definition: GlobalTest.php:304
wfShorthandToInteger($string= '', $default=-1)
Converts shorthand byte notation to integer form.
wfMkdirParents($dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
wfDebugMem($exact=false)
Send a line giving PHP memory usage.
static provideMakeUrlIndexes()
Definition: GlobalTest.php:552
static provideWfMatchesDomainList()
Definition: GlobalTest.php:609
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
mimeTypeMatch($type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
static provideShorthand()
array( shorthand, expected integer )
Definition: GlobalTest.php:417
static provideMerge()
Definition: GlobalTest.php:488
wfMakeUrlIndexes($url)
Make URL indexes, appropriate for the el_index field of externallinks.
static getLocalClusterInstance()
Get the main cluster-local cache object.
testUrlencode()
wfUrlencode
Definition: GlobalTest.php:84
testArrayToCGI2()
wfArrayToCgi
Definition: GlobalTest.php:173
wfUrlencode($s)
We want some things to be included as literal characters in our title URLs for prettiness, which urlencode encodes by default.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
wfBoolToStr($value)
Convenience function converts boolean values into "true" or "false" (string) values.
wfIsWindows()
Check if the operating system is Windows.
testWfGlobalCacheKey()
Definition: GlobalTest.php:726
wfExpandIRI($url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
getNewTempFile()
Obtains a new temporary file name.
wfRandomString($length=32)
Get a random string containing a number of pseudo-random hex characters.
testWfForeignMemcKey()
Definition: GlobalTest.php:717
wfNegotiateType($cprefs, $sprefs)
Returns the 'best' match between a client's requested internet media types and the server's list of a...
wfArrayDiff2($a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':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:1796
testMakeUrlIndexes($url, $expected)
provideMakeUrlIndexes() wfMakeUrlIndexes
Definition: GlobalTest.php:547
wfGlobalCacheKey()
Make a cache key with database-agnostic prefix.
testWfMatchesDomainList($url, $domains, $expected, $description)
provideWfMatchesDomainList wfMatchesDomainList
Definition: GlobalTest.php:604
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
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:1798
static provideCgiToArray()
Definition: GlobalTest.php:181
testArrayToCGI($array, $result)
provideArrayToCGI wfArrayToCgi
Definition: GlobalTest.php:166
wfCgiToArray($query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
static provideForWfArrayDiff2()
Definition: GlobalTest.php:36
testMerge($old, $mine, $yours, $expectedMergeResult, $expectedText)
Definition: GlobalTest.php:471
wfReadOnly()
Check whether the wiki is in read-only mode.
static provideWfShellWikiCmdList()
Definition: GlobalTest.php:734
wfShellWikiCmd($script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
testReadOnlyEmpty()
wfReadOnly
Definition: GlobalTest.php:106
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1004
wfClientAcceptsGzip($force=false)
wfMatchesDomainList($url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
static provideCgiRoundTrip()
Definition: GlobalTest.php:210
testNegotiateType()
wfNegotiateType
Definition: GlobalTest.php:259
testMimeTypeMatch()
mimeTypeMatch
Definition: GlobalTest.php:234
$cache
Definition: mcc.php:33
testWfMkdirParents()
wfMkdirParents
Definition: GlobalTest.php:665
testRandomString()
wfRandomString
Definition: GlobalTest.php:69
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
wfMerge($old, $mine, $yours, &$result)
wfMerge attempts to merge differences between three texts.
testWfShorthandToInteger($shorthand, $expected)
test
Definition: GlobalTest.php:410
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
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:35
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped, if not ready.
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
testClientAcceptsGzipTest()
wfClientAcceptsGzip
Definition: GlobalTest.php:346
testExpandIRI()
wfExpandIRI
Definition: GlobalTest.php:93
testRandom()
wfRandom
Definition: GlobalTest.php:60
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
wfMemcKey()
Make a cache key for the local wiki.
testCgiRoundTrip($cgi)
provideCgiRoundTrip wfArrayToCgi
Definition: GlobalTest.php:227
setMwGlobals($pairs, $value=null)
testWfArrayDiff2($a, $b, $expected)
provideForWfArrayDiff2 wfArrayDiff2
Definition: GlobalTest.php:29
testWfPercentTest()
wfPercent
Definition: GlobalTest.php:380
testWfShellWikiCmd($script, $parameters, $options, $expected, $description)
provideWfShellWikiCmdList wfShellWikiCmd
Definition: GlobalTest.php:678
static provideArrayToCGI()
Definition: GlobalTest.php:135
testReadOnlySet()
wfReadOnly
Definition: GlobalTest.php:117
testCgiToArray($cgi, $result)
provideCgiToArray wfCgiToArray
Definition: GlobalTest.php:206