2011-01-01 03:39:37 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2011-05-31 20:35:35 +00:00
|
|
|
* Although marked as a stub, can work independently.
|
|
|
|
|
*
|
2011-01-01 03:39:37 +00:00
|
|
|
* @group Database
|
2011-02-26 21:49:42 +00:00
|
|
|
* @group Parser
|
2011-05-31 20:35:35 +00:00
|
|
|
* @group Stub
|
2013-10-22 23:50:38 +00:00
|
|
|
*
|
|
|
|
|
* @todo covers tags
|
2011-01-01 03:39:37 +00:00
|
|
|
*/
|
|
|
|
|
class NewParserTest extends MediaWikiTestCase {
|
2016-02-17 09:09:32 +00:00
|
|
|
static protected $articles = []; // Array of test articles defined by the tests
|
2012-10-08 10:56:20 +00:00
|
|
|
/* The data provider is run on a different instance than the test, so it must be static
|
2011-02-26 21:49:42 +00:00
|
|
|
* When running tests from several files, all tests will see all articles.
|
|
|
|
|
*/
|
2012-01-28 01:20:42 +00:00
|
|
|
static protected $backendToUse;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
public $keepUploads = false;
|
|
|
|
|
public $runDisabled = false;
|
2013-02-23 04:26:08 +00:00
|
|
|
public $runParsoid = false;
|
2011-01-01 03:39:37 +00:00
|
|
|
public $regex = '';
|
|
|
|
|
public $showProgress = true;
|
2016-02-17 09:09:32 +00:00
|
|
|
public $savedWeirdGlobals = [];
|
|
|
|
|
public $savedGlobals = [];
|
|
|
|
|
public $hooks = [];
|
|
|
|
|
public $functionHooks = [];
|
|
|
|
|
public $transparentHooks = [];
|
2011-01-10 18:43:59 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Fuzz test
|
2011-01-01 18:10:28 +00:00
|
|
|
public $maxFuzzTestLength = 300;
|
|
|
|
|
public $fuzzSeed = 0;
|
|
|
|
|
public $memoryLimit = 50;
|
2011-01-10 18:43:59 +00:00
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
/**
|
|
|
|
|
* @var DjVuSupport
|
|
|
|
|
*/
|
|
|
|
|
private $djVuSupport;
|
2014-05-18 07:17:25 +00:00
|
|
|
/**
|
|
|
|
|
* @var TidySupport
|
|
|
|
|
*/
|
|
|
|
|
private $tidySupport;
|
2013-12-18 17:56:15 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
protected $file = false;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2013-05-20 13:21:02 +00:00
|
|
|
public static function setUpBeforeClass() {
|
|
|
|
|
// Inject ParserTest well-known interwikis
|
|
|
|
|
ParserTest::setupInterwikis();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2013-10-02 19:28:37 +00:00
|
|
|
global $wgNamespaceAliases, $wgContLang;
|
2011-02-26 21:49:42 +00:00
|
|
|
global $wgHooks, $IP;
|
2012-11-05 10:10:42 +00:00
|
|
|
|
2012-10-22 23:53:51 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Setup CLI arguments
|
2014-05-05 16:10:07 +00:00
|
|
|
if ( $this->getCliArg( 'regex' ) ) {
|
|
|
|
|
$this->regex = $this->getCliArg( 'regex' );
|
2011-01-01 05:53:04 +00:00
|
|
|
} else {
|
|
|
|
|
# Matches anything
|
|
|
|
|
$this->regex = '';
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 05:53:04 +00:00
|
|
|
$this->keepUploads = $this->getCliArg( 'keep-uploads' );
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals = [];
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2013-02-18 17:58:35 +00:00
|
|
|
$tmpGlobals['wgLanguageCode'] = 'en';
|
|
|
|
|
$tmpGlobals['wgContLang'] = Language::factory( 'en' );
|
2013-04-20 20:15:20 +00:00
|
|
|
$tmpGlobals['wgSitename'] = 'MediaWiki';
|
|
|
|
|
$tmpGlobals['wgServer'] = 'http://example.org';
|
2014-05-06 09:31:24 +00:00
|
|
|
$tmpGlobals['wgServerName'] = 'example.org';
|
2016-02-23 02:13:11 +00:00
|
|
|
$tmpGlobals['wgScriptPath'] = '';
|
2011-01-01 22:16:54 +00:00
|
|
|
$tmpGlobals['wgScript'] = '/index.php';
|
2016-02-23 02:13:11 +00:00
|
|
|
$tmpGlobals['wgResourceBasePath'] = '';
|
|
|
|
|
$tmpGlobals['wgStylePath'] = '/skins';
|
|
|
|
|
$tmpGlobals['wgExtensionAssetsPath'] = '/extensions';
|
2011-01-01 22:16:54 +00:00
|
|
|
$tmpGlobals['wgArticlePath'] = '/wiki/$1';
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals['wgActionPaths'] = [];
|
2013-04-20 20:15:20 +00:00
|
|
|
$tmpGlobals['wgVariantArticlePath'] = false;
|
|
|
|
|
$tmpGlobals['wgEnableUploads'] = true;
|
2014-08-08 19:44:01 +00:00
|
|
|
$tmpGlobals['wgUploadNavigationUrl'] = false;
|
2011-01-01 22:16:54 +00:00
|
|
|
$tmpGlobals['wgThumbnailScriptPath'] = false;
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals['wgLocalFileRepo'] = [
|
2013-02-15 10:24:31 +00:00
|
|
|
'class' => 'LocalRepo',
|
|
|
|
|
'name' => 'local',
|
|
|
|
|
'url' => 'http://example.com/images',
|
|
|
|
|
'hashLevels' => 2,
|
2011-01-01 03:39:37 +00:00
|
|
|
'transformVia404' => false,
|
2013-02-15 10:24:31 +00:00
|
|
|
'backend' => 'local-backend'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
|
|
|
|
$tmpGlobals['wgForeignFileRepos'] = [];
|
|
|
|
|
$tmpGlobals['wgDefaultExternalStore'] = [];
|
2015-05-19 21:47:33 +00:00
|
|
|
$tmpGlobals['wgParserCacheType'] = CACHE_NONE;
|
2013-04-20 20:15:20 +00:00
|
|
|
$tmpGlobals['wgCapitalLinks'] = true;
|
|
|
|
|
$tmpGlobals['wgNoFollowLinks'] = true;
|
2016-06-01 05:20:36 +00:00
|
|
|
$tmpGlobals['wgNoFollowDomainExceptions'] = [ 'no-nofollow.org' ];
|
2013-04-20 20:15:20 +00:00
|
|
|
$tmpGlobals['wgExternalLinkTarget'] = false;
|
|
|
|
|
$tmpGlobals['wgThumbnailScriptPath'] = false;
|
|
|
|
|
$tmpGlobals['wgUseImageResize'] = true;
|
|
|
|
|
$tmpGlobals['wgAllowExternalImages'] = true;
|
|
|
|
|
$tmpGlobals['wgRawHtml'] = false;
|
|
|
|
|
$tmpGlobals['wgExperimentalHtmlIds'] = false;
|
|
|
|
|
$tmpGlobals['wgAdaptiveMessageCache'] = true;
|
|
|
|
|
$tmpGlobals['wgUseDatabaseMessages'] = true;
|
|
|
|
|
$tmpGlobals['wgLocaltimezone'] = 'UTC';
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals['wgGroupPermissions'] = [
|
|
|
|
|
'*' => [
|
2013-04-20 20:15:20 +00:00
|
|
|
'createaccount' => true,
|
|
|
|
|
'read' => true,
|
|
|
|
|
'edit' => true,
|
|
|
|
|
'createpage' => true,
|
|
|
|
|
'createtalk' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
] ];
|
|
|
|
|
$tmpGlobals['wgNamespaceProtection'] = [ NS_MEDIAWIKI => 'editinterface' ];
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2013-07-16 18:06:04 +00:00
|
|
|
$tmpGlobals['wgParser'] = new StubObject(
|
|
|
|
|
'wgParser', $GLOBALS['wgParserConf']['class'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $GLOBALS['wgParserConf'] ] );
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2013-05-24 12:56:06 +00:00
|
|
|
$tmpGlobals['wgFileExtensions'][] = 'svg';
|
|
|
|
|
$tmpGlobals['wgSVGConverter'] = 'rsvg';
|
2013-07-16 18:06:04 +00:00
|
|
|
$tmpGlobals['wgSVGConverters']['rsvg'] =
|
2015-02-05 18:14:34 +00:00
|
|
|
'$path/rsvg-convert -w $width -h $height -o $output $input';
|
2013-05-24 12:56:06 +00:00
|
|
|
|
2011-01-01 22:16:54 +00:00
|
|
|
if ( $GLOBALS['wgStyleDirectory'] === false ) {
|
|
|
|
|
$tmpGlobals['wgStyleDirectory'] = "$IP/skins";
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2013-04-28 21:13:49 +00:00
|
|
|
# Replace all media handlers with a mock. We do not need to generate
|
|
|
|
|
# actual thumbnails to do parser testing, we only care about receiving
|
|
|
|
|
# a ThumbnailImage properly initialized.
|
|
|
|
|
global $wgMediaHandlers;
|
2013-05-17 14:47:00 +00:00
|
|
|
foreach ( $wgMediaHandlers as $type => $handler ) {
|
2013-04-28 21:13:49 +00:00
|
|
|
$tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
|
|
|
|
|
}
|
2013-05-24 12:56:06 +00:00
|
|
|
// Vector images have to be handled slightly differently
|
|
|
|
|
$tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
|
2013-04-28 21:13:49 +00:00
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
// DjVu images have to be handled slightly differently
|
|
|
|
|
$tmpGlobals['wgMediaHandlers']['image/vnd.djvu'] = 'MockDjVuHandler';
|
|
|
|
|
|
2016-02-12 15:31:58 +00:00
|
|
|
// Ogg video/audio increasingly more differently
|
|
|
|
|
$tmpGlobals['wgMediaHandlers']['application/ogg'] = 'MockOggHandler';
|
|
|
|
|
|
2013-04-20 20:15:20 +00:00
|
|
|
$tmpHooks = $wgHooks;
|
|
|
|
|
$tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
|
|
|
|
|
$tmpHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
|
|
|
|
|
$tmpGlobals['wgHooks'] = $tmpHooks;
|
2013-10-02 19:28:37 +00:00
|
|
|
# add a namespace shadowing a interwiki link, to test
|
|
|
|
|
# proper precedence when resolving links. (bug 51680)
|
2016-05-12 18:35:20 +00:00
|
|
|
$tmpGlobals['wgExtraNamespaces'] = [
|
|
|
|
|
100 => 'MemoryAlpha',
|
|
|
|
|
101 => 'MemoryAlpha_talk'
|
|
|
|
|
];
|
2011-01-01 22:16:54 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals['wgLocalInterwikis'] = [ 'local', 'mi' ];
|
2014-06-26 21:50:46 +00:00
|
|
|
# "extra language links"
|
|
|
|
|
# see https://gerrit.wikimedia.org/r/111390
|
2016-02-17 09:09:32 +00:00
|
|
|
$tmpGlobals['wgExtraInterlanguageLinkPrefixes'] = [ 'mul' ];
|
2014-06-26 21:50:46 +00:00
|
|
|
|
2014-05-18 07:17:25 +00:00
|
|
|
// DjVu support
|
2013-12-18 17:56:15 +00:00
|
|
|
$this->djVuSupport = new DjVuSupport();
|
2014-05-18 07:17:25 +00:00
|
|
|
// Tidy support
|
|
|
|
|
$this->tidySupport = new TidySupport();
|
2016-04-07 02:24:29 +00:00
|
|
|
$tmpGlobals['wgTidyConfig'] = $this->tidySupport->getConfig();
|
2014-05-18 07:17:25 +00:00
|
|
|
$tmpGlobals['wgUseTidy'] = false;
|
2013-12-18 17:56:15 +00:00
|
|
|
|
2013-04-20 20:15:20 +00:00
|
|
|
$this->setMwGlobals( $tmpGlobals );
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 22:16:54 +00:00
|
|
|
$this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
|
|
|
|
|
$this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 22:16:54 +00:00
|
|
|
$wgNamespaceAliases['Image'] = NS_FILE;
|
|
|
|
|
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
|
2013-10-02 19:28:37 +00:00
|
|
|
|
|
|
|
|
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
|
|
|
|
|
$wgContLang->resetNamespaces(); # reset namespace cache
|
2016-04-25 05:41:32 +00:00
|
|
|
ParserTest::resetTitleServices();
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function tearDown() {
|
2013-10-02 19:28:37 +00:00
|
|
|
global $wgNamespaceAliases, $wgContLang;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 22:16:54 +00:00
|
|
|
$wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
|
|
|
|
|
$wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2015-08-31 04:42:55 +00:00
|
|
|
MWTidy::destroySingleton();
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
// Restore backends
|
|
|
|
|
RepoGroup::destroySingleton();
|
2012-01-07 01:33:23 +00:00
|
|
|
FileBackendGroup::destroySingleton();
|
2012-10-22 23:53:51 +00:00
|
|
|
|
2013-05-04 12:21:39 +00:00
|
|
|
// Remove temporary pages from the link cache
|
|
|
|
|
LinkCache::singleton()->clear();
|
|
|
|
|
|
|
|
|
|
// Restore message cache (temporary pages and $wgUseDatabaseMessages)
|
|
|
|
|
MessageCache::destroyInstance();
|
|
|
|
|
|
2012-10-22 23:53:51 +00:00
|
|
|
parent::tearDown();
|
2013-10-02 19:28:37 +00:00
|
|
|
|
|
|
|
|
MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
|
|
|
|
|
$wgContLang->resetNamespaces(); # reset namespace cache
|
2011-01-01 20:57:13 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2013-08-22 18:38:50 +00:00
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
|
ParserTest::tearDownInterwikis();
|
|
|
|
|
parent::tearDownAfterClass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 17:26:25 +00:00
|
|
|
function addDBDataOnce() {
|
2012-01-25 23:11:53 +00:00
|
|
|
# disabled for performance
|
2015-09-11 13:44:59 +00:00
|
|
|
# $this->tablesUsed[] = 'image';
|
2012-01-25 23:11:53 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
# Update certain things in site_stats
|
2011-07-25 22:01:19 +00:00
|
|
|
$this->db->insert( 'site_stats',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ],
|
2016-03-07 17:26:25 +00:00
|
|
|
__METHOD__,
|
|
|
|
|
[ 'IGNORE' ]
|
2012-01-25 23:11:53 +00:00
|
|
|
);
|
2011-01-01 20:57:13 +00:00
|
|
|
|
|
|
|
|
$user = User::newFromId( 0 );
|
2011-02-26 21:49:42 +00:00
|
|
|
LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
# Upload DB table entries for files.
|
|
|
|
|
# We will upload the actual files later. Note that if anything causes LocalFile::load()
|
|
|
|
|
# to be triggered before then, it will break via maybeUpgrade() setting the fileExists
|
|
|
|
|
# member to false and storing it in cache.
|
2013-02-27 00:12:12 +00:00
|
|
|
# note that the size/width/height/bits/etc of the file
|
|
|
|
|
# are actually set by inspecting the file itself; the arguments
|
|
|
|
|
# to recordUpload2 have no effect. That said, we try to make things
|
|
|
|
|
# match up so it is less confusing to readers of the code & tests.
|
2011-01-01 20:57:13 +00:00
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
2012-01-25 23:11:53 +00:00
|
|
|
$image->recordUpload2(
|
|
|
|
|
'', // archive name
|
2012-08-16 08:00:45 +00:00
|
|
|
'Upload of some lame file',
|
2012-01-25 23:11:53 +00:00
|
|
|
'Some lame file',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-02-27 00:12:12 +00:00
|
|
|
'size' => 7881,
|
2013-02-15 10:24:31 +00:00
|
|
|
'width' => 1941,
|
|
|
|
|
'height' => 220,
|
2013-02-27 00:12:12 +00:00
|
|
|
'bits' => 8,
|
2013-02-15 10:24:31 +00:00
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/jpeg',
|
2016-02-17 09:09:32 +00:00
|
|
|
'metadata' => serialize( [] ),
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '1', 16, 36, 31 ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'fileExists' => true ],
|
2012-01-25 23:11:53 +00:00
|
|
|
$this->db->timestamp( '20010115123500' ), $user
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-01-01 20:57:13 +00:00
|
|
|
|
2013-02-27 00:12:12 +00:00
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Thumb.png' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
2013-02-27 00:12:12 +00:00
|
|
|
$image->recordUpload2(
|
|
|
|
|
'', // archive name
|
|
|
|
|
'Upload of some lame thumbnail',
|
|
|
|
|
'Some lame thumbnail',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-02-27 00:12:12 +00:00
|
|
|
'size' => 22589,
|
|
|
|
|
'width' => 135,
|
|
|
|
|
'height' => 135,
|
|
|
|
|
'bits' => 8,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/png',
|
2016-02-17 09:09:32 +00:00
|
|
|
'metadata' => serialize( [] ),
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '2', 16, 36, 31 ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'fileExists' => true ],
|
2013-02-27 00:12:12 +00:00
|
|
|
$this->db->timestamp( '20130225203040' ), $user
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
# This image will be blacklisted in [[MediaWiki:Bad image list]]
|
|
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
2012-01-25 23:11:53 +00:00
|
|
|
$image->recordUpload2(
|
|
|
|
|
'', // archive name
|
2012-08-16 08:00:45 +00:00
|
|
|
'zomgnotcensored',
|
|
|
|
|
'Borderline image',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2013-02-15 10:24:31 +00:00
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 320,
|
|
|
|
|
'height' => 240,
|
|
|
|
|
'bits' => 24,
|
|
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/jpeg',
|
2016-02-17 09:09:32 +00:00
|
|
|
'metadata' => serialize( [] ),
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '3', 16, 36, 31 ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'fileExists' => true ],
|
2012-01-25 23:11:53 +00:00
|
|
|
$this->db->timestamp( '20010115123500' ), $user
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-05-24 12:56:06 +00:00
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.svg' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
|
|
|
|
$image->recordUpload2( '', 'Upload of some lame SVG', 'Some lame SVG', [
|
2013-05-24 12:56:06 +00:00
|
|
|
'size' => 12345,
|
2014-03-18 17:00:11 +00:00
|
|
|
'width' => 240,
|
|
|
|
|
'height' => 180,
|
2014-06-03 19:44:53 +00:00
|
|
|
'bits' => 0,
|
2013-05-24 12:56:06 +00:00
|
|
|
'media_type' => MEDIATYPE_DRAWING,
|
|
|
|
|
'mime' => 'image/svg+xml',
|
2016-02-17 09:09:32 +00:00
|
|
|
'metadata' => serialize( [] ),
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
2013-05-24 12:56:06 +00:00
|
|
|
'fileExists' => true
|
2016-02-17 09:09:32 +00:00
|
|
|
], $this->db->timestamp( '20010115123500' ), $user );
|
2013-05-24 12:56:06 +00:00
|
|
|
}
|
2013-12-18 17:56:15 +00:00
|
|
|
|
2016-01-07 08:41:23 +00:00
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Video.ogv' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
|
|
|
|
$image->recordUpload2( '', 'A pretty movie', 'Will it play', [
|
2016-01-07 08:41:23 +00:00
|
|
|
'size' => 12345,
|
2016-02-12 15:31:58 +00:00
|
|
|
'width' => 320,
|
|
|
|
|
'height' => 240,
|
2016-01-07 08:41:23 +00:00
|
|
|
'bits' => 0,
|
|
|
|
|
'media_type' => MEDIATYPE_VIDEO,
|
|
|
|
|
'mime' => 'application/ogg',
|
2016-02-17 09:09:32 +00:00
|
|
|
'metadata' => serialize( [] ),
|
2016-02-12 15:31:58 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 32 ),
|
2016-01-07 08:41:23 +00:00
|
|
|
'fileExists' => true
|
2016-02-17 09:09:32 +00:00
|
|
|
], $this->db->timestamp( '20010115123500' ), $user );
|
2016-01-07 08:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2016-05-18 15:48:04 +00:00
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Audio.oga' ) );
|
|
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
|
|
|
|
$image->recordUpload2( '', 'An awesome hitsong ', 'Will it play', [
|
|
|
|
|
'size' => 12345,
|
|
|
|
|
'width' => 0,
|
|
|
|
|
'height' => 0,
|
|
|
|
|
'bits' => 0,
|
|
|
|
|
'media_type' => MEDIATYPE_AUDIO,
|
|
|
|
|
'mime' => 'application/ogg',
|
|
|
|
|
'metadata' => serialize( [] ),
|
|
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 32 ),
|
|
|
|
|
'fileExists' => true
|
|
|
|
|
], $this->db->timestamp( '20010115123500' ), $user );
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
# A DjVu file
|
|
|
|
|
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$this->db->selectField( 'image', '1', [ 'img_name' => $image->getName() ] ) ) {
|
|
|
|
|
$image->recordUpload2( '', 'Upload a DjVu', 'A DjVu', [
|
2013-12-18 17:56:15 +00:00
|
|
|
'size' => 3249,
|
|
|
|
|
'width' => 2480,
|
|
|
|
|
'height' => 3508,
|
2014-06-03 19:44:53 +00:00
|
|
|
'bits' => 0,
|
2013-12-18 17:56:15 +00:00
|
|
|
'media_type' => MEDIATYPE_BITMAP,
|
|
|
|
|
'mime' => 'image/vnd.djvu',
|
|
|
|
|
'metadata' => '<?xml version="1.0" ?>
|
|
|
|
|
<!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
|
|
|
|
|
<DjVuXML>
|
|
|
|
|
<HEAD></HEAD>
|
|
|
|
|
<BODY><OBJECT height="3508" width="2480">
|
|
|
|
|
<PARAM name="DPI" value="300" />
|
|
|
|
|
<PARAM name="GAMMA" value="2.2" />
|
|
|
|
|
</OBJECT>
|
|
|
|
|
<OBJECT height="3508" width="2480">
|
|
|
|
|
<PARAM name="DPI" value="300" />
|
|
|
|
|
<PARAM name="GAMMA" value="2.2" />
|
|
|
|
|
</OBJECT>
|
|
|
|
|
<OBJECT height="3508" width="2480">
|
|
|
|
|
<PARAM name="DPI" value="300" />
|
|
|
|
|
<PARAM name="GAMMA" value="2.2" />
|
|
|
|
|
</OBJECT>
|
|
|
|
|
<OBJECT height="3508" width="2480">
|
|
|
|
|
<PARAM name="DPI" value="300" />
|
|
|
|
|
<PARAM name="GAMMA" value="2.2" />
|
|
|
|
|
</OBJECT>
|
|
|
|
|
<OBJECT height="3508" width="2480">
|
|
|
|
|
<PARAM name="DPI" value="300" />
|
|
|
|
|
<PARAM name="GAMMA" value="2.2" />
|
|
|
|
|
</OBJECT>
|
|
|
|
|
</BODY>
|
|
|
|
|
</DjVuXML>',
|
2015-11-24 22:51:42 +00:00
|
|
|
'sha1' => Wikimedia\base_convert( '', 16, 36, 31 ),
|
2013-12-18 17:56:15 +00:00
|
|
|
'fileExists' => true
|
2016-02-17 09:09:32 +00:00
|
|
|
], $this->db->timestamp( '20140115123600' ), $user );
|
2013-12-18 17:56:15 +00:00
|
|
|
}
|
2011-01-01 20:57:13 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// ParserTest setup/teardown functions
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
/**
|
|
|
|
|
* Set up the global variables for a consistent environment for each test.
|
|
|
|
|
* Ideally this should replace the global configuration entirely.
|
2014-08-25 16:50:35 +00:00
|
|
|
* @param array $opts
|
|
|
|
|
* @param string $config
|
|
|
|
|
* @return RequestContext
|
2011-01-01 03:39:37 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected function setupGlobals( $opts = [], $config = '' ) {
|
2012-01-28 01:20:42 +00:00
|
|
|
global $wgFileBackends;
|
2011-01-01 03:39:37 +00:00
|
|
|
# Find out values for some special options.
|
|
|
|
|
$lang =
|
|
|
|
|
self::getOptionValue( 'language', $opts, 'en' );
|
|
|
|
|
$variant =
|
|
|
|
|
self::getOptionValue( 'variant', $opts, false );
|
|
|
|
|
$maxtoclevel =
|
|
|
|
|
self::getOptionValue( 'wgMaxTocLevel', $opts, 999 );
|
|
|
|
|
$linkHolderBatchSize =
|
|
|
|
|
self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
|
|
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
$uploadDir = $this->getUploadDir();
|
2014-05-05 16:10:07 +00:00
|
|
|
if ( $this->getCliArg( 'use-filebackend' ) ) {
|
2012-01-28 01:20:42 +00:00
|
|
|
if ( self::$backendToUse ) {
|
|
|
|
|
$backend = self::$backendToUse;
|
|
|
|
|
} else {
|
2014-05-05 16:10:07 +00:00
|
|
|
$name = $this->getCliArg( 'use-filebackend' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$useConfig = [];
|
2012-01-28 01:20:42 +00:00
|
|
|
foreach ( $wgFileBackends as $conf ) {
|
|
|
|
|
if ( $conf['name'] == $name ) {
|
|
|
|
|
$useConfig = $conf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$useConfig['name'] = 'local-backend'; // swap name
|
2013-12-03 20:55:44 +00:00
|
|
|
unset( $useConfig['lockManager'] );
|
|
|
|
|
unset( $useConfig['fileJournal'] );
|
2013-12-19 01:41:02 +00:00
|
|
|
$class = $useConfig['class'];
|
2012-01-28 01:20:42 +00:00
|
|
|
self::$backendToUse = new $class( $useConfig );
|
|
|
|
|
$backend = self::$backendToUse;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-04-28 21:13:49 +00:00
|
|
|
# Replace with a mock. We do not care about generating real
|
|
|
|
|
# files on the filesystem, just need to expose the file
|
|
|
|
|
# informations.
|
2016-02-17 09:09:32 +00:00
|
|
|
$backend = new MockFileBackend( [
|
2013-02-15 10:24:31 +00:00
|
|
|
'name' => 'local-backend',
|
2016-03-19 00:08:06 +00:00
|
|
|
'wikiId' => wfWikiID()
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-01-28 01:20:42 +00:00
|
|
|
}
|
2012-01-25 23:11:53 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$settings = [
|
|
|
|
|
'wgLocalFileRepo' => [
|
2013-02-15 10:24:31 +00:00
|
|
|
'class' => 'LocalRepo',
|
|
|
|
|
'name' => 'local',
|
|
|
|
|
'url' => 'http://example.com/images',
|
|
|
|
|
'hashLevels' => 2,
|
2011-01-01 03:39:37 +00:00
|
|
|
'transformVia404' => false,
|
2013-02-15 10:24:31 +00:00
|
|
|
'backend' => $backend
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2011-01-01 03:39:37 +00:00
|
|
|
'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
|
|
|
|
|
'wgLanguageCode' => $lang,
|
|
|
|
|
'wgDBprefix' => $this->db->getType() != 'oracle' ? 'unittest_' : 'ut_',
|
2013-07-10 22:10:14 +00:00
|
|
|
'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'wgNamespacesWithSubpages' => [ NS_MAIN => isset( $opts['subpage'] ) ],
|
2013-07-10 22:10:14 +00:00
|
|
|
'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'wgThumbLimits' => [ self::getOptionValue( 'thumbsize', $opts, 180 ) ],
|
2011-01-01 03:39:37 +00:00
|
|
|
'wgMaxTocLevel' => $maxtoclevel,
|
2013-06-21 15:39:29 +00:00
|
|
|
'wgUseTeX' => isset( $opts['math'] ) || isset( $opts['texvc'] ),
|
2012-01-25 23:11:53 +00:00
|
|
|
'wgMathDirectory' => $uploadDir . '/math',
|
2011-01-01 03:39:37 +00:00
|
|
|
'wgDefaultLanguageVariant' => $variant,
|
|
|
|
|
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
|
2016-04-07 02:24:29 +00:00
|
|
|
'wgUseTidy' => false,
|
|
|
|
|
'wgTidyConfig' => isset( $opts['tidy'] ) ? $this->tidySupport->getConfig() : null
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-01-01 03:39:37 +00:00
|
|
|
|
|
|
|
|
if ( $config ) {
|
|
|
|
|
$configLines = explode( "\n", $config );
|
|
|
|
|
|
|
|
|
|
foreach ( $configLines as $line ) {
|
|
|
|
|
list( $var, $value ) = explode( '=', $line, 2 );
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
$settings[$var] = eval( "return $value;" ); // ???
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->savedGlobals = [];
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2012-08-13 22:18:50 +00:00
|
|
|
/** @since 1.20 */
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ParserTestGlobals', [ &$settings ] );
|
2012-08-13 22:18:50 +00:00
|
|
|
|
2013-04-20 20:15:20 +00:00
|
|
|
$langObj = Language::factory( $lang );
|
|
|
|
|
$settings['wgContLang'] = $langObj;
|
|
|
|
|
$settings['wgLang'] = $langObj;
|
|
|
|
|
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$settings['wgOut'] = $context->getOutput();
|
|
|
|
|
$settings['wgUser'] = $context->getUser();
|
|
|
|
|
$settings['wgRequest'] = $context->getRequest();
|
|
|
|
|
|
2014-03-19 18:51:21 +00:00
|
|
|
// We (re)set $wgThumbLimits to a single-element array above.
|
|
|
|
|
$context->getUser()->setOption( 'thumbsize', 0 );
|
|
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
foreach ( $settings as $var => $val ) {
|
|
|
|
|
if ( array_key_exists( $var, $GLOBALS ) ) {
|
|
|
|
|
$this->savedGlobals[$var] = $GLOBALS[$var];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$GLOBALS[$var] = $val;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 04:42:55 +00:00
|
|
|
MWTidy::destroySingleton();
|
2011-01-01 03:39:37 +00:00
|
|
|
MagicWord::clearCache();
|
2013-05-04 12:21:39 +00:00
|
|
|
|
|
|
|
|
# The entries saved into RepoGroup cache with previous globals will be wrong.
|
2011-12-20 03:52:06 +00:00
|
|
|
RepoGroup::destroySingleton();
|
2012-01-07 01:33:23 +00:00
|
|
|
FileBackendGroup::destroySingleton();
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
# Create dummy files in storage
|
|
|
|
|
$this->setupUploads();
|
|
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
# Publish the articles after we have the final language set
|
|
|
|
|
$this->publishTestArticles();
|
|
|
|
|
|
2012-08-16 08:00:45 +00:00
|
|
|
MessageCache::destroyInstance();
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-11-10 12:49:10 +00:00
|
|
|
return $context;
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
/**
|
2012-01-25 23:11:53 +00:00
|
|
|
* Get an FS upload directory (only applies to FSFileBackend)
|
2011-01-01 20:57:13 +00:00
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @return string The directory
|
2011-01-01 20:57:13 +00:00
|
|
|
*/
|
2012-01-25 23:11:53 +00:00
|
|
|
protected function getUploadDir() {
|
2011-01-01 20:57:13 +00:00
|
|
|
if ( $this->keepUploads ) {
|
2015-02-11 01:42:33 +00:00
|
|
|
// Don't use getNewTempDirectory() as this is meant to persist
|
2011-01-01 20:57:13 +00:00
|
|
|
$dir = wfTempDir() . '/mwParser-images';
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
if ( is_dir( $dir ) ) {
|
|
|
|
|
return $dir;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-02-11 01:42:33 +00:00
|
|
|
$dir = $this->getNewTempDirectory();
|
2011-01-01 20:57:13 +00:00
|
|
|
}
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
if ( file_exists( $dir ) ) {
|
|
|
|
|
wfDebug( "Already exists!\n" );
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
return $dir;
|
|
|
|
|
}
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
return $dir;
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
/**
|
|
|
|
|
* Create a dummy uploads directory which will contain a couple
|
|
|
|
|
* of files in order to pass existence tests.
|
|
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @return string The directory
|
2012-01-25 23:11:53 +00:00
|
|
|
*/
|
|
|
|
|
protected function setupUploads() {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
$base = $this->getBaseDir();
|
|
|
|
|
$backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
|
2016-02-17 09:09:32 +00:00
|
|
|
$backend->prepare( [ 'dir' => "$base/local-public/3/3a" ] );
|
|
|
|
|
$backend->store( [
|
2014-07-24 17:03:17 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
|
|
|
|
|
'dst' => "$base/local-public/3/3a/Foobar.jpg"
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/local-public/e/ea" ] );
|
|
|
|
|
$backend->store( [
|
2014-07-24 17:03:17 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/wiki.png",
|
|
|
|
|
'dst' => "$base/local-public/e/ea/Thumb.png"
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/local-public/0/09" ] );
|
|
|
|
|
$backend->store( [
|
2014-07-24 17:03:17 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/headbg.jpg",
|
|
|
|
|
'dst' => "$base/local-public/0/09/Bad.jpg"
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
|
|
|
|
$backend->prepare( [ 'dir' => "$base/local-public/5/5f" ] );
|
|
|
|
|
$backend->store( [
|
2014-07-24 17:03:17 +00:00
|
|
|
'src' => "$IP/tests/phpunit/data/parser/LoremIpsum.djvu",
|
|
|
|
|
'dst' => "$base/local-public/5/5f/LoremIpsum.djvu"
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2013-05-24 12:56:06 +00:00
|
|
|
|
|
|
|
|
// No helpful SVG file to copy, so make one ourselves
|
2013-12-19 01:41:02 +00:00
|
|
|
$data = '<?xml version="1.0" encoding="utf-8"?>' .
|
2014-03-18 17:00:11 +00:00
|
|
|
'<svg xmlns="http://www.w3.org/2000/svg"' .
|
|
|
|
|
' version="1.1" width="240" height="180"/>';
|
2013-05-24 12:56:06 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$backend->prepare( [ 'dir' => "$base/local-public/f/ff" ] );
|
|
|
|
|
$backend->quickCreate( [
|
2013-12-19 01:41:02 +00:00
|
|
|
'content' => $data, 'dst' => "$base/local-public/f/ff/Foobar.svg"
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-01-25 23:11:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-16 21:07:37 +00:00
|
|
|
/**
|
|
|
|
|
* Restore default values and perform any necessary clean-up
|
|
|
|
|
* after each test runs.
|
|
|
|
|
*/
|
|
|
|
|
protected function teardownGlobals() {
|
2012-01-25 23:11:53 +00:00
|
|
|
$this->teardownUploads();
|
|
|
|
|
|
2011-06-16 21:07:37 +00:00
|
|
|
foreach ( $this->savedGlobals as $var => $val ) {
|
|
|
|
|
$GLOBALS[$var] = $val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the dummy uploads directory
|
|
|
|
|
*/
|
2012-01-25 23:11:53 +00:00
|
|
|
private function teardownUploads() {
|
2011-06-16 21:07:37 +00:00
|
|
|
if ( $this->keepUploads ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-28 21:13:49 +00:00
|
|
|
$backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
|
2013-05-17 14:47:00 +00:00
|
|
|
if ( $backend instanceof MockFileBackend ) {
|
2013-04-28 21:13:49 +00:00
|
|
|
# In memory backend, so dont bother cleaning them up.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
$base = $this->getBaseDir();
|
2011-06-16 21:07:37 +00:00
|
|
|
// delete the files first, then the dirs.
|
|
|
|
|
self::deleteFiles(
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2012-01-25 23:11:53 +00:00
|
|
|
"$base/local-public/3/3a/Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/100px-Foobar.jpg",
|
2012-01-25 23:11:53 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/137px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/1500px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/177px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/206px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/20px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/220px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/265px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/270px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/274px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/300px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/30px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/330px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/353px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/360px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/400px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/40px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/440px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/442px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/450px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/50px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/600px-Foobar.jpg",
|
|
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/70px-Foobar.jpg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/75px-Foobar.jpg",
|
2012-11-16 22:28:39 +00:00
|
|
|
"$base/local-thumb/3/3a/Foobar.jpg/960px-Foobar.jpg",
|
2011-06-16 21:07:37 +00:00
|
|
|
|
2013-02-27 00:12:12 +00:00
|
|
|
"$base/local-public/e/ea/Thumb.png",
|
|
|
|
|
|
2012-01-27 22:57:14 +00:00
|
|
|
"$base/local-public/0/09/Bad.jpg",
|
2011-06-16 21:07:37 +00:00
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
"$base/local-public/5/5f/LoremIpsum.djvu",
|
|
|
|
|
"$base/local-thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
|
|
|
|
|
"$base/local-thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
|
|
|
|
|
"$base/local-thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
|
|
|
|
|
|
2013-05-24 12:56:06 +00:00
|
|
|
"$base/local-public/f/ff/Foobar.svg",
|
2014-03-25 17:13:50 +00:00
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/3000px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/4000px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.png",
|
|
|
|
|
"$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.png",
|
2013-05-24 12:56:06 +00:00
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
"$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2011-06-16 21:07:37 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete the specified files, if they exist.
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param array $files Full paths to files to delete.
|
2011-06-16 21:07:37 +00:00
|
|
|
*/
|
|
|
|
|
private static function deleteFiles( $files ) {
|
2012-01-25 23:11:53 +00:00
|
|
|
$backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
|
|
|
|
|
foreach ( $files as $file ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$backend->delete( [ 'src' => $file ], [ 'force' => 1 ] );
|
2012-01-25 23:11:53 +00:00
|
|
|
}
|
2011-06-16 21:07:37 +00:00
|
|
|
foreach ( $files as $file ) {
|
2015-11-18 18:32:05 +00:00
|
|
|
$tmp = FileBackend::parentStoragePath( $file );
|
|
|
|
|
while ( $tmp ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$backend->clean( [ 'dir' => $tmp ] )->isOK() ) {
|
2012-01-27 22:57:14 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2015-11-18 18:32:05 +00:00
|
|
|
$tmp = FileBackend::parentStoragePath( $tmp );
|
2011-06-16 21:07:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 23:11:53 +00:00
|
|
|
protected function getBaseDir() {
|
|
|
|
|
return 'mwstore://local-backend';
|
2011-06-16 21:07:37 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
public function parserTestProvider() {
|
|
|
|
|
if ( $this->file === false ) {
|
|
|
|
|
global $wgParserTestFiles;
|
|
|
|
|
$this->file = $wgParserTestFiles[0];
|
|
|
|
|
}
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2016-04-07 05:20:38 +00:00
|
|
|
return new TestFileDataProvider( $this->file, $this );
|
2011-02-26 21:49:42 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
/**
|
|
|
|
|
* Set the file from whose tests will be run by this instance
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $filename
|
2011-02-26 21:49:42 +00:00
|
|
|
*/
|
|
|
|
|
public function setParserTestFile( $filename ) {
|
|
|
|
|
$this->file = $filename;
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2012-04-20 17:34:15 +00:00
|
|
|
/**
|
|
|
|
|
* @group medium
|
2015-11-26 20:25:03 +00:00
|
|
|
* @group ParserTests
|
2012-04-20 17:34:15 +00:00
|
|
|
* @dataProvider parserTestProvider
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $desc
|
|
|
|
|
* @param string $input
|
|
|
|
|
* @param string $result
|
|
|
|
|
* @param array $opts
|
|
|
|
|
* @param array $config
|
2012-04-20 17:34:15 +00:00
|
|
|
*/
|
2011-02-26 21:49:42 +00:00
|
|
|
public function testParserTest( $desc, $input, $result, $opts, $config ) {
|
2012-01-25 23:11:53 +00:00
|
|
|
if ( $this->regex != '' && !preg_match( '/' . $this->regex . '/', $desc ) ) {
|
|
|
|
|
$this->assertTrue( true ); // XXX: don't flood output with "test made no assertions"
|
2015-09-11 13:44:59 +00:00
|
|
|
// $this->markTestSkipped( 'Filtered out by the user' );
|
2012-01-25 23:11:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-03-18 21:45:32 +00:00
|
|
|
|
2012-10-12 13:39:01 +00:00
|
|
|
if ( !$this->isWikitextNS( NS_MAIN ) ) {
|
|
|
|
|
// parser tests frequently assume that the main namespace contains wikitext.
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo When setting up pages, force the content model. Only skip if
|
2012-10-12 13:39:01 +00:00
|
|
|
// $wgtContentModelUseDB is false.
|
|
|
|
|
$this->markTestSkipped( "Main namespace does not support wikitext,"
|
2013-02-15 10:24:31 +00:00
|
|
|
. "skipping parser test: $desc" );
|
2012-10-12 13:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-18 21:45:32 +00:00
|
|
|
wfDebug( "Running parser test: $desc\n" );
|
|
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
$opts = $this->parseOptions( $opts );
|
2011-11-10 12:49:10 +00:00
|
|
|
$context = $this->setupGlobals( $opts, $config );
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2011-11-10 12:49:10 +00:00
|
|
|
$user = $context->getUser();
|
|
|
|
|
$options = ParserOptions::newFromContext( $context );
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
if ( isset( $opts['title'] ) ) {
|
|
|
|
|
$titleText = $opts['title'];
|
2013-02-15 10:24:31 +00:00
|
|
|
} else {
|
2011-02-26 21:49:42 +00:00
|
|
|
$titleText = 'Parser test';
|
2011-01-01 05:53:04 +00:00
|
|
|
}
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
$local = isset( $opts['local'] );
|
|
|
|
|
$preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
|
|
|
|
|
$parser = $this->getParser( $preprocessor );
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
$title = Title::newFromText( $titleText );
|
|
|
|
|
|
2013-06-21 15:39:29 +00:00
|
|
|
# Parser test requiring math. Make sure texvc is executable
|
|
|
|
|
# or just skip such tests.
|
|
|
|
|
if ( isset( $opts['math'] ) || isset( $opts['texvc'] ) ) {
|
|
|
|
|
global $wgTexvc;
|
|
|
|
|
|
|
|
|
|
if ( !isset( $wgTexvc ) ) {
|
|
|
|
|
$this->markTestSkipped( "SKIPPED: \$wgTexvc is not set" );
|
|
|
|
|
} elseif ( !is_executable( $wgTexvc ) ) {
|
|
|
|
|
$this->markTestSkipped( "SKIPPED: texvc binary does not exist"
|
|
|
|
|
. " or is not executable.\n"
|
|
|
|
|
. "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-16 18:26:52 +00:00
|
|
|
|
2013-12-18 17:56:15 +00:00
|
|
|
if ( isset( $opts['djvu'] ) ) {
|
|
|
|
|
if ( !$this->djVuSupport->isEnabled() ) {
|
|
|
|
|
$this->markTestSkipped( "SKIPPED: djvu binaries do not exist or are not executable.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-21 15:39:29 +00:00
|
|
|
|
2015-03-16 18:26:52 +00:00
|
|
|
if ( isset( $opts['tidy'] ) ) {
|
|
|
|
|
if ( !$this->tidySupport->isEnabled() ) {
|
|
|
|
|
$this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
|
|
|
|
|
} else {
|
|
|
|
|
$options->setTidy( true );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
if ( isset( $opts['pst'] ) ) {
|
|
|
|
|
$out = $parser->preSaveTransform( $input, $title, $user, $options );
|
|
|
|
|
} elseif ( isset( $opts['msg'] ) ) {
|
2011-06-29 10:58:54 +00:00
|
|
|
$out = $parser->transformMsg( $input, $options, $title );
|
2011-02-26 21:49:42 +00:00
|
|
|
} elseif ( isset( $opts['section'] ) ) {
|
|
|
|
|
$section = $opts['section'];
|
|
|
|
|
$out = $parser->getSection( $input, $section );
|
|
|
|
|
} elseif ( isset( $opts['replace'] ) ) {
|
|
|
|
|
$section = $opts['replace'][0];
|
|
|
|
|
$replace = $opts['replace'][1];
|
|
|
|
|
$out = $parser->replaceSection( $input, $section, $replace );
|
|
|
|
|
} elseif ( isset( $opts['comment'] ) ) {
|
2011-08-05 15:17:19 +00:00
|
|
|
$out = Linker::formatComment( $input, $title, $local );
|
2011-02-26 21:49:42 +00:00
|
|
|
} elseif ( isset( $opts['preload'] ) ) {
|
2013-03-22 16:44:34 +00:00
|
|
|
$out = $parser->getPreloadText( $input, $title, $options );
|
2011-02-26 21:49:42 +00:00
|
|
|
} else {
|
|
|
|
|
$output = $parser->parse( $input, $title, $options, true, true, 1337 );
|
2013-08-22 22:22:03 +00:00
|
|
|
$output->setTOCEnabled( !isset( $opts['notoc'] ) );
|
2011-02-26 21:49:42 +00:00
|
|
|
$out = $output->getText();
|
2014-05-18 07:17:25 +00:00
|
|
|
if ( isset( $opts['tidy'] ) ) {
|
2015-03-16 18:26:52 +00:00
|
|
|
$out = preg_replace( '/\s+$/', '', $out );
|
2014-05-18 07:17:25 +00:00
|
|
|
}
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
if ( isset( $opts['showtitle'] ) ) {
|
|
|
|
|
if ( $output->getTitleText() ) {
|
|
|
|
|
$title = $output->getTitleText();
|
2011-01-01 20:57:13 +00:00
|
|
|
}
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
$out = "$title\n$out";
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-02 20:08:43 +00:00
|
|
|
if ( isset( $opts['showindicators'] ) ) {
|
|
|
|
|
$indicators = '';
|
|
|
|
|
foreach ( $output->getIndicators() as $id => $content ) {
|
|
|
|
|
$indicators .= "$id=$content\n";
|
|
|
|
|
}
|
|
|
|
|
$out = $indicators . $out;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
if ( isset( $opts['ill'] ) ) {
|
2014-05-18 07:17:25 +00:00
|
|
|
$out = implode( ' ', $output->getLanguageLinks() );
|
2011-02-26 21:49:42 +00:00
|
|
|
} elseif ( isset( $opts['cat'] ) ) {
|
2011-11-10 12:49:10 +00:00
|
|
|
$outputPage = $context->getOutput();
|
|
|
|
|
$outputPage->addCategoryLinks( $output->getCategories() );
|
|
|
|
|
$cats = $outputPage->getCategoryLinks();
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
if ( isset( $cats['normal'] ) ) {
|
2014-05-18 07:17:25 +00:00
|
|
|
$out = implode( ' ', $cats['normal'] );
|
2011-02-26 21:49:42 +00:00
|
|
|
} else {
|
|
|
|
|
$out = '';
|
2011-01-01 17:05:08 +00:00
|
|
|
}
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-02-26 21:49:42 +00:00
|
|
|
$parser->mPreprocessor = null;
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-02-26 21:49:42 +00:00
|
|
|
|
|
|
|
|
$this->teardownGlobals();
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
$this->assertEquals( $result, $out, $desc );
|
2011-01-01 18:10:28 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
/**
|
|
|
|
|
* Run a fuzz test series
|
|
|
|
|
* Draw input from a set of test files
|
2011-08-09 16:13:56 +00:00
|
|
|
*
|
2012-07-10 15:16:46 +00:00
|
|
|
* @todo fixme Needs some work to not eat memory until the world explodes
|
2011-08-09 16:13:56 +00:00
|
|
|
*
|
2012-01-10 20:50:34 +00:00
|
|
|
* @group ParserFuzz
|
2011-01-01 18:10:28 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testFuzzTests() {
|
2011-01-01 18:10:28 +00:00
|
|
|
global $wgParserTestFiles;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
$files = $wgParserTestFiles;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2014-05-05 16:10:07 +00:00
|
|
|
if ( $this->getCliArg( 'file' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$files = [ $this->getCliArg( 'file' ) ];
|
2011-01-01 18:10:28 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
$dict = $this->getFuzzInput( $files );
|
|
|
|
|
$dictSize = strlen( $dict );
|
|
|
|
|
$logMaxLength = log( $this->maxFuzzTestLength );
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-07-21 22:04:55 +00:00
|
|
|
ini_set( 'memory_limit', $this->memoryLimit * 1048576 );
|
2011-01-01 18:10:28 +00:00
|
|
|
|
|
|
|
|
$user = new User;
|
|
|
|
|
$opts = ParserOptions::newFromUser( $user );
|
|
|
|
|
$title = Title::makeTitle( NS_MAIN, 'Parser_test' );
|
|
|
|
|
|
|
|
|
|
$id = 1;
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
while ( true ) {
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
// Generate test input
|
|
|
|
|
mt_srand( ++$this->fuzzSeed );
|
|
|
|
|
$totalLength = mt_rand( 1, $this->maxFuzzTestLength );
|
|
|
|
|
$input = '';
|
|
|
|
|
|
|
|
|
|
while ( strlen( $input ) < $totalLength ) {
|
|
|
|
|
$logHairLength = mt_rand( 0, 1000000 ) / 1000000 * $logMaxLength;
|
|
|
|
|
$hairLength = min( intval( exp( $logHairLength ) ), $dictSize );
|
|
|
|
|
$offset = mt_rand( 0, $dictSize - $hairLength );
|
|
|
|
|
$input .= substr( $dict, $offset, $hairLength );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->setupGlobals();
|
|
|
|
|
$parser = $this->getParser();
|
|
|
|
|
|
|
|
|
|
// Run the test
|
|
|
|
|
try {
|
|
|
|
|
$parser->parse( $input, $title, $opts );
|
|
|
|
|
$this->assertTrue( true, "Test $id, fuzz seed {$this->fuzzSeed}" );
|
|
|
|
|
} catch ( Exception $exception ) {
|
2011-02-09 17:21:39 +00:00
|
|
|
$input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2013-07-16 18:06:04 +00:00
|
|
|
$this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\n" .
|
|
|
|
|
"Input: $input_dump\n\nError: {$exception->getMessage()}\n\n" .
|
|
|
|
|
"Backtrace: {$exception->getTraceAsString()}" );
|
2011-01-01 18:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->teardownGlobals();
|
|
|
|
|
$parser->__destruct();
|
|
|
|
|
|
|
|
|
|
if ( $id % 100 == 0 ) {
|
|
|
|
|
$usage = intval( memory_get_usage( true ) / $this->memoryLimit / 1048576 * 100 );
|
2015-09-11 13:44:59 +00:00
|
|
|
// echo "{$this->fuzzSeed}: $numSuccess/$numTotal (mem: $usage%)\n";
|
2011-01-01 18:10:28 +00:00
|
|
|
if ( $usage > 90 ) {
|
|
|
|
|
$ret = "Out of memory:\n";
|
|
|
|
|
$memStats = $this->getMemoryBreakdown();
|
|
|
|
|
|
|
|
|
|
foreach ( $memStats as $name => $usage ) {
|
|
|
|
|
$ret .= "$name: $usage\n";
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
throw new MWException( $ret );
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
$id++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-10 18:41:31 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Various getter functions
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
/**
|
|
|
|
|
* Get an input dictionary from a set of parser test files
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param array $filenames
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return string
|
2011-01-01 18:10:28 +00:00
|
|
|
*/
|
|
|
|
|
function getFuzzInput( $filenames ) {
|
|
|
|
|
$dict = '';
|
|
|
|
|
|
|
|
|
|
foreach ( $filenames as $filename ) {
|
|
|
|
|
$contents = file_get_contents( $filename );
|
|
|
|
|
preg_match_all( '/!!\s*input\n(.*?)\n!!\s*result/s', $contents, $matches );
|
|
|
|
|
|
|
|
|
|
foreach ( $matches[1] as $match ) {
|
|
|
|
|
$dict .= $match . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dict;
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 18:10:28 +00:00
|
|
|
/**
|
|
|
|
|
* Get a memory usage breakdown
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return array
|
2011-01-01 18:10:28 +00:00
|
|
|
*/
|
|
|
|
|
function getMemoryBreakdown() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$memStats = [];
|
2011-01-01 18:10:28 +00:00
|
|
|
|
|
|
|
|
foreach ( $GLOBALS as $name => $value ) {
|
|
|
|
|
$memStats['$' . $name] = strlen( serialize( $value ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$classes = get_declared_classes();
|
|
|
|
|
|
|
|
|
|
foreach ( $classes as $class ) {
|
|
|
|
|
$rc = new ReflectionClass( $class );
|
|
|
|
|
$props = $rc->getStaticProperties();
|
|
|
|
|
$memStats[$class] = strlen( serialize( $props ) );
|
|
|
|
|
$methods = $rc->getMethods();
|
|
|
|
|
|
|
|
|
|
foreach ( $methods as $method ) {
|
|
|
|
|
$memStats[$class] += strlen( serialize( $method->getStaticVariables() ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$functions = get_defined_functions();
|
|
|
|
|
|
|
|
|
|
foreach ( $functions['user'] as $function ) {
|
|
|
|
|
$rf = new ReflectionFunction( $function );
|
|
|
|
|
$memStats["$function()"] = strlen( serialize( $rf->getStaticVariables() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
asort( $memStats );
|
|
|
|
|
|
|
|
|
|
return $memStats;
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
/**
|
|
|
|
|
* Get a Parser object
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param Preprocessor $preprocessor
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return Parser
|
2011-01-01 03:39:37 +00:00
|
|
|
*/
|
|
|
|
|
function getParser( $preprocessor = null ) {
|
2011-03-06 23:28:32 +00:00
|
|
|
global $wgParserConf;
|
2011-01-01 03:39:37 +00:00
|
|
|
|
|
|
|
|
$class = $wgParserConf['class'];
|
2016-02-17 09:09:32 +00:00
|
|
|
$parser = new $class( [ 'preprocessorClass' => $preprocessor ] + $wgParserConf );
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ParserTestParser', [ &$parser ] );
|
2011-01-01 03:39:37 +00:00
|
|
|
|
|
|
|
|
return $parser;
|
|
|
|
|
}
|
2011-01-10 18:43:59 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Various action functions
|
2011-01-01 03:39:37 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
public function addArticle( $name, $text, $line ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
self::$articles[$name] = [ $text, $line ];
|
2011-07-25 22:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
public function publishTestArticles() {
|
|
|
|
|
if ( empty( self::$articles ) ) {
|
|
|
|
|
return;
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:19:10 +00:00
|
|
|
foreach ( self::$articles as $name => $info ) {
|
|
|
|
|
list( $text, $line ) = $info;
|
2012-01-09 22:33:00 +00:00
|
|
|
ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' );
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
/**
|
|
|
|
|
* Steal a callback function from the primary parser, save it for
|
|
|
|
|
* application to our scary parser. If the hook is not installed,
|
|
|
|
|
* abort processing of this file.
|
|
|
|
|
*
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @return bool True if tag hook is present
|
2011-01-01 03:39:37 +00:00
|
|
|
*/
|
|
|
|
|
public function requireHook( $name ) {
|
|
|
|
|
global $wgParser;
|
2013-02-15 10:24:31 +00:00
|
|
|
$wgParser->firstCallInit(); // make sure hooks are loaded.
|
2011-02-26 21:49:42 +00:00
|
|
|
return isset( $wgParser->mTagHooks[$name] );
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
2011-01-10 18:43:59 +00:00
|
|
|
|
2011-02-26 21:49:42 +00:00
|
|
|
public function requireFunctionHook( $name ) {
|
|
|
|
|
global $wgParser;
|
2013-02-15 10:24:31 +00:00
|
|
|
$wgParser->firstCallInit(); // make sure hooks are loaded.
|
2011-02-26 21:49:42 +00:00
|
|
|
return isset( $wgParser->mFunctionHooks[$name] );
|
|
|
|
|
}
|
2013-02-15 10:24:31 +00:00
|
|
|
|
2014-06-20 15:36:08 +00:00
|
|
|
public function requireTransparentHook( $name ) {
|
|
|
|
|
global $wgParser;
|
|
|
|
|
$wgParser->firstCallInit(); // make sure hooks are loaded.
|
|
|
|
|
return isset( $wgParser->mTransparentTagHooks[$name] );
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Various "cleanup" functions
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 20:57:13 +00:00
|
|
|
/**
|
|
|
|
|
* Remove last character if it is a newline
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $s
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return string
|
2011-01-01 20:57:13 +00:00
|
|
|
*/
|
|
|
|
|
public function removeEndingNewline( $s ) {
|
|
|
|
|
if ( substr( $s, -1 ) === "\n" ) {
|
|
|
|
|
return substr( $s, 0, -1 );
|
2013-02-15 10:24:31 +00:00
|
|
|
} else {
|
2011-01-01 20:57:13 +00:00
|
|
|
return $s;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-10 18:43:59 +00:00
|
|
|
|
2015-09-11 13:44:59 +00:00
|
|
|
// Test options parser functions
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
protected function parseOptions( $instring ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$opts = [];
|
2011-01-01 03:39:37 +00:00
|
|
|
// foo
|
|
|
|
|
// foo=bar
|
|
|
|
|
// foo="bar baz"
|
|
|
|
|
// foo=[[bar baz]]
|
|
|
|
|
// foo=bar,"baz quux"
|
|
|
|
|
$regex = '/\b
|
|
|
|
|
([\w-]+) # Key
|
|
|
|
|
\b
|
|
|
|
|
(?:\s*
|
|
|
|
|
= # First sub-value
|
|
|
|
|
\s*
|
|
|
|
|
(
|
|
|
|
|
"
|
|
|
|
|
[^"]* # Quoted val
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
|
\[\[
|
|
|
|
|
[^]]* # Link target
|
|
|
|
|
\]\]
|
|
|
|
|
|
|
|
|
|
|
[\w-]+ # Plain word
|
|
|
|
|
)
|
|
|
|
|
(?:\s*
|
|
|
|
|
, # Sub-vals 1..N
|
|
|
|
|
\s*
|
|
|
|
|
(
|
|
|
|
|
"[^"]*" # Quoted val
|
|
|
|
|
|
|
|
|
|
|
\[\[[^]]*\]\] # Link target
|
|
|
|
|
|
|
|
|
|
|
[\w-]+ # Plain word
|
|
|
|
|
)
|
|
|
|
|
)*
|
|
|
|
|
)?
|
|
|
|
|
/x';
|
|
|
|
|
|
|
|
|
|
if ( preg_match_all( $regex, $instring, $matches, PREG_SET_ORDER ) ) {
|
|
|
|
|
foreach ( $matches as $bits ) {
|
|
|
|
|
array_shift( $bits );
|
|
|
|
|
$key = strtolower( array_shift( $bits ) );
|
|
|
|
|
if ( count( $bits ) == 0 ) {
|
|
|
|
|
$opts[$key] = true;
|
|
|
|
|
} elseif ( count( $bits ) == 1 ) {
|
|
|
|
|
$opts[$key] = $this->cleanupOption( array_shift( $bits ) );
|
|
|
|
|
} else {
|
|
|
|
|
// Array!
|
2016-02-17 09:09:32 +00:00
|
|
|
$opts[$key] = array_map( [ $this, 'cleanupOption' ], $bits );
|
2011-01-01 03:39:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
return $opts;
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
protected function cleanupOption( $opt ) {
|
|
|
|
|
if ( substr( $opt, 0, 1 ) == '"' ) {
|
|
|
|
|
return substr( $opt, 1, -1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( substr( $opt, 0, 2 ) == '[[' ) {
|
|
|
|
|
return substr( $opt, 2, -2 );
|
|
|
|
|
}
|
2013-04-26 12:00:22 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
return $opt;
|
|
|
|
|
}
|
2011-07-25 22:01:19 +00:00
|
|
|
|
2011-01-01 03:39:37 +00:00
|
|
|
/**
|
|
|
|
|
* Use a regex to find out the value of an option
|
2014-04-17 18:43:42 +00:00
|
|
|
* @param string $key Name of option val to retrieve
|
|
|
|
|
* @param array $opts Options array to look in
|
|
|
|
|
* @param mixed $default Default value returned if not found
|
2014-08-25 16:50:35 +00:00
|
|
|
* @return mixed
|
2011-01-01 03:39:37 +00:00
|
|
|
*/
|
|
|
|
|
protected static function getOptionValue( $key, $opts, $default ) {
|
|
|
|
|
$key = strtolower( $key );
|
|
|
|
|
|
|
|
|
|
if ( isset( $opts[$key] ) ) {
|
|
|
|
|
return $opts[$key];
|
|
|
|
|
} else {
|
|
|
|
|
return $default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|