8 protected function setUp() {
12 unlink( $readOnlyFile );
15 'wgReadOnlyFile' => $readOnlyFile,
21 'file://', # Non-
default
46 [ [
'a' ], [
'a',
'b',
'c' ] ],
47 [ [
'a' ], [
'a',
'b' ] ],
48 [ 1 => [
'a',
'b',
'c' ] ],
87 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
88 wfUrlencode(
"\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
96 "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
98 .
"%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
99 .
"%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
100 .
"%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
101 .
"%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
112 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache();
124 $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
125 $readOnlyMode->clearCache();
128 fwrite( $f,
'Message' );
133 $this->assertTrue(
wfReadOnly() ); # Check cached
136 $readOnlyMode->clearCache();
148 'wgReadOnly' =>
'reason'
156 [ [
'foo' =>
'bar' ],
'foo=bar' ],
157 [ [
'foo' =>
'' ],
'foo=' ],
158 [ [
'foo' => 1 ],
'foo=1' ],
159 [ [
'foo' =>
true ],
'foo=1' ],
160 [ [
'foo' =>
false ],
'' ],
161 [ [
'foo' => null ],
'' ],
162 [ [
'foo' =>
'A&B=5+6@!"\'' ],
'foo=A%26B%3D5%2B6%40%21%22%27' ],
164 [
'foo' =>
'bar',
'baz' =>
'is',
'asdf' =>
'qwerty' ],
165 'foo=bar&baz=is&asdf=qwerty'
167 [ [
'foo' => [
'bar' =>
'baz' ] ],
'foo%5Bbar%5D=baz' ],
169 [
'foo' => [
'bar' =>
'baz',
'qwerty' =>
'asdf' ] ],
170 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
172 [ [
'foo' => [
'bar',
'baz' ] ],
'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
174 [
'foo' => [
'bar' => [
'bar' =>
'baz' ] ] ],
175 'foo%5Bbar%5D%5Bbar%5D=baz'
196 [
'foo' =>
'bar',
'baz' =>
'overridden value' ] ) );
202 [
'foo=bar', [
'foo' =>
'bar' ] ],
203 [
'foo=', [
'foo' =>
'' ] ],
204 [
'foo', [
'foo' =>
'' ] ],
205 [
'foo=bar&qwerty=asdf', [
'foo' =>
'bar',
'qwerty' =>
'asdf' ] ],
206 [
'foo=A%26B%3D5%2B6%40%21%22%27', [
'foo' =>
'A&B=5+6@!"\'' ] ],
207 [
'foo%5Bbar%5D=baz', [
'foo' => [
'bar' =>
'baz' ] ] ],
209 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
210 [
'foo' => [
'bar' =>
'baz',
'qwerty' =>
'asdf' ] ]
212 [
'foo%5B0%5D=bar&foo%5B1%5D=baz', [
'foo' => [ 0 =>
'bar', 1 =>
'baz' ] ] ],
214 'foo%5Bbar%5D%5Bbar%5D=baz',
215 [
'foo' => [
'bar' => [
'bar' =>
'baz' ] ] ]
233 [
'foo=bar&baz=biz' ],
234 [
'foo=A%26B%3D5%2B6%40%21%22%27' ],
235 [
'foo%5Bbar%5D=baz' ],
236 [
'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
237 [
'foo%5Bbar%5D%5Bbar%5D=baz' ],
256 [
'application/xhtml+xml' => 1.0,
258 'text/plain' => 0.3 ] ) );
263 'text/*' => 0.5 ] ) );
267 [
'*/*' => 1.0 ] ) );
270 [
'image/png' => 1.0,
271 'image/svg+xml' => 0.5 ] ) );
281 [
'application/xhtml+xml' => 1.0,
285 [
'text/html' => 1.0 ] ) );
287 'application/xhtml+xml',
289 [
'application/xhtml+xml' => 1.0,
293 [
'application/xhtml+xml' => 1.0,
294 'text/html' => 0.5 ] ) );
298 [
'text/html' => 1.0,
301 'application/xhtml+xml' => 0.2 ],
302 [
'application/xhtml+xml' => 1.0,
303 'text/html' => 0.5 ] ) );
310 [
'application/xhtml+xml' => 1.0,
311 'text/html' => 0.5 ] ) );
315 [
'application/xhtml+xml' => 1.0 ] ) );
326 'wgDebugLogFile' => $debugLogFile,
328 'wgDebugTimestamps' =>
false
331 wfDebug(
"This is a normal string" );
332 $this->assertEquals(
"This is a normal string\n", file_get_contents( $debugLogFile ) );
333 unlink( $debugLogFile );
335 wfDebug(
"This is nöt an ASCII string" );
336 $this->assertEquals(
"This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
337 unlink( $debugLogFile );
339 wfDebug(
"\00305This has böth UTF and control chars\003" );
341 " 05This has böth UTF and control chars \n",
342 file_get_contents( $debugLogFile )
344 unlink( $debugLogFile );
347 $this->assertGreaterThan(
349 preg_replace(
'/\D/',
'', file_get_contents( $debugLogFile ) )
351 unlink( $debugLogFile );
354 $this->assertGreaterThan(
356 preg_replace(
'/\D/',
'', file_get_contents( $debugLogFile ) )
358 unlink( $debugLogFile );
369 'compress, gzip' =>
true,
370 'gzip;q=1.0' =>
true,
373 'gzip;q=abcde' =>
true,
374 'gzip;q=12345678.9' =>
true,
378 if ( isset( $_SERVER[
'HTTP_ACCEPT_ENCODING'] ) ) {
379 $old_server_setting = $_SERVER[
'HTTP_ACCEPT_ENCODING'];
382 foreach ( $settings as $encoding => $expect ) {
383 $_SERVER[
'HTTP_ACCEPT_ENCODING'] = $encoding;
389 if ( isset( $old_server_setting ) ) {
390 $_SERVER[
'HTTP_ACCEPT_ENCODING'] = $old_server_setting;
399 [ 6 / 7,
'0.86%', 2,
false ],
401 [ 22 / 7,
'3.14286%', 5 ],
404 [ 10 / 3,
'0%', -1 ],
405 [ 3 / 4 / 5,
'0.1%', 1 ],
406 [ 6 / 7 * 8,
'6.8571428571%', 10 ],
409 foreach ( $pcts as $pct ) {
410 if ( !isset( $pct[2] ) ) {
413 if ( !isset( $pct[3] ) ) {
417 $this->assertEquals(
wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
427 $this->assertEquals( $expected,
440 # Failures returns 0 :(
444 # Int, strings with spaces
453 [
'1m', 1024 * 1024 ],
454 [
'1M', 1024 * 1024 ],
455 [
'1g', 1024 * 1024 * 1024 ],
456 [
'1G', 1024 * 1024 * 1024 ],
483 $successfulMerge =
wfMerge(
"old1\n\nold2",
"old1\n\nnew2",
"new1\n\nold2", $mergedText );
486 $conflictingMerge =
wfMerge(
'old',
'old and mine',
'old and yours', $mergedText );
488 $this->assertEquals(
true, $successfulMerge );
489 $this->assertEquals(
false, $conflictingMerge );
504 public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
505 $expectedMergeAttemptResult ) {
509 $attemptMergeResult =
null;
510 $isMerged =
wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
512 $msg =
'Merge should be a ';
513 $msg .= $expectedMergeResult ?
'success' :
'failure';
514 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
515 $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
519 $this->assertEquals( $expectedText, $mergedText,
520 'is merged text as expected?' );
525 $EXPECT_MERGE_SUCCESS =
true;
526 $EXPECT_MERGE_FAILURE =
false;
537 "one one one ONE ONE\n" .
547 $EXPECT_MERGE_SUCCESS,
550 "one one one ONE ONE\n" .
564 "one one one ONE ONE\n" .
574 $EXPECT_MERGE_FAILURE,
595 $this->assertEquals( $expected, $index,
"wfMakeUrlIndexes(\"$url\")" );
602 'https://example.org/test.cgi?id=12345',
603 [
'https://org.example./test.cgi?id=12345' ]
608 'mailto:wiki@wikimedia.org',
609 [
'mailto:org.wikimedia@wiki.' ]
615 'file:///whatever/you/like.txt',
616 [
'file://./whatever/you/like.txt' ]
620 'file:///c:/whatever/you/like.txt',
621 [
'file://./c:/whatever/you/like.txt' ]
625 'file://intranet/whatever/you/like.txt',
626 [
'file://intranet./whatever/you/like.txt' ]
637 '//example.org/test.cgi?id=12345',
639 'http://org.example./test.cgi?id=12345',
640 'https://org.example./test.cgi?id=12345'
652 $this->assertEquals( $expected, $actual, $description );
657 $protocols = [
'HTTP' =>
'http:',
'HTTPS' =>
'https:',
'protocol-relative' =>
'' ];
658 foreach ( $protocols as $pDesc => $p ) {
659 $a = array_merge( $a, [
661 "$p//www.example.com",
664 "No matches for empty domains array, $pDesc URL"
667 "$p//www.example.com",
668 [
'www.example.com' ],
670 "Exact match in domains array, $pDesc URL"
673 "$p//www.example.com",
676 "Match without subdomain in domains array, $pDesc URL"
679 "$p//www.example2.com",
680 [
'www.example.com',
'www.example2.com',
'www.example3.com' ],
682 "Exact match with other domains in array, $pDesc URL"
685 "$p//www.example2.com",
686 [
'example.com',
'example2.com',
'example3,com' ],
688 "Match without subdomain with other domains in array, $pDesc URL"
691 "$p//www.example4.com",
692 [
'example.com',
'example2.com',
'example3,com' ],
694 "Domain not in array, $pDesc URL"
697 "$p//nds-nl.wikipedia.org",
698 [
'nl.wikipedia.org' ],
700 "Non-matching substring of domain, $pDesc URL"
714 Wikimedia\suppressWarnings();
716 Wikimedia\restoreWarnings();
717 $this->assertFalse( $ok );
725 $expected, $description
729 $expected = str_replace(
"'",
'"', $expected );
732 $this->assertEquals( $expected, $actual, $description );
737 'wgDBname' =>
'example',
746 'wgDBname' =>
'example',
747 'wgDBprefix' =>
'mw_',
759 $cache = ObjectCache::getLocalClusterInstance();
761 $cache->makeKey(
'foo', 123,
'bar' ),
770 $cache = ObjectCache::getLocalClusterInstance();
771 $keyspace = $this->readAttribute(
$cache,
'keyspace' );
774 $cache->makeKey(
'foo',
'bar' )
782 $cache = ObjectCache::getLocalClusterInstance();
784 $cache->makeGlobalKey(
'foo', 123,
'bar' ),
793 [
'eval.php', [
'--help',
'--test' ], [],
794 "'$wgPhpCli' 'eval.php' '--help' '--test'",
795 "Called eval.php --help --test" ],
796 [
'eval.php', [
'--help',
'--test space' ], [
'php' =>
'php5' ],
797 "'php5' 'eval.php' '--help' '--test space'",
798 "Called eval.php --help --test with php option" ],
799 [
'eval.php', [
'--help',
'--test',
'X' ], [
'wrapper' =>
'MWScript.php' ],
800 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
801 "Called eval.php --help --test with wrapper option" ],
804 [
'--help',
'--test',
'y' ],
805 [
'php' =>
'php5',
'wrapper' =>
'MWScript.php' ],
806 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
807 "Called eval.php --help --test with wrapper and php option"
$wgPhpCli
Executable path of the PHP cli binary.
$wgReadOnly
Set this to a string to put the wiki into read-only mode.
$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 between 0 and 1, in a way not likely to give duplicate values for any real...
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.
wfGlobalCacheKey()
Make a cache key with database-agnostic prefix.
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.
wfMemcKey()
Make a cache key for the local wiki.
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
wfMakeUrlIndexes( $url)
Make URL indexes, appropriate for the el_index field of externallinks.
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
wfForeignMemcKey( $db, $prefix)
Make a cache key for a foreign DB.
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.
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,...
Database GlobalFunctions.
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()
static provideMakeUrlIndexes()
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText, $expectedMergeAttemptResult)
static provideCgiToArray()
testArrayToCGI( $array, $result)
provideArrayToCGI wfArrayToCgi
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....
testRandomString()
wfRandomString
testCgiRoundTrip( $cgi)
provideCgiRoundTrip wfArrayToCgi
testWfGlobalCacheKey()
wfGlobalCacheKey
testWfShorthandToInteger( $shorthand, $expected)
test
testReadOnlySet()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
testArrayToCGI2()
wfArrayToCgi
static provideCgiRoundTrip()
static provideWfShellWikiCmdList()
static provideForWfArrayDiff2()
static provideWfMatchesDomainList()
testMakeUrlIndexes( $url, $expected)
provideMakeUrlIndexes() wfMakeUrlIndexes
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
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
processing should stop and the error should be shown to the user * false