public function startWrite( $code ) {
if ( !file_exists( $this->directory ) ) {
- if ( !wfMkdirParents( $this->directory ) ) {
+ if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
throw new MWException( "Unable to create the localisation store " .
"directory \"{$this->directory}\"" );
}
$mydir2 = substr($filename,0,strrpos($filename,'/')); # subdirectory level 2
$mydir1 = substr($mydir2,0,strrpos($mydir2,'/')); # subdirectory level 1
- wfMkdirParents( $mydir1 );
- wfMkdirParents( $mydir2 );
+ wfMkdirParents( $mydir1, null, __METHOD__ );
+ wfMkdirParents( $mydir2, null, __METHOD__ );
}
public function saveToFileCache( $text ) {
global $wgCacheDirectory;
$filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
- wfMkdirParents( $wgCacheDirectory ); // might fail
+ wfMkdirParents( $wgCacheDirectory, null, __METHOD__ ); // might fail
wfSuppressWarnings();
$file = fopen( $filename, 'w' );
$filename = "$wgCacheDirectory/messages-" . wfWikiID() . "-$code";
$tempFilename = $filename . '.tmp';
- wfMkdirParents( $wgCacheDirectory ); // might fail
+ wfMkdirParents( $wgCacheDirectory, null, __METHOD__ ); // might fail
wfSuppressWarnings();
$file = fopen( $tempFilename, 'w' );
* same contents as the source
*/
function storeBatch( $triplets, $flags = 0 ) {
- wfDebug( __METHOD__ . ': Storing ' . count( $triplets ) .
+ wfDebug( __METHOD__ . ': Storing ' . count( $triplets ) .
" triplets; flags: {$flags}\n" );
-
+
// Try creating directories
- if ( !wfMkdirParents( $this->directory ) ) {
+ if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
return $this->newFatal( 'upload_directory_missing', $this->directory );
}
if ( !is_writable( $this->directory ) ) {
return $this->newFatal( 'upload_directory_read_only', $this->directory );
}
-
- // Validate each triplet
+
+ // Validate each triplet
$status = $this->newGood();
foreach ( $triplets as $i => $triplet ) {
list( $srcPath, $dstZone, $dstRel ) = $triplet;
// Create destination directories for this triplet
if ( !is_dir( $dstDir ) ) {
- if ( !wfMkdirParents( $dstDir ) ) {
+ if ( !wfMkdirParents( $dstDir, null, __METHOD__ ) ) {
return $this->newFatal( 'directorycreateerror', $dstDir );
}
if ( $dstZone == 'deleted' ) {
}
}
- // Resolve source
+ // Resolve source
if ( self::isVirtualUrl( $srcPath ) ) {
$srcPath = $triplets[$i][0] = $this->resolveVirtualUrl( $srcPath );
}
$status->fatal( 'filenotfound', $srcPath );
continue;
}
-
+
// Check overwriting
if ( !( $flags & self::OVERWRITE ) && file_exists( $dstPath ) ) {
if ( $flags & self::OVERWRITE_SAME ) {
$hashSource = sha1_file( $srcPath );
$hashDest = sha1_file( $dstPath );
wfRestoreWarnings();
-
+
if ( $hashDest === false || $hashSource !== $hashDest ) {
- wfDebug( __METHOD__ . ': File copy validation failed: ' .
+ wfDebug( __METHOD__ . ': File copy validation failed: ' .
"$srcPath ($hashSource) to $dstPath ($hashDest)\n" );
-
+
$status->error( 'filecopyerror', $srcPath, $dstPath );
$good = false;
}
}
return $status;
}
-
+
/**
* Deletes a batch of files. Each file can be a (zone, rel) pairs, a
- * virtual url or a real path. It will try to delete each file, but
+ * virtual url or a real path. It will try to delete each file, but
* ignores any errors that may occur
- *
+ *
* @param $pairs array List of files to delete
*/
function cleanupBatch( $files ) {
$path = "$root/$rel";
} else {
if ( self::isVirtualUrl( $file ) ) {
- // This is a virtual url, resolve it
+ // This is a virtual url, resolve it
$path = $this->resolveVirtualUrl( $file );
} else {
// This is a full file name
$path = $file;
}
}
-
+
wfSuppressWarnings();
unlink( $path );
wfRestoreWarnings();
*/
function publishBatch( $triplets, $flags = 0 ) {
// Perform initial checks
- if ( !wfMkdirParents( $this->directory ) ) {
+ if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
return $this->newFatal( 'upload_directory_missing', $this->directory );
}
if ( !is_writable( $this->directory ) ) {
$dstDir = dirname( $dstPath );
$archiveDir = dirname( $archivePath );
// Abort immediately on directory creation errors since they're likely to be repetitive
- if ( !is_dir( $dstDir ) && !wfMkdirParents( $dstDir ) ) {
+ if ( !is_dir( $dstDir ) && !wfMkdirParents( $dstDir, null, __METHOD__ ) ) {
return $this->newFatal( 'directorycreateerror', $dstDir );
}
- if ( !is_dir( $archiveDir ) && !wfMkdirParents( $archiveDir ) ) {
+ if ( !is_dir( $archiveDir ) && !wfMkdirParents( $archiveDir, null, __METHOD__ ) ) {
return $this->newFatal( 'directorycreateerror', $archiveDir );
}
if ( !is_file( $srcPath ) ) {
$archivePath = "{$this->deletedDir}/$archiveRel";
$archiveDir = dirname( $archivePath );
if ( !is_dir( $archiveDir ) ) {
- if ( !wfMkdirParents( $archiveDir ) ) {
+ if ( !wfMkdirParents( $archiveDir, null, __METHOD__ ) ) {
$status->fatal( 'directorycreateerror', $archiveDir );
continue;
}
return false;
}
if ( !is_dir($localPath) ) {
- if( !wfMkdirParents($localPath) ) {
+ if( !wfMkdirParents( $localPath, null, __METHOD__ ) ) {
wfDebug( __METHOD__ . " could not create directory $localPath for thumb\n" );
return $foreignUrl;
}
# if it's still writable
if ( $create ) {
wfSuppressWarnings();
- $ok = wfMkdirParents( $dir, 0700 );
+ $ok = wfMkdirParents( $dir, 0700, __METHOD__ );
wfRestoreWarnings();
if ( !$ok ) {
return Status::newFatal( 'config-sqlite-mkdir-error', $dir );
wfDebug( __METHOD__ . ": Swapping width and height because the file will be rotated $rotation degrees\n" );
$swapDimensions = true;
- list( $params['width'], $params['height'] ) =
+ list( $params['width'], $params['height'] ) =
array( $params['width'], $params['height'] );
- list( $params['physicalWidth'], $params['physicalHeight'] ) =
+ list( $params['physicalWidth'], $params['physicalHeight'] ) =
array( $params['physicalWidth'], $params['physicalHeight'] );
}
}
if ( $params['physicalWidth'] >= $srcWidth ) {
if ( $swapDimensions ) {
$params['physicalWidth'] = $srcHeight;
- $params['physicalHeight'] = $srcWidth;
+ $params['physicalHeight'] = $srcWidth;
} else {
$params['physicalWidth'] = $srcWidth;
$params['physicalHeight'] = $srcHeight;
}
}
-
+
# Skip scaling limit checks if no scaling is required
if ( !$image->mustRender() )
- return true;
+ return true;
# Don't thumbnail an image so big that it will fill hard drives and send servers into swap
# JPEG has the handy property of allowing thumbnailing without full decompression, so we make
return true;
}
-
+
/**
* Extracts the width/height if the image will be scaled before rotating
- *
+ *
* @param $params array Parameters as returned by normaliseParams
* @param $rotation int The rotation angle that will be applied
* @return array ($width, $height) array
}
# Try to make a target path for the thumbnail
- if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
+ if ( !wfMkdirParents( dirname( $dstPath, null, __METHOD__ ) ) ) {
wfDebug( __METHOD__ . ": Unable to create thumbnail destination directory, falling back to client scaling\n" );
return $this->getClientScalingThumbnailImage( $image, $scalerParams );
}
}
if ( $scaler != 'client' && $dstPath ) {
- if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
+ if ( !wfMkdirParents( dirname( $dstPath, null, __METHOD__ ) ) ) {
# Unable to create a path for the thumbnail
return 'client';
}
if ( strval( $wgImageMagickTempDir ) !== '' ) {
$env['MAGICK_TMPDIR'] = $wgImageMagickTempDir;
}
-
+
$rotation = $this->getRotation( $image );
list( $width, $height ) = $this->extractPreRotationDimensions( $params, $rotation );
return new ThumbnailImage( $image, $dstUrl, $width, $height, $dstPath, $page );
}
- if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
+ if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) {
return new MediaTransformError( 'thumbnail_error', $width, $height, wfMsg( 'thumbnail_dest_directory' ) );
}
# Use a subshell (brackets) to aggregate stderr from both pipeline commands
# before redirecting it to the overall stdout. This works in both Linux and Windows XP.
- $cmd = '(' . wfEscapeShellArg( $wgDjvuRenderer ) . " -format=ppm -page={$page}" .
+ $cmd = '(' . wfEscapeShellArg( $wgDjvuRenderer ) . " -format=ppm -page={$page}" .
" -size={$params['physicalWidth']}x{$params['physicalHeight']} " .
wfEscapeShellArg( $srcPath );
if ( $wgDjvuPostProcessor ) {
return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath );
}
- if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
+ if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) {
return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
wfMsg( 'thumbnail_dest_directory' ) );
}
if ( is_array( $wgSVGConverters[$wgSVGConverter] ) ) {
// This is a PHP callable
$func = $wgSVGConverters[$wgSVGConverter][0];
- $args = array_merge( array( $srcPath, $dstPath, $width, $height ),
+ $args = array_merge( array( $srcPath, $dstPath, $width, $height ),
array_slice( $wgSVGConverters[$wgSVGConverter], 1 ) );
if ( !is_callable( $func ) ) {
throw new MWException( "$func is not callable" );
}
return true;
}
-
+
public static function rasterizeImagickExt( $srcPath, $dstPath, $width, $height ) {
$im = new Imagick( $srcPath );
$im->setImageFormat( 'png' );
$im->setBackgroundColor( 'transparent' );
$im->setImageDepth( 8 );
-
+
if ( !$im->thumbnailImage( intval( $width ), intval( $height ), /* fit */ false ) ) {
return 'Could not resize image';
}
__METHOD__ );
$dir = dirname( $finalPath );
if ( !file_exists( $dir ) ) {
- if ( !wfMkdirParents( $dir ) ) {
+ if ( !wfMkdirParents( $dir, null, __METHOD__ ) ) {
$this->log( "RENAME FAILED, COULD NOT CREATE $dir" );
$db->rollback();
return;
}
# Create directory if needed
if ( $fspath && !is_dir( $fspath ) ) {
- wfMkdirParents( $fspath ) or die( "Can not create directory $fspath.\n" );
+ wfMkdirParents( $fspath, null, __METHOD__ ) or die( "Can not create directory $fspath.\n" );
}
return realpath( $fspath ) . DIRECTORY_SEPARATOR ;
if ( is_null( $title ) ) {
return;
}
- $dbw->begin();
$revision = Revision::newFromTitle( $title );
if ( !$revision ) {
return;
}
+ $dbw->begin();
+
$options = new ParserOptions;
$parserOutput = $wgParser->parse( $revision->getText(), $title, $options, true, true, $revision->getId() );
$update = new LinksUpdate( $title, $parserOutput, false );
/**
* Removes non-existing links from pages from pagelinks, imagelinks,
- * categorylinks, templatelinks and externallinks tables.
+ * categorylinks, templatelinks, externallinks, interwikilinks, langlinks and redirect tables.
*
* @param $maxLag
* @param $batchSize The size of deletion batches
$counter = 0;
$list = array();
$this->output( "0.." );
-
foreach ( $results as $row ) {
$counter++;
$list[] = $row->$field;
return $dir;
}
- wfMkdirParents( $dir . '/3/3a' );
+ wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
- wfMkdirParents( $dir . '/0/09' );
+ wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
return $dir;
/* The dataProvider is run on a different instance than the test, so it must be static
* When running tests from several files, all tests will see all articles.
*/
-
+
public $uploadDir;
public $keepUploads = false;
public $runDisabled = false;
public $memoryLimit = 50;
protected $file = false;
-
+
/*function __construct($a = null,$b = array(),$c = null ) {
parent::__construct($a,$b,$c);
}*/
-
+
function setUp() {
global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
global $wgHooks, $IP;
$wgContLang = Language::factory( 'en' );
-
+
//Setup CLI arguments
if ( $this->getCliArg( 'regex=' ) ) {
$this->regex = $this->getCliArg( 'regex=' );
# Matches anything
$this->regex = '';
}
-
+
$this->keepUploads = $this->getCliArg( 'keep-uploads' );
-
+
$tmpGlobals = array();
-
+
$tmpGlobals['wgScript'] = '/index.php';
$tmpGlobals['wgScriptPath'] = '/';
$tmpGlobals['wgArticlePath'] = '/wiki/$1';
'hashLevels' => 2,
'transformVia404' => false,
);
-
+
$tmpGlobals['wgEnableParserCache'] = false;
$tmpGlobals['wgHooks'] = $wgHooks;
$tmpGlobals['wgDeferredUpdateList'] = array();
if ( $GLOBALS['wgStyleDirectory'] === false ) {
$tmpGlobals['wgStyleDirectory'] = "$IP/skins";
}
-
-
+
+
foreach ( $tmpGlobals as $var => $val ) {
if ( array_key_exists( $var, $GLOBALS ) ) {
$this->savedInitialGlobals[$var] = $GLOBALS[$var];
$GLOBALS[$var] = $val;
}
-
+
$this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
$this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
$this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
-
+
$wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
$wgNamespaceAliases['Image'] = NS_FILE;
$wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
-
+
}
-
+
public function tearDown() {
-
+
foreach ( $this->savedInitialGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
-
+
global $wgNamespaceProtection, $wgNamespaceAliases;
-
+
$wgNamespaceProtection[NS_MEDIAWIKI] = $this->savedWeirdGlobals['mw_namespace_protection'];
$wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
$wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
}
-
+
function addDBData() {
# Hack: insert a few Wikipedia in-project interwiki prefixes,
# for testing inter-language links
# Update certain things in site_stats
- $this->db->insert( 'site_stats',
+ $this->db->insert( 'site_stats',
array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
__METHOD__,
/**
$user = User::newFromId( 0 );
LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
-
+
$image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
$image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
'size' => 12345,
), $this->db->timestamp( '20010115123500' ), $user );
}
-
-
-
-
+
+
+
+
//ParserTest setup/teardown functions
-
+
/**
* Set up the global variables for a consistent environment for each test.
* Ideally this should replace the global configuration entirely.
# The entries saved into RepoGroup cache with previous globals will be wrong.
RepoGroup::destroySingleton();
MessageCache::singleton()->destroyInstance();
-
+
global $wgUser;
$wgUser = new User();
}
return $dir;
}
- wfMkdirParents( $dir . '/3/3a' );
+ wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
- wfMkdirParents( $dir . '/0/09' );
+ wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
return $dir;
}
-
+
/**
* Restore default values and perform any necessary clean-up
* after each test runs.
foreach ( $this->savedGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
-
+
$this->teardownUploadDir( $this->uploadDir );
}
}
}
}
-
+
public function parserTestProvider() {
if ( $this->file === false ) {
global $wgParserTestFiles;
}
return new TestFileIterator( $this->file, $this );
}
-
+
/**
* Set the file from whose tests will be run by this instance
*/
public function setParserTestFile( $filename ) {
$this->file = $filename;
}
-
+
/** @dataProvider parserTestProvider */
public function testParserTest( $desc, $input, $result, $opts, $config ) {
if ( !preg_match( '/' . $this->regex . '/', $desc ) ) return; //$this->markTestSkipped( 'Filtered out by the user' );
$local = isset( $opts['local'] );
$preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
$parser = $this->getParser( $preprocessor );
-
+
$title = Title::newFromText( $titleText );
if ( isset( $opts['pst'] ) ) {
}
$this->teardownGlobals();
-
+
$this->assertEquals( $result, $out, $desc );
}
-
+
/**
* Run a fuzz test series
* Draw input from a set of test files
*/
function testFuzzTests() {
-
+
$this->markTestIncomplete( 'Breaks tesla due to memory restrictions' );
-
+
global $wgParserTestFiles;
-
+
$files = $wgParserTestFiles;
-
+
if( $this->getCliArg( 'file=' ) ) {
$files = array( $this->getCliArg( 'file=' ) );
}
-
+
$dict = $this->getFuzzInput( $files );
$dictSize = strlen( $dict );
$logMaxLength = log( $this->maxFuzzTestLength );
-
+
ini_set( 'memory_limit', $this->memoryLimit * 1048576 );
$user = new User;
$title = Title::makeTitle( NS_MAIN, 'Parser_test' );
$id = 1;
-
+
while ( true ) {
-
+
// Generate test input
mt_srand( ++$this->fuzzSeed );
$totalLength = mt_rand( 1, $this->maxFuzzTestLength );
$this->assertTrue( true, "Test $id, fuzz seed {$this->fuzzSeed}" );
} catch ( Exception $exception ) {
$input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
-
+
$this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\nInput: $input_dump\n\nError: {$exception->getMessage()}\n\nBacktrace: {$exception->getTraceAsString()}" );
}
foreach ( $memStats as $name => $usage ) {
$ret .= "$name: $usage\n";
}
-
+
throw new MWException( $ret );
}
}
-
+
$id++;
-
+
}
}
//Various getter functions
-
+
/**
* Get an input dictionary from a set of parser test files
*/
return $dict;
}
-
+
/**
* Get a memory usage breakdown
*/
return $memStats;
}
-
+
/**
* Get a Parser object
*/
public function addArticle( $name, $text, $line ) {
self::$articles[$name] = $text;
- }
-
+ }
+
public function publishTestArticles() {
if ( empty( self::$articles ) ) {
return;
}
}
}
-
+
/**
* Steal a callback function from the primary parser, save it for
* application to our scary parser. If the hook is not installed,
return isset( $wgParser->mFunctionHooks[$name] );
}
//Various "cleanup" functions
-
+
/*
* Run the "tidy" command on text if the $wgUseTidy
* global is true
return $text;
}
-
+
/**
* Remove last character if it is a newline
*/
}
//Test options parser functions
-
+
protected function parseOptions( $instring ) {
$opts = array();
// foo
}
return $opts;
}
-
+
protected function cleanupOption( $opt ) {
if ( substr( $opt, 0, 1 ) == '"' ) {
return substr( $opt, 1, -1 );
}
return $opt;
}
-
+
/**
* Use a regex to find out the value of an option
* @param $key String: name of option val to retrieve
return $dir;
}
- wfMkdirParents( $dir . '/3/3a' );
+ wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
- wfMkdirParents( $dir . '/0/09' );
+ wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
return $dir;