Go to the documentation of this file.
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" ) );
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 ],
487 public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
491 $isMerged =
wfMerge( $old, $mine, $yours, $mergedText );
493 $msg =
'Merge should be a ';
494 $msg .= $expectedMergeResult ?
'success' :
'failure';
495 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
499 $this->assertEquals( $expectedText, $mergedText,
500 'is merged text as expected?' );
505 $EXPECT_MERGE_SUCCESS =
true;
506 $EXPECT_MERGE_FAILURE =
false;
517 "one one one ONE ONE\n" .
527 $EXPECT_MERGE_SUCCESS,
530 "one one one ONE ONE\n" .
541 "one one one ONE ONE\n" .
551 $EXPECT_MERGE_FAILURE,
565 $this->assertEquals( $expected, $index,
"wfMakeUrlIndexes(\"$url\")" );
572 'https://example.org/test.cgi?id=12345',
573 [
'https://org.example./test.cgi?id=12345' ]
578 'mailto:wiki@wikimedia.org',
579 [
'mailto:org.wikimedia@wiki.' ]
585 'file:///whatever/you/like.txt',
586 [
'file://./whatever/you/like.txt' ]
590 'file:///c:/whatever/you/like.txt',
591 [
'file://./c:/whatever/you/like.txt' ]
595 'file://intranet/whatever/you/like.txt',
596 [
'file://intranet./whatever/you/like.txt' ]
607 '//example.org/test.cgi?id=12345',
609 'http://org.example./test.cgi?id=12345',
610 'https://org.example./test.cgi?id=12345'
622 $this->assertEquals( $expected, $actual, $description );
627 $protocols = [
'HTTP' =>
'http:',
'HTTPS' =>
'https:',
'protocol-relative' =>
'' ];
628 foreach ( $protocols
as $pDesc => $p ) {
629 $a = array_merge( $a, [
631 "$p//www.example.com",
634 "No matches for empty domains array, $pDesc URL"
637 "$p//www.example.com",
638 [
'www.example.com' ],
640 "Exact match in domains array, $pDesc URL"
643 "$p//www.example.com",
646 "Match without subdomain in domains array, $pDesc URL"
649 "$p//www.example2.com",
650 [
'www.example.com',
'www.example2.com',
'www.example3.com' ],
652 "Exact match with other domains in array, $pDesc URL"
655 "$p//www.example2.com",
656 [
'example.com',
'example2.com',
'example3,com' ],
658 "Match without subdomain with other domains in array, $pDesc URL"
661 "$p//www.example4.com",
662 [
'example.com',
'example2.com',
'example3,com' ],
664 "Domain not in array, $pDesc URL"
667 "$p//nds-nl.wikipedia.org",
668 [
'nl.wikipedia.org' ],
670 "Non-matching substring of domain, $pDesc URL"
684 MediaWiki\suppressWarnings();
686 MediaWiki\restoreWarnings();
687 $this->assertFalse( $ok );
695 $expected, $description
699 $expected = str_replace(
"'",
'"', $expected );
702 $this->assertEquals( $expected, $actual, $description );
707 'wgDBname' =>
'example',
716 'wgDBname' =>
'example',
717 'wgDBprefix' =>
'mw_',
728 $cache->makeKey(
'foo', 123,
'bar' ),
735 $keyspace = $this->readAttribute(
$cache,
'keyspace' );
738 $cache->makeKey(
'foo',
'bar' )
745 $cache->makeGlobalKey(
'foo', 123,
'bar' ),
754 [
'eval.php', [
'--help',
'--test' ], [],
755 "'$wgPhpCli' 'eval.php' '--help' '--test'",
756 "Called eval.php --help --test" ],
757 [
'eval.php', [
'--help',
'--test space' ], [
'php' =>
'php5' ],
758 "'php5' 'eval.php' '--help' '--test space'",
759 "Called eval.php --help --test with php option" ],
760 [
'eval.php', [
'--help',
'--test',
'X' ], [
'wrapper' =>
'MWScript.php' ],
761 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
762 "Called eval.php --help --test with wrapper option" ],
765 [
'--help',
'--test',
'y' ],
766 [
'php' =>
'php5',
'wrapper' =>
'MWScript.php' ],
767 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
768 "Called eval.php --help --test with wrapper and php option"
$wgPhpCli
Executable path of the PHP cli binary (php/php5).
wfPercent( $nr, $acc=2, $round=true)
testRandomString()
wfRandomString
testMimeTypeMatch()
mimeTypeMatch
testReadOnlyGlobalChange()
This behaviour could probably be deprecated.
processing should stop and the error should be shown to the user * false
static getLocalClusterInstance()
Get the main cluster-local cache object.
wfMerge( $old, $mine, $yours, &$result)
wfMerge attempts to merge differences between three texts.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
testCgiRoundTrip( $cgi)
provideCgiRoundTrip wfArrayToCgi
wfNegotiateType( $cprefs, $sprefs)
Returns the 'best' match between a client's requested internet media types and the server's list of a...
wfMakeUrlIndexes( $url)
Make URL indexes, appropriate for the el_index field of externallinks.
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:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
wfReadOnly()
Check whether the wiki is in read-only mode.
testExpandIRI()
wfExpandIRI
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
testClientAcceptsGzipTest()
wfClientAcceptsGzip
wfShellWikiCmd( $script, array $parameters=[], array $options=[])
Generate a shell-escaped command line string to run a MediaWiki cli script.
testWfArrayDiff2( $a, $b, $expected)
provideForWfArrayDiff2 wfArrayDiff2
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
testWfShellWikiCmd( $script, $parameters, $options, $expected, $description)
provideWfShellWikiCmdList wfShellWikiCmd
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText)
testWfPercentTest()
wfPercent
wfMemcKey()
Make a cache key for the local wiki.
mimeTypeMatch( $type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
wfGlobalCacheKey()
Make a cache key with database-agnostic prefix.
static provideArrayToCGI()
wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
Database GlobalFunctions.
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
when a variable name is used in a it is silently declared as a new masking the global
wfForeignMemcKey( $db, $prefix)
Make a cache key for a foreign DB.
testCgiToArray( $cgi, $result)
provideCgiToArray wfCgiToArray
testReadOnlySet()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static provideMakeUrlIndexes()
$wgDebugTimestamps
Prefix debug messages with relative timestamp.
wfClientAcceptsGzip( $force=false)
Whether the client accept gzip encoding.
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
wfIsWindows()
Check if the operating system is Windows.
testDebugFunctionTest()
wfDebug wfDebugMem
$wgReadOnly
Set this to a string to put the wiki into read-only mode.
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
testWfMatchesDomainList( $url, $domains, $expected, $description)
provideWfMatchesDomainList wfMatchesDomainList
static provideWfMatchesDomainList()
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
testWfShorthandToInteger( $shorthand, $expected)
test
static provideShorthand()
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
wfReadOnlyReason()
Check if the site is in read-only mode and return the message if so.
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
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
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
testUrlencode()
wfUrlencode
testArrayToCGI2()
wfArrayToCgi
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
testArrayToCGI( $array, $result)
provideArrayToCGI wfArrayToCgi
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
testReadOnlyEmpty()
Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions....
static provideCgiToArray()
testMakeUrlIndexes( $url, $expected)
provideMakeUrlIndexes() wfMakeUrlIndexes
static provideForWfArrayDiff2()
testNegotiateType()
wfNegotiateType
static provideCgiRoundTrip()
static provideWfShellWikiCmdList()
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
testWfMkdirParents()
wfMkdirParents