529fc92b66404f913364bc7a987a83075b49ef9a
4 * Although marked as a stub, can work independently.
10 class NewParserTest
extends MediaWikiTestCase
{
12 static protected $articles = array(); // Array of test articles defined by the tests
13 /* The dataProvider is run on a different instance than the test, so it must be static
14 * When running tests from several files, all tests will see all articles.
18 public $keepUploads = false;
19 public $runDisabled = false;
21 public $showProgress = true;
22 public $savedInitialGlobals = array();
23 public $savedWeirdGlobals = array();
24 public $savedGlobals = array();
25 public $hooks = array();
26 public $functionHooks = array();
29 public $maxFuzzTestLength = 300;
31 public $memoryLimit = 50;
33 protected $file = false;
36 global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
38 $wgContLang = Language
::factory( 'en' );
41 if ( $this->getCliArg( 'regex=' ) ) {
42 $this->regex
= $this->getCliArg( 'regex=' );
48 $this->keepUploads
= $this->getCliArg( 'keep-uploads' );
50 $tmpGlobals = array();
52 $tmpGlobals['wgScript'] = '/index.php';
53 $tmpGlobals['wgScriptPath'] = '/';
54 $tmpGlobals['wgArticlePath'] = '/wiki/$1';
55 $tmpGlobals['wgStyleSheetPath'] = '/skins';
56 $tmpGlobals['wgStylePath'] = '/skins';
57 $tmpGlobals['wgThumbnailScriptPath'] = false;
58 $tmpGlobals['wgLocalFileRepo'] = array(
59 'class' => 'LocalRepo',
61 'url' => 'http://example.com/images',
63 'transformVia404' => false,
64 'backend' => 'local-backend'
66 $tmpGlobals['wgForeignFileRepos'] = array();
67 $tmpGlobals['wgEnableParserCache'] = false;
68 $tmpGlobals['wgHooks'] = $wgHooks;
69 $tmpGlobals['wgDeferredUpdateList'] = array();
70 $tmpGlobals['wgMemc'] = wfGetMainCache();
71 $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
72 $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
74 // $tmpGlobals['wgContLang'] = new StubContLang;
75 $tmpGlobals['wgUser'] = new User
;
76 $context = new RequestContext();
77 $tmpGlobals['wgLang'] = $context->getLanguage();
78 $tmpGlobals['wgOut'] = $context->getOutput();
79 $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
80 $tmpGlobals['wgRequest'] = $context->getRequest();
82 if ( $GLOBALS['wgStyleDirectory'] === false ) {
83 $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
87 foreach ( $tmpGlobals as $var => $val ) {
88 if ( array_key_exists( $var, $GLOBALS ) ) {
89 $this->savedInitialGlobals
[$var] = $GLOBALS[$var];
92 $GLOBALS[$var] = $val;
95 $this->savedWeirdGlobals
['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI
];
96 $this->savedWeirdGlobals
['image_alias'] = $wgNamespaceAliases['Image'];
97 $this->savedWeirdGlobals
['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
99 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
100 $wgNamespaceAliases['Image'] = NS_FILE
;
101 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
104 public function tearDown() {
105 foreach ( $this->savedInitialGlobals
as $var => $val ) {
106 $GLOBALS[$var] = $val;
109 global $wgNamespaceProtection, $wgNamespaceAliases;
111 $wgNamespaceProtection[NS_MEDIAWIKI
] = $this->savedWeirdGlobals
['mw_namespace_protection'];
112 $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals
['image_alias'];
113 $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals
['image_talk_alias'];
116 RepoGroup
::destroySingleton();
117 FileBackendGroup
::destroySingleton();
120 function addDBData() {
121 $this->tablesUsed
[] = 'image';
122 # Hack: insert a few Wikipedia in-project interwiki prefixes,
123 # for testing inter-language links
124 $this->db
->insert( 'interwiki', array(
125 array( 'iw_prefix' => 'wikipedia',
126 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
130 array( 'iw_prefix' => 'meatball',
131 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
135 array( 'iw_prefix' => 'zh',
136 'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
140 array( 'iw_prefix' => 'es',
141 'iw_url' => 'http://es.wikipedia.org/wiki/$1',
145 array( 'iw_prefix' => 'fr',
146 'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
150 array( 'iw_prefix' => 'ru',
151 'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
156 * @todo Fixme! Why are we inserting duplicate data here? Shouldn't
157 * need this IGNORE or shouldn't need the insert at all.
159 ), __METHOD__
, array( 'IGNORE' ) );
162 # Update certain things in site_stats
163 $this->db
->insert( 'site_stats',
164 array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
165 __METHOD__
, array( 'IGNORE' ) );
167 # Reinitialise the LocalisationCache to match the database state
168 Language
::getLocalisationCache()->unloadAll();
170 # Clear the message cache
171 MessageCache
::singleton()->clear();
173 $this->uploadDir
= $this->setupUploadDir();
175 $user = User
::newFromId( 0 );
176 LinkCache
::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
178 $image = wfLocalFile( Title
::makeTitle( NS_FILE
, 'Foobar.jpg' ) );
179 $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
184 'media_type' => MEDIATYPE_BITMAP
,
185 'mime' => 'image/jpeg',
186 'metadata' => serialize( array() ),
187 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
189 ), $this->db
->timestamp( '20010115123500' ), $user );
191 # This image will be blacklisted in [[MediaWiki:Bad image list]]
192 $image = wfLocalFile( Title
::makeTitle( NS_FILE
, 'Bad.jpg' ) );
193 $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array(
198 'media_type' => MEDIATYPE_BITMAP
,
199 'mime' => 'image/jpeg',
200 'metadata' => serialize( array() ),
201 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
203 ), $this->db
->timestamp( '20010115123500' ), $user );
210 //ParserTest setup/teardown functions
213 * Set up the global variables for a consistent environment for each test.
214 * Ideally this should replace the global configuration entirely.
216 protected function setupGlobals( $opts = '', $config = '' ) {
217 # Find out values for some special options.
219 self
::getOptionValue( 'language', $opts, 'en' );
221 self
::getOptionValue( 'variant', $opts, false );
223 self
::getOptionValue( 'wgMaxTocLevel', $opts, 999 );
224 $linkHolderBatchSize =
225 self
::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
228 'wgServer' => 'http://Britney-Spears',
229 'wgScript' => '/index.php',
230 'wgScriptPath' => '/',
231 'wgArticlePath' => '/wiki/$1',
232 'wgExtensionAssetsPath' => '/extensions',
233 'wgActionPaths' => array(),
234 'wgLocalFileRepo' => array(
235 'class' => 'LocalRepo',
237 'url' => 'http://example.com/images',
239 'transformVia404' => false,
240 'backend' => new FSFileBackend( array(
241 'name' => 'local-backend',
242 'lockManager' => 'nullLockManager',
243 'containerPaths' => array(
244 'local-public' => "$this->uploadDir",
245 'local-thumb' => "$this->uploadDir/thumb",
249 'wgEnableUploads' => self
::getOptionValue( 'wgEnableUploads', $opts, true ),
250 'wgStylePath' => '/skins',
251 'wgStyleSheetPath' => '/skins',
252 'wgSitename' => 'MediaWiki',
253 'wgLanguageCode' => $lang,
254 'wgDBprefix' => $this->db
->getType() != 'oracle' ?
'unittest_' : 'ut_',
255 'wgRawHtml' => isset( $opts['rawhtml'] ),
257 'wgContLang' => null,
258 'wgNamespacesWithSubpages' => array( 0 => isset( $opts['subpage'] ) ),
259 'wgMaxTocLevel' => $maxtoclevel,
260 'wgCapitalLinks' => true,
261 'wgNoFollowLinks' => true,
262 'wgNoFollowDomainExceptions' => array(),
263 'wgThumbnailScriptPath' => false,
264 'wgUseImageResize' => false,
265 'wgUseTeX' => isset( $opts['math'] ),
266 'wgMathDirectory' => $this->uploadDir
. '/math',
267 'wgLocaltimezone' => 'UTC',
268 'wgAllowExternalImages' => true,
269 'wgUseTidy' => false,
270 'wgDefaultLanguageVariant' => $variant,
271 'wgVariantArticlePath' => false,
272 'wgGroupPermissions' => array( '*' => array(
273 'createaccount' => true,
276 'createpage' => true,
277 'createtalk' => true,
279 'wgNamespaceProtection' => array( NS_MEDIAWIKI
=> 'editinterface' ),
280 'wgDefaultExternalStore' => array(),
281 'wgForeignFileRepos' => array(),
282 'wgLinkHolderBatchSize' => $linkHolderBatchSize,
283 'wgExperimentalHtmlIds' => false,
284 'wgExternalLinkTarget' => false,
285 'wgAlwaysUseTidy' => false,
287 'wgCleanupPresentationalAttributes' => true,
288 'wgWellFormedXml' => true,
289 'wgAllowMicrodataAttributes' => true,
290 'wgAdaptiveMessageCache' => true,
291 'wgUseDatabaseMessages' => true,
295 $configLines = explode( "\n", $config );
297 foreach ( $configLines as $line ) {
298 list( $var, $value ) = explode( '=', $line, 2 );
300 $settings[$var] = eval( "return $value;" ); //???
304 $this->savedGlobals
= array();
306 foreach ( $settings as $var => $val ) {
307 if ( array_key_exists( $var, $GLOBALS ) ) {
308 $this->savedGlobals
[$var] = $GLOBALS[$var];
311 $GLOBALS[$var] = $val;
314 $langObj = Language
::factory( $lang );
315 $GLOBALS['wgContLang'] = $langObj;
316 $context = new RequestContext();
317 $GLOBALS['wgLang'] = $context->getLanguage();
319 $GLOBALS['wgMemc'] = new EmptyBagOStuff
;
320 $GLOBALS['wgOut'] = $context->getOutput();
321 $GLOBALS['wgUser'] = $context->getUser();
325 $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
326 $wgHooks['ParserGetVariableValueTs'][] = 'NewParserTest::getFakeTimestamp';
328 MagicWord
::clearCache();
329 RepoGroup
::destroySingleton();
330 FileBackendGroup
::destroySingleton();
332 # Publish the articles after we have the final language set
333 $this->publishTestArticles();
335 # The entries saved into RepoGroup cache with previous globals will be wrong.
336 RepoGroup
::destroySingleton();
337 FileBackendGroup
::destroySingleton();
338 MessageCache
::singleton()->destroyInstance();
344 * Create a dummy uploads directory which will contain a couple
345 * of files in order to pass existence tests.
347 * @return String: the directory
349 protected function setupUploadDir() {
352 if ( $this->keepUploads
) {
353 $dir = wfTempDir() . '/mwParser-images';
355 if ( is_dir( $dir ) ) {
359 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
362 // wfDebug( "Creating upload directory $dir\n" );
363 if ( file_exists( $dir ) ) {
364 wfDebug( "Already exists!\n" );
368 wfMkdirParents( $dir . '/3/3a', null, __METHOD__
);
369 copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
370 wfMkdirParents( $dir . '/0/09', null, __METHOD__
);
371 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
377 * Restore default values and perform any necessary clean-up
378 * after each test runs.
380 protected function teardownGlobals() {
381 foreach ( $this->savedGlobals
as $var => $val ) {
382 $GLOBALS[$var] = $val;
385 RepoGroup
::destroySingleton();
386 LinkCache
::singleton()->clear();
388 $this->teardownUploadDir( $this->uploadDir
);
392 * Remove the dummy uploads directory
394 private function teardownUploadDir( $dir ) {
395 if ( $this->keepUploads
) {
399 // delete the files first, then the dirs.
402 "$dir/3/3a/Foobar.jpg",
403 "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
404 "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
405 "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
406 "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
410 "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
420 "$dir/thumb/3/3a/Foobar.jpg",
437 * Delete the specified files, if they exist.
438 * @param $files Array: full paths to files to delete.
440 private static function deleteFiles( $files ) {
441 foreach ( $files as $file ) {
442 if ( file_exists( $file ) ) {
449 * Delete the specified directories, if they exist. Must be empty.
450 * @param $dirs Array: full paths to directories to delete.
452 private static function deleteDirs( $dirs ) {
453 foreach ( $dirs as $dir ) {
454 if ( is_dir( $dir ) ) {
460 public function parserTestProvider() {
461 if ( $this->file
=== false ) {
462 global $wgParserTestFiles;
463 $this->file
= $wgParserTestFiles[0];
465 return new TestFileIterator( $this->file
, $this );
469 * Set the file from whose tests will be run by this instance
471 public function setParserTestFile( $filename ) {
472 $this->file
= $filename;
475 /** @dataProvider parserTestProvider */
476 public function testParserTest( $desc, $input, $result, $opts, $config ) {
477 if ( !preg_match( '/' . $this->regex
. '/', $desc ) ) return; //$this->markTestSkipped( 'Filtered out by the user' );
479 wfDebug( "Running parser test: $desc\n" );
481 $opts = $this->parseOptions( $opts );
482 $context = $this->setupGlobals( $opts, $config );
484 $user = $context->getUser();
485 $options = ParserOptions
::newFromContext( $context );
487 if ( isset( $opts['title'] ) ) {
488 $titleText = $opts['title'];
491 $titleText = 'Parser test';
494 $local = isset( $opts['local'] );
495 $preprocessor = isset( $opts['preprocessor'] ) ?
$opts['preprocessor'] : null;
496 $parser = $this->getParser( $preprocessor );
498 $title = Title
::newFromText( $titleText );
500 if ( isset( $opts['pst'] ) ) {
501 $out = $parser->preSaveTransform( $input, $title, $user, $options );
502 } elseif ( isset( $opts['msg'] ) ) {
503 $out = $parser->transformMsg( $input, $options, $title );
504 } elseif ( isset( $opts['section'] ) ) {
505 $section = $opts['section'];
506 $out = $parser->getSection( $input, $section );
507 } elseif ( isset( $opts['replace'] ) ) {
508 $section = $opts['replace'][0];
509 $replace = $opts['replace'][1];
510 $out = $parser->replaceSection( $input, $section, $replace );
511 } elseif ( isset( $opts['comment'] ) ) {
512 $out = Linker
::formatComment( $input, $title, $local );
513 } elseif ( isset( $opts['preload'] ) ) {
514 $out = $parser->getpreloadText( $input, $title, $options );
516 $output = $parser->parse( $input, $title, $options, true, true, 1337 );
517 $out = $output->getText();
519 if ( isset( $opts['showtitle'] ) ) {
520 if ( $output->getTitleText() ) {
521 $title = $output->getTitleText();
524 $out = "$title\n$out";
527 if ( isset( $opts['ill'] ) ) {
528 $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
529 } elseif ( isset( $opts['cat'] ) ) {
530 $outputPage = $context->getOutput();
531 $outputPage->addCategoryLinks( $output->getCategories() );
532 $cats = $outputPage->getCategoryLinks();
534 if ( isset( $cats['normal'] ) ) {
535 $out = $this->tidy( implode( ' ', $cats['normal'] ) );
540 $parser->mPreprocessor
= null;
542 $result = $this->tidy( $result );
545 $this->teardownGlobals();
547 $this->assertEquals( $result, $out, $desc );
551 * Run a fuzz test series
552 * Draw input from a set of test files
554 * @todo @fixme Needs some work to not eat memory until the world explodes
558 function testFuzzTests() {
559 global $wgParserTestFiles;
561 $files = $wgParserTestFiles;
563 if( $this->getCliArg( 'file=' ) ) {
564 $files = array( $this->getCliArg( 'file=' ) );
567 $dict = $this->getFuzzInput( $files );
568 $dictSize = strlen( $dict );
569 $logMaxLength = log( $this->maxFuzzTestLength
);
571 ini_set( 'memory_limit', $this->memoryLimit
* 1048576 );
574 $opts = ParserOptions
::newFromUser( $user );
575 $title = Title
::makeTitle( NS_MAIN
, 'Parser_test' );
581 // Generate test input
582 mt_srand( ++
$this->fuzzSeed
);
583 $totalLength = mt_rand( 1, $this->maxFuzzTestLength
);
586 while ( strlen( $input ) < $totalLength ) {
587 $logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
588 $hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
589 $offset = mt_rand( 0, $dictSize - $hairLength );
590 $input .= substr( $dict, $offset, $hairLength );
593 $this->setupGlobals();
594 $parser = $this->getParser();
598 $parser->parse( $input, $title, $opts );
599 $this->assertTrue( true, "Test $id, fuzz seed {$this->fuzzSeed}" );
600 } catch ( Exception
$exception ) {
601 $input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
603 $this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\nInput: $input_dump\n\nError: {$exception->getMessage()}\n\nBacktrace: {$exception->getTraceAsString()}" );
606 $this->teardownGlobals();
607 $parser->__destruct();
609 if ( $id %
100 == 0 ) {
610 $usage = intval( memory_get_usage( true ) / $this->memoryLimit
/ 1048576 * 100 );
611 //echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
613 $ret = "Out of memory:\n";
614 $memStats = $this->getMemoryBreakdown();
616 foreach ( $memStats as $name => $usage ) {
617 $ret .= "$name: $usage\n";
620 throw new MWException( $ret );
629 //Various getter functions
632 * Get an input dictionary from a set of parser test files
634 function getFuzzInput( $filenames ) {
637 foreach ( $filenames as $filename ) {
638 $contents = file_get_contents( $filename );
639 preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
641 foreach ( $matches[1] as $match ) {
642 $dict .= $match . "\n";
650 * Get a memory usage breakdown
652 function getMemoryBreakdown() {
655 foreach ( $GLOBALS as $name => $value ) {
656 $memStats['$' . $name] = strlen( serialize( $value ) );
659 $classes = get_declared_classes();
661 foreach ( $classes as $class ) {
662 $rc = new ReflectionClass( $class );
663 $props = $rc->getStaticProperties();
664 $memStats[$class] = strlen( serialize( $props ) );
665 $methods = $rc->getMethods();
667 foreach ( $methods as $method ) {
668 $memStats[$class] +
= strlen( serialize( $method->getStaticVariables() ) );
672 $functions = get_defined_functions();
674 foreach ( $functions['user'] as $function ) {
675 $rf = new ReflectionFunction( $function );
676 $memStats["$function()"] = strlen( serialize( $rf->getStaticVariables() ) );
685 * Get a Parser object
687 function getParser( $preprocessor = null ) {
688 global $wgParserConf;
690 $class = $wgParserConf['class'];
691 $parser = new $class( array( 'preprocessorClass' => $preprocessor ) +
$wgParserConf );
693 wfRunHooks( 'ParserTestParser', array( &$parser ) );
698 //Various action functions
700 public function addArticle( $name, $text, $line ) {
701 self
::$articles[$name] = array( $text, $line );
704 public function publishTestArticles() {
705 if ( empty( self
::$articles ) ) {
709 foreach ( self
::$articles as $name => $info ) {
710 list( $text, $line ) = $info;
711 self
::injectArticle( $name, $text, $line, 'ignoreduplicate' );
716 * Insert a temporary test article
717 * @param $name String: the title, including any prefix
718 * @param $text String: the article text
719 * @param $line Integer: the input line number, for reporting errors
720 * @param $ignoreDuplicate Boolean: whether to silently ignore duplicate pages
722 private static function injectArticle( $name, $text, $line = 'unknown', $ignoreDuplicate = '' ) {
723 global $wgCapitalLinks;
725 $oldCapitalLinks = $wgCapitalLinks;
726 $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637
728 $text = TestFileIterator
::chomp( $text );
729 $name = TestFileIterator
::chomp( $name );
731 $title = Title
::newFromText( $name );
733 if ( is_null( $title ) ) {
734 throw new MWException( "invalid title '$name' at line $line\n" );
737 $page = WikiPage
::factory( $title );
738 $page->loadPageData( 'fromdbmaster' );
740 if ( $page->exists() ) {
741 if ( $ignoreDuplicate == 'ignoreduplicate' ) {
744 throw new MWException( "duplicate article '$name' at line $line\n" );
748 $page->doEdit( $text, '', EDIT_NEW
);
750 $wgCapitalLinks = $oldCapitalLinks;
755 * Steal a callback function from the primary parser, save it for
756 * application to our scary parser. If the hook is not installed,
757 * abort processing of this file.
759 * @param $name String
760 * @return Bool true if tag hook is present
762 public function requireHook( $name ) {
764 $wgParser->firstCallInit( ); // make sure hooks are loaded.
765 return isset( $wgParser->mTagHooks
[$name] );
768 public function requireFunctionHook( $name ) {
770 $wgParser->firstCallInit( ); // make sure hooks are loaded.
771 return isset( $wgParser->mFunctionHooks
[$name] );
773 //Various "cleanup" functions
776 * Run the "tidy" command on text if the $wgUseTidy
779 * @param $text String: the text to tidy
782 protected function tidy( $text ) {
786 $text = MWTidy
::tidy( $text );
793 * Remove last character if it is a newline
795 public function removeEndingNewline( $s ) {
796 if ( substr( $s, -1 ) === "\n" ) {
797 return substr( $s, 0, -1 );
804 public function showRunFile( $file ) {
808 //Test options parser functions
810 protected function parseOptions( $instring ) {
816 // foo=bar,"baz quux"
840 \[\[[^]]*\]\] # Link target
848 if ( preg_match_all( $regex, $instring, $matches, PREG_SET_ORDER
) ) {
849 foreach ( $matches as $bits ) {
850 array_shift( $bits );
851 $key = strtolower( array_shift( $bits ) );
852 if ( count( $bits ) == 0 ) {
854 } elseif ( count( $bits ) == 1 ) {
855 $opts[$key] = $this->cleanupOption( array_shift( $bits ) );
858 $opts[$key] = array_map( array( $this, 'cleanupOption' ), $bits );
865 protected function cleanupOption( $opt ) {
866 if ( substr( $opt, 0, 1 ) == '"' ) {
867 return substr( $opt, 1, -1 );
870 if ( substr( $opt, 0, 2 ) == '[[' ) {
871 return substr( $opt, 2, -2 );
877 * Use a regex to find out the value of an option
878 * @param $key String: name of option val to retrieve
879 * @param $opts Options array to look in
880 * @param $default Mixed: default value returned if not found
882 protected static function getOptionValue( $key, $opts, $default ) {
883 $key = strtolower( $key );
885 if ( isset( $opts[$key] ) ) {
892 public static function getFakeTimestamp( &$parser, &$ts ) {