59 $this->regex = $this->
getCliArg(
'regex' );
65 $this->keepUploads = $this->
getCliArg(
'keep-uploads' );
69 $tmpGlobals[
'wgLanguageCode'] =
'en';
71 $tmpGlobals[
'wgSitename'] =
'MediaWiki';
72 $tmpGlobals[
'wgServer'] =
'http://example.org';
73 $tmpGlobals[
'wgServerName'] =
'example.org';
74 $tmpGlobals[
'wgScriptPath'] =
'';
75 $tmpGlobals[
'wgScript'] =
'/index.php';
76 $tmpGlobals[
'wgResourceBasePath'] =
'';
77 $tmpGlobals[
'wgStylePath'] =
'/skins';
78 $tmpGlobals[
'wgExtensionAssetsPath'] =
'/extensions';
79 $tmpGlobals[
'wgArticlePath'] =
'/wiki/$1';
80 $tmpGlobals[
'wgActionPaths'] = [];
81 $tmpGlobals[
'wgVariantArticlePath'] =
false;
82 $tmpGlobals[
'wgEnableUploads'] =
true;
83 $tmpGlobals[
'wgUploadNavigationUrl'] =
false;
84 $tmpGlobals[
'wgThumbnailScriptPath'] =
false;
85 $tmpGlobals[
'wgLocalFileRepo'] = [
86 'class' =>
'LocalRepo',
88 'url' =>
'http://example.com/images',
90 'transformVia404' =>
false,
91 'backend' =>
'local-backend'
93 $tmpGlobals[
'wgForeignFileRepos'] = [];
94 $tmpGlobals[
'wgDefaultExternalStore'] = [];
96 $tmpGlobals[
'wgCapitalLinks'] =
true;
97 $tmpGlobals[
'wgNoFollowLinks'] =
true;
98 $tmpGlobals[
'wgNoFollowDomainExceptions'] = [];
99 $tmpGlobals[
'wgExternalLinkTarget'] =
false;
100 $tmpGlobals[
'wgThumbnailScriptPath'] =
false;
101 $tmpGlobals[
'wgUseImageResize'] =
true;
102 $tmpGlobals[
'wgAllowExternalImages'] =
true;
103 $tmpGlobals[
'wgRawHtml'] =
false;
104 $tmpGlobals[
'wgExperimentalHtmlIds'] =
false;
105 $tmpGlobals[
'wgAdaptiveMessageCache'] =
true;
106 $tmpGlobals[
'wgUseDatabaseMessages'] =
true;
107 $tmpGlobals[
'wgLocaltimezone'] =
'UTC';
108 $tmpGlobals[
'wgGroupPermissions'] = [
110 'createaccount' =>
true,
113 'createpage' =>
true,
114 'createtalk' =>
true,
116 $tmpGlobals[
'wgNamespaceProtection'] = [
NS_MEDIAWIKI =>
'editinterface' ];
119 'wgParser',
$GLOBALS[
'wgParserConf'][
'class'],
122 $tmpGlobals[
'wgFileExtensions'][] =
'svg';
123 $tmpGlobals[
'wgSVGConverter'] =
'rsvg';
124 $tmpGlobals[
'wgSVGConverters'][
'rsvg'] =
125 '$path/rsvg-convert -w $width -h $height -o $output $input';
127 if (
$GLOBALS[
'wgStyleDirectory'] ===
false ) {
128 $tmpGlobals[
'wgStyleDirectory'] =
"$IP/skins";
131 # Replace all media handlers with a mock. We do not need to generate
132 # actual thumbnails to do parser testing, we only care about receiving
133 # a ThumbnailImage properly initialized.
136 $tmpGlobals[
'wgMediaHandlers'][
$type] =
'MockBitmapHandler';
139 $tmpGlobals[
'wgMediaHandlers'][
'image/svg+xml'] =
'MockSvgHandler';
142 $tmpGlobals[
'wgMediaHandlers'][
'image/vnd.djvu'] =
'MockDjVuHandler';
145 $tmpGlobals[
'wgMediaHandlers'][
'application/ogg'] =
'MockOggHandler';
148 $tmpHooks[
'ParserTestParser'][] =
'ParserTestParserHook::setup';
149 $tmpHooks[
'ParserGetVariableValueTs'][] =
'ParserTest::getFakeTimestamp';
150 $tmpGlobals[
'wgHooks'] = $tmpHooks;
151 # add a namespace shadowing a interwiki link, to test
152 # proper precedence when resolving links. (bug 51680)
153 $tmpGlobals[
'wgExtraNamespaces'] = [ 100 =>
'MemoryAlpha' ];
155 $tmpGlobals[
'wgLocalInterwikis'] = [
'local',
'mi' ];
156 # "extra language links"
157 # see https://gerrit.wikimedia.org/r/111390
158 $tmpGlobals[
'wgExtraInterlanguageLinkPrefixes'] = [
'mul' ];
164 $tmpGlobals[
'wgTidyConfig'] = null;
165 $tmpGlobals[
'wgUseTidy'] =
false;
166 $tmpGlobals[
'wgDebugTidy'] =
false;
167 $tmpGlobals[
'wgTidyConf'] = $IP .
'/includes/tidy/tidy.conf';
168 $tmpGlobals[
'wgTidyOpts'] =
'';
169 $tmpGlobals[
'wgTidyInternal'] = $this->tidySupport->isInternal();
173 $this->savedWeirdGlobals[
'image_alias'] = $wgNamespaceAliases[
'Image'];
174 $this->savedWeirdGlobals[
'image_talk_alias'] = $wgNamespaceAliases[
'Image_talk'];
176 $wgNamespaceAliases[
'Image'] =
NS_FILE;
180 $wgContLang->resetNamespaces(); # reset
namespace cache
186 $wgNamespaceAliases[
'Image'] = $this->savedWeirdGlobals[
'image_alias'];
187 $wgNamespaceAliases[
'Image_talk'] = $this->savedWeirdGlobals[
'image_talk_alias'];
204 $wgContLang->resetNamespaces(); # reset
namespace cache
209 parent::tearDownAfterClass();
213 # disabled for performance
214 # $this->tablesUsed[] = 'image';
216 # Update certain things in site_stats
217 $this->db->insert(
'site_stats',
218 [
'ss_row_id' => 1,
'ss_images' => 2,
'ss_good_articles' => 1 ],
226 # Upload DB table entries for files.
227 # We will upload the actual files later. Note that if anything causes LocalFile::load()
228 # to be triggered before then, it will break via maybeUpgrade() setting the fileExists
229 # member to false and storing it in cache.
230 # note that the size/width/height/bits/etc of the file
231 # are actually set by inspecting the file itself; the arguments
232 # to recordUpload2 have no effect. That said, we try to make things
233 # match up so it is less confusing to readers of the code & tests.
235 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
236 $image->recordUpload2(
238 'Upload of some lame file',
246 'mime' =>
'image/jpeg',
248 'sha1' => Wikimedia\base_convert(
'1', 16, 36, 31 ),
249 'fileExists' =>
true ],
250 $this->db->timestamp(
'20010115123500' ),
$user
255 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
256 $image->recordUpload2(
258 'Upload of some lame thumbnail',
259 'Some lame thumbnail',
266 'mime' =>
'image/png',
268 'sha1' => Wikimedia\base_convert(
'2', 16, 36, 31 ),
269 'fileExists' =>
true ],
270 $this->db->timestamp(
'20130225203040' ),
$user
274 # This image will be blacklisted in [[MediaWiki:Bad image list]]
276 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
277 $image->recordUpload2(
287 'mime' =>
'image/jpeg',
289 'sha1' => Wikimedia\base_convert(
'3', 16, 36, 31 ),
290 'fileExists' =>
true ],
291 $this->db->timestamp(
'20010115123500' ),
$user
295 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
296 $image->recordUpload2(
'',
'Upload of some lame SVG',
'Some lame SVG', [
302 'mime' =>
'image/svg+xml',
304 'sha1' => Wikimedia\base_convert(
'', 16, 36, 31 ),
306 ], $this->db->timestamp(
'20010115123500' ),
$user );
310 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
311 $image->recordUpload2(
'',
'A pretty movie',
'Will it play', [
317 'mime' =>
'application/ogg',
319 'sha1' => Wikimedia\base_convert(
'', 16, 36, 32 ),
321 ], $this->db->timestamp(
'20010115123500' ),
$user );
327 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
328 $image->recordUpload2(
'',
'Upload a DjVu',
'A DjVu', [
334 'mime' =>
'image/vnd.djvu',
335 'metadata' =>
'<?xml version="1.0" ?>
336 <!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
339 <BODY><OBJECT height="3508" width="2480">
340 <PARAM name="DPI" value="300" />
341 <PARAM name="GAMMA" value="2.2" />
343 <OBJECT height="3508" width="2480">
344 <PARAM name="DPI" value="300" />
345 <PARAM name="GAMMA" value="2.2" />
347 <OBJECT height="3508" width="2480">
348 <PARAM name="DPI" value="300" />
349 <PARAM name="GAMMA" value="2.2" />
351 <OBJECT height="3508" width="2480">
352 <PARAM name="DPI" value="300" />
353 <PARAM name="GAMMA" value="2.2" />
355 <OBJECT height="3508" width="2480">
356 <PARAM name="DPI" value="300" />
357 <PARAM name="GAMMA" value="2.2" />
361 'sha1' => Wikimedia\base_convert(
'', 16, 36, 31 ),
363 ], $this->db->timestamp(
'20140115123600' ),
$user );
378 # Find out values for some special options.
380 self::getOptionValue(
'language', $opts,
'en' );
382 self::getOptionValue(
'variant', $opts,
false );
384 self::getOptionValue(
'wgMaxTocLevel', $opts, 999 );
385 $linkHolderBatchSize =
386 self::getOptionValue(
'wgLinkHolderBatchSize', $opts, 1000 );
389 if ( $this->
getCliArg(
'use-filebackend' ) ) {
390 if ( self::$backendToUse ) {
391 $backend = self::$backendToUse;
395 foreach ( $wgFileBackends
as $conf ) {
396 if ( $conf[
'name'] ==
$name ) {
400 $useConfig[
'name'] =
'local-backend';
401 unset( $useConfig[
'lockManager'] );
402 unset( $useConfig[
'fileJournal'] );
403 $class = $useConfig[
'class'];
404 self::$backendToUse =
new $class( $useConfig );
405 $backend = self::$backendToUse;
408 # Replace with a mock. We do not care about generating real
409 # files on the filesystem, just need to expose the file
412 'name' =>
'local-backend',
418 'wgLocalFileRepo' => [
419 'class' =>
'LocalRepo',
421 'url' =>
'http://example.com/images',
423 'transformVia404' =>
false,
424 'backend' => $backend
426 'wgEnableUploads' => self::getOptionValue(
'wgEnableUploads', $opts,
true ),
427 'wgLanguageCode' =>
$lang,
428 'wgDBprefix' => $this->db->getType() !=
'oracle' ?
'unittest_' :
'ut_',
429 'wgRawHtml' => self::getOptionValue(
'wgRawHtml', $opts,
false ),
430 'wgNamespacesWithSubpages' => [
NS_MAIN => isset( $opts[
'subpage'] ) ],
431 'wgAllowExternalImages' => self::getOptionValue(
'wgAllowExternalImages', $opts,
true ),
432 'wgThumbLimits' => [ self::getOptionValue(
'thumbsize', $opts, 180 ) ],
433 'wgMaxTocLevel' => $maxtoclevel,
434 'wgUseTeX' => isset( $opts[
'math'] ) || isset( $opts[
'texvc'] ),
435 'wgMathDirectory' => $uploadDir .
'/math',
436 'wgDefaultLanguageVariant' => $variant,
437 'wgLinkHolderBatchSize' => $linkHolderBatchSize,
438 'wgUseTidy' => isset( $opts[
'tidy'] ),
442 $configLines = explode(
"\n", $config );
444 foreach ( $configLines
as $line ) {
445 list( $var,
$value ) = explode(
'=', $line, 2 );
447 $settings[$var] = eval(
"return $value;" );
451 $this->savedGlobals = [];
454 Hooks::run(
'ParserTestGlobals', [ &$settings ] );
457 $settings[
'wgContLang'] = $langObj;
458 $settings[
'wgLang'] = $langObj;
461 $settings[
'wgOut'] =
$context->getOutput();
462 $settings[
'wgUser'] =
$context->getUser();
463 $settings[
'wgRequest'] =
$context->getRequest();
466 $context->getUser()->setOption(
'thumbsize', 0 );
468 foreach ( $settings
as $var => $val ) {
469 if ( array_key_exists( $var,
$GLOBALS ) ) {
470 $this->savedGlobals[$var] =
$GLOBALS[$var];
479 # The entries saved into RepoGroup cache with previous globals will be wrong.
483 # Create dummy files in storage
486 # Publish the articles after we have the final language set
500 if ( $this->keepUploads ) {
504 if ( is_dir(
$dir ) ) {
511 if ( file_exists(
$dir ) ) {
512 wfDebug(
"Already exists!\n" );
531 $backend->prepare( [
'dir' =>
"$base/local-public/3/3a" ] );
533 'src' =>
"$IP/tests/phpunit/data/parser/headbg.jpg",
534 'dst' =>
"$base/local-public/3/3a/Foobar.jpg"
536 $backend->prepare( [
'dir' =>
"$base/local-public/e/ea" ] );
538 'src' =>
"$IP/tests/phpunit/data/parser/wiki.png",
539 'dst' =>
"$base/local-public/e/ea/Thumb.png"
541 $backend->prepare( [
'dir' =>
"$base/local-public/0/09" ] );
543 'src' =>
"$IP/tests/phpunit/data/parser/headbg.jpg",
544 'dst' =>
"$base/local-public/0/09/Bad.jpg"
546 $backend->prepare( [
'dir' =>
"$base/local-public/5/5f" ] );
548 'src' =>
"$IP/tests/phpunit/data/parser/LoremIpsum.djvu",
549 'dst' =>
"$base/local-public/5/5f/LoremIpsum.djvu"
553 $data =
'<?xml version="1.0" encoding="utf-8"?>' .
554 '<svg xmlns="http://www.w3.org/2000/svg"' .
555 ' version="1.1" width="240" height="180"/>';
557 $backend->prepare( [
'dir' =>
"$base/local-public/f/ff" ] );
558 $backend->quickCreate( [
559 'content' => $data,
'dst' =>
"$base/local-public/f/ff/Foobar.svg"
570 foreach ( $this->savedGlobals
as $var => $val ) {
579 if ( $this->keepUploads ) {
585 # In memory backend, so dont bother cleaning them up.
593 "$base/local-public/3/3a/Foobar.jpg",
594 "$base/local-thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg",
595 "$base/local-thumb/3/3a/Foobar.jpg/100px-Foobar.jpg",
596 "$base/local-thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
597 "$base/local-thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg",
598 "$base/local-thumb/3/3a/Foobar.jpg/137px-Foobar.jpg",
599 "$base/local-thumb/3/3a/Foobar.jpg/1500px-Foobar.jpg",
600 "$base/local-thumb/3/3a/Foobar.jpg/177px-Foobar.jpg",
601 "$base/local-thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
602 "$base/local-thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
603 "$base/local-thumb/3/3a/Foobar.jpg/206px-Foobar.jpg",
604 "$base/local-thumb/3/3a/Foobar.jpg/20px-Foobar.jpg",
605 "$base/local-thumb/3/3a/Foobar.jpg/220px-Foobar.jpg",
606 "$base/local-thumb/3/3a/Foobar.jpg/265px-Foobar.jpg",
607 "$base/local-thumb/3/3a/Foobar.jpg/270px-Foobar.jpg",
608 "$base/local-thumb/3/3a/Foobar.jpg/274px-Foobar.jpg",
609 "$base/local-thumb/3/3a/Foobar.jpg/300px-Foobar.jpg",
610 "$base/local-thumb/3/3a/Foobar.jpg/30px-Foobar.jpg",
611 "$base/local-thumb/3/3a/Foobar.jpg/330px-Foobar.jpg",
612 "$base/local-thumb/3/3a/Foobar.jpg/353px-Foobar.jpg",
613 "$base/local-thumb/3/3a/Foobar.jpg/360px-Foobar.jpg",
614 "$base/local-thumb/3/3a/Foobar.jpg/400px-Foobar.jpg",
615 "$base/local-thumb/3/3a/Foobar.jpg/40px-Foobar.jpg",
616 "$base/local-thumb/3/3a/Foobar.jpg/440px-Foobar.jpg",
617 "$base/local-thumb/3/3a/Foobar.jpg/442px-Foobar.jpg",
618 "$base/local-thumb/3/3a/Foobar.jpg/450px-Foobar.jpg",
619 "$base/local-thumb/3/3a/Foobar.jpg/50px-Foobar.jpg",
620 "$base/local-thumb/3/3a/Foobar.jpg/600px-Foobar.jpg",
621 "$base/local-thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
622 "$base/local-thumb/3/3a/Foobar.jpg/70px-Foobar.jpg",
623 "$base/local-thumb/3/3a/Foobar.jpg/75px-Foobar.jpg",
624 "$base/local-thumb/3/3a/Foobar.jpg/960px-Foobar.jpg",
626 "$base/local-public/e/ea/Thumb.png",
628 "$base/local-public/0/09/Bad.jpg",
630 "$base/local-public/5/5f/LoremIpsum.djvu",
631 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
632 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
633 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
635 "$base/local-public/f/ff/Foobar.svg",
636 "$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
637 "$base/local-thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
638 "$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.png",
639 "$base/local-thumb/f/ff/Foobar.svg/3000px-Foobar.svg.png",
640 "$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.png",
641 "$base/local-thumb/f/ff/Foobar.svg/4000px-Foobar.svg.png",
642 "$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.png",
643 "$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.png",
644 "$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.png",
646 "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
658 $backend->delete( [
'src' => $file ], [
'force' => 1 ] );
663 if ( !$backend->clean( [
'dir' => $tmp ] )->isOK() ) {
672 return 'mwstore://local-backend';
676 if ( $this->
file ===
false ) {
677 global $wgParserTestFiles;
678 $this->
file = $wgParserTestFiles[0];
689 $this->
file = $filename;
703 if ( $this->regex !=
'' && !preg_match(
'/' . $this->regex .
'/', $desc ) ) {
704 $this->assertTrue(
true );
713 $this->markTestSkipped(
"Main namespace does not support wikitext,"
714 .
"skipping parser test: $desc" );
717 wfDebug(
"Running parser test: $desc\n" );
725 if ( isset( $opts[
'title'] ) ) {
726 $titleText = $opts[
'title'];
728 $titleText =
'Parser test';
731 $local = isset( $opts[
'local'] );
732 $preprocessor = isset( $opts[
'preprocessor'] ) ? $opts[
'preprocessor'] : null;
737 # Parser test requiring math. Make sure texvc is executable
738 # or just skip such tests.
739 if ( isset( $opts[
'math'] ) || isset( $opts[
'texvc'] ) ) {
742 if ( !isset( $wgTexvc ) ) {
743 $this->markTestSkipped(
"SKIPPED: \$wgTexvc is not set" );
744 } elseif ( !is_executable( $wgTexvc ) ) {
745 $this->markTestSkipped(
"SKIPPED: texvc binary does not exist"
746 .
" or is not executable.\n"
747 .
"Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
751 if ( isset( $opts[
'djvu'] ) ) {
752 if ( !$this->djVuSupport->isEnabled() ) {
753 $this->markTestSkipped(
"SKIPPED: djvu binaries do not exist or are not executable.\n" );
757 if ( isset( $opts[
'tidy'] ) ) {
758 if ( !$this->tidySupport->isEnabled() ) {
759 $this->markTestSkipped(
"SKIPPED: tidy extension is not installed.\n" );
765 if ( isset( $opts[
'pst'] ) ) {
767 } elseif ( isset( $opts[
'msg'] ) ) {
769 } elseif ( isset( $opts[
'section'] ) ) {
772 } elseif ( isset( $opts[
'replace'] ) ) {
774 $replace = $opts[
'replace'][1];
776 } elseif ( isset( $opts[
'comment'] ) ) {
778 } elseif ( isset( $opts[
'preload'] ) ) {
784 if ( isset( $opts[
'tidy'] ) ) {
785 $out = preg_replace(
'/\s+$/',
'',
$out );
788 if ( isset( $opts[
'showtitle'] ) ) {
793 $out =
"$title\n$out";
796 if ( isset( $opts[
'showindicators'] ) ) {
799 $indicators .=
"$id=$content\n";
804 if ( isset( $opts[
'ill'] ) ) {
806 } elseif ( isset( $opts[
'cat'] ) ) {
807 $outputPage =
$context->getOutput();
809 $cats = $outputPage->getCategoryLinks();
811 if ( isset( $cats[
'normal'] ) ) {
812 $out = implode(
' ', $cats[
'normal'] );
834 global $wgParserTestFiles;
836 $files = $wgParserTestFiles;
843 $dictSize = strlen( $dict );
844 $logMaxLength = log( $this->maxFuzzTestLength );
846 ini_set(
'memory_limit', $this->memoryLimit * 1048576 );
857 mt_srand( ++$this->fuzzSeed );
858 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
861 while ( strlen( $input ) < $totalLength ) {
862 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
863 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
864 $offset = mt_rand( 0, $dictSize - $hairLength );
865 $input .= substr( $dict, $offset, $hairLength );
874 $this->assertTrue(
true,
"Test $id, fuzz seed {$this->fuzzSeed}" );
876 $input_dump = sprintf(
"string(%d) \"%s\"\n", strlen( $input ), $input );
878 $this->assertTrue(
false,
"Test $id, fuzz seed {$this->fuzzSeed}. \n\n" .
879 "Input: $input_dump\n\nError: {$exception->getMessage()}\n\n" .
880 "Backtrace: {$exception->getTraceAsString()}" );
886 if ( $id % 100 == 0 ) {
887 $usage = intval( memory_get_usage(
true ) / $this->memoryLimit / 1048576 * 100 );
890 $ret =
"Out of memory:\n";
893 foreach ( $memStats
as $name => $usage ) {
894 $ret .=
"$name: $usage\n";
915 foreach ( $filenames
as $filename ) {
916 $contents = file_get_contents( $filename );
917 preg_match_all(
'/!!\s*input\n(.*?)\n!!\s*result/s', $contents,
$matches );
920 $dict .= $match .
"\n";
938 $classes = get_declared_classes();
940 foreach ( $classes
as $class ) {
941 $rc =
new ReflectionClass( $class );
942 $props = $rc->getStaticProperties();
943 $memStats[$class] = strlen(
serialize( $props ) );
944 $methods = $rc->getMethods();
946 foreach ( $methods
as $method ) {
947 $memStats[$class] += strlen(
serialize( $method->getStaticVariables() ) );
951 $functions = get_defined_functions();
953 foreach ( $functions[
'user']
as $function ) {
954 $rf =
new ReflectionFunction( $function );
955 $memStats[
"$function()"] = strlen(
serialize( $rf->getStaticVariables() ) );
971 $class = $wgParserConf[
'class'];
972 $parser =
new $class( [
'preprocessorClass' => $preprocessor ] + $wgParserConf );
986 if ( empty( self::$articles ) ) {
990 foreach ( self::$articles
as $name => $info ) {
1006 $wgParser->firstCallInit();
1007 return isset( $wgParser->mTagHooks[
$name] );
1012 $wgParser->firstCallInit();
1013 return isset( $wgParser->mFunctionHooks[
$name] );
1018 $wgParser->firstCallInit();
1019 return isset( $wgParser->mTransparentTagHooks[
$name] );
1030 if ( substr(
$s, -1 ) ===
"\n" ) {
1031 return substr(
$s, 0, -1 );
1067 "[^"]*" # Quoted val
1069 \[\[[^]]*\]\] # Link target
1077 if ( preg_match_all(
$regex, $instring,
$matches, PREG_SET_ORDER ) ) {
1079 array_shift( $bits );
1080 $key = strtolower( array_shift( $bits ) );
1081 if ( count( $bits ) == 0 ) {
1083 } elseif ( count( $bits ) == 1 ) {
1087 $opts[
$key] = array_map( [ $this,
'cleanupOption' ], $bits );
1096 if ( substr( $opt, 0, 1 ) ==
'"' ) {
1097 return substr( $opt, 1, -1 );
1100 if ( substr( $opt, 0, 2 ) ==
'[[' ) {
1101 return substr( $opt, 2, -2 );
1117 if ( isset( $opts[
$key] ) ) {
#define the
table suitable for use with IDatabase::select()
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Group all the pieces relevant to the context of a request into one instance.
teardownUploads()
Remove the dummy uploads directory.
Class simulating a backend store.
static addArticle($name, $text, $line= 'unknown', $ignoreDuplicate= '')
Insert a temporary test article.
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 & $ret
setupUploads()
Create a dummy uploads directory which will contain a couple of files in order to pass existence test...
getFuzzInput($filenames)
Get an input dictionary from a set of parser test files.
if(!isset($args[0])) $lang
static destroyInstance()
Destroy the singleton instance.
$wgFileBackends
File backend structure configuration.
static destroySingleton()
Destroy the singleton instance, so that a new one will be created next time singleton() is called...
getUploadDir()
Get an FS upload directory (only applies to FSFileBackend)
static newFromId($id)
Static factory method for creation from a given user ID.
$wgNamespaceAliases
Namespace aliases.
$wgHooks['ArticleShow'][]
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
$wgMediaHandlers
Plugins for media file type handling.
when a variable name is used in a it is silently declared as a new local masking the global
static destroySingleton()
Destroy the singleton instance.
static newFromUser($user)
Get a ParserOptions object from a given user.
wfLocalFile($title)
Get an object referring to a locally registered file.
static tearDownAfterClass()
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
you have access to all of the normal MediaWiki so you can get a DB use the cache
static getOptionValue($key, $opts, $default)
Use a regex to find out the value of an option.
static destroySingleton()
Destroy the current singleton instance.
static tearDownInterwikis()
Remove the hardcoded interwiki lookup table.
when a variable name is used in a function
static deleteFiles($files)
Delete the specified files, if they exist.
requireTransparentHook($name)
wfTempDir()
Tries to get the system directory for temporary files.
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 and make changes or fix bugs In we can take all the code that deals with the little used title reversing we can concentrate it all in an extension file
static singleton()
Get an instance of this class.
getMemoryBreakdown()
Get a memory usage breakdown.
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
getParser($preprocessor=null)
Get a Parser object.
static singleton()
Get a RepoGroup instance.
Although marked as a stub, can work independently.
testFuzzTests()
Run a fuzz test series Draw input from a set of test files.
static clearCache()
Clear the self::$mObjects variable For use in parser tests.
Class to implement stub globals, which are globals that delay loading the their associated module cod...
static setupInterwikis()
Insert hardcoded interwiki in the lookup table.
namespace and then decline to actually register it file or subcat img or subcat $title
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Initialize and detect the DjVu files support.
addArticle($name, $text, $line)
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
An iterator for use as a phpunit data provider.
static formatComment($comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
testParserTest($desc, $input, $result, $opts, $config)
medium ParserTests parserTestProvider
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 the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Initialize and detect the tidy support.
setupGlobals($opts=[], $config= '')
Set up the global variables for a consistent environment for each test.
static setUpBeforeClass()
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
setParserTestFile($filename)
Set the file from whose tests will be run by this instance.
teardownGlobals()
Restore default values and perform any necessary clean-up after each test runs.
removeEndingNewline($s)
Remove last character if it is a newline.
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 $content
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
requireHook($name)
Steal a callback function from the primary parser, save it for application to our scary parser...
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
static factory($code)
Get a cached or new language object for a given language code.
requireFunctionHook($name)
static getCanonicalNamespaces($rebuild=false)
Returns array of all defined namespaces with their canonical (English) names.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
static parentStoragePath($storagePath)
Get the parent storage directory of a storage path.
Allows to change the fields on the form that will be generated $name