MediaWiki REL1_27
NewParserTest.php
Go to the documentation of this file.
1<?php
2
13 static protected $articles = []; // Array of test articles defined by the tests
14 /* The data provider is run on a different instance than the test, so it must be static
15 * When running tests from several files, all tests will see all articles.
16 */
17 static protected $backendToUse;
18
19 public $keepUploads = false;
20 public $runDisabled = false;
21 public $runParsoid = false;
22 public $regex = '';
23 public $showProgress = true;
24 public $savedWeirdGlobals = [];
25 public $savedGlobals = [];
26 public $hooks = [];
27 public $functionHooks = [];
28 public $transparentHooks = [];
29
30 // Fuzz test
31 public $maxFuzzTestLength = 300;
32 public $fuzzSeed = 0;
33 public $memoryLimit = 50;
34
38 private $djVuSupport;
42 private $tidySupport;
43
44 protected $file = false;
45
46 public static function setUpBeforeClass() {
47 // Inject ParserTest well-known interwikis
49 }
50
51 protected function setUp() {
54
55 parent::setUp();
56
57 // Setup CLI arguments
58 if ( $this->getCliArg( 'regex' ) ) {
59 $this->regex = $this->getCliArg( 'regex' );
60 } else {
61 # Matches anything
62 $this->regex = '';
63 }
64
65 $this->keepUploads = $this->getCliArg( 'keep-uploads' );
66
67 $tmpGlobals = [];
68
69 $tmpGlobals['wgLanguageCode'] = 'en';
70 $tmpGlobals['wgContLang'] = Language::factory( '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',
87 'name' => 'local',
88 'url' => 'http://example.com/images',
89 'hashLevels' => 2,
90 'transformVia404' => false,
91 'backend' => 'local-backend'
92 ];
93 $tmpGlobals['wgForeignFileRepos'] = [];
94 $tmpGlobals['wgDefaultExternalStore'] = [];
95 $tmpGlobals['wgParserCacheType'] = CACHE_NONE;
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'] = [
109 '*' => [
110 'createaccount' => true,
111 'read' => true,
112 'edit' => true,
113 'createpage' => true,
114 'createtalk' => true,
115 ] ];
116 $tmpGlobals['wgNamespaceProtection'] = [ NS_MEDIAWIKI => 'editinterface' ];
117
118 $tmpGlobals['wgParser'] = new StubObject(
119 'wgParser', $GLOBALS['wgParserConf']['class'],
120 [ $GLOBALS['wgParserConf'] ] );
121
122 $tmpGlobals['wgFileExtensions'][] = 'svg';
123 $tmpGlobals['wgSVGConverter'] = 'rsvg';
124 $tmpGlobals['wgSVGConverters']['rsvg'] =
125 '$path/rsvg-convert -w $width -h $height -o $output $input';
126
127 if ( $GLOBALS['wgStyleDirectory'] === false ) {
128 $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
129 }
130
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.
135 foreach ( $wgMediaHandlers as $type => $handler ) {
136 $tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
137 }
138 // Vector images have to be handled slightly differently
139 $tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
140
141 // DjVu images have to be handled slightly differently
142 $tmpGlobals['wgMediaHandlers']['image/vnd.djvu'] = 'MockDjVuHandler';
143
144 // Ogg video/audio increasingly more differently
145 $tmpGlobals['wgMediaHandlers']['application/ogg'] = 'MockOggHandler';
146
147 $tmpHooks = $wgHooks;
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' ];
154
155 $tmpGlobals['wgLocalInterwikis'] = [ 'local', 'mi' ];
156 # "extra language links"
157 # see https://gerrit.wikimedia.org/r/111390
158 $tmpGlobals['wgExtraInterlanguageLinkPrefixes'] = [ 'mul' ];
159
160 // DjVu support
161 $this->djVuSupport = new DjVuSupport();
162 // Tidy support
163 $this->tidySupport = new TidySupport();
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();
170
171 $this->setMwGlobals( $tmpGlobals );
172
173 $this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
174 $this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
175
176 $wgNamespaceAliases['Image'] = NS_FILE;
177 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
178
179 MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
180 $wgContLang->resetNamespaces(); # reset namespace cache
181 }
182
183 protected function tearDown() {
185
186 $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
187 $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
188
190
191 // Restore backends
194
195 // Remove temporary pages from the link cache
196 LinkCache::singleton()->clear();
197
198 // Restore message cache (temporary pages and $wgUseDatabaseMessages)
200
201 parent::tearDown();
202
203 MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
204 $wgContLang->resetNamespaces(); # reset namespace cache
205 }
206
207 public static function tearDownAfterClass() {
209 parent::tearDownAfterClass();
210 }
211
212 function addDBDataOnce() {
213 # disabled for performance
214 # $this->tablesUsed[] = 'image';
215
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 ],
219 __METHOD__,
220 [ 'IGNORE' ]
221 );
222
223 $user = User::newFromId( 0 );
224 LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
225
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.
234 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
235 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
236 $image->recordUpload2(
237 '', // archive name
238 'Upload of some lame file',
239 'Some lame file',
240 [
241 'size' => 7881,
242 'width' => 1941,
243 'height' => 220,
244 'bits' => 8,
245 'media_type' => MEDIATYPE_BITMAP,
246 'mime' => 'image/jpeg',
247 'metadata' => serialize( [] ),
248 'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
249 'fileExists' => true ],
250 $this->db->timestamp( '20010115123500' ), $user
251 );
252 }
253
254 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Thumb.png' ) );
255 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
256 $image->recordUpload2(
257 '', // archive name
258 'Upload of some lame thumbnail',
259 'Some lame thumbnail',
260 [
261 'size' => 22589,
262 'width' => 135,
263 'height' => 135,
264 'bits' => 8,
265 'media_type' => MEDIATYPE_BITMAP,
266 'mime' => 'image/png',
267 'metadata' => serialize( [] ),
268 'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
269 'fileExists' => true ],
270 $this->db->timestamp( '20130225203040' ), $user
271 );
272 }
273
274 # This image will be blacklisted in [[MediaWiki:Bad image list]]
275 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
276 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
277 $image->recordUpload2(
278 '', // archive name
279 'zomgnotcensored',
280 'Borderline image',
281 [
282 'size' => 12345,
283 'width' => 320,
284 'height' => 240,
285 'bits' => 24,
286 'media_type' => MEDIATYPE_BITMAP,
287 'mime' => 'image/jpeg',
288 'metadata' => serialize( [] ),
289 'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
290 'fileExists' => true ],
291 $this->db->timestamp( '20010115123500' ), $user
292 );
293 }
294 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.svg' ) );
295 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
296 $image->recordUpload2( '', 'Upload of some lame SVG', 'Some lame SVG', [
297 'size' => 12345,
298 'width' => 240,
299 'height' => 180,
300 'bits' => 0,
301 'media_type' => MEDIATYPE_DRAWING,
302 'mime' => 'image/svg+xml',
303 'metadata' => serialize( [] ),
304 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
305 'fileExists' => true
306 ], $this->db->timestamp( '20010115123500' ), $user );
307 }
308
309 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Video.ogv' ) );
310 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
311 $image->recordUpload2( '', 'A pretty movie', 'Will it play', [
312 'size' => 12345,
313 'width' => 320,
314 'height' => 240,
315 'bits' => 0,
316 'media_type' => MEDIATYPE_VIDEO,
317 'mime' => 'application/ogg',
318 'metadata' => serialize( [] ),
319 'sha1' => Wikimedia\base_convert( '', 16, 36, 32 ),
320 'fileExists' => true
321 ], $this->db->timestamp( '20010115123500' ), $user );
322 }
323
324 # A DjVu file
325 # A DjVu file
326 $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
327 if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
328 $image->recordUpload2( '', 'Upload a DjVu', 'A DjVu', [
329 'size' => 3249,
330 'width' => 2480,
331 'height' => 3508,
332 'bits' => 0,
333 'media_type' => MEDIATYPE_BITMAP,
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">
337<DjVuXML>
338<HEAD></HEAD>
339<BODY><OBJECT height="3508" width="2480">
340<PARAM name="DPI" value="300" />
341<PARAM name="GAMMA" value="2.2" />
342</OBJECT>
343<OBJECT height="3508" width="2480">
344<PARAM name="DPI" value="300" />
345<PARAM name="GAMMA" value="2.2" />
346</OBJECT>
347<OBJECT height="3508" width="2480">
348<PARAM name="DPI" value="300" />
349<PARAM name="GAMMA" value="2.2" />
350</OBJECT>
351<OBJECT height="3508" width="2480">
352<PARAM name="DPI" value="300" />
353<PARAM name="GAMMA" value="2.2" />
354</OBJECT>
355<OBJECT height="3508" width="2480">
356<PARAM name="DPI" value="300" />
357<PARAM name="GAMMA" value="2.2" />
358</OBJECT>
359</BODY>
360</DjVuXML>',
361 'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
362 'fileExists' => true
363 ], $this->db->timestamp( '20140115123600' ), $user );
364 }
365 }
366
367 // ParserTest setup/teardown functions
368
376 protected function setupGlobals( $opts = [], $config = '' ) {
378 # Find out values for some special options.
379 $lang =
380 self::getOptionValue( 'language', $opts, 'en' );
381 $variant =
382 self::getOptionValue( 'variant', $opts, false );
383 $maxtoclevel =
384 self::getOptionValue( 'wgMaxTocLevel', $opts, 999 );
385 $linkHolderBatchSize =
386 self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
387
388 $uploadDir = $this->getUploadDir();
389 if ( $this->getCliArg( 'use-filebackend' ) ) {
390 if ( self::$backendToUse ) {
391 $backend = self::$backendToUse;
392 } else {
393 $name = $this->getCliArg( 'use-filebackend' );
394 $useConfig = [];
395 foreach ( $wgFileBackends as $conf ) {
396 if ( $conf['name'] == $name ) {
397 $useConfig = $conf;
398 }
399 }
400 $useConfig['name'] = 'local-backend'; // swap name
401 unset( $useConfig['lockManager'] );
402 unset( $useConfig['fileJournal'] );
403 $class = $useConfig['class'];
404 self::$backendToUse = new $class( $useConfig );
405 $backend = self::$backendToUse;
406 }
407 } else {
408 # Replace with a mock. We do not care about generating real
409 # files on the filesystem, just need to expose the file
410 # informations.
411 $backend = new MockFileBackend( [
412 'name' => 'local-backend',
413 'wikiId' => wfWikiID()
414 ] );
415 }
416
417 $settings = [
418 'wgLocalFileRepo' => [
419 'class' => 'LocalRepo',
420 'name' => 'local',
421 'url' => 'http://example.com/images',
422 'hashLevels' => 2,
423 'transformVia404' => false,
424 'backend' => $backend
425 ],
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'] ),
439 ];
440
441 if ( $config ) {
442 $configLines = explode( "\n", $config );
443
444 foreach ( $configLines as $line ) {
445 list( $var, $value ) = explode( '=', $line, 2 );
446
447 $settings[$var] = eval( "return $value;" ); // ???
448 }
449 }
450
451 $this->savedGlobals = [];
452
454 Hooks::run( 'ParserTestGlobals', [ &$settings ] );
455
456 $langObj = Language::factory( $lang );
457 $settings['wgContLang'] = $langObj;
458 $settings['wgLang'] = $langObj;
459
460 $context = new RequestContext();
461 $settings['wgOut'] = $context->getOutput();
462 $settings['wgUser'] = $context->getUser();
463 $settings['wgRequest'] = $context->getRequest();
464
465 // We (re)set $wgThumbLimits to a single-element array above.
466 $context->getUser()->setOption( 'thumbsize', 0 );
467
468 foreach ( $settings as $var => $val ) {
469 if ( array_key_exists( $var, $GLOBALS ) ) {
470 $this->savedGlobals[$var] = $GLOBALS[$var];
471 }
472
473 $GLOBALS[$var] = $val;
474 }
475
478
479 # The entries saved into RepoGroup cache with previous globals will be wrong.
482
483 # Create dummy files in storage
484 $this->setupUploads();
485
486 # Publish the articles after we have the final language set
487 $this->publishTestArticles();
488
490
491 return $context;
492 }
493
499 protected function getUploadDir() {
500 if ( $this->keepUploads ) {
501 // Don't use getNewTempDirectory() as this is meant to persist
502 $dir = wfTempDir() . '/mwParser-images';
503
504 if ( is_dir( $dir ) ) {
505 return $dir;
506 }
507 } else {
508 $dir = $this->getNewTempDirectory();
509 }
510
511 if ( file_exists( $dir ) ) {
512 wfDebug( "Already exists!\n" );
513
514 return $dir;
515 }
516
517 return $dir;
518 }
519
526 protected function setupUploads() {
527 global $IP;
528
529 $base = $this->getBaseDir();
530 $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
531 $backend->prepare( [ 'dir' => "$base/local-public/3/3a" ] );
532 $backend->store( [
533 'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
534 'dst' => "$base/local-public/3/3a/Foobar.jpg"
535 ] );
536 $backend->prepare( [ 'dir' => "$base/local-public/e/ea" ] );
537 $backend->store( [
538 'src' => "$IP/tests/phpunit/data/parser/wiki.png",
539 'dst' => "$base/local-public/e/ea/Thumb.png"
540 ] );
541 $backend->prepare( [ 'dir' => "$base/local-public/0/09" ] );
542 $backend->store( [
543 'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
544 'dst' => "$base/local-public/0/09/Bad.jpg"
545 ] );
546 $backend->prepare( [ 'dir' => "$base/local-public/5/5f" ] );
547 $backend->store( [
548 'src' => "$IP/tests/phpunit/data/parser/LoremIpsum.djvu",
549 'dst' => "$base/local-public/5/5f/LoremIpsum.djvu"
550 ] );
551
552 // No helpful SVG file to copy, so make one ourselves
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"/>';
556
557 $backend->prepare( [ 'dir' => "$base/local-public/f/ff" ] );
558 $backend->quickCreate( [
559 'content' => $data, 'dst' => "$base/local-public/f/ff/Foobar.svg"
560 ] );
561 }
562
567 protected function teardownGlobals() {
568 $this->teardownUploads();
569
570 foreach ( $this->savedGlobals as $var => $val ) {
571 $GLOBALS[$var] = $val;
572 }
573 }
574
578 private function teardownUploads() {
579 if ( $this->keepUploads ) {
580 return;
581 }
582
583 $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
584 if ( $backend instanceof MockFileBackend ) {
585 # In memory backend, so dont bother cleaning them up.
586 return;
587 }
588
589 $base = $this->getBaseDir();
590 // delete the files first, then the dirs.
591 self::deleteFiles(
592 [
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",
625
626 "$base/local-public/e/ea/Thumb.png",
627
628 "$base/local-public/0/09/Bad.jpg",
629
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",
634
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",
645
646 "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
647 ]
648 );
649 }
650
655 private static function deleteFiles( $files ) {
656 $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
657 foreach ( $files as $file ) {
658 $backend->delete( [ 'src' => $file ], [ 'force' => 1 ] );
659 }
660 foreach ( $files as $file ) {
661 $tmp = FileBackend::parentStoragePath( $file );
662 while ( $tmp ) {
663 if ( !$backend->clean( [ 'dir' => $tmp ] )->isOK() ) {
664 break;
665 }
666 $tmp = FileBackend::parentStoragePath( $tmp );
667 }
668 }
669 }
670
671 protected function getBaseDir() {
672 return 'mwstore://local-backend';
673 }
674
675 public function parserTestProvider() {
676 if ( $this->file === false ) {
678 $this->file = $wgParserTestFiles[0];
679 }
680
681 return new TestFileDataProvider( $this->file, $this );
682 }
683
688 public function setParserTestFile( $filename ) {
689 $this->file = $filename;
690 }
691
702 public function testParserTest( $desc, $input, $result, $opts, $config ) {
703 if ( $this->regex != '' && !preg_match( '/' . $this->regex . '/', $desc ) ) {
704 $this->assertTrue( true ); // XXX: don't flood output with "test made no assertions"
705 // $this->markTestSkipped( 'Filtered out by the user' );
706 return;
707 }
708
709 if ( !$this->isWikitextNS( NS_MAIN ) ) {
710 // parser tests frequently assume that the main namespace contains wikitext.
711 // @todo When setting up pages, force the content model. Only skip if
712 // $wgtContentModelUseDB is false.
713 $this->markTestSkipped( "Main namespace does not support wikitext,"
714 . "skipping parser test: $desc" );
715 }
716
717 wfDebug( "Running parser test: $desc\n" );
718
719 $opts = $this->parseOptions( $opts );
720 $context = $this->setupGlobals( $opts, $config );
721
722 $user = $context->getUser();
724
725 if ( isset( $opts['title'] ) ) {
726 $titleText = $opts['title'];
727 } else {
728 $titleText = 'Parser test';
729 }
730
731 $local = isset( $opts['local'] );
732 $preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
733 $parser = $this->getParser( $preprocessor );
734
735 $title = Title::newFromText( $titleText );
736
737 # Parser test requiring math. Make sure texvc is executable
738 # or just skip such tests.
739 if ( isset( $opts['math'] ) || isset( $opts['texvc'] ) ) {
740 global $wgTexvc;
741
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'" );
748 }
749 }
750
751 if ( isset( $opts['djvu'] ) ) {
752 if ( !$this->djVuSupport->isEnabled() ) {
753 $this->markTestSkipped( "SKIPPED: djvu binaries do not exist or are not executable.\n" );
754 }
755 }
756
757 if ( isset( $opts['tidy'] ) ) {
758 if ( !$this->tidySupport->isEnabled() ) {
759 $this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
760 } else {
761 $options->setTidy( true );
762 }
763 }
764
765 if ( isset( $opts['pst'] ) ) {
766 $out = $parser->preSaveTransform( $input, $title, $user, $options );
767 } elseif ( isset( $opts['msg'] ) ) {
768 $out = $parser->transformMsg( $input, $options, $title );
769 } elseif ( isset( $opts['section'] ) ) {
770 $section = $opts['section'];
771 $out = $parser->getSection( $input, $section );
772 } elseif ( isset( $opts['replace'] ) ) {
773 $section = $opts['replace'][0];
774 $replace = $opts['replace'][1];
775 $out = $parser->replaceSection( $input, $section, $replace );
776 } elseif ( isset( $opts['comment'] ) ) {
777 $out = Linker::formatComment( $input, $title, $local );
778 } elseif ( isset( $opts['preload'] ) ) {
779 $out = $parser->getPreloadText( $input, $title, $options );
780 } else {
781 $output = $parser->parse( $input, $title, $options, true, true, 1337 );
782 $output->setTOCEnabled( !isset( $opts['notoc'] ) );
783 $out = $output->getText();
784 if ( isset( $opts['tidy'] ) ) {
785 $out = preg_replace( '/\s+$/', '', $out );
786 }
787
788 if ( isset( $opts['showtitle'] ) ) {
789 if ( $output->getTitleText() ) {
791 }
792
793 $out = "$title\n$out";
794 }
795
796 if ( isset( $opts['showindicators'] ) ) {
797 $indicators = '';
798 foreach ( $output->getIndicators() as $id => $content ) {
799 $indicators .= "$id=$content\n";
800 }
801 $out = $indicators . $out;
802 }
803
804 if ( isset( $opts['ill'] ) ) {
805 $out = implode( ' ', $output->getLanguageLinks() );
806 } elseif ( isset( $opts['cat'] ) ) {
807 $outputPage = $context->getOutput();
808 $outputPage->addCategoryLinks( $output->getCategories() );
809 $cats = $outputPage->getCategoryLinks();
810
811 if ( isset( $cats['normal'] ) ) {
812 $out = implode( ' ', $cats['normal'] );
813 } else {
814 $out = '';
815 }
816 }
817 $parser->mPreprocessor = null;
818 }
819
820 $this->teardownGlobals();
821
822 $this->assertEquals( $result, $out, $desc );
823 }
824
833 public function testFuzzTests() {
835
837
838 if ( $this->getCliArg( 'file' ) ) {
839 $files = [ $this->getCliArg( 'file' ) ];
840 }
841
842 $dict = $this->getFuzzInput( $files );
843 $dictSize = strlen( $dict );
844 $logMaxLength = log( $this->maxFuzzTestLength );
845
846 ini_set( 'memory_limit', $this->memoryLimit * 1048576 );
847
848 $user = new User;
850 $title = Title::makeTitle( NS_MAIN, 'Parser_test' );
851
852 $id = 1;
853
854 while ( true ) {
855
856 // Generate test input
857 mt_srand( ++$this->fuzzSeed );
858 $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
859 $input = '';
860
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 );
866 }
867
868 $this->setupGlobals();
869 $parser = $this->getParser();
870
871 // Run the test
872 try {
873 $parser->parse( $input, $title, $opts );
874 $this->assertTrue( true, "Test $id, fuzz seed {$this->fuzzSeed}" );
875 } catch ( Exception $exception ) {
876 $input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
877
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()}" );
881 }
882
883 $this->teardownGlobals();
884 $parser->__destruct();
885
886 if ( $id % 100 == 0 ) {
887 $usage = intval( memory_get_usage( true ) / $this->memoryLimit / 1048576 * 100 );
888 // echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
889 if ( $usage > 90 ) {
890 $ret = "Out of memory:\n";
891 $memStats = $this->getMemoryBreakdown();
892
893 foreach ( $memStats as $name => $usage ) {
894 $ret .= "$name: $usage\n";
895 }
896
897 throw new MWException( $ret );
898 }
899 }
900
901 $id++;
902 }
903 }
904
905 // Various getter functions
906
912 function getFuzzInput( $filenames ) {
913 $dict = '';
914
915 foreach ( $filenames as $filename ) {
916 $contents = file_get_contents( $filename );
917 preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
918
919 foreach ( $matches[1] as $match ) {
920 $dict .= $match . "\n";
921 }
922 }
923
924 return $dict;
925 }
926
932 $memStats = [];
933
934 foreach ( $GLOBALS as $name => $value ) {
935 $memStats['$' . $name] = strlen( serialize( $value ) );
936 }
937
938 $classes = get_declared_classes();
939
940 foreach ( $classes as $class ) {
941 $rc = new ReflectionClass( $class );
942 $props = $rc->getStaticProperties();
943 $memStats[$class] = strlen( serialize( $props ) );
944 $methods = $rc->getMethods();
945
946 foreach ( $methods as $method ) {
947 $memStats[$class] += strlen( serialize( $method->getStaticVariables() ) );
948 }
949 }
950
951 $functions = get_defined_functions();
952
953 foreach ( $functions['user'] as $function ) {
954 $rf = new ReflectionFunction( $function );
955 $memStats["$function()"] = strlen( serialize( $rf->getStaticVariables() ) );
956 }
957
958 asort( $memStats );
959
960 return $memStats;
961 }
962
968 function getParser( $preprocessor = null ) {
970
971 $class = $wgParserConf['class'];
972 $parser = new $class( [ 'preprocessorClass' => $preprocessor ] + $wgParserConf );
973
974 Hooks::run( 'ParserTestParser', [ &$parser ] );
975
976 return $parser;
977 }
978
979 // Various action functions
980
981 public function addArticle( $name, $text, $line ) {
982 self::$articles[$name] = [ $text, $line ];
983 }
984
985 public function publishTestArticles() {
986 if ( empty( self::$articles ) ) {
987 return;
988 }
989
990 foreach ( self::$articles as $name => $info ) {
991 list( $text, $line ) = $info;
992 ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' );
993 }
994 }
995
1004 public function requireHook( $name ) {
1006 $wgParser->firstCallInit(); // make sure hooks are loaded.
1007 return isset( $wgParser->mTagHooks[$name] );
1008 }
1009
1010 public function requireFunctionHook( $name ) {
1012 $wgParser->firstCallInit(); // make sure hooks are loaded.
1013 return isset( $wgParser->mFunctionHooks[$name] );
1014 }
1015
1016 public function requireTransparentHook( $name ) {
1018 $wgParser->firstCallInit(); // make sure hooks are loaded.
1019 return isset( $wgParser->mTransparentTagHooks[$name] );
1020 }
1021
1022 // Various "cleanup" functions
1023
1029 public function removeEndingNewline( $s ) {
1030 if ( substr( $s, -1 ) === "\n" ) {
1031 return substr( $s, 0, -1 );
1032 } else {
1033 return $s;
1034 }
1035 }
1036
1037 // Test options parser functions
1038
1039 protected function parseOptions( $instring ) {
1040 $opts = [];
1041 // foo
1042 // foo=bar
1043 // foo="bar baz"
1044 // foo=[[bar baz]]
1045 // foo=bar,"baz quux"
1046 $regex = '/\b
1047 ([\w-]+) # Key
1048 \b
1049 (?:\s*
1050 = # First sub-value
1051 \s*
1052 (
1053 "
1054 [^"]* # Quoted val
1055 "
1056 |
1057 \[\[
1058 [^]]* # Link target
1059 \]\]
1060 |
1061 [\w-]+ # Plain word
1062 )
1063 (?:\s*
1064 , # Sub-vals 1..N
1065 \s*
1066 (
1067 "[^"]*" # Quoted val
1068 |
1069 \[\[[^]]*\]\] # Link target
1070 |
1071 [\w-]+ # Plain word
1072 )
1073 )*
1074 )?
1075 /x';
1076
1077 if ( preg_match_all( $regex, $instring, $matches, PREG_SET_ORDER ) ) {
1078 foreach ( $matches as $bits ) {
1079 array_shift( $bits );
1080 $key = strtolower( array_shift( $bits ) );
1081 if ( count( $bits ) == 0 ) {
1082 $opts[$key] = true;
1083 } elseif ( count( $bits ) == 1 ) {
1084 $opts[$key] = $this->cleanupOption( array_shift( $bits ) );
1085 } else {
1086 // Array!
1087 $opts[$key] = array_map( [ $this, 'cleanupOption' ], $bits );
1088 }
1089 }
1090 }
1091
1092 return $opts;
1093 }
1094
1095 protected function cleanupOption( $opt ) {
1096 if ( substr( $opt, 0, 1 ) == '"' ) {
1097 return substr( $opt, 1, -1 );
1098 }
1099
1100 if ( substr( $opt, 0, 2 ) == '[[' ) {
1101 return substr( $opt, 2, -2 );
1102 }
1103
1104 return $opt;
1105 }
1106
1114 protected static function getOptionValue( $key, $opts, $default ) {
1115 $key = strtolower( $key );
1116
1117 if ( isset( $opts[$key] ) ) {
1118 return $opts[$key];
1119 } else {
1120 return $default;
1121 }
1122 }
1123}
serialize()
$GLOBALS['IP']
$wgFileBackends
File backend structure configuration.
$wgParserTestFiles
Parser test suite files to be run by parserTests.php when no specific filename is passed to it.
$wgMediaHandlers
Plugins for media file type handling.
$wgParserConf
Parser configuration.
$wgNamespaceAliases
Namespace aliases.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTempDir()
Tries to get the system directory for temporary files.
wfLocalFile( $title)
Get an object referring to a locally registered file.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
$wgParser
Definition Setup.php:809
$IP
Definition WebStart.php:58
$line
Definition cdb.php:59
Initialize and detect the DjVu files support.
static destroySingleton()
Destroy the singleton instance.
static parentStoragePath( $storagePath)
Get the parent storage directory of a storage path.
static singleton()
Get an instance of this class.
Definition LinkCache.php:61
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...
Definition Linker.php:1290
MediaWiki exception.
static getCanonicalNamespaces( $rebuild=false)
Returns array of all defined namespaces with their canonical (English) names.
static destroySingleton()
Destroy the current singleton instance.
Definition MWTidy.php:153
static clearCache()
Clear the self::$mObjects variable For use in parser tests.
setMwGlobals( $pairs, $value=null)
static destroyInstance()
Destroy the singleton instance.
Class simulating a backend store.
Although marked as a stub, can work independently.
TidySupport $tidySupport
requireHook( $name)
Steal a callback function from the primary parser, save it for application to our scary parser.
getMemoryBreakdown()
Get a memory usage breakdown.
testParserTest( $desc, $input, $result, $opts, $config)
medium ParserTests parserTestProvider
static setUpBeforeClass()
requireTransparentHook( $name)
teardownGlobals()
Restore default values and perform any necessary clean-up after each test runs.
getParser( $preprocessor=null)
Get a Parser object.
setParserTestFile( $filename)
Set the file from whose tests will be run by this instance.
parseOptions( $instring)
static getOptionValue( $key, $opts, $default)
Use a regex to find out the value of an option.
testFuzzTests()
Run a fuzz test series Draw input from a set of test files.
addArticle( $name, $text, $line)
removeEndingNewline( $s)
Remove last character if it is a newline.
getFuzzInput( $filenames)
Get an input dictionary from a set of parser test files.
DjVuSupport $djVuSupport
setupGlobals( $opts=[], $config='')
Set up the global variables for a consistent environment for each test.
static deleteFiles( $files)
Delete the specified files, if they exist.
setupUploads()
Create a dummy uploads directory which will contain a couple of files in order to pass existence test...
getUploadDir()
Get an FS upload directory (only applies to FSFileBackend)
teardownUploads()
Remove the dummy uploads directory.
requireFunctionHook( $name)
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
static newFromUser( $user)
Get a ParserOptions object from a given user.
setTOCEnabled( $flag)
static addArticle( $name, $text, $line='unknown', $ignoreDuplicate='')
Insert a temporary test article.
static tearDownInterwikis()
Remove the hardcoded interwiki lookup table.
static setupInterwikis()
Insert hardcoded interwiki in the lookup table.
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
static destroySingleton()
Destroy the singleton instance, so that a new one will be created next time singleton() is called.
Definition RepoGroup.php:73
Group all the pieces relevant to the context of a request into one instance.
Class to implement stub globals, which are globals that delay loading the their associated module cod...
An iterator for use as a phpunit data provider.
Initialize and detect the tidy support.
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition Title.php:524
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition Title.php:277
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
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
Definition deferred.txt:11
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
Definition design.txt:57
when a variable name is used in a function
Definition design.txt:94
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
const MEDIATYPE_DRAWING
Definition Defines.php:118
const MEDIATYPE_VIDEO
Definition Defines.php:123
const NS_FILE
Definition Defines.php:76
const CACHE_NONE
Definition Defines.php:103
const NS_MAIN
Definition Defines.php:70
const NS_MEDIAWIKI
Definition Defines.php:78
const NS_FILE_TALK
Definition Defines.php:77
const MEDIATYPE_BITMAP
Definition Defines.php:116
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
Definition hooks.txt:1048
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
Definition hooks.txt:249
do that in ParserLimitReportFormat instead $parser
Definition hooks.txt:2341
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
Definition hooks.txt:1799
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
Definition hooks.txt:877
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
Definition hooks.txt:1042
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
Definition hooks.txt:1040
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
Definition hooks.txt:1810
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
Definition hooks.txt:2413
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:944
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
Definition hooks.txt:846
$wgHooks['ArticleShow'][]
Definition hooks.txt:110
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
Definition hooks.txt:108
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
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
Definition hooks.txt:885
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:2727
if(count( $args)==0) $dir
$files
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
Definition injection.txt:37
$context
Definition load.php:44
you have access to all of the normal MediaWiki so you can get a DB use the cache
#define the
table suitable for use with IDatabase::select()
if(!isset( $args[0])) $lang