Go to the documentation of this file.
4 protected function setUp() {
7 $readOnlyFile = tempnam(
wfTempDir(),
"mwtest_readonly" );
8 unlink( $readOnlyFile );
11 'wgReadOnlyFile' => $readOnlyFile,
12 'wgUrlProtocols' =>
array(
17 'file://', # Non-
default
25 if ( file_exists( $wgReadOnlyFile ) ) {
26 unlink( $wgReadOnlyFile );
63 # This could hypothetically fail, but it shouldn't ;)
73 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
74 wfUrlencode(
"\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
82 "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
83 wfExpandIRI(
"https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
101 global $wgReadOnly, $wgReadOnlyFile;
103 $f = fopen( $wgReadOnlyFile,
"wt" );
104 fwrite(
$f,
'Message' );
106 $wgReadOnly =
null; # Check
on $wgReadOnlyFile
109 $this->assertTrue(
wfReadOnly() ); # Check cached
111 unlink( $wgReadOnlyFile );
112 $wgReadOnly =
null; # Clean
cache
127 array(
array(
'foo' =>
'A&B=5+6@!"\'' ),
'foo=A%26B%3D5%2B6%40%21%22%27' ),
128 array(
array(
'foo' =>
'bar',
'baz' =>
'is',
'asdf' =>
'qwerty' ),
'foo=bar&baz=is&asdf=qwerty' ),
129 array(
array(
'foo' =>
array(
'bar' =>
'baz' ) ),
'foo%5Bbar%5D=baz' ),
130 array(
array(
'foo' =>
array(
'bar' =>
'baz',
'qwerty' =>
'asdf' ) ),
'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf' ),
131 array(
array(
'foo' =>
array(
'bar',
'baz' ) ),
'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
132 array(
array(
'foo' =>
array(
'bar' =>
array(
'bar' =>
'baz' ) ) ),
'foo%5Bbar%5D%5Bbar%5D=baz' ),
151 array(
'baz' =>
'bar' ),
152 array(
'foo' =>
'bar',
'baz' =>
'overridden value' ) ) );
161 array(
'foo=bar&qwerty=asdf',
array(
'foo' =>
'bar',
'qwerty' =>
'asdf' ) ),
162 array(
'foo=A%26B%3D5%2B6%40%21%22%27',
array(
'foo' =>
'A&B=5+6@!"\'' ) ),
163 array(
'foo%5Bbar%5D=baz',
array(
'foo' =>
array(
'bar' =>
'baz' ) ) ),
164 array(
'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
array(
'foo' =>
array(
'bar' =>
'baz',
'qwerty' =>
'asdf' ) ) ),
165 array(
'foo%5B0%5D=bar&foo%5B1%5D=baz',
array(
'foo' =>
array( 0 =>
'bar', 1 =>
'baz' ) ) ),
166 array(
'foo%5Bbar%5D%5Bbar%5D=baz',
array(
'foo' =>
array(
'bar' =>
array(
'bar' =>
'baz' ) ) ) ),
183 array(
'foo=bar&baz=biz' ),
184 array(
'foo=A%26B%3D5%2B6%40%21%22%27' ),
185 array(
'foo%5Bbar%5D=baz' ),
186 array(
'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
187 array(
'foo%5Bbar%5D%5Bbar%5D=baz' ),
206 array(
'application/xhtml+xml' => 1.0,
208 'text/plain' => 0.3 ) ) );
212 array(
'image/*' => 1.0,
213 'text/*' => 0.5 ) ) );
217 array(
'*/*' => 1.0 ) ) );
220 array(
'image/png' => 1.0,
221 'image/svg+xml' => 0.5 ) ) );
231 array(
'application/xhtml+xml' => 1.0,
235 array(
'text/html' => 1.0 ) ) );
237 'application/xhtml+xml',
239 array(
'application/xhtml+xml' => 1.0,
243 array(
'application/xhtml+xml' => 1.0,
244 'text/html' => 0.5 ) ) );
248 array(
'text/html' => 1.0,
251 'application/xhtml+xml' => 0.2 ),
252 array(
'application/xhtml+xml' => 1.0,
253 'text/html' => 0.5 ) ) );
257 array(
'text/*' => 1.0,
260 array(
'application/xhtml+xml' => 1.0,
261 'text/html' => 0.5 ) ) );
264 array(
'text/*' => 1.0 ),
265 array(
'application/xhtml+xml' => 1.0 ) ) );
274 global $wgDebugLogFile, $wgDebugTimestamps;
276 $old_log_file = $wgDebugLogFile;
277 $wgDebugLogFile = tempnam(
wfTempDir(),
'mw-' );
278 # @todo FIXME: $wgDebugTimestamps should be tested
279 $old_wgDebugTimestamps = $wgDebugTimestamps;
280 $wgDebugTimestamps =
false;
282 wfDebug(
"This is a normal string" );
283 $this->assertEquals(
"This is a normal string", file_get_contents( $wgDebugLogFile ) );
284 unlink( $wgDebugLogFile );
286 wfDebug(
"This is nöt an ASCII string" );
287 $this->assertEquals(
"This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
288 unlink( $wgDebugLogFile );
290 wfDebug(
"\00305This has böth UTF and control chars\003" );
291 $this->assertEquals(
" 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
292 unlink( $wgDebugLogFile );
295 $this->assertGreaterThan( 1000, preg_replace(
'/\D/',
'', file_get_contents( $wgDebugLogFile ) ) );
296 unlink( $wgDebugLogFile );
299 $this->assertGreaterThan( 1000000, preg_replace(
'/\D/',
'', file_get_contents( $wgDebugLogFile ) ) );
300 unlink( $wgDebugLogFile );
302 $wgDebugLogFile = $old_log_file;
303 $wgDebugTimestamps = $old_wgDebugTimestamps;
315 'compress, gzip' =>
true,
316 'gzip;q=1.0' =>
true,
319 'gzip;q=abcde' =>
true,
320 'gzip;q=12345678.9' =>
true,
324 if ( isset( $_SERVER[
'HTTP_ACCEPT_ENCODING'] ) ) {
325 $old_server_setting = $_SERVER[
'HTTP_ACCEPT_ENCODING'];
328 foreach ( $settings
as $encoding => $expect ) {
329 $_SERVER[
'HTTP_ACCEPT_ENCODING'] = $encoding;
335 if ( isset( $old_server_setting ) ) {
336 $_SERVER[
'HTTP_ACCEPT_ENCODING'] = $old_server_setting;
347 $this->assertEquals( $var1, 1,
'var1 is set originally' );
348 $this->assertEquals( $var2, 2,
'var1 is set originally' );
350 swap( $var1, $var2 );
352 $this->assertEquals( $var1, 2,
'var1 is swapped' );
353 $this->assertEquals( $var2, 1,
'var2 is swapped' );
362 array( 6 / 7,
'0.86%', 2,
false ),
363 array( 3 / 3,
'1%' ),
364 array( 22 / 7,
'3.14286%', 5 ),
365 array( 3 / 6,
'0.5%' ),
366 array( 1 / 3,
'0%', 0 ),
367 array( 10 / 3,
'0%', -1 ),
368 array( 3 / 4 / 5,
'0.1%', 1 ),
369 array( 6 / 7 * 8,
'6.8571428571%', 10 ),
372 foreach ( $pcts
as $pct ) {
373 if ( !isset( $pct[2] ) ) {
376 if ( !isset( $pct[3] ) ) {
380 $this->assertEquals(
wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
390 $this->assertEquals( $expected,
403 # Failures returns 0 :(
404 array(
'ABCDEFG', 0 ),
411 array(
' 1023 ', 1023 ),
416 array(
'1m', 1024 * 1024 ),
417 array(
'1M', 1024 * 1024 ),
418 array(
'1g', 1024 * 1024 * 1024 ),
419 array(
'1G', 1024 * 1024 * 1024 ),
424 array(
'-500', -500 ),
425 array(
'-1k', -1024 ),
450 public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
454 $isMerged =
wfMerge( $old, $mine, $yours, $mergedText );
456 $msg =
'Merge should be a ';
457 $msg .= $expectedMergeResult ?
'success' :
'failure';
458 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
462 $this->assertEquals( $expectedText, $mergedText,
463 'is merged text as expected?' );
468 $EXPECT_MERGE_SUCCESS =
true;
469 $EXPECT_MERGE_FAILURE =
false;
480 "one one one ONE ONE\n" .
490 $EXPECT_MERGE_SUCCESS,
493 "one one one ONE ONE\n" .
504 "one one one ONE ONE\n" .
514 $EXPECT_MERGE_FAILURE,
528 $this->assertEquals( $expected, $index,
"wfMakeUrlIndexes(\"$url\")" );
535 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
536 array(
'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
541 'mailto:wiki@wikimedia.org',
542 array(
'mailto:org.wikimedia@wiki.' )
548 'file:///whatever/you/like.txt',
549 array(
'file://./whatever/you/like.txt' )
553 'file:///c:/whatever/you/like.txt',
554 array(
'file://./c:/whatever/you/like.txt' )
558 'file://intranet/whatever/you/like.txt',
559 array(
'file://intranet./whatever/you/like.txt' )
571 '//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
573 'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
574 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
586 $this->assertEquals( $expected, $actual, $description );
591 $protocols =
array(
'HTTP' =>
'http:',
'HTTPS' =>
'https:',
'protocol-relative' =>
'' );
592 foreach ( $protocols
as $pDesc => $p ) {
593 $a = array_merge( $a,
array(
594 array(
"$p//www.example.com",
array(),
false,
"No matches for empty domains array, $pDesc URL" ),
595 array(
"$p//www.example.com",
array(
'www.example.com' ),
true,
"Exact match in domains array, $pDesc URL" ),
596 array(
"$p//www.example.com",
array(
'example.com' ),
true,
"Match without subdomain in domains array, $pDesc URL" ),
597 array(
"$p//www.example2.com",
array(
'www.example.com',
'www.example2.com',
'www.example3.com' ),
true,
"Exact match with other domains in array, $pDesc URL" ),
598 array(
"$p//www.example2.com",
array(
'example.com',
'example2.com',
'example3,com' ),
true,
"Match without subdomain with other domains in array, $pDesc URL" ),
599 array(
"$p//www.example4.com",
array(
'example.com',
'example2.com',
'example3,com' ),
false,
"Domain not in array, $pDesc URL" ),
600 array(
"$p//nds-nl.wikipedia.org",
array(
'nl.wikipedia.org' ),
false,
"Non-matching substring of domain, $pDesc URL" ),
616 $this->assertFalse(
$ok );
626 $expected = str_replace(
"'",
'"', $expected );
629 $this->assertEquals( $expected, $actual, $description );
637 "'$wgPhpCli' 'eval.php' '--help' '--test'",
638 "Called eval.php --help --test" ),
639 array(
'eval.php',
array(
'--help',
'--test space' ),
array(
'php' =>
'php5' ),
640 "'php5' 'eval.php' '--help' '--test space'",
641 "Called eval.php --help --test with php option" ),
642 array(
'eval.php',
array(
'--help',
'--test',
'X' ),
array(
'wrapper' =>
'MWScript.php' ),
643 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
644 "Called eval.php --help --test with wrapper option" ),
645 array(
'eval.php',
array(
'--help',
'--test',
'y' ),
array(
'php' =>
'php5',
'wrapper' =>
'MWScript.php' ),
646 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
647 "Called eval.php --help --test with wrapper and php option" ),
it sets a lot of them automatically from query strings
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. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag '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 '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. '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 '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 '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 wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() '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 User::isValidEmailAddr(), 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 '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) '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. '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
wfPercent( $nr, $acc=2, $round=true)
testMimeTypeMatch()
@covers mimeTypeMatch
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
wfShellMaintenanceCmd( $script, array $parameters=array(), array $options=array())
Alias to wfShellWikiCmd()
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)
@dataProvider provideCgiRoundTrip @covers 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.
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
if(!defined( 'MEDIAWIKI')) wfArrayDiff2( $a, $b)
Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
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()
@covers wfExpandIRI
wfExpandIRI( $url)
Take a URL, make sure it's expanded to fully qualified, and replace any encoded non-ASCII Unicode cha...
you have access to all of the normal MediaWiki so you can get a DB use the cache
testClientAcceptsGzipTest()
@covers wfClientAcceptsGzip
testWfArrayDiff2( $a, $b, $expected)
@dataProvider provideForWfArrayDiff2 @covers wfArrayDiff2
wfBoolToStr( $value)
Convenience function converts boolean values into "true" or "false" (string) values.
testRandom()
@covers wfRandom
testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText)
testWfPercentTest()
@covers wfPercent
mimeTypeMatch( $type, $avail)
Checks if a given MIME type matches any of the keys in the given array.
static provideArrayToCGI()
wfRestoreWarnings()
Restore error level to previous value.
swap(&$x, &$y)
Swap two variables.
wfShorthandToInteger( $string='')
Converts shorthand byte notation to integer form.
wfCgiToArray( $query)
This is the logical opposite of wfArrayToCgi(): it accepts a query string as its argument and returns...
testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description)
@dataProvider provideWfShellMaintenanceCmdList @covers wfShellMaintenanceCmd
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
testCgiToArray( $cgi, $result)
@dataProvider provideCgiToArray @covers wfCgiToArray
testReadOnlySet()
@covers wfReadOnly
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
static provideMakeUrlIndexes()
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfClientAcceptsGzip( $force=false)
wfIsWindows()
Check if the operating system is Windows.
testDebugFunctionTest()
@covers wfDebug @covers wfDebugMem
testSwapVarsTest()
@covers swap
wfDebugMem( $exact=false)
Send a line giving PHP memory usage.
testWfMatchesDomainList( $url, $domains, $expected, $description)
@dataProvider provideWfMatchesDomainList @covers wfMatchesDomainList
static provideWfMatchesDomainList()
testWfShorthandToInteger( $shorthand, $expected)
test
static provideShorthand()
array( shorthand, expected integer )
wfRandom()
Get a random decimal value between 0 and 1, in a way not likely to give duplicate values for any real...
wfTempDir()
Tries to get the system directory for temporary files.
wfMatchesDomainList( $url, $domains)
Check whether a given URL has a domain that occurs in a given set of domains.
testUrlencode()
@covers wfUrlencode
testArrayToCGI2()
@covers wfArrayToCgi
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
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)
@dataProvider provideArrayToCGI @covers wfArrayToCgi
static provideWfShellMaintenanceCmdList()
testReadOnlyEmpty()
@covers wfReadOnly
static provideCgiToArray()
testMakeUrlIndexes( $url, $expected)
@dataProvider provideMakeUrlIndexes() @covers wfMakeUrlIndexes
static provideForWfArrayDiff2()
testNegotiateType()
@covers wfNegotiateType
static provideCgiRoundTrip()
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes two arrays as input, and returns a CGI-style string, e.g.
testWfMkdirParents()
@covers wfMkdirParents