MediaWiki REL1_33
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 'wgReadOnly' => null,
18 'wgReadOnlyFile' => $readOnlyFile,
19 'wgUrlProtocols' => [
20 'http://',
21 'https://',
22 'mailto:',
23 '//',
24 'file://', # Non-default
25 ],
26 ] );
27 }
28
33 public function testWfArrayDiff2( $a, $b, $expected ) {
34 $this->assertEquals(
35 wfArrayDiff2( $a, $b ), $expected
36 );
37 }
38
39 // @todo Provide more tests
40 public static function provideForWfArrayDiff2() {
41 // $a $b $expected
42 return [
43 [
44 [ 'a', 'b' ],
45 [ 'a', 'b' ],
46 [],
47 ],
48 [
49 [ [ 'a' ], [ 'a', 'b', 'c' ] ],
50 [ [ 'a' ], [ 'a', 'b' ] ],
51 [ 1 => [ 'a', 'b', 'c' ] ],
52 ],
53 ];
54 }
55
56 /*
57 * Test cases for random functions could hypothetically fail,
58 * even though they shouldn't.
59 */
60
64 public function testRandom() {
65 $this->assertFalse(
66 wfRandom() == wfRandom()
67 );
68 }
69
73 public function testRandomString() {
74 $this->assertFalse(
76 );
77 $this->assertEquals(
78 strlen( wfRandomString( 10 ) ), 10
79 );
80 $this->assertTrue(
81 preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
82 );
83 }
84
88 public function testUrlencode() {
89 $this->assertEquals(
90 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
91 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
92 }
93
97 public function testExpandIRI() {
98 $this->assertEquals(
99 "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
100 wfExpandIRI( "https://te.wikibooks.org/wiki/"
101 . "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
102 . "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
103 . "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
104 . "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
105 }
106
111 public function testReadOnlyEmpty() {
112 $this->assertFalse( wfReadOnly() );
113 $this->assertFalse( wfReadOnly() );
114 }
115
120 public function testReadOnlySet() {
121 global $wgReadOnlyFile;
122
123 $f = fopen( $wgReadOnlyFile, "wt" );
124 fwrite( $f, 'Message' );
125 fclose( $f );
126
127 // Reset the service to avoid cached results
128 $this->overrideMwServices();
129
130 $this->assertTrue( wfReadOnly() );
131 $this->assertTrue( wfReadOnly() ); # Check cached
132 }
133
138 public function testReadOnlyGlobalChange() {
139 $this->assertFalse( wfReadOnlyReason() );
140
141 $this->setMwGlobals( [
142 'wgReadOnly' => 'reason'
143 ] );
144 $this->overrideMwServices();
145
146 $this->assertSame( 'reason', wfReadOnlyReason() );
147 }
148
149 public static function provideArrayToCGI() {
150 return [
151 [ [], '' ], // empty
152 [ [ 'foo' => 'bar' ], 'foo=bar' ], // string test
153 [ [ 'foo' => '' ], 'foo=' ], // empty string test
154 [ [ 'foo' => 1 ], 'foo=1' ], // number test
155 [ [ 'foo' => true ], 'foo=1' ], // true test
156 [ [ 'foo' => false ], '' ], // false test
157 [ [ 'foo' => null ], '' ], // null test
158 [ [ 'foo' => 'A&B=5+6@!"\'' ], 'foo=A%26B%3D5%2B6%40%21%22%27' ], // urlencoding test
159 [
160 [ 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ],
161 'foo=bar&baz=is&asdf=qwerty'
162 ], // multi-item test
163 [ [ 'foo' => [ 'bar' => 'baz' ] ], 'foo%5Bbar%5D=baz' ],
164 [
165 [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ],
166 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
167 ],
168 [ [ 'foo' => [ 'bar', 'baz' ] ], 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
169 [
170 [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ],
171 'foo%5Bbar%5D%5Bbar%5D=baz'
172 ],
173 ];
174 }
175
180 public function testArrayToCGI( $array, $result ) {
181 $this->assertEquals( $result, wfArrayToCgi( $array ) );
182 }
183
187 public function testArrayToCGI2() {
188 $this->assertEquals(
189 "baz=bar&foo=bar",
191 [ 'baz' => 'bar' ],
192 [ 'foo' => 'bar', 'baz' => 'overridden value' ] ) );
193 }
194
195 public static function provideCgiToArray() {
196 return [
197 [ '', [] ], // empty
198 [ 'foo=bar', [ 'foo' => 'bar' ] ], // string
199 [ 'foo=', [ 'foo' => '' ] ], // empty string
200 [ 'foo', [ 'foo' => '' ] ], // missing =
201 [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
202 [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
203 [ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
204 [
205 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
206 [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
207 ],
208 [ 'foo%5B0%5D=bar&foo%5B1%5D=baz', [ 'foo' => [ 0 => 'bar', 1 => 'baz' ] ] ],
209 [
210 'foo%5Bbar%5D%5Bbar%5D=baz',
211 [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
212 ],
213 ];
214 }
215
220 public function testCgiToArray( $cgi, $result ) {
221 $this->assertEquals( $result, wfCgiToArray( $cgi ) );
222 }
223
224 public static function provideCgiRoundTrip() {
225 return [
226 [ '' ],
227 [ 'foo=bar' ],
228 [ 'foo=' ],
229 [ 'foo=bar&baz=biz' ],
230 [ 'foo=A%26B%3D5%2B6%40%21%22%27' ],
231 [ 'foo%5Bbar%5D=baz' ],
232 [ 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
233 [ 'foo%5Bbar%5D%5Bbar%5D=baz' ],
234 ];
235 }
236
241 public function testCgiRoundTrip( $cgi ) {
242 $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
243 }
244
248 public function testMimeTypeMatch() {
249 $this->assertEquals(
250 'text/html',
251 mimeTypeMatch( 'text/html',
252 [ 'application/xhtml+xml' => 1.0,
253 'text/html' => 0.7,
254 'text/plain' => 0.3 ] ) );
255 $this->assertEquals(
256 'text/*',
257 mimeTypeMatch( 'text/html',
258 [ 'image/*' => 1.0,
259 'text/*' => 0.5 ] ) );
260 $this->assertEquals(
261 '*/*',
262 mimeTypeMatch( 'text/html',
263 [ '*/*' => 1.0 ] ) );
264 $this->assertNull(
265 mimeTypeMatch( 'text/html',
266 [ 'image/png' => 1.0,
267 'image/svg+xml' => 0.5 ] ) );
268 }
269
273 public function testNegotiateType() {
274 $this->assertEquals(
275 'text/html',
277 [ 'application/xhtml+xml' => 1.0,
278 'text/html' => 0.7,
279 'text/plain' => 0.5,
280 'text/*' => 0.2 ],
281 [ 'text/html' => 1.0 ] ) );
282 $this->assertEquals(
283 'application/xhtml+xml',
285 [ 'application/xhtml+xml' => 1.0,
286 'text/html' => 0.7,
287 'text/plain' => 0.5,
288 'text/*' => 0.2 ],
289 [ 'application/xhtml+xml' => 1.0,
290 'text/html' => 0.5 ] ) );
291 $this->assertEquals(
292 'text/html',
294 [ 'text/html' => 1.0,
295 'text/plain' => 0.5,
296 'text/*' => 0.5,
297 'application/xhtml+xml' => 0.2 ],
298 [ 'application/xhtml+xml' => 1.0,
299 'text/html' => 0.5 ] ) );
300 $this->assertEquals(
301 'text/html',
303 [ 'text/*' => 1.0,
304 'image/*' => 0.7,
305 '*/*' => 0.3 ],
306 [ 'application/xhtml+xml' => 1.0,
307 'text/html' => 0.5 ] ) );
308 $this->assertNull(
310 [ 'text/*' => 1.0 ],
311 [ 'application/xhtml+xml' => 1.0 ] ) );
312 }
313
318 public function testDebugFunctionTest() {
319 $debugLogFile = $this->getNewTempFile();
320
321 $this->setMwGlobals( [
322 'wgDebugLogFile' => $debugLogFile,
323 #  @todo FIXME: $wgDebugTimestamps should be tested
324 'wgDebugTimestamps' => false,
325 ] );
326 $this->setLogger( 'wfDebug', new LegacyLogger( 'wfDebug' ) );
327
328 wfDebug( "This is a normal string" );
329 $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
330 unlink( $debugLogFile );
331
332 wfDebug( "This is nöt an ASCII string" );
333 $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
334 unlink( $debugLogFile );
335
336 wfDebug( "\00305This has böth UTF and control chars\003" );
337 $this->assertEquals(
338 " 05This has böth UTF and control chars \n",
339 file_get_contents( $debugLogFile )
340 );
341 unlink( $debugLogFile );
342
343 wfDebugMem();
344 $this->assertGreaterThan(
345 1000,
346 preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
347 );
348 unlink( $debugLogFile );
349
350 wfDebugMem( true );
351 $this->assertGreaterThan(
352 1000000,
353 preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
354 );
355 unlink( $debugLogFile );
356 }
357
361 public function testClientAcceptsGzipTest() {
362 $settings = [
363 'gzip' => true,
364 'bzip' => false,
365 '*' => false,
366 'compress, gzip' => true,
367 'gzip;q=1.0' => true,
368 'foozip' => false,
369 'foo*zip' => false,
370 'gzip;q=abcde' => true, // is this REALLY valid?
371 'gzip;q=12345678.9' => true,
372 ' gzip' => true,
373 ];
374
375 if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
376 $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
377 }
378
379 foreach ( $settings as $encoding => $expect ) {
380 $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
381
382 $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
383 "'$encoding' => " . wfBoolToStr( $expect ) );
384 }
385
386 if ( isset( $old_server_setting ) ) {
387 $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
388 }
389 }
390
394 public function testWfPercentTest() {
395 $pcts = [
396 [ 6 / 7, '0.86%', 2, false ],
397 [ 3 / 3, '1%' ],
398 [ 22 / 7, '3.14286%', 5 ],
399 [ 3 / 6, '0.5%' ],
400 [ 1 / 3, '0%', 0 ],
401 [ 10 / 3, '0%', -1 ],
402 [ 3 / 4 / 5, '0.1%', 1 ],
403 [ 6 / 7 * 8, '6.8571428571%', 10 ],
404 ];
405
406 foreach ( $pcts as $pct ) {
407 if ( !isset( $pct[2] ) ) {
408 $pct[2] = 2;
409 }
410 if ( !isset( $pct[3] ) ) {
411 $pct[3] = true;
412 }
413
414 $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
415 }
416 }
417
423 public function testWfShorthandToInteger( $shorthand, $expected ) {
424 $this->assertEquals( $expected,
425 wfShorthandToInteger( $shorthand )
426 );
427 }
428
429 public static function provideShorthand() {
430 // Syntax: [ shorthand, expected integer ]
431 return [
432 # Null, empty ...
433 [ '', -1 ],
434 [ ' ', -1 ],
435 [ null, -1 ],
436
437 # Failures returns 0 :(
438 [ 'ABCDEFG', 0 ],
439 [ 'Ak', 0 ],
440
441 # Int, strings with spaces
442 [ 1, 1 ],
443 [ ' 1 ', 1 ],
444 [ 1023, 1023 ],
445 [ ' 1023 ', 1023 ],
446
447 # kilo, Mega, Giga
448 [ '1k', 1024 ],
449 [ '1K', 1024 ],
450 [ '1m', 1024 * 1024 ],
451 [ '1M', 1024 * 1024 ],
452 [ '1g', 1024 * 1024 * 1024 ],
453 [ '1G', 1024 * 1024 * 1024 ],
454
455 # Negatives
456 [ -1, -1 ],
457 [ -500, -500 ],
458 [ '-500', -500 ],
459 [ '-1k', -1024 ],
460
461 # Zeroes
462 [ '0', 0 ],
463 [ '0k', 0 ],
464 [ '0M', 0 ],
465 [ '0G', 0 ],
466 [ '-0', 0 ],
467 [ '-0k', 0 ],
468 [ '-0M', 0 ],
469 [ '-0G', 0 ],
470 ];
471 }
472
478
479 $mergedText = null;
480 $successfulMerge = wfMerge( "old1\n\nold2", "old1\n\nnew2", "new1\n\nold2", $mergedText );
481
482 $mergedText = null;
483 $conflictingMerge = wfMerge( 'old', 'old and mine', 'old and yours', $mergedText );
484
485 $this->assertEquals( true, $successfulMerge );
486 $this->assertEquals( false, $conflictingMerge );
487 }
488
501 public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
502 $expectedMergeAttemptResult ) {
504
505 $mergedText = null;
506 $attemptMergeResult = null;
507 $isMerged = wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
508
509 $msg = 'Merge should be a ';
510 $msg .= $expectedMergeResult ? 'success' : 'failure';
511 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
512 $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
513
514 if ( $isMerged ) {
515 // Verify the merged text
516 $this->assertEquals( $expectedText, $mergedText,
517 'is merged text as expected?' );
518 }
519 }
520
521 public static function provideMerge() {
522 $EXPECT_MERGE_SUCCESS = true;
523 $EXPECT_MERGE_FAILURE = false;
524
525 return [
526 // #0: clean merge
527 [
528 // old:
529 "one one one\n" . // trimmed
530 "\n" .
531 "two two two",
532
533 // mine:
534 "one one one ONE ONE\n" .
535 "\n" .
536 "two two two\n", // with tailing whitespace
537
538 // yours:
539 "one one one\n" .
540 "\n" .
541 "two two TWO TWO", // trimmed
542
543 // ok:
544 $EXPECT_MERGE_SUCCESS,
545
546 // result:
547 "one one one ONE ONE\n" .
548 "\n" .
549 "two two TWO TWO\n", // note: will always end in a newline
550
551 // mergeAttemptResult:
552 "",
553 ],
554
555 // #1: conflict, fail
556 [
557 // old:
558 "one one one", // trimmed
559
560 // mine:
561 "one one one ONE ONE\n" .
562 "\n" .
563 "bla bla\n" .
564 "\n", // with tailing whitespace
565
566 // yours:
567 "one one one\n" .
568 "\n" .
569 "two two", // trimmed
570
571 $EXPECT_MERGE_FAILURE,
572
573 // result:
574 null,
575
576 // mergeAttemptResult:
577 "1,3c\n" .
578 "one one one\n" .
579 "\n" .
580 "two two\n" .
581 ".\n",
582 ],
583 ];
584 }
585
590 public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
591 $actual = wfMatchesDomainList( $url, $domains );
592 $this->assertEquals( $expected, $actual, $description );
593 }
594
595 public static function provideWfMatchesDomainList() {
596 $a = [];
597 $protocols = [ 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ];
598 foreach ( $protocols as $pDesc => $p ) {
599 $a = array_merge( $a, [
600 [
601 "$p//www.example.com",
602 [],
603 false,
604 "No matches for empty domains array, $pDesc URL"
605 ],
606 [
607 "$p//www.example.com",
608 [ 'www.example.com' ],
609 true,
610 "Exact match in domains array, $pDesc URL"
611 ],
612 [
613 "$p//www.example.com",
614 [ 'example.com' ],
615 true,
616 "Match without subdomain in domains array, $pDesc URL"
617 ],
618 [
619 "$p//www.example2.com",
620 [ 'www.example.com', 'www.example2.com', 'www.example3.com' ],
621 true,
622 "Exact match with other domains in array, $pDesc URL"
623 ],
624 [
625 "$p//www.example2.com",
626 [ 'example.com', 'example2.com', 'example3,com' ],
627 true,
628 "Match without subdomain with other domains in array, $pDesc URL"
629 ],
630 [
631 "$p//www.example4.com",
632 [ 'example.com', 'example2.com', 'example3,com' ],
633 false,
634 "Domain not in array, $pDesc URL"
635 ],
636 [
637 "$p//nds-nl.wikipedia.org",
638 [ 'nl.wikipedia.org' ],
639 false,
640 "Non-matching substring of domain, $pDesc URL"
641 ],
642 ] );
643 }
644
645 return $a;
646 }
647
651 public function testWfMkdirParents() {
652 // Should not return true if file exists instead of directory
653 $fname = $this->getNewTempFile();
654 Wikimedia\suppressWarnings();
655 $ok = wfMkdirParents( $fname );
656 Wikimedia\restoreWarnings();
657 $this->assertFalse( $ok );
658 }
659
664 public function testWfShellWikiCmd( $script, $parameters, $options,
665 $expected, $description
666 ) {
667 if ( wfIsWindows() ) {
668 // Approximation that's good enough for our purposes just now
669 $expected = str_replace( "'", '"', $expected );
670 }
671 $actual = wfShellWikiCmd( $script, $parameters, $options );
672 $this->assertEquals( $expected, $actual, $description );
673 }
674
675 public function wfWikiID() {
676 $this->setMwGlobals( [
677 'wgDBname' => 'example',
678 'wgDBprefix' => '',
679 ] );
680 $this->assertEquals(
681 wfWikiID(),
682 'example'
683 );
684
685 $this->setMwGlobals( [
686 'wgDBname' => 'example',
687 'wgDBprefix' => 'mw_',
688 ] );
689 $this->assertEquals(
690 wfWikiID(),
691 'example-mw_'
692 );
693 }
694
698 public function testWfMemcKey() {
699 $cache = ObjectCache::getLocalClusterInstance();
700 $this->assertEquals(
701 $cache->makeKey( 'foo', 123, 'bar' ),
702 wfMemcKey( 'foo', 123, 'bar' )
703 );
704 }
705
709 public function testWfForeignMemcKey() {
710 $cache = ObjectCache::getLocalClusterInstance();
711 $keyspace = $this->readAttribute( $cache, 'keyspace' );
712 $this->assertEquals(
713 wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
714 $cache->makeKey( 'foo', 'bar' )
715 );
716 }
717
721 public function testWfGlobalCacheKey() {
722 $cache = ObjectCache::getLocalClusterInstance();
723 $this->assertEquals(
724 $cache->makeGlobalKey( 'foo', 123, 'bar' ),
725 wfGlobalCacheKey( 'foo', 123, 'bar' )
726 );
727 }
728
729 public static function provideWfShellWikiCmdList() {
730 global $wgPhpCli;
731
732 return [
733 [ 'eval.php', [ '--help', '--test' ], [],
734 "'$wgPhpCli' 'eval.php' '--help' '--test'",
735 "Called eval.php --help --test" ],
736 [ 'eval.php', [ '--help', '--test space' ], [ 'php' => 'php5' ],
737 "'php5' 'eval.php' '--help' '--test space'",
738 "Called eval.php --help --test with php option" ],
739 [ 'eval.php', [ '--help', '--test', 'X' ], [ 'wrapper' => 'MWScript.php' ],
740 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
741 "Called eval.php --help --test with wrapper option" ],
742 [
743 'eval.php',
744 [ '--help', '--test', 'y' ],
745 [ 'php' => 'php5', 'wrapper' => 'MWScript.php' ],
746 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
747 "Called eval.php --help --test with wrapper and php option"
748 ],
749 ];
750 }
751 /* @todo many more! */
752}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgPhpCli
Executable path of the PHP cli binary.
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
$wgDebugTimestamps
Prefix debug messages with relative timestamp.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfNegotiateType( $cprefs, $sprefs)
Returns the 'best' match between a client's requested internet media types and the server's list of a...
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
wfReadOnly()
Check whether the wiki is in read-only mode.
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
wfPercent( $nr, $acc=2, $round=true)
wfMerge( $old, $mine, $yours, &$result, &$mergeAttemptResult=null)
wfMerge attempts to merge differences between three texts.
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
wfGlobalCacheKey(... $args)
Make a cache key with database-agnostic prefix.
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
wfMemcKey(... $args)
Make a cache key for the local wiki.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
wfIsWindows()
Check if the operating system is Windows.
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
wfForeignMemcKey( $db, $prefix,... $args)
Make a cache key for a foreign DB.
mimeTypeMatch( $type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition Setup.php:123
Database GlobalFunctions.
Definition GlobalTest.php:9
testCgiToArray( $cgi, $result)
provideCgiToArray wfCgiToArray
testWfArrayDiff2( $a, $b, $expected)
provideForWfArrayDiff2 wfArrayDiff2
testMerge_worksWithLessParameters()
wfMerge
testExpandIRI()
wfExpandIRI
testDebugFunctionTest()
wfDebug wfDebugMem
testWfPercentTest()
wfPercent
testMimeTypeMatch()
mimeTypeMatch
static provideShorthand()
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText, $expectedMergeAttemptResult)
static provideCgiToArray()
testArrayToCGI( $array, $result)
provideArrayToCGI wfArrayToCgi
testRandom()
wfRandom
testWfMkdirParents()
wfMkdirParents
testWfMatchesDomainList( $url, $domains, $expected, $description)
provideWfMatchesDomainList wfMatchesDomainList
static provideArrayToCGI()
testNegotiateType()
wfNegotiateType
testClientAcceptsGzipTest()
wfClientAcceptsGzip
testUrlencode()
wfUrlencode
testReadOnlyGlobalChange()
This behaviour could probably be deprecated.
testWfShellWikiCmd( $script, $parameters, $options, $expected, $description)
provideWfShellWikiCmdList wfShellWikiCmd
testWfForeignMemcKey()
wfForeignMemcKey
testReadOnlyEmpty()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
static provideMerge()
testRandomString()
wfRandomString
testCgiRoundTrip( $cgi)
provideCgiRoundTrip wfArrayToCgi
testWfGlobalCacheKey()
wfGlobalCacheKey
testWfShorthandToInteger( $shorthand, $expected)
test
testWfMemcKey()
wfMemcKey
testReadOnlySet()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
testArrayToCGI2()
wfArrayToCgi
static provideCgiRoundTrip()
static provideWfShellWikiCmdList()
static provideForWfArrayDiff2()
static provideWfMatchesDomainList()
getNewTempFile()
Obtains a new temporary file name.
overrideMwServices(Config $configOverrides=null, array $services=[])
Stashes the global instance of MediaWikiServices, and installs a new one, allowing test cases to over...
setLogger( $channel, LoggerInterface $logger)
Sets the logger for a specified channel, for the duration of the test.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
markTestSkippedIfNoDiff3()
Check, if $wgDiff3 is set and ready to merge Will mark the calling test as skipped,...
PSR-3 logger that mimics the historic implementation of MediaWiki's former wfErrorLog logging impleme...
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
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. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition hooks.txt:1991
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:1999
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition hooks.txt:783
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:2004
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
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
$cache
Definition mcc.php:33
$f
Definition router.php:79