From bb39b5a6e48c2b4ffe4bbbb5028b3a7f7542b354 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sat, 23 Nov 2013 21:00:11 +0100 Subject: [PATCH] Update formatting of file repo classes Change-Id: I780070e07352d84d7cda7628994b28b04e8a1ebf --- includes/filerepo/FSRepo.php | 1 - includes/filerepo/FileRepo.php | 48 +++- includes/filerepo/FileRepoStatus.php | 2 + includes/filerepo/ForeignAPIRepo.php | 24 +- includes/filerepo/ForeignDBRepo.php | 2 + includes/filerepo/ForeignDBViaLBRepo.php | 1 + includes/filerepo/LocalRepo.php | 23 +- includes/filerepo/NullRepo.php | 3 +- includes/filerepo/RepoGroup.php | 16 +- includes/filerepo/file/ArchivedFile.php | 25 +- includes/filerepo/file/File.php | 71 +++++- includes/filerepo/file/ForeignAPIFile.php | 9 + includes/filerepo/file/ForeignDBFile.php | 2 +- includes/filerepo/file/LocalFile.php | 238 ++++++++++-------- includes/filerepo/file/OldLocalFile.php | 49 ++-- .../filerepo/file/UnregisteredLocalFile.php | 7 + 16 files changed, 363 insertions(+), 158 deletions(-) diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index 42c9c94535..046b97c6bb 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -31,7 +31,6 @@ * @deprecated since 1.19 */ class FSRepo extends FileRepo { - /** * @param $info array * @throws MWException diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index faed9536ed..963a2520cc 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -167,6 +167,7 @@ class FileRepo { throw new MWException( "No '$zone' zone defined in the {$this->name} repo." ); } } + return $status; } @@ -193,6 +194,7 @@ class FileRepo { if ( $suffix !== false ) { $path .= '/' . rawurlencode( $suffix ); } + return $path; } @@ -242,10 +244,11 @@ class FileRepo { */ public function getZoneHandlerUrl( $zone ) { if ( isset( $this->zones[$zone]['handlerUrl'] ) - && in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) ) - { + && in_array( $zone, array( 'public', 'temp', 'thumb', 'transcoded' ) ) + ) { return $this->zones[$zone]['handlerUrl']; } + return false; } @@ -273,6 +276,7 @@ class FileRepo { if ( !$base ) { throw new MWException( __METHOD__ . ": invalid zone: $zone" ); } + return $base . '/' . rawurldecode( $rel ); } @@ -286,6 +290,7 @@ class FileRepo { if ( !isset( $this->zones[$zone] ) ) { return array( null, null ); // bogus } + return array( $this->zones[$zone]['container'], $this->zones[$zone]['directory'] ); } @@ -304,6 +309,7 @@ class FileRepo { if ( $base != '' ) { // may not be set $base = "/{$base}"; } + return "mwstore://$backendName/{$container}{$base}"; } @@ -390,9 +396,11 @@ class FileRepo { } if ( $img->exists() ) { $img->redirectedFrom( $title->getDBkey() ); + return $img; } } + return false; } @@ -423,6 +431,7 @@ class FileRepo { $result[$file->getTitle()->getDBkey()] = $file; } } + return $result; } @@ -457,6 +466,7 @@ class FileRepo { } } } + return false; } @@ -487,6 +497,7 @@ class FileRepo { $result[$hash] = $files; } } + return $result; } @@ -546,6 +557,7 @@ class FileRepo { } else { $name = $title->getDBkey(); } + return $name; } @@ -596,6 +608,7 @@ class FileRepo { for ( $i = 1; $i <= $levels; $i++ ) { $path .= substr( $hash, 0, $i ) . '/'; } + return $path; } } @@ -628,8 +641,10 @@ class FileRepo { public function makeUrl( $query = '', $entry = 'index' ) { if ( isset( $this->scriptDirUrl ) ) { $ext = isset( $this->scriptExtension ) ? $this->scriptExtension : '.php'; + return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}{$ext}", $query ); } + return false; } @@ -667,6 +682,7 @@ class FileRepo { # and just sort of hope index.php is right. ;) return $this->makeUrl( "title=Image:$encName" ); } + return false; } @@ -710,6 +726,7 @@ class FileRepo { return $this->makeUrl( 'title=MediaWiki:Filepage.css&' . wfArrayToCgi( Skin::getDynamicStylesheetQuery() ) ); } + return false; } @@ -988,6 +1005,7 @@ class FileRepo { $temp = $this->getVirtualUrl( 'temp' ); if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) { wfDebug( __METHOD__ . ": Invalid temp virtual URL\n" ); + return false; } @@ -1238,6 +1256,7 @@ class FileRepo { */ public function fileExists( $file ) { $result = $this->fileExistsBatch( array( $file ) ); + return $result[0]; } @@ -1253,6 +1272,7 @@ class FileRepo { $file = $this->resolveToStoragePath( $file ); $result[$key] = $this->backend->fileExists( array( 'src' => $file ) ); } + return $result; } @@ -1367,6 +1387,7 @@ class FileRepo { for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) { $path .= $key[$i] . '/'; } + return $path; } @@ -1382,6 +1403,7 @@ class FileRepo { if ( $this->isVirtualUrl( $path ) ) { return $this->resolveVirtualUrl( $path ); } + return $path; } @@ -1394,6 +1416,7 @@ class FileRepo { */ public function getLocalCopy( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getLocalCopy( array( 'src' => $path ) ); } @@ -1407,6 +1430,7 @@ class FileRepo { */ public function getLocalReference( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getLocalReference( array( 'src' => $path ) ); } @@ -1419,6 +1443,7 @@ class FileRepo { */ public function getFileProps( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getFileProps( array( 'src' => $path ) ); } @@ -1430,6 +1455,7 @@ class FileRepo { */ public function getFileTimestamp( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getFileTimestamp( array( 'src' => $path ) ); } @@ -1441,6 +1467,7 @@ class FileRepo { */ public function getFileSize( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getFileSize( array( 'src' => $path ) ); } @@ -1452,6 +1479,7 @@ class FileRepo { */ public function getFileSha1( $virtualUrl ) { $path = $this->resolveToStoragePath( $virtualUrl ); + return $this->backend->getFileSha1Base36( array( 'src' => $path ) ); } @@ -1465,6 +1493,7 @@ class FileRepo { public function streamFile( $virtualUrl, $headers = array() ) { $path = $this->resolveToStoragePath( $virtualUrl ); $params = array( 'src' => $path, 'headers' => $headers ); + return $this->backend->streamFile( $params )->isOK(); } @@ -1516,6 +1545,7 @@ class FileRepo { if ( strval( $filename ) == '' ) { return false; } + return FileBackend::isPathTraversalFree( $filename ); } @@ -1564,6 +1594,7 @@ class FileRepo { public function newFatal( $message /*, parameters...*/ ) { $params = func_get_args(); array_unshift( $params, $this ); + return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params ); } @@ -1596,7 +1627,8 @@ class FileRepo { * STUB * @param $title Title of image */ - public function invalidateImageRedirect( Title $title ) {} + public function invalidateImageRedirect( Title $title ) { + } /** * Get the human-readable name of the repo @@ -1608,6 +1640,7 @@ class FileRepo { if ( $this->isLocal() ) { return null; } + // 'shared-repo-name-wikimediacommons' is used when $wgUseInstantCommons = true return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text(); } @@ -1624,6 +1657,7 @@ class FileRepo { $ext = FileBackend::extensionFromPath( $name ); $name = ( $ext == '' ) ? 'thumbnail' : "thumbnail.$ext"; } + return $name; } @@ -1658,6 +1692,7 @@ class FileRepo { public function getLocalCacheKey( /*...*/ ) { $args = func_get_args(); array_unshift( $args, 'filerepo', $this->getName() ); + return call_user_func_array( 'wfMemcKey', $args ); } @@ -1680,13 +1715,13 @@ class FileRepo { ), 'thumb' => array( 'container' => $this->zones['thumb']['container'], - 'directory' => ( $this->zones['thumb']['directory'] == '' ) + 'directory' => $this->zones['thumb']['directory'] == '' ? 'temp' : $this->zones['thumb']['directory'] . '/temp' ), 'transcoded' => array( 'container' => $this->zones['transcoded']['container'], - 'directory' => ( $this->zones['transcoded']['directory'] == '' ) + 'directory' => $this->zones['transcoded']['directory'] == '' ? 'temp' : $this->zones['transcoded']['directory'] . '/temp' ) @@ -1715,7 +1750,8 @@ class FileRepo { * @return void * @throws MWException */ - protected function assertWritableRepo() {} + protected function assertWritableRepo() { + } /** * Return information about the repository. diff --git a/includes/filerepo/FileRepoStatus.php b/includes/filerepo/FileRepoStatus.php index 5300e5ee19..56fddf4637 100644 --- a/includes/filerepo/FileRepoStatus.php +++ b/includes/filerepo/FileRepoStatus.php @@ -37,6 +37,7 @@ class FileRepoStatus extends Status { $result = new self( $repo ); call_user_func_array( array( &$result, 'error' ), $params ); $result->ok = false; + return $result; } @@ -48,6 +49,7 @@ class FileRepoStatus extends Status { static function newGood( $repo = false, $value = null ) { $result = new self( $repo ); $result->value = $value; + return $result; } diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index e64c88a911..b4db65369e 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -110,6 +110,7 @@ class ForeignAPIRepo extends FileRepo { if ( $time ) { return false; } + return parent::newFile( $title, $time ); } @@ -136,8 +137,11 @@ class ForeignAPIRepo extends FileRepo { } } - $data = $this->fetchImageQuery( array( 'titles' => implode( $files, '|' ), - 'prop' => 'imageinfo' ) ); + $data = $this->fetchImageQuery( array( + 'titles' => implode( $files, '|' ), + 'prop' => 'imageinfo' ) + ); + if ( isset( $data['query']['pages'] ) ) { # First, get results from the query. Note we only care whether the image exists, # not whether it has a description page. @@ -161,6 +165,7 @@ class ForeignAPIRepo extends FileRepo { $results[$key] = $this->mFileExists[$file]; } } + return $results; } @@ -211,6 +216,7 @@ class ForeignAPIRepo extends FileRepo { } } } + return false; } @@ -234,6 +240,7 @@ class ForeignAPIRepo extends FileRepo { $ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img ); } } + return $ret; } @@ -258,6 +265,7 @@ class ForeignAPIRepo extends FileRepo { if ( $data && $info && isset( $info['thumburl'] ) ) { wfDebug( __METHOD__ . " got remote thumb " . $info['thumburl'] . "\n" ); $result = $info; + return $info['thumburl']; } else { return false; @@ -286,6 +294,7 @@ class ForeignAPIRepo extends FileRepo { if ( $data && $info && isset( $info['thumberror'] ) ) { wfDebug( __METHOD__ . " got remote thumb error " . $info['thumberror'] . "\n" ); + return new MediaTransformError( 'thumbnail_error_remote', $width, @@ -332,6 +341,7 @@ class ForeignAPIRepo extends FileRepo { if ( isset( $knownThumbUrls[$sizekey] ) ) { wfDebug( __METHOD__ . ': Got thumburl from local cache: ' . "{$knownThumbUrls[$sizekey]} \n" ); + return $knownThumbUrls[$sizekey]; } /* This size is not yet known */ @@ -342,6 +352,7 @@ class ForeignAPIRepo extends FileRepo { if ( !$foreignUrl ) { wfDebug( __METHOD__ . " Could not find thumburl\n" ); + return false; } @@ -349,6 +360,7 @@ class ForeignAPIRepo extends FileRepo { $fileName = rawurldecode( pathinfo( $foreignUrl, PATHINFO_BASENAME ) ); if ( !$this->validateFilename( $fileName ) ) { wfDebug( __METHOD__ . " The deduced filename $fileName is not safe\n" ); + return false; } $localPath = $this->getZonePath( 'thumb' ) . "/" . $this->getHashPath( $name ) . $name; @@ -356,7 +368,8 @@ class ForeignAPIRepo extends FileRepo { $localUrl = $this->getZoneUrl( 'thumb' ) . "/" . $this->getHashPath( $name ) . rawurlencode( $name ) . "/" . rawurlencode( $fileName ); if ( $backend->fileExists( array( 'src' => $localFilename ) ) - && isset( $metadata['timestamp'] ) ) { + && isset( $metadata['timestamp'] ) + ) { wfDebug( __METHOD__ . " Thumbnail was already downloaded before\n" ); $modified = $backend->getFileTimestamp( array( 'src' => $localFilename ) ); $remoteModified = strtotime( $metadata['timestamp'] ); @@ -366,6 +379,7 @@ class ForeignAPIRepo extends FileRepo { /* Use our current and already downloaded thumbnail */ $knownThumbUrls[$sizekey] = $localUrl; $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry ); + return $localUrl; } /* There is a new Commons file, or existing thumbnail older than a month */ @@ -373,6 +387,7 @@ class ForeignAPIRepo extends FileRepo { $thumb = self::httpGet( $foreignUrl ); if ( !$thumb ) { wfDebug( __METHOD__ . " Could not download thumb\n" ); + return false; } @@ -381,11 +396,13 @@ class ForeignAPIRepo extends FileRepo { $params = array( 'dst' => $localFilename, 'content' => $thumb ); if ( !$backend->quickCreate( $params )->isOK() ) { wfDebug( __METHOD__ . " could not write to thumb path '$localFilename'\n" ); + return $foreignUrl; } $knownThumbUrls[$sizekey] = $localUrl; $wgMemc->set( $key, $knownThumbUrls, $this->apiThumbCacheExpiry ); wfDebug( __METHOD__ . " got local thumb $localUrl, saving to cache \n" ); + return $localUrl; } @@ -416,6 +433,7 @@ class ForeignAPIRepo extends FileRepo { if ( in_array( $zone, $supported ) ) { return parent::getZonePath( $zone ); } + return false; } diff --git a/includes/filerepo/ForeignDBRepo.php b/includes/filerepo/ForeignDBRepo.php index 37c657236d..9cccf3b551 100644 --- a/includes/filerepo/ForeignDBRepo.php +++ b/includes/filerepo/ForeignDBRepo.php @@ -68,6 +68,7 @@ class ForeignDBRepo extends LocalRepo { ) ); } + return $this->dbConn; } @@ -95,6 +96,7 @@ class ForeignDBRepo extends LocalRepo { if ( $this->hasSharedCache() ) { $args = func_get_args(); array_unshift( $args, $this->dbName, $this->tablePrefix ); + return call_user_func_array( 'wfForeignMemcKey', $args ); } else { return false; diff --git a/includes/filerepo/ForeignDBViaLBRepo.php b/includes/filerepo/ForeignDBViaLBRepo.php index 7951fb1383..a002aad60e 100644 --- a/includes/filerepo/ForeignDBViaLBRepo.php +++ b/includes/filerepo/ForeignDBViaLBRepo.php @@ -69,6 +69,7 @@ class ForeignDBViaLBRepo extends LocalRepo { if ( $this->hasSharedCache() ) { $args = func_get_args(); array_unshift( $args, $this->wiki ); + return implode( ':', $args ); } else { return false; diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 9b62243b7c..49c2b8fa0e 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -29,12 +29,12 @@ * @ingroup FileRepo */ class LocalRepo extends FileRepo { - var $fileFactory = array( 'LocalFile' , 'newFromTitle' ); - var $fileFactoryKey = array( 'LocalFile' , 'newFromKey' ); - var $fileFromRowFactory = array( 'LocalFile' , 'newFromRow' ); - var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' ); - var $oldFileFactoryKey = array( 'OldLocalFile', 'newFromKey' ); - var $oldFileFromRowFactory = array( 'OldLocalFile', 'newFromRow' ); + var $fileFactory = array( 'LocalFile', 'newFromTitle' ); + var $fileFactoryKey = array( 'LocalFile', 'newFromKey' ); + var $fileFromRowFactory = array( 'LocalFile', 'newFromRow' ); + var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' ); + var $oldFileFactoryKey = array( 'OldLocalFile', 'newFromKey' ); + var $oldFileFromRowFactory = array( 'OldLocalFile', 'newFromRow' ); /** * @throws MWException @@ -97,6 +97,7 @@ class LocalRepo extends FileRepo { } $dbw->commit( __METHOD__ ); } + return $status; } @@ -111,6 +112,7 @@ class LocalRepo extends FileRepo { $options = ( $lock === 'lock' ) ? array( 'FOR UPDATE' ) : array(); $dbw = $this->getMasterDB(); + return (bool)$dbw->selectField( 'filearchive', '1', array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ), __METHOD__, $options @@ -131,6 +133,7 @@ class LocalRepo extends FileRepo { $ext = File::normalizeExtension( substr( $key, strcspn( $key, '.' ) + 1 ) ); $dbw = $this->getMasterDB(); + return (bool)$dbw->selectField( 'oldimage', '1', array( 'oi_sha1' => $sha1, 'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(), ".$ext" ), @@ -178,6 +181,7 @@ class LocalRepo extends FileRepo { $id = $this->getArticleID( $title ); if ( !$id ) { $wgMemc->add( $memcKey, " ", $expiry ); + return false; } $dbr = $this->getSlaveDB(); @@ -191,9 +195,11 @@ class LocalRepo extends FileRepo { if ( $row && $row->rd_namespace == NS_FILE ) { $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title ); $wgMemc->add( $memcKey, $targetTitle->getDBkey(), $expiry ); + return $targetTitle; } else { $wgMemc->add( $memcKey, '', $expiry ); + return false; } } @@ -219,6 +225,7 @@ class LocalRepo extends FileRepo { ), __METHOD__ //Function name ); + return $id; } @@ -299,13 +306,14 @@ class LocalRepo extends FileRepo { 'img_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ), __METHOD__, $selectOptions - ); + ); // Build file objects $files = array(); foreach ( $res as $row ) { $files[] = $this->newFileFromRow( $row ); } + return $files; } @@ -334,6 +342,7 @@ class LocalRepo extends FileRepo { */ function getSharedCacheKey( /*...*/ ) { $args = func_get_args(); + return call_user_func_array( 'wfMemcKey', $args ); } diff --git a/includes/filerepo/NullRepo.php b/includes/filerepo/NullRepo.php index dda51cea6b..29e4cad97c 100644 --- a/includes/filerepo/NullRepo.php +++ b/includes/filerepo/NullRepo.php @@ -30,7 +30,8 @@ class NullRepo extends FileRepo { /** * @param $info array|null */ - function __construct( $info ) {} + function __construct( $info ) { + } protected function assertWritableRepo() { throw new MWException( get_class( $this ) . ': write operations are not supported.' ); diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index b2b9477ab3..62e9cc0bb3 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -53,6 +53,7 @@ class RepoGroup { } global $wgLocalFileRepo, $wgForeignFileRepos; self::$instance = new RepoGroup( $wgLocalFileRepo, $wgForeignFileRepos ); + return self::$instance; } @@ -126,14 +127,15 @@ class RepoGroup { # Check the cache if ( empty( $options['ignoreRedirect'] ) && empty( $options['private'] ) - && empty( $options['bypassCache'] ) ) - { + && empty( $options['bypassCache'] ) + ) { $time = isset( $options['time'] ) ? $options['time'] : ''; $dbkey = $title->getDBkey(); if ( isset( $this->cache[$dbkey][$time] ) ) { wfDebug( __METHOD__ . ": got File:$dbkey from process cache\n" ); # Move it to the end of the list so that we can delete the LRU entry later $this->pingCache( $dbkey ); + # Return the entry return $this->cache[$dbkey][$time]; } @@ -195,6 +197,7 @@ class RepoGroup { $images = array_merge( $images, $repo->findFiles( $items ) ); } + return $images; } @@ -218,6 +221,7 @@ class RepoGroup { return $redir; } } + return false; } @@ -243,6 +247,7 @@ class RepoGroup { } } } + return $file; } @@ -262,6 +267,7 @@ class RepoGroup { $result = array_merge( $result, $repo->findBySha1( $hash ) ); } usort( $result, 'File::compare' ); + return $result; } @@ -284,6 +290,7 @@ class RepoGroup { foreach ( $result as $hash => $files ) { usort( $result[$hash], 'File::compare' ); } + return $result; } @@ -319,6 +326,7 @@ class RepoGroup { return $repo; } } + return false; } @@ -347,6 +355,7 @@ class RepoGroup { return true; } } + return false; } @@ -379,6 +388,7 @@ class RepoGroup { */ protected function newRepo( $info ) { $class = $info['class']; + return new $class( $info ); } @@ -397,6 +407,7 @@ class RepoGroup { if ( count( $bits ) != 3 ) { throw new MWException( __METHOD__ . ": invalid mwrepo URL: $url" ); } + return $bits; } @@ -411,6 +422,7 @@ class RepoGroup { $repoName = 'local'; } $repo = $this->getRepo( $repoName ); + return $repo->getFileProps( $fileName ); } else { return FSFile::getPropsFromPath( $fileName ); diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index 749f11a5e1..5d72c0cf1a 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -32,10 +32,10 @@ class ArchivedFile { */ var $id, # filearchive row ID $name, # image name - $group, # FileStore storage group + $group, # FileStore storage group $key, # FileStore sha1 key $size, # file dimensions - $bits, # size in bytes + $bits, # size in bytes $width, # width $height, # height $metadata, # metadata string @@ -169,6 +169,7 @@ class ArchivedFile { public static function newFromRow( $row ) { $file = new ArchivedFile( Title::makeTitle( NS_FILE, $row->fa_name ) ); $file->loadFromRow( $row ); + return $file; } @@ -256,6 +257,7 @@ class ArchivedFile { */ public function getID() { $this->load(); + return $this->id; } @@ -264,6 +266,7 @@ class ArchivedFile { */ public function exists() { $this->load(); + return $this->exists; } @@ -273,6 +276,7 @@ class ArchivedFile { */ public function getKey() { $this->load(); + return $this->key; } @@ -298,6 +302,7 @@ class ArchivedFile { */ public function getWidth() { $this->load(); + return $this->width; } @@ -307,6 +312,7 @@ class ArchivedFile { */ public function getHeight() { $this->load(); + return $this->height; } @@ -316,6 +322,7 @@ class ArchivedFile { */ public function getMetadata() { $this->load(); + return $this->metadata; } @@ -325,6 +332,7 @@ class ArchivedFile { */ public function getSize() { $this->load(); + return $this->size; } @@ -334,6 +342,7 @@ class ArchivedFile { */ public function getBits() { $this->load(); + return $this->bits; } @@ -343,6 +352,7 @@ class ArchivedFile { */ public function getMimeType() { $this->load(); + return $this->mime; } @@ -354,6 +364,7 @@ class ArchivedFile { if ( !isset( $this->handler ) ) { $this->handler = MediaHandler::getHandler( $this->getMimeType() ); } + return $this->handler; } @@ -369,6 +380,7 @@ class ArchivedFile { $this->pageCount = false; } } + return $this->pageCount; } @@ -379,6 +391,7 @@ class ArchivedFile { */ public function getMediaType() { $this->load(); + return $this->media_type; } @@ -389,6 +402,7 @@ class ArchivedFile { */ public function getTimestamp() { $this->load(); + return wfTimestamp( TS_MW, $this->timestamp ); } @@ -400,6 +414,7 @@ class ArchivedFile { */ function getSha1() { $this->load(); + return $this->sha1; } @@ -452,6 +467,7 @@ class ArchivedFile { */ public function getRawUser() { $this->load(); + return $this->user; } @@ -462,6 +478,7 @@ class ArchivedFile { */ public function getRawUserText() { $this->load(); + return $this->user_text; } @@ -472,6 +489,7 @@ class ArchivedFile { */ public function getRawDescription() { $this->load(); + return $this->description; } @@ -481,6 +499,7 @@ class ArchivedFile { */ public function getVisibility() { $this->load(); + return $this->deleted; } @@ -492,6 +511,7 @@ class ArchivedFile { */ public function isDeleted( $field ) { $this->load(); + return ( $this->deleted & $field ) == $field; } @@ -504,6 +524,7 @@ class ArchivedFile { */ public function userCan( $field, User $user = null ) { $this->load(); + return Revision::userCanBitfield( $this->deleted, $field, $user ); } } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 5a5221f9bc..b7a504aa65 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -174,6 +174,7 @@ abstract class File { if ( !$ret && $exception !== false ) { throw new MWException( "`$title` is not a valid file title." ); } + return $ret; } @@ -183,6 +184,7 @@ abstract class File { return null; } else { $this->$name = call_user_func( $function ); + return $this->$name; } } @@ -224,6 +226,7 @@ abstract class File { $n = strrpos( $new, '.' ); $newExt = self::normalizeExtension( $n ? substr( $new, $n + 1 ) : '' ); $mimeMagic = MimeMagic::singleton(); + return $mimeMagic->isMatchingExtension( $newExt, $oldMime ); } @@ -232,7 +235,8 @@ abstract class File { * Called by ImagePage * STUB */ - function upgradeRow() {} + function upgradeRow() { + } /** * Split an internet media type into its two components; if not @@ -271,6 +275,7 @@ abstract class File { $this->assertRepoDefined(); $this->name = $this->repo->getNameFromTitle( $this->title ); } + return $this->name; } @@ -285,6 +290,7 @@ abstract class File { $this->extension = self::normalizeExtension( $n ? substr( $this->getName(), $n + 1 ) : '' ); } + return $this->extension; } @@ -306,6 +312,7 @@ abstract class File { if ( $this->redirected ) { return $this->getRedirectedTitle(); } + return $this->title; } @@ -320,6 +327,7 @@ abstract class File { $ext = $this->getExtension(); $this->url = $this->repo->getZoneUrl( 'public', $ext ) . '/' . $this->getUrlRel(); } + return $this->url; } @@ -351,6 +359,7 @@ abstract class File { } else { wfDebug( __METHOD__ . ': supposed to render ' . $this->getName() . ' (' . $this->getMimeType() . "), but can't!\n" ); + return $this->getURL(); #hm... return NULL? } } else { @@ -376,6 +385,7 @@ abstract class File { $this->assertRepoDefined(); $this->path = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel(); } + return $this->path; } @@ -394,6 +404,7 @@ abstract class File { $this->fsFile = false; // null => false; cache negative hits } } + return ( $this->fsFile ) ? $this->fsFile->getPath() : false; @@ -520,6 +531,7 @@ abstract class File { */ public function getCommonMetaArray() { $handler = $this->getHandler(); + return $handler->getCommonMetaArray( $this ); } @@ -601,6 +613,7 @@ abstract class File { if ( !isset( $this->canRender ) ) { $this->canRender = $this->getHandler() && $this->handler->canRender( $this ); } + return $this->canRender; } @@ -652,6 +665,7 @@ abstract class File { if ( !isset( $this->isSafeFile ) ) { $this->isSafeFile = $this->_getIsSafeFile(); } + return $this->isSafeFile; } @@ -753,6 +767,7 @@ abstract class File { } } } + return $this->transformScript; } @@ -771,6 +786,7 @@ abstract class File { return $this->iconThumb(); } $hp['width'] = $width; + return $this->transform( $hp ); } @@ -787,6 +803,7 @@ abstract class File { $name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) ) ? $this->repo->nameForThumb( $this->getName() ) : $this->getName(); + return $this->generateThumbName( $name, $params ); } @@ -809,6 +826,7 @@ abstract class File { if ( $thumbExt != $extension ) { $thumbName .= ".$thumbExt"; } + return $thumbName; } @@ -838,6 +856,7 @@ abstract class File { if ( is_null( $thumb ) || $thumb->isError() ) { return ''; } + return $thumb->getUrl(); } @@ -986,6 +1005,7 @@ abstract class File { } while ( false ); wfProfileOut( __METHOD__ ); + return is_object( $thumb ) ? $thumb : false; } @@ -999,6 +1019,7 @@ abstract class File { if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) { $fileName .= ".$thumbExt"; } + return FileBackend::makeContentDisposition( 'inline', $fileName ); } @@ -1007,7 +1028,8 @@ abstract class File { * STUB * Overridden by LocalFile */ - function migrateThumbFile( $thumbName ) {} + function migrateThumbFile( $thumbName ) { + } /** * Get a MediaHandler instance for this file @@ -1018,6 +1040,7 @@ abstract class File { if ( !isset( $this->handler ) ) { $this->handler = MediaHandler::getHandler( $this->getMimeType() ); } + return $this->handler; } @@ -1035,9 +1058,11 @@ abstract class File { $filepath = $wgStyleDirectory . $path; if ( file_exists( $filepath ) ) { // always FS $params = array( 'width' => 120, 'height' => 120 ); + return new ThumbnailImage( $this, $wgStylePath . $path, false, $params ); } } + return null; } @@ -1066,7 +1091,8 @@ abstract class File { * @param array $options Options, which include: * 'forThumbRefresh' : The purging is only to refresh thumbnails */ - function purgeCache( $options = array() ) {} + function purgeCache( $options = array() ) { + } /** * Purge the file description page, but don't go after @@ -1132,7 +1158,8 @@ abstract class File { * STUB * Overridden in LocalFile. */ - public function resetHistory() {} + public function resetHistory() { + } /** * Get the filename hash component of the directory including trailing slash, @@ -1146,6 +1173,7 @@ abstract class File { $this->assertRepoDefined(); $this->hashPath = $this->repo->getHashPath( $this->getName() ); } + return $this->hashPath; } @@ -1173,6 +1201,7 @@ abstract class File { } else { $path .= $suffix; } + return $path; } @@ -1189,6 +1218,7 @@ abstract class File { if ( $suffix !== false ) { $path .= '/' . $suffix; } + return $path; } @@ -1218,6 +1248,7 @@ abstract class File { } else { $path .= $suffix; } + return $path; } @@ -1230,6 +1261,7 @@ abstract class File { */ function getArchivePath( $suffix = false ) { $this->assertRepoDefined(); + return $this->repo->getZonePath( 'public' ) . '/' . $this->getArchiveRel( $suffix ); } @@ -1243,6 +1275,7 @@ abstract class File { */ function getArchiveThumbPath( $archiveName, $suffix = false ) { $this->assertRepoDefined(); + return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getArchiveThumbRel( $archiveName, $suffix ); } @@ -1256,6 +1289,7 @@ abstract class File { */ function getThumbPath( $suffix = false ) { $this->assertRepoDefined(); + return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix ); } @@ -1268,6 +1302,7 @@ abstract class File { */ function getTranscodedPath( $suffix = false ) { $this->assertRepoDefined(); + return $this->repo->getZonePath( 'transcoded' ) . '/' . $this->getThumbRel( $suffix ); } @@ -1287,6 +1322,7 @@ abstract class File { } else { $path .= rawurlencode( $suffix ); } + return $path; } @@ -1308,6 +1344,7 @@ abstract class File { } else { $path .= rawurlencode( $suffix ); } + return $path; } @@ -1326,6 +1363,7 @@ abstract class File { if ( $suffix !== false ) { $path .= '/' . rawurlencode( $suffix ); } + return $path; } @@ -1364,6 +1402,7 @@ abstract class File { if ( $suffix !== false ) { $path .= '/' . rawurlencode( $suffix ); } + return $path; } @@ -1382,6 +1421,7 @@ abstract class File { } else { $path .= rawurlencode( $suffix ); } + return $path; } @@ -1398,6 +1438,7 @@ abstract class File { if ( $suffix !== false ) { $path .= '/' . rawurlencode( $suffix ); } + return $path; } @@ -1406,6 +1447,7 @@ abstract class File { */ function isHashed() { $this->assertRepoDefined(); + return (bool)$this->repo->getHashLevels(); } @@ -1468,6 +1510,7 @@ abstract class File { if ( !$this->getHandler() ) { return false; } + return $this->getHandler()->formatMetadata( $this, $this->getMetadata() ); } @@ -1536,6 +1579,7 @@ abstract class File { */ function wasDeleted() { $title = $this->getTitle(); + return $title && $title->isDeletedQuick(); } @@ -1616,6 +1660,7 @@ abstract class File { $this->pageCount = false; } } + return $this->pageCount; } @@ -1648,6 +1693,7 @@ abstract class File { if ( !$this->getHandler() ) { return false; } + return $this->handler->getImageSize( $this, $fileName ); } @@ -1683,11 +1729,16 @@ abstract class File { if ( $renderUrl ) { if ( $this->repo->descriptionCacheExpiry > 0 ) { wfDebug( "Attempting to get the description from cache..." ); - $key = $this->repo->getLocalCacheKey( 'RemoteFileDescription', 'url', $lang->getCode(), - $this->getName() ); + $key = $this->repo->getLocalCacheKey( + 'RemoteFileDescription', + 'url', + $lang->getCode(), + $this->getName() + ); $obj = $wgMemc->get( $key ); if ( $obj ) { wfDebug( "success!\n" ); + return $obj; } wfDebug( "miss\n" ); @@ -1697,6 +1748,7 @@ abstract class File { if ( $res && $this->repo->descriptionCacheExpiry > 0 ) { $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); } + return $res; } else { return false; @@ -1726,6 +1778,7 @@ abstract class File { */ function getTimestamp() { $this->assertRepoDefined(); + return $this->repo->getFileTimestamp( $this->getPath() ); } @@ -1736,6 +1789,7 @@ abstract class File { */ function getSha1() { $this->assertRepoDefined(); + return $this->repo->getFileSha1( $this->getPath() ); } @@ -1751,6 +1805,7 @@ abstract class File { } $ext = $this->getExtension(); $dotExt = $ext === '' ? '' : ".$ext"; + return $hash . $dotExt; } @@ -1781,6 +1836,7 @@ abstract class File { wfDeprecated( __METHOD__, '1.19' ); $fsFile = new FSFile( $path ); + return $fsFile->getProps(); } @@ -1800,6 +1856,7 @@ abstract class File { wfDeprecated( __METHOD__, '1.19' ); $fsFile = new FSFile( $path ); + return $fsFile->getSha1Base36(); } @@ -1866,8 +1923,10 @@ abstract class File { if ( !$this->redirectTitle ) { $this->redirectTitle = Title::makeTitle( NS_FILE, $this->redirected ); } + return $this->redirectTitle; } + return null; } diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 0b3d5dfdb0..2f713a9cf7 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -78,6 +78,7 @@ class ForeignAPIFile extends File { } else { $img = new self( $title, $repo, $info, true ); } + return $img; } else { return null; @@ -133,6 +134,7 @@ class ForeignAPIFile extends File { ); if ( $thumbUrl === false ) { global $wgLang; + return $this->repo->getThumbError( $this->getName(), $width, @@ -141,6 +143,7 @@ class ForeignAPIFile extends File { $wgLang->getCode() ); } + return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params ); } @@ -169,6 +172,7 @@ class ForeignAPIFile extends File { if ( isset( $this->mInfo['metadata'] ) ) { return serialize( self::parseMetadata( $this->mInfo['metadata'] ) ); } + return null; } @@ -179,6 +183,7 @@ class ForeignAPIFile extends File { if ( isset( $this->mInfo['extmetadata'] ) ) { return $this->mInfo['extmetadata']; } + return null; } @@ -194,6 +199,7 @@ class ForeignAPIFile extends File { foreach ( $metadata as $meta ) { $ret[$meta['name']] = self::parseMetadata( $meta['value'] ); } + return $ret; } @@ -254,6 +260,7 @@ class ForeignAPIFile extends File { $magic = MimeMagic::singleton(); $this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); } + return $this->mInfo['mime']; } @@ -265,6 +272,7 @@ class ForeignAPIFile extends File { return $this->mInfo['mediatype']; } $magic = MimeMagic::singleton(); + return $magic->getMediaType( null, $this->getMimeType() ); } @@ -288,6 +296,7 @@ class ForeignAPIFile extends File { if ( $suffix ) { $path = $path . $suffix . '/'; } + return $path; } else { return null; diff --git a/includes/filerepo/file/ForeignDBFile.php b/includes/filerepo/file/ForeignDBFile.php index 01d6b0f539..b7a5c35fe6 100644 --- a/includes/filerepo/file/ForeignDBFile.php +++ b/includes/filerepo/file/ForeignDBFile.php @@ -27,7 +27,6 @@ * @ingroup FileAbstraction */ class ForeignDBFile extends LocalFile { - /** * @param $title * @param $repo @@ -51,6 +50,7 @@ class ForeignDBFile extends LocalFile { $title = Title::makeTitle( NS_FILE, $row->img_name ); $file = new self( $title, $repo ); $file->loadFromRow( $row ); + return $file; } diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 2cd4f90745..d94bbada96 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -210,6 +210,7 @@ class LocalFile extends File { if ( !$key ) { wfProfileOut( __METHOD__ ); + return false; } @@ -236,6 +237,7 @@ class LocalFile extends File { } wfProfileOut( __METHOD__ ); + return $this->dataLoaded; } @@ -407,6 +409,7 @@ class LocalFile extends File { foreach ( $array as $name => $value ) { $decoded[substr( $name, $prefixLength )] = $value; } + return $decoded; } @@ -518,6 +521,7 @@ class LocalFile extends File { if ( !$this->fileExists ) { wfDebug( __METHOD__ . ": file does not exist, aborting\n" ); wfProfileOut( __METHOD__ ); + return; } @@ -526,6 +530,7 @@ class LocalFile extends File { if ( wfReadOnly() ) { wfProfileOut( __METHOD__ ); + return; } wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" ); @@ -597,6 +602,7 @@ class LocalFile extends File { list( $fileExists ) = $this->repo->fileExists( $this->getVirtualUrl() ); $this->missing = !$fileExists; } + return $this->missing; } @@ -684,6 +690,7 @@ class LocalFile extends File { */ function getBitDepth() { $this->load(); + return $this->bits; } @@ -693,6 +700,7 @@ class LocalFile extends File { */ public function getSize() { $this->load(); + return $this->size; } @@ -702,6 +710,7 @@ class LocalFile extends File { */ function getMimeType() { $this->load(); + return $this->mime; } @@ -712,6 +721,7 @@ class LocalFile extends File { */ function getMediaType() { $this->load(); + return $this->media_type; } @@ -727,6 +737,7 @@ class LocalFile extends File { */ public function exists() { $this->load(); + return $this->fileExists; } @@ -761,7 +772,6 @@ class LocalFile extends File { clearstatcache(); } */ - /* if ( $this->repo->fileExists( $thumbDir ) ) { // Delete file where directory should be @@ -793,7 +803,8 @@ class LocalFile extends File { foreach ( $iterator as $file ) { $files[] = $file; } - } catch ( FileBackendError $e ) {} // suppress (bug 54674) + } catch ( FileBackendError $e ) { + } // suppress (bug 54674) return $files; } @@ -1011,7 +1022,7 @@ class LocalFile extends File { $dbr = $this->repo->getSlaveDB(); - if ( $this->historyLine == 0 ) {// called for the first time, return line from cur + if ( $this->historyLine == 0 ) { // called for the first time, return line from cur $this->historyRes = $dbr->select( 'image', array( '*', @@ -1025,6 +1036,7 @@ class LocalFile extends File { if ( 0 == $dbr->numRows( $this->historyRes ) ) { $this->historyRes = null; + return false; } } elseif ( $this->historyLine == 1 ) { @@ -1034,7 +1046,7 @@ class LocalFile extends File { array( 'ORDER BY' => 'oi_timestamp DESC' ) ); } - $this->historyLine ++; + $this->historyLine++; return $dbr->fetchObject( $this->historyRes ); } @@ -1088,8 +1100,8 @@ class LocalFile extends File { if ( !$props ) { wfProfileIn( __METHOD__ . '-getProps' ); if ( $this->repo->isVirtualUrl( $srcPath ) - || FileBackend::isStoragePath( $srcPath ) ) - { + || FileBackend::isStoragePath( $srcPath ) + ) { $props = $this->repo->getFileProps( $srcPath ); } else { $props = FSFile::getPropsFromPath( $srcPath ); @@ -1141,8 +1153,7 @@ class LocalFile extends File { * @return bool */ function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '', - $watch = false, $timestamp = false, User $user = null ) - { + $watch = false, $timestamp = false, User $user = null ) { if ( !$user ) { global $wgUser; $user = $wgUser; @@ -1157,6 +1168,7 @@ class LocalFile extends File { if ( $watch ) { $user->addWatch( $this->getTitle() ); } + return true; } @@ -1203,6 +1215,7 @@ class LocalFile extends File { if ( !$this->fileExists ) { wfDebug( __METHOD__ . ": File " . $this->getRel() . " went missing!\n" ); wfProfileOut( __METHOD__ ); + return false; } @@ -1242,21 +1255,21 @@ class LocalFile extends File { # Insert previous contents into oldimage $dbw->insertSelect( 'oldimage', 'image', array( - 'oi_name' => 'img_name', + 'oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes( $oldver ), - 'oi_size' => 'img_size', - 'oi_width' => 'img_width', - 'oi_height' => 'img_height', - 'oi_bits' => 'img_bits', - 'oi_timestamp' => 'img_timestamp', - 'oi_description' => 'img_description', - 'oi_user' => 'img_user', - 'oi_user_text' => 'img_user_text', - 'oi_metadata' => 'img_metadata', - 'oi_media_type' => 'img_media_type', - 'oi_major_mime' => 'img_major_mime', - 'oi_minor_mime' => 'img_minor_mime', - 'oi_sha1' => 'img_sha1' + 'oi_size' => 'img_size', + 'oi_width' => 'img_width', + 'oi_height' => 'img_height', + 'oi_bits' => 'img_bits', + 'oi_timestamp' => 'img_timestamp', + 'oi_description' => 'img_description', + 'oi_user' => 'img_user', + 'oi_user_text' => 'img_user_text', + 'oi_metadata' => 'img_metadata', + 'oi_media_type' => 'img_media_type', + 'oi_major_mime' => 'img_major_mime', + 'oi_minor_mime' => 'img_minor_mime', + 'oi_sha1' => 'img_sha1' ), array( 'img_name' => $this->getName() ), __METHOD__ @@ -1265,19 +1278,19 @@ class LocalFile extends File { # Update the current image row $dbw->update( 'image', array( /* SET */ - 'img_size' => $this->size, - 'img_width' => intval( $this->width ), - 'img_height' => intval( $this->height ), - 'img_bits' => $this->bits, - 'img_media_type' => $this->media_type, - 'img_major_mime' => $this->major_mime, - 'img_minor_mime' => $this->minor_mime, - 'img_timestamp' => $timestamp, + 'img_size' => $this->size, + 'img_width' => intval( $this->width ), + 'img_height' => intval( $this->height ), + 'img_bits' => $this->bits, + 'img_media_type' => $this->media_type, + 'img_major_mime' => $this->major_mime, + 'img_minor_mime' => $this->minor_mime, + 'img_timestamp' => $timestamp, 'img_description' => $comment, - 'img_user' => $user->getId(), - 'img_user_text' => $user->getName(), - 'img_metadata' => $dbw->encodeBlob( $this->metadata ), - 'img_sha1' => $this->sha1 + 'img_user' => $user->getId(), + 'img_user_text' => $user->getName(), + 'img_metadata' => $dbw->encodeBlob( $this->metadata ), + 'img_sha1' => $this->sha1 ), array( 'img_name' => $this->getName() ), __METHOD__ @@ -1413,6 +1426,7 @@ class LocalFile extends File { } wfProfileOut( __METHOD__ ); + return true; } @@ -1426,7 +1440,7 @@ class LocalFile extends File { * * @param string $srcPath local filesystem path to the source image * @param $flags Integer: a bitwise combination of: - * File::DELETE_SOURCE Delete the source file, i.e. move rather than copy + * File::DELETE_SOURCE Delete the source file, i.e. move rather than copy * @param array $options Optional additional parameters * @return FileRepoStatus object. On success, the value member contains the * archive name, or an empty string if it was a new file. @@ -1445,7 +1459,7 @@ class LocalFile extends File { * @param string $srcPath local filesystem path to the source image * @param string $dstRel target relative path * @param $flags Integer: a bitwise combination of: - * File::DELETE_SOURCE Delete the source file, i.e. move rather than copy + * File::DELETE_SOURCE Delete the source file, i.e. move rather than copy * @param array $options Optional additional parameters * @return FileRepoStatus object. On success, the value member contains the * archive name, or an empty string if it was a new file. @@ -1512,7 +1526,7 @@ class LocalFile extends File { // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside. $this->getRepo()->getMasterDB()->onTransactionIdle( - function() use ( $oldTitleFile, $newTitleFile, $archiveNames ) { + function () use ( $oldTitleFile, $newTitleFile, $archiveNames ) { $oldTitleFile->purgeEverything(); foreach ( $archiveNames as $archiveName ) { $oldTitleFile->purgeOldThumbnails( $archiveName ); @@ -1566,7 +1580,7 @@ class LocalFile extends File { // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside. $file = $this; $this->getRepo()->getMasterDB()->onTransactionIdle( - function() use ( $file, $archiveNames ) { + function () use ( $file, $archiveNames ) { global $wgUseSquid; $file->purgeEverything(); @@ -1696,6 +1710,7 @@ class LocalFile extends File { return false; } $pout = $content->getParserOutput( $this->title, null, new ParserOptions( null, $lang ) ); + return $pout->getText(); } @@ -1707,8 +1722,8 @@ class LocalFile extends File { if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) { return ''; } elseif ( $audience == self::FOR_THIS_USER - && !$this->userCan( self::DELETED_COMMENT, $user ) ) - { + && !$this->userCan( self::DELETED_COMMENT, $user ) + ) { return ''; } else { return $this->description; @@ -1720,6 +1735,7 @@ class LocalFile extends File { */ function getTimestamp() { $this->load(); + return $this->timestamp; } @@ -1753,9 +1769,10 @@ class LocalFile extends File { */ function isCacheable() { $this->load(); + // If extra data (metadata) was not loaded then it must have been large return $this->extraDataLoaded - && strlen( serialize( $this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN; + && strlen( serialize( $this->metadata ) ) <= self::CACHE_FIELD_MAX_LEN; } /** @@ -1779,7 +1796,7 @@ class LocalFile extends File { if ( !$cache->lock( $key, 60 ) ) { throw new MWException( "Could not acquire lock for '{$this->getName()}.'" ); } - $dbw->onTransactionIdle( function() use ( $cache, $key ) { + $dbw->onTransactionIdle( function () use ( $cache, $key ) { $cache->unlock( $key ); // release on commit } ); } @@ -1989,27 +2006,27 @@ class LocalFileDeleteBatch { $dbw->insertSelect( 'filearchive', 'image', array( 'fa_storage_group' => $encGroup, - 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END", - 'fa_deleted_user' => $encUserId, + 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END", + 'fa_deleted_user' => $encUserId, 'fa_deleted_timestamp' => $encTimestamp, - 'fa_deleted_reason' => $encReason, - 'fa_deleted' => $this->suppress ? $bitfield : 0, + 'fa_deleted_reason' => $encReason, + 'fa_deleted' => $this->suppress ? $bitfield : 0, - 'fa_name' => 'img_name', + 'fa_name' => 'img_name', 'fa_archive_name' => 'NULL', - 'fa_size' => 'img_size', - 'fa_width' => 'img_width', - 'fa_height' => 'img_height', - 'fa_metadata' => 'img_metadata', - 'fa_bits' => 'img_bits', - 'fa_media_type' => 'img_media_type', - 'fa_major_mime' => 'img_major_mime', - 'fa_minor_mime' => 'img_minor_mime', - 'fa_description' => 'img_description', - 'fa_user' => 'img_user', - 'fa_user_text' => 'img_user_text', - 'fa_timestamp' => 'img_timestamp', - 'fa_sha1' => 'img_sha1', + 'fa_size' => 'img_size', + 'fa_width' => 'img_width', + 'fa_height' => 'img_height', + 'fa_metadata' => 'img_metadata', + 'fa_bits' => 'img_bits', + 'fa_media_type' => 'img_media_type', + 'fa_major_mime' => 'img_major_mime', + 'fa_minor_mime' => 'img_minor_mime', + 'fa_description' => 'img_description', + 'fa_user' => 'img_user', + 'fa_user_text' => 'img_user_text', + 'fa_timestamp' => 'img_timestamp', + 'fa_sha1' => 'img_sha1', ), $where, __METHOD__ ); } @@ -2021,27 +2038,27 @@ class LocalFileDeleteBatch { $dbw->insertSelect( 'filearchive', 'oldimage', array( 'fa_storage_group' => $encGroup, - 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END", - 'fa_deleted_user' => $encUserId, + 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END", + 'fa_deleted_user' => $encUserId, 'fa_deleted_timestamp' => $encTimestamp, - 'fa_deleted_reason' => $encReason, - 'fa_deleted' => $this->suppress ? $bitfield : 'oi_deleted', + 'fa_deleted_reason' => $encReason, + 'fa_deleted' => $this->suppress ? $bitfield : 'oi_deleted', - 'fa_name' => 'oi_name', + 'fa_name' => 'oi_name', 'fa_archive_name' => 'oi_archive_name', - 'fa_size' => 'oi_size', - 'fa_width' => 'oi_width', - 'fa_height' => 'oi_height', - 'fa_metadata' => 'oi_metadata', - 'fa_bits' => 'oi_bits', - 'fa_media_type' => 'oi_media_type', - 'fa_major_mime' => 'oi_major_mime', - 'fa_minor_mime' => 'oi_minor_mime', - 'fa_description' => 'oi_description', - 'fa_user' => 'oi_user', - 'fa_user_text' => 'oi_user_text', - 'fa_timestamp' => 'oi_timestamp', - 'fa_sha1' => 'oi_sha1', + 'fa_size' => 'oi_size', + 'fa_width' => 'oi_width', + 'fa_height' => 'oi_height', + 'fa_metadata' => 'oi_metadata', + 'fa_bits' => 'oi_bits', + 'fa_media_type' => 'oi_media_type', + 'fa_major_mime' => 'oi_major_mime', + 'fa_minor_mime' => 'oi_minor_mime', + 'fa_description' => 'oi_description', + 'fa_user' => 'oi_user', + 'fa_user_text' => 'oi_user_text', + 'fa_timestamp' => 'oi_timestamp', + 'fa_sha1' => 'oi_sha1', ), $where, __METHOD__ ); } } @@ -2129,6 +2146,7 @@ class LocalFileDeleteBatch { // TODO: delete the defunct filearchive rows if we are using a non-transactional DB $this->file->unlockAndRollback(); wfProfileOut( __METHOD__ ); + return $this->status; } @@ -2291,7 +2309,8 @@ class LocalFileRestoreBatch { if ( is_null( $row->fa_major_mime ) || $row->fa_major_mime == 'unknown' || is_null( $row->fa_minor_mime ) || $row->fa_minor_mime == 'unknown' || is_null( $row->fa_media_type ) || $row->fa_media_type == 'UNKNOWN' - || is_null( $row->fa_metadata ) ) { + || is_null( $row->fa_metadata ) + ) { // Refresh our metadata // Required for a new current revision; nice for older ones too. :) $props = RepoGroup::singleton()->getFileProps( $deletedUrl ); @@ -2300,7 +2319,7 @@ class LocalFileRestoreBatch { 'minor_mime' => $row->fa_minor_mime, 'major_mime' => $row->fa_major_mime, 'media_type' => $row->fa_media_type, - 'metadata' => $row->fa_metadata + 'metadata' => $row->fa_metadata ); } @@ -2308,20 +2327,20 @@ class LocalFileRestoreBatch { // This revision will be published as the new current version $destRel = $this->file->getRel(); $insertCurrent = array( - 'img_name' => $row->fa_name, - 'img_size' => $row->fa_size, - 'img_width' => $row->fa_width, - 'img_height' => $row->fa_height, - 'img_metadata' => $props['metadata'], - 'img_bits' => $row->fa_bits, - 'img_media_type' => $props['media_type'], - 'img_major_mime' => $props['major_mime'], - 'img_minor_mime' => $props['minor_mime'], + 'img_name' => $row->fa_name, + 'img_size' => $row->fa_size, + 'img_width' => $row->fa_width, + 'img_height' => $row->fa_height, + 'img_metadata' => $props['metadata'], + 'img_bits' => $row->fa_bits, + 'img_media_type' => $props['media_type'], + 'img_major_mime' => $props['major_mime'], + 'img_minor_mime' => $props['minor_mime'], 'img_description' => $row->fa_description, - 'img_user' => $row->fa_user, - 'img_user_text' => $row->fa_user_text, - 'img_timestamp' => $row->fa_timestamp, - 'img_sha1' => $sha1 + 'img_user' => $row->fa_user, + 'img_user_text' => $row->fa_user_text, + 'img_timestamp' => $row->fa_timestamp, + 'img_sha1' => $sha1 ); // The live (current) version cannot be hidden! @@ -2347,22 +2366,22 @@ class LocalFileRestoreBatch { $archiveNames[$archiveName] = true; $destRel = $this->file->getArchiveRel( $archiveName ); $insertBatch[] = array( - 'oi_name' => $row->fa_name, + 'oi_name' => $row->fa_name, 'oi_archive_name' => $archiveName, - 'oi_size' => $row->fa_size, - 'oi_width' => $row->fa_width, - 'oi_height' => $row->fa_height, - 'oi_bits' => $row->fa_bits, - 'oi_description' => $row->fa_description, - 'oi_user' => $row->fa_user, - 'oi_user_text' => $row->fa_user_text, - 'oi_timestamp' => $row->fa_timestamp, - 'oi_metadata' => $props['metadata'], - 'oi_media_type' => $props['media_type'], - 'oi_major_mime' => $props['major_mime'], - 'oi_minor_mime' => $props['minor_mime'], - 'oi_deleted' => $this->unsuppress ? 0 : $row->fa_deleted, - 'oi_sha1' => $sha1 ); + 'oi_size' => $row->fa_size, + 'oi_width' => $row->fa_width, + 'oi_height' => $row->fa_height, + 'oi_bits' => $row->fa_bits, + 'oi_description' => $row->fa_description, + 'oi_user' => $row->fa_user, + 'oi_user_text' => $row->fa_user_text, + 'oi_timestamp' => $row->fa_timestamp, + 'oi_metadata' => $props['metadata'], + 'oi_media_type' => $props['media_type'], + 'oi_major_mime' => $props['major_mime'], + 'oi_minor_mime' => $props['minor_mime'], + 'oi_deleted' => $this->unsuppress ? 0 : $row->fa_deleted, + 'oi_sha1' => $sha1 ); } $deleteIds[] = $row->fa_id; @@ -2649,6 +2668,7 @@ class LocalFileMoveBatch { if ( !$statusDb->isGood() ) { $this->file->unlockAndRollback(); $statusDb->ok = false; + return $statusDb; } wfDebugLog( 'imagemove', "Renamed {$this->file->getName()} in database: {$statusDb->successCount} successes, {$statusDb->failCount} failures" ); @@ -2664,6 +2684,7 @@ class LocalFileMoveBatch { $this->file->unlockAndRollback(); // unlocks the destination wfDebugLog( 'imagemove', "Error in moving files: " . $statusMove->getWikiText() ); $statusMove->ok = false; + return $statusMove; } $this->file->unlock(); // done @@ -2701,6 +2722,7 @@ class LocalFileMoveBatch { } else { $status->failCount++; $status->fatal( 'imageinvalidfilename' ); + return $status; } diff --git a/includes/filerepo/file/OldLocalFile.php b/includes/filerepo/file/OldLocalFile.php index 2c545963c3..a655b39405 100644 --- a/includes/filerepo/file/OldLocalFile.php +++ b/includes/filerepo/file/OldLocalFile.php @@ -44,6 +44,7 @@ class OldLocalFile extends LocalFile { if ( $time === null ) { throw new MWException( __METHOD__ . ' got null for $time parameter' ); } + return new self( $title, $repo, $time, null ); } @@ -66,6 +67,7 @@ class OldLocalFile extends LocalFile { $title = Title::makeTitle( NS_FILE, $row->oi_name ); $file = new self( $title, $repo, null, $row->oi_archive_name ); $file->loadFromRow( $row, 'oi_' ); + return $file; } @@ -150,6 +152,7 @@ class OldLocalFile extends LocalFile { if ( !isset( $this->archive_name ) ) { $this->load(); } + return $this->archive_name; } @@ -233,6 +236,7 @@ class OldLocalFile extends LocalFile { $fields = parent::getCacheFields( $prefix ); $fields[] = $prefix . 'archive_name'; $fields[] = $prefix . 'deleted'; + return $fields; } @@ -258,6 +262,7 @@ class OldLocalFile extends LocalFile { if ( !$this->fileExists ) { wfDebug( __METHOD__ . ": file does not exist, aborting\n" ); wfProfileOut( __METHOD__ ); + return; } @@ -267,15 +272,15 @@ class OldLocalFile extends LocalFile { wfDebug( __METHOD__ . ': upgrading ' . $this->archive_name . " to the current schema\n" ); $dbw->update( 'oldimage', array( - 'oi_size' => $this->size, // sanity - 'oi_width' => $this->width, - 'oi_height' => $this->height, - 'oi_bits' => $this->bits, + 'oi_size' => $this->size, // sanity + 'oi_width' => $this->width, + 'oi_height' => $this->height, + 'oi_bits' => $this->bits, 'oi_media_type' => $this->media_type, 'oi_major_mime' => $major, 'oi_minor_mime' => $minor, - 'oi_metadata' => $this->metadata, - 'oi_sha1' => $this->sha1, + 'oi_metadata' => $this->metadata, + 'oi_sha1' => $this->sha1, ), array( 'oi_name' => $this->getName(), 'oi_archive_name' => $this->archive_name ), @@ -291,6 +296,7 @@ class OldLocalFile extends LocalFile { */ function isDeleted( $field ) { $this->load(); + return ( $this->deleted & $field ) == $field; } @@ -300,6 +306,7 @@ class OldLocalFile extends LocalFile { */ function getVisibility() { $this->load(); + return (int)$this->deleted; } @@ -313,6 +320,7 @@ class OldLocalFile extends LocalFile { */ function userCan( $field, User $user = null ) { $this->load(); + return Revision::userCanBitfield( $this->deleted, $field, $user ); } @@ -370,21 +378,21 @@ class OldLocalFile extends LocalFile { $dbw->insert( 'oldimage', array( - 'oi_name' => $this->getName(), + 'oi_name' => $this->getName(), 'oi_archive_name' => $archiveName, - 'oi_size' => $props['size'], - 'oi_width' => intval( $props['width'] ), - 'oi_height' => intval( $props['height'] ), - 'oi_bits' => $props['bits'], - 'oi_timestamp' => $dbw->timestamp( $timestamp ), - 'oi_description' => $comment, - 'oi_user' => $user->getId(), - 'oi_user_text' => $user->getName(), - 'oi_metadata' => $props['metadata'], - 'oi_media_type' => $props['media_type'], - 'oi_major_mime' => $props['major_mime'], - 'oi_minor_mime' => $props['minor_mime'], - 'oi_sha1' => $props['sha1'], + 'oi_size' => $props['size'], + 'oi_width' => intval( $props['width'] ), + 'oi_height' => intval( $props['height'] ), + 'oi_bits' => $props['bits'], + 'oi_timestamp' => $dbw->timestamp( $timestamp ), + 'oi_description' => $comment, + 'oi_user' => $user->getId(), + 'oi_user_text' => $user->getName(), + 'oi_metadata' => $props['metadata'], + 'oi_media_type' => $props['media_type'], + 'oi_major_mime' => $props['major_mime'], + 'oi_minor_mime' => $props['minor_mime'], + 'oi_sha1' => $props['sha1'], ), __METHOD__ ); @@ -392,5 +400,4 @@ class OldLocalFile extends LocalFile { return true; } - } diff --git a/includes/filerepo/file/UnregisteredLocalFile.php b/includes/filerepo/file/UnregisteredLocalFile.php index 47ba6d6b29..0d9a830a88 100644 --- a/includes/filerepo/file/UnregisteredLocalFile.php +++ b/includes/filerepo/file/UnregisteredLocalFile.php @@ -105,6 +105,7 @@ class UnregisteredLocalFile extends File { } $this->dims[$page] = $this->handler->getPageDimensions( $this, $page ); } + return $this->dims[$page]; } @@ -114,6 +115,7 @@ class UnregisteredLocalFile extends File { */ function getWidth( $page = 1 ) { $dim = $this->cachePageDimensions( $page ); + return $dim['width']; } @@ -123,6 +125,7 @@ class UnregisteredLocalFile extends File { */ function getHeight( $page = 1 ) { $dim = $this->cachePageDimensions( $page ); + return $dim['height']; } @@ -134,6 +137,7 @@ class UnregisteredLocalFile extends File { $magic = MimeMagic::singleton(); $this->mime = $magic->guessMimeType( $this->getLocalRefPath() ); } + return $this->mime; } @@ -145,6 +149,7 @@ class UnregisteredLocalFile extends File { if ( !$this->getHandler() ) { return false; } + return $this->handler->getImageSize( $this, $this->getLocalRefPath() ); } @@ -159,6 +164,7 @@ class UnregisteredLocalFile extends File { $this->metadata = $this->handler->getMetadata( $this, $this->getLocalRefPath() ); } } + return $this->metadata; } @@ -179,6 +185,7 @@ class UnregisteredLocalFile extends File { */ function getSize() { $this->assertRepoDefined(); + return $this->repo->getFileSize( $this->path ); } -- 2.20.1