From 222b01f5169f1c7e69762e0e8904c24f78f71882 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 28 Jul 2010 11:52:48 +0200 Subject: update to MediaWiki 1.16.0 --- includes/filerepo/FSRepo.php | 103 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 7 deletions(-) (limited to 'includes/filerepo/FSRepo.php') diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index d561e61b..0dd9d0f7 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -6,7 +6,7 @@ * @ingroup FileRepo */ class FSRepo extends FileRepo { - var $directory, $deletedDir, $url, $deletedHashLevels; + var $directory, $deletedDir, $deletedHashLevels, $fileMode; var $fileFactory = array( 'UnregisteredLocalFile', 'newFromTitle' ); var $oldFileFactory = false; var $pathDisclosureProtection = 'simple'; @@ -23,6 +23,17 @@ class FSRepo extends FileRepo { $this->deletedHashLevels = isset( $info['deletedHashLevels'] ) ? $info['deletedHashLevels'] : $this->hashLevels; $this->deletedDir = isset( $info['deletedDir'] ) ? $info['deletedDir'] : false; + $this->fileMode = isset( $info['fileMode'] ) ? $info['fileMode'] : 0644; + if ( isset( $info['thumbDir'] ) ) { + $this->thumbDir = $info['thumbDir']; + } else { + $this->thumbDir = "{$this->directory}/thumb"; + } + if ( isset( $info['thumbUrl'] ) ) { + $this->thumbUrl = $info['thumbUrl']; + } else { + $this->thumbUrl = "{$this->url}/thumb"; + } } /** @@ -57,13 +68,15 @@ class FSRepo extends FileRepo { return "{$this->directory}/temp"; case 'deleted': return $this->deletedDir; + case 'thumb': + return $this->thumbDir; default: return false; } } /** - * Get the URL corresponding to one of the three basic zones + * @see FileRepo::getZoneUrl() */ function getZoneUrl( $zone ) { switch ( $zone ) { @@ -72,9 +85,11 @@ class FSRepo extends FileRepo { case 'temp': return "{$this->url}/temp"; case 'deleted': - return false; // no public URL + return parent::getZoneUrl( $zone ); // no public URL + case 'thumb': + return $this->thumbUrl; default: - return false; + return parent::getZoneUrl( $zone ); } } @@ -203,7 +218,7 @@ class FSRepo extends FileRepo { } } if ( $good ) { - chmod( $dstPath, 0644 ); + $this->chmod( $dstPath ); $status->successCount++; } else { $status->failCount++; @@ -212,6 +227,70 @@ class FSRepo extends FileRepo { return $status; } + function append( $srcPath, $toAppendPath, $flags = 0 ) { + $status = $this->newGood(); + + // Resolve the virtual URL + if ( self::isVirtualUrl( $srcPath ) ) { + $srcPath = $this->resolveVirtualUrl( $srcPath ); + } + // Make sure the files are there + if ( !is_file( $srcPath ) ) + $status->fatal( 'filenotfound', $srcPath ); + + if ( !is_file( $toAppendPath ) ) + $status->fatal( 'filenotfound', $toAppendPath ); + + if ( !$status->isOk() ) return $status; + + // Do the append + $chunk = file_get_contents( $toAppendPath ); + if( $chunk === false ) { + $status->fatal( 'fileappenderrorread', $toAppendPath ); + } + + if( $status->isOk() ) { + if ( file_put_contents( $srcPath, $chunk, FILE_APPEND ) ) { + $status->value = $srcPath; + } else { + $status->fatal( 'fileappenderror', $toAppendPath, $srcPath); + } + } + + if ( $flags & self::DELETE_SOURCE ) { + unlink( $toAppendPath ); + } + + return $status; + } + + /** + * Checks existence of specified array of files. + * + * @param array $files URLs of files to check + * @param integer $flags Bitwise combination of the following flags: + * self::FILES_ONLY Mark file as existing only if it is a file (not directory) + * @return Either array of files and existence flags, or false + */ + function fileExistsBatch( $files, $flags = 0 ) { + if ( !file_exists( $this->directory ) || !is_readable( $this->directory ) ) { + return false; + } + $result = array(); + foreach ( $files as $key => $file ) { + if ( self::isVirtualUrl( $file ) ) { + $file = $this->resolveVirtualUrl( $file ); + } + if( $flags & self::FILES_ONLY ) { + $result[$key] = is_file( $file ); + } else { + $result[$key] = file_exists( $file ); + } + } + + return $result; + } + /** * Take all available measures to prevent web accessibility of new deleted * directories, in case the user has not configured offline storage @@ -362,7 +441,7 @@ class FSRepo extends FileRepo { $status->successCount++; wfDebug(__METHOD__.": wrote tempfile $srcPath to $dstPath\n"); // Thread-safe override for umask - chmod( $dstPath, 0644 ); + $this->chmod( $dstPath ); } else { $status->failCount++; } @@ -439,7 +518,7 @@ class FSRepo extends FileRepo { $status->error( 'filerenameerror', $srcPath, $archivePath ); $good = false; } else { - @chmod( $archivePath, 0644 ); + $this->chmod( $archivePath ); } } if ( $good ) { @@ -534,4 +613,14 @@ class FSRepo extends FileRepo { return strtr( $param, $this->simpleCleanPairs ); } + /** + * Chmod a file, supressing the warnings. + * @param String $path The path to change + */ + protected function chmod( $path ) { + wfSuppressWarnings(); + chmod( $path, $this->fileMode ); + wfRestoreWarnings(); + } + } -- cgit v1.2.3-54-g00ecf