58 $this->regex = $this->
getCliArg(
'regex' );
64 $this->keepUploads = $this->
getCliArg(
'keep-uploads' );
68 $tmpGlobals[
'wgLanguageCode'] =
'en';
70 $tmpGlobals[
'wgSitename'] =
'MediaWiki';
71 $tmpGlobals[
'wgServer'] =
'http://example.org';
72 $tmpGlobals[
'wgServerName'] =
'example.org';
73 $tmpGlobals[
'wgScriptPath'] =
'';
74 $tmpGlobals[
'wgScript'] =
'/index.php';
75 $tmpGlobals[
'wgResourceBasePath'] =
'';
76 $tmpGlobals[
'wgStylePath'] =
'/skins';
77 $tmpGlobals[
'wgExtensionAssetsPath'] =
'/extensions';
78 $tmpGlobals[
'wgArticlePath'] =
'/wiki/$1';
79 $tmpGlobals[
'wgActionPaths'] = [];
80 $tmpGlobals[
'wgVariantArticlePath'] =
false;
81 $tmpGlobals[
'wgEnableUploads'] =
true;
82 $tmpGlobals[
'wgUploadNavigationUrl'] =
false;
83 $tmpGlobals[
'wgThumbnailScriptPath'] =
false;
84 $tmpGlobals[
'wgLocalFileRepo'] = [
85 'class' =>
'LocalRepo',
87 'url' =>
'http://example.com/images',
89 'transformVia404' =>
false,
90 'backend' =>
'local-backend'
92 $tmpGlobals[
'wgForeignFileRepos'] = [];
93 $tmpGlobals[
'wgDefaultExternalStore'] = [];
95 $tmpGlobals[
'wgCapitalLinks'] =
true;
96 $tmpGlobals[
'wgNoFollowLinks'] =
true;
97 $tmpGlobals[
'wgNoFollowDomainExceptions'] = [
'no-nofollow.org' ];
98 $tmpGlobals[
'wgExternalLinkTarget'] =
false;
99 $tmpGlobals[
'wgThumbnailScriptPath'] =
false;
100 $tmpGlobals[
'wgUseImageResize'] =
true;
101 $tmpGlobals[
'wgAllowExternalImages'] =
true;
102 $tmpGlobals[
'wgRawHtml'] =
false;
103 $tmpGlobals[
'wgExperimentalHtmlIds'] =
false;
104 $tmpGlobals[
'wgAdaptiveMessageCache'] =
true;
105 $tmpGlobals[
'wgUseDatabaseMessages'] =
true;
106 $tmpGlobals[
'wgLocaltimezone'] =
'UTC';
107 $tmpGlobals[
'wgGroupPermissions'] = [
109 'createaccount' =>
true,
112 'createpage' =>
true,
113 'createtalk' =>
true,
115 $tmpGlobals[
'wgNamespaceProtection'] = [
NS_MEDIAWIKI =>
'editinterface' ];
118 'wgParser',
$GLOBALS[
'wgParserConf'][
'class'],
121 $tmpGlobals[
'wgFileExtensions'][] =
'svg';
122 $tmpGlobals[
'wgSVGConverter'] =
'rsvg';
123 $tmpGlobals[
'wgSVGConverters'][
'rsvg'] =
124 '$path/rsvg-convert -w $width -h $height -o $output $input';
126 if (
$GLOBALS[
'wgStyleDirectory'] ===
false ) {
127 $tmpGlobals[
'wgStyleDirectory'] =
"$IP/skins";
130 # Replace all media handlers with a mock. We do not need to generate
131 # actual thumbnails to do parser testing, we only care about receiving
132 # a ThumbnailImage properly initialized.
135 $tmpGlobals[
'wgMediaHandlers'][
$type] =
'MockBitmapHandler';
138 $tmpGlobals[
'wgMediaHandlers'][
'image/svg+xml'] =
'MockSvgHandler';
141 $tmpGlobals[
'wgMediaHandlers'][
'image/vnd.djvu'] =
'MockDjVuHandler';
144 $tmpGlobals[
'wgMediaHandlers'][
'application/ogg'] =
'MockOggHandler';
147 $tmpHooks[
'ParserTestParser'][] =
'ParserTestParserHook::setup';
148 $tmpHooks[
'ParserGetVariableValueTs'][] =
'ParserTest::getFakeTimestamp';
149 $tmpGlobals[
'wgHooks'] = $tmpHooks;
150 # add a namespace shadowing a interwiki link, to test
151 # proper precedence when resolving links. (bug 51680)
152 $tmpGlobals[
'wgExtraNamespaces'] = [
153 100 =>
'MemoryAlpha',
154 101 =>
'MemoryAlpha_talk'
157 $tmpGlobals[
'wgLocalInterwikis'] = [
'local',
'mi' ];
158 # "extra language links"
159 # see https://gerrit.wikimedia.org/r/111390
160 $tmpGlobals[
'wgExtraInterlanguageLinkPrefixes'] = [
'mul' ];
166 $tmpGlobals[
'wgTidyConfig'] = $this->tidySupport->getConfig();
167 $tmpGlobals[
'wgUseTidy'] =
false;
171 $this->savedWeirdGlobals[
'image_alias'] = $wgNamespaceAliases[
'Image'];
172 $this->savedWeirdGlobals[
'image_talk_alias'] = $wgNamespaceAliases[
'Image_talk'];
174 $wgNamespaceAliases[
'Image'] =
NS_FILE;
178 $wgContLang->resetNamespaces(); # reset
namespace cache
179 ParserTest::resetTitleServices();
185 $wgNamespaceAliases[
'Image'] = $this->savedWeirdGlobals[
'image_alias'];
186 $wgNamespaceAliases[
'Image_talk'] = $this->savedWeirdGlobals[
'image_talk_alias'];
203 $wgContLang->resetNamespaces(); # reset
namespace cache
208 parent::tearDownAfterClass();
212 # disabled for performance
213 # $this->tablesUsed[] = 'image';
215 # Update certain things in site_stats
216 $this->db->insert(
'site_stats',
217 [
'ss_row_id' => 1,
'ss_images' => 2,
'ss_good_articles' => 1 ],
225 # Upload DB table entries for files.
226 # We will upload the actual files later. Note that if anything causes LocalFile::load()
227 # to be triggered before then, it will break via maybeUpgrade() setting the fileExists
228 # member to false and storing it in cache.
229 # note that the size/width/height/bits/etc of the file
230 # are actually set by inspecting the file itself; the arguments
231 # to recordUpload2 have no effect. That said, we try to make things
232 # match up so it is less confusing to readers of the code & tests.
234 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
235 $image->recordUpload2(
237 'Upload of some lame file',
245 'mime' =>
'image/jpeg',
247 'sha1' => Wikimedia\base_convert(
'1', 16, 36, 31 ),
248 'fileExists' =>
true ],
249 $this->db->timestamp(
'20010115123500' ),
$user
254 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
255 $image->recordUpload2(
257 'Upload of some lame thumbnail',
258 'Some lame thumbnail',
265 'mime' =>
'image/png',
267 'sha1' => Wikimedia\base_convert(
'2', 16, 36, 31 ),
268 'fileExists' =>
true ],
269 $this->db->timestamp(
'20130225203040' ),
$user
273 # This image will be blacklisted in [[MediaWiki:Bad image list]]
275 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
276 $image->recordUpload2(
286 'mime' =>
'image/jpeg',
288 'sha1' => Wikimedia\base_convert(
'3', 16, 36, 31 ),
289 'fileExists' =>
true ],
290 $this->db->timestamp(
'20010115123500' ),
$user
294 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
295 $image->recordUpload2(
'',
'Upload of some lame SVG',
'Some lame SVG', [
301 'mime' =>
'image/svg+xml',
303 'sha1' => Wikimedia\base_convert(
'', 16, 36, 31 ),
305 ], $this->db->timestamp(
'20010115123500' ),
$user );
309 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
310 $image->recordUpload2(
'',
'A pretty movie',
'Will it play', [
316 'mime' =>
'application/ogg',
318 'sha1' => Wikimedia\base_convert(
'', 16, 36, 32 ),
320 ], $this->db->timestamp(
'20010115123500' ),
$user );
324 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
325 $image->recordUpload2(
'',
'An awesome hitsong ',
'Will it play', [
331 'mime' =>
'application/ogg',
333 'sha1' => Wikimedia\base_convert(
'', 16, 36, 32 ),
335 ], $this->db->timestamp(
'20010115123500' ),
$user );
340 if ( !$this->db->selectField(
'image',
'1', [
'img_name' => $image->getName() ] ) ) {
341 $image->recordUpload2(
'',
'Upload a DjVu',
'A DjVu', [
347 'mime' =>
'image/vnd.djvu',
348 'metadata' =>
'<?xml version="1.0" ?>
349 <!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
352 <BODY><OBJECT height="3508" width="2480">
353 <PARAM name="DPI" value="300" />
354 <PARAM name="GAMMA" value="2.2" />
356 <OBJECT height="3508" width="2480">
357 <PARAM name="DPI" value="300" />
358 <PARAM name="GAMMA" value="2.2" />
360 <OBJECT height="3508" width="2480">
361 <PARAM name="DPI" value="300" />
362 <PARAM name="GAMMA" value="2.2" />
364 <OBJECT height="3508" width="2480">
365 <PARAM name="DPI" value="300" />
366 <PARAM name="GAMMA" value="2.2" />
368 <OBJECT height="3508" width="2480">
369 <PARAM name="DPI" value="300" />
370 <PARAM name="GAMMA" value="2.2" />
374 'sha1' => Wikimedia\base_convert(
'', 16, 36, 31 ),
376 ], $this->db->timestamp(
'20140115123600' ),
$user );
391 # Find out values for some special options.
393 self::getOptionValue(
'language', $opts,
'en' );
395 self::getOptionValue(
'variant', $opts,
false );
397 self::getOptionValue(
'wgMaxTocLevel', $opts, 999 );
398 $linkHolderBatchSize =
399 self::getOptionValue(
'wgLinkHolderBatchSize', $opts, 1000 );
402 if ( $this->
getCliArg(
'use-filebackend' ) ) {
403 if ( self::$backendToUse ) {
404 $backend = self::$backendToUse;
408 foreach ( $wgFileBackends
as $conf ) {
409 if ( $conf[
'name'] ==
$name ) {
413 $useConfig[
'name'] =
'local-backend';
414 unset( $useConfig[
'lockManager'] );
415 unset( $useConfig[
'fileJournal'] );
416 $class = $useConfig[
'class'];
417 self::$backendToUse =
new $class( $useConfig );
418 $backend = self::$backendToUse;
421 # Replace with a mock. We do not care about generating real
422 # files on the filesystem, just need to expose the file
425 'name' =>
'local-backend',
431 'wgLocalFileRepo' => [
432 'class' =>
'LocalRepo',
434 'url' =>
'http://example.com/images',
436 'transformVia404' =>
false,
437 'backend' => $backend
439 'wgEnableUploads' => self::getOptionValue(
'wgEnableUploads', $opts,
true ),
440 'wgLanguageCode' =>
$lang,
441 'wgDBprefix' => $this->db->getType() !=
'oracle' ?
'unittest_' :
'ut_',
442 'wgRawHtml' => self::getOptionValue(
'wgRawHtml', $opts,
false ),
443 'wgNamespacesWithSubpages' => [
NS_MAIN => isset( $opts[
'subpage'] ) ],
444 'wgAllowExternalImages' => self::getOptionValue(
'wgAllowExternalImages', $opts,
true ),
445 'wgThumbLimits' => [ self::getOptionValue(
'thumbsize', $opts, 180 ) ],
446 'wgMaxTocLevel' => $maxtoclevel,
447 'wgUseTeX' => isset( $opts[
'math'] ) || isset( $opts[
'texvc'] ),
448 'wgMathDirectory' => $uploadDir .
'/math',
449 'wgDefaultLanguageVariant' => $variant,
450 'wgLinkHolderBatchSize' => $linkHolderBatchSize,
451 'wgUseTidy' =>
false,
452 'wgTidyConfig' => isset( $opts[
'tidy'] ) ? $this->tidySupport->getConfig() : null
456 $configLines = explode(
"\n", $config );
458 foreach ( $configLines
as $line ) {
459 list( $var,
$value ) = explode(
'=', $line, 2 );
461 $settings[$var] = eval(
"return $value;" );
465 $this->savedGlobals = [];
468 Hooks::run(
'ParserTestGlobals', [ &$settings ] );
471 $settings[
'wgContLang'] = $langObj;
472 $settings[
'wgLang'] = $langObj;
475 $settings[
'wgOut'] =
$context->getOutput();
476 $settings[
'wgUser'] =
$context->getUser();
477 $settings[
'wgRequest'] =
$context->getRequest();
480 $context->getUser()->setOption(
'thumbsize', 0 );
482 foreach ( $settings
as $var => $val ) {
483 if ( array_key_exists( $var,
$GLOBALS ) ) {
484 $this->savedGlobals[$var] =
$GLOBALS[$var];
493 # The entries saved into RepoGroup cache with previous globals will be wrong.
497 # Create dummy files in storage
500 # Publish the articles after we have the final language set
514 if ( $this->keepUploads ) {
518 if ( is_dir(
$dir ) ) {
525 if ( file_exists(
$dir ) ) {
526 wfDebug(
"Already exists!\n" );
545 $backend->prepare( [
'dir' =>
"$base/local-public/3/3a" ] );
547 'src' =>
"$IP/tests/phpunit/data/parser/headbg.jpg",
548 'dst' =>
"$base/local-public/3/3a/Foobar.jpg"
550 $backend->prepare( [
'dir' =>
"$base/local-public/e/ea" ] );
552 'src' =>
"$IP/tests/phpunit/data/parser/wiki.png",
553 'dst' =>
"$base/local-public/e/ea/Thumb.png"
555 $backend->prepare( [
'dir' =>
"$base/local-public/0/09" ] );
557 'src' =>
"$IP/tests/phpunit/data/parser/headbg.jpg",
558 'dst' =>
"$base/local-public/0/09/Bad.jpg"
560 $backend->prepare( [
'dir' =>
"$base/local-public/5/5f" ] );
562 'src' =>
"$IP/tests/phpunit/data/parser/LoremIpsum.djvu",
563 'dst' =>
"$base/local-public/5/5f/LoremIpsum.djvu"
567 $data =
'<?xml version="1.0" encoding="utf-8"?>' .
568 '<svg xmlns="http://www.w3.org/2000/svg"' .
569 ' version="1.1" width="240" height="180"/>';
571 $backend->prepare( [
'dir' =>
"$base/local-public/f/ff" ] );
572 $backend->quickCreate( [
573 'content' => $data,
'dst' =>
"$base/local-public/f/ff/Foobar.svg"
584 foreach ( $this->savedGlobals
as $var => $val ) {
593 if ( $this->keepUploads ) {
599 # In memory backend, so dont bother cleaning them up.
607 "$base/local-public/3/3a/Foobar.jpg",
608 "$base/local-thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg",
609 "$base/local-thumb/3/3a/Foobar.jpg/100px-Foobar.jpg",
610 "$base/local-thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
611 "$base/local-thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg",
612 "$base/local-thumb/3/3a/Foobar.jpg/137px-Foobar.jpg",
613 "$base/local-thumb/3/3a/Foobar.jpg/1500px-Foobar.jpg",
614 "$base/local-thumb/3/3a/Foobar.jpg/177px-Foobar.jpg",
615 "$base/local-thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
616 "$base/local-thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
617 "$base/local-thumb/3/3a/Foobar.jpg/206px-Foobar.jpg",
618 "$base/local-thumb/3/3a/Foobar.jpg/20px-Foobar.jpg",
619 "$base/local-thumb/3/3a/Foobar.jpg/220px-Foobar.jpg",
620 "$base/local-thumb/3/3a/Foobar.jpg/265px-Foobar.jpg",
621 "$base/local-thumb/3/3a/Foobar.jpg/270px-Foobar.jpg",
622 "$base/local-thumb/3/3a/Foobar.jpg/274px-Foobar.jpg",
623 "$base/local-thumb/3/3a/Foobar.jpg/300px-Foobar.jpg",
624 "$base/local-thumb/3/3a/Foobar.jpg/30px-Foobar.jpg",
625 "$base/local-thumb/3/3a/Foobar.jpg/330px-Foobar.jpg",
626 "$base/local-thumb/3/3a/Foobar.jpg/353px-Foobar.jpg",
627 "$base/local-thumb/3/3a/Foobar.jpg/360px-Foobar.jpg",
628 "$base/local-thumb/3/3a/Foobar.jpg/400px-Foobar.jpg",
629 "$base/local-thumb/3/3a/Foobar.jpg/40px-Foobar.jpg",
630 "$base/local-thumb/3/3a/Foobar.jpg/440px-Foobar.jpg",
631 "$base/local-thumb/3/3a/Foobar.jpg/442px-Foobar.jpg",
632 "$base/local-thumb/3/3a/Foobar.jpg/450px-Foobar.jpg",
633 "$base/local-thumb/3/3a/Foobar.jpg/50px-Foobar.jpg",
634 "$base/local-thumb/3/3a/Foobar.jpg/600px-Foobar.jpg",
635 "$base/local-thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
636 "$base/local-thumb/3/3a/Foobar.jpg/70px-Foobar.jpg",
637 "$base/local-thumb/3/3a/Foobar.jpg/75px-Foobar.jpg",
638 "$base/local-thumb/3/3a/Foobar.jpg/960px-Foobar.jpg",
640 "$base/local-public/e/ea/Thumb.png",
642 "$base/local-public/0/09/Bad.jpg",
644 "$base/local-public/5/5f/LoremIpsum.djvu",
645 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
646 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
647 "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
649 "$base/local-public/f/ff/Foobar.svg",
650 "$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
651 "$base/local-thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
652 "$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.png",
653 "$base/local-thumb/f/ff/Foobar.svg/3000px-Foobar.svg.png",
654 "$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.png",
655 "$base/local-thumb/f/ff/Foobar.svg/4000px-Foobar.svg.png",
656 "$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.png",
657 "$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.png",
658 "$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.png",
660 "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
672 $backend->delete( [
'src' => $file ], [
'force' => 1 ] );
677 if ( !$backend->clean( [
'dir' => $tmp ] )->isOK() ) {
686 return 'mwstore://local-backend';
690 if ( $this->
file ===
false ) {
692 $this->
file = $wgParserTestFiles[0];
703 $this->
file = $filename;
717 if ( $this->regex !=
'' && !preg_match(
'/' . $this->regex .
'/', $desc ) ) {
718 $this->assertTrue(
true );
727 $this->markTestSkipped(
"Main namespace does not support wikitext,"
728 .
"skipping parser test: $desc" );
731 wfDebug(
"Running parser test: $desc\n" );
739 if ( isset( $opts[
'title'] ) ) {
740 $titleText = $opts[
'title'];
742 $titleText =
'Parser test';
745 $local = isset( $opts[
'local'] );
746 $preprocessor = isset( $opts[
'preprocessor'] ) ? $opts[
'preprocessor'] : null;
751 # Parser test requiring math. Make sure texvc is executable
752 # or just skip such tests.
753 if ( isset( $opts[
'math'] ) || isset( $opts[
'texvc'] ) ) {
756 if ( !isset( $wgTexvc ) ) {
757 $this->markTestSkipped(
"SKIPPED: \$wgTexvc is not set" );
758 } elseif ( !is_executable( $wgTexvc ) ) {
759 $this->markTestSkipped(
"SKIPPED: texvc binary does not exist"
760 .
" or is not executable.\n"
761 .
"Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
765 if ( isset( $opts[
'djvu'] ) ) {
766 if ( !$this->djVuSupport->isEnabled() ) {
767 $this->markTestSkipped(
"SKIPPED: djvu binaries do not exist or are not executable.\n" );
771 if ( isset( $opts[
'tidy'] ) ) {
772 if ( !$this->tidySupport->isEnabled() ) {
773 $this->markTestSkipped(
"SKIPPED: tidy extension is not installed.\n" );
779 if ( isset( $opts[
'pst'] ) ) {
781 } elseif ( isset( $opts[
'msg'] ) ) {
783 } elseif ( isset( $opts[
'section'] ) ) {
786 } elseif ( isset( $opts[
'replace'] ) ) {
788 $replace = $opts[
'replace'][1];
790 } elseif ( isset( $opts[
'comment'] ) ) {
792 } elseif ( isset( $opts[
'preload'] ) ) {
798 if ( isset( $opts[
'tidy'] ) ) {
799 $out = preg_replace(
'/\s+$/',
'',
$out );
802 if ( isset( $opts[
'showtitle'] ) ) {
807 $out =
"$title\n$out";
810 if ( isset( $opts[
'showindicators'] ) ) {
813 $indicators .=
"$id=$content\n";
818 if ( isset( $opts[
'ill'] ) ) {
820 } elseif ( isset( $opts[
'cat'] ) ) {
821 $outputPage =
$context->getOutput();
823 $cats = $outputPage->getCategoryLinks();
825 if ( isset( $cats[
'normal'] ) ) {
826 $out = implode(
' ', $cats[
'normal'] );
857 $dictSize = strlen( $dict );
858 $logMaxLength = log( $this->maxFuzzTestLength );
860 ini_set(
'memory_limit', $this->memoryLimit * 1048576 );
871 mt_srand( ++$this->fuzzSeed );
872 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
875 while ( strlen( $input ) < $totalLength ) {
876 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
877 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
878 $offset = mt_rand( 0, $dictSize - $hairLength );
879 $input .= substr( $dict, $offset, $hairLength );
888 $this->assertTrue(
true,
"Test $id, fuzz seed {$this->fuzzSeed}" );
889 }
catch ( Exception $exception ) {
890 $input_dump = sprintf(
"string(%d) \"%s\"\n", strlen( $input ), $input );
892 $this->assertTrue(
false,
"Test $id, fuzz seed {$this->fuzzSeed}. \n\n" .
893 "Input: $input_dump\n\nError: {$exception->getMessage()}\n\n" .
894 "Backtrace: {$exception->getTraceAsString()}" );
900 if ( $id % 100 == 0 ) {
901 $usage = intval( memory_get_usage(
true ) / $this->memoryLimit / 1048576 * 100 );
904 $ret =
"Out of memory:\n";
907 foreach ( $memStats
as $name => $usage ) {
908 $ret .=
"$name: $usage\n";
929 foreach ( $filenames
as $filename ) {
930 $contents = file_get_contents( $filename );
931 preg_match_all(
'/!!\s*input\n(.*?)\n!!\s*result/s', $contents,
$matches );
934 $dict .= $match .
"\n";
952 $classes = get_declared_classes();
954 foreach ( $classes
as $class ) {
955 $rc =
new ReflectionClass( $class );
956 $props = $rc->getStaticProperties();
957 $memStats[$class] = strlen(
serialize( $props ) );
958 $methods = $rc->getMethods();
960 foreach ( $methods
as $method ) {
961 $memStats[$class] += strlen(
serialize( $method->getStaticVariables() ) );
965 $functions = get_defined_functions();
967 foreach ( $functions[
'user']
as $function ) {
968 $rf =
new ReflectionFunction( $function );
969 $memStats[
"$function()"] = strlen(
serialize( $rf->getStaticVariables() ) );
985 $class = $wgParserConf[
'class'];
986 $parser =
new $class( [
'preprocessorClass' => $preprocessor ] + $wgParserConf );
1000 if ( empty( self::$articles ) ) {
1004 foreach ( self::$articles
as $name => $info ) {
1020 $wgParser->firstCallInit();
1021 return isset( $wgParser->mTagHooks[
$name] );
1026 $wgParser->firstCallInit();
1027 return isset( $wgParser->mFunctionHooks[
$name] );
1032 $wgParser->firstCallInit();
1033 return isset( $wgParser->mTransparentTagHooks[
$name] );
1044 if ( substr(
$s, -1 ) ===
"\n" ) {
1045 return substr(
$s, 0, -1 );
1081 "[^"]*" # Quoted val
1083 \[\[[^]]*\]\] # Link target
1091 if ( preg_match_all(
$regex, $instring,
$matches, PREG_SET_ORDER ) ) {
1093 array_shift( $bits );
1094 $key = strtolower( array_shift( $bits ) );
1095 if ( count( $bits ) == 0 ) {
1097 } elseif ( count( $bits ) == 1 ) {
1101 $opts[$key] = array_map( [ $this,
'cleanupOption' ], $bits );
1110 if ( substr( $opt, 0, 1 ) ==
'"' ) {
1111 return substr( $opt, 1, -1 );
1114 if ( substr( $opt, 0, 2 ) ==
'[[' ) {
1115 return substr( $opt, 2, -2 );
1129 $key = strtolower( $key );
1131 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
$wgParserTestFiles
Parser test suite files to be run by parserTests.php when no specific filename is passed to it...
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.
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':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
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.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $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.
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
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.
unless you explicitly specified the no dev flag during the install In this case just run composer update Otherwise follow the installation instructions in the PHPUnit Manual at
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