static function newFromKey( $sha1, $repo, $timestamp = false ) {
$dbr = $repo->getSlaveDB();
- $conds = array( 'img_sha1' => $sha1 );
+ $conds = [ 'img_sha1' => $sha1 ];
if ( $timestamp ) {
$conds['img_timestamp'] = $dbr->timestamp( $timestamp );
}
* @return array
*/
static function selectFields() {
- return array(
+ return [
'img_name',
'img_size',
'img_width',
'img_user_text',
'img_timestamp',
'img_sha1',
- );
+ ];
}
/**
}
$fields = $this->getCacheFields( '' );
- $cacheVal = array( 'version' => MW_FILE_VERSION );
+ $cacheVal = [ 'version' => MW_FILE_VERSION ];
$cacheVal['fileExists'] = $this->fileExists;
if ( $this->fileExists ) {
* @return array
*/
function getCacheFields( $prefix = 'img_' ) {
- static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
+ static $fields = [ 'size', 'width', 'height', 'bits', 'media_type',
'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user',
- 'user_text', 'description' );
- static $results = array();
+ 'user_text', 'description' ];
+ static $results = [];
if ( $prefix == '' ) {
return $fields;
}
if ( !isset( $results[$prefix] ) ) {
- $prefixedFields = array();
+ $prefixedFields = [];
foreach ( $fields as $field ) {
$prefixedFields[] = $prefix . $field;
}
* @return array
*/
function getLazyCacheFields( $prefix = 'img_' ) {
- static $fields = array( 'metadata' );
- static $results = array();
+ static $fields = [ 'metadata' ];
+ static $results = [];
if ( $prefix == '' ) {
return $fields;
}
if ( !isset( $results[$prefix] ) ) {
- $prefixedFields = array();
+ $prefixedFields = [];
foreach ( $fields as $field ) {
$prefixedFields[] = $prefix . $field;
}
: $this->repo->getSlaveDB();
$row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
- array( 'img_name' => $this->getName() ), $fname );
+ [ 'img_name' => $this->getName() ], $fname );
if ( $row ) {
$this->loadFromRow( $row );
$fieldMap = false;
$row = $dbr->selectRow( 'image', $this->getLazyCacheFields( 'img_' ),
- array( 'img_name' => $this->getName(), 'img_timestamp' => $this->getTimestamp() ),
+ [ 'img_name' => $this->getName(), 'img_timestamp' => $this->getTimestamp() ],
$fname );
if ( $row ) {
$fieldMap = $this->unprefixRow( $row, 'img_' );
} else {
# File may have been uploaded over in the meantime; check the old versions
$row = $dbr->selectRow( 'oldimage', $this->getLazyCacheFields( 'oi_' ),
- array( 'oi_name' => $this->getName(), 'oi_timestamp' => $this->getTimestamp() ),
+ [ 'oi_name' => $this->getName(), 'oi_timestamp' => $this->getTimestamp() ],
$fname );
if ( $row ) {
$fieldMap = $this->unprefixRow( $row, 'oi_' );
throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
}
- $decoded = array();
+ $decoded = [];
foreach ( $array as $name => $value ) {
$decoded[substr( $name, $prefixLength )] = $value;
}
// Use unary + so that overflows will be upgraded to double instead of
// being trucated as with intval(). This is important to allow >2GB
// files on 32-bit systems.
- foreach ( array( 'size', 'width', 'height', 'bits' ) as $field ) {
+ foreach ( [ 'size', 'width', 'height', 'bits' ] as $field ) {
$decoded[$field] = +$decoded[$field];
}
wfDebug( __METHOD__ . ': upgrading ' . $this->getName() . " to the current schema\n" );
$dbw->update( 'image',
- array(
+ [
'img_size' => $this->size, // sanity
'img_width' => $this->width,
'img_height' => $this->height,
'img_minor_mime' => $minor,
'img_metadata' => $dbw->encodeBlob( $this->metadata ),
'img_sha1' => $this->sha1,
- ),
- array( 'img_name' => $this->getName() ),
+ ],
+ [ 'img_name' => $this->getName() ],
__METHOD__
);
$pageId = $this->title->getArticleID();
if ( $pageId !== null ) {
- $url = $this->repo->makeUrl( array( 'curid' => $pageId ) );
+ $url = $this->repo->makeUrl( [ 'curid' => $pageId ] );
if ( $url !== false ) {
return $url;
}
}
$backend = $this->repo->getBackend();
- $files = array( $dir );
+ $files = [ $dir ];
try {
- $iterator = $backend->getFileList( array( 'dir' => $dir ) );
+ $iterator = $backend->getFileList( [ 'dir' => $dir ] );
foreach ( $iterator as $file ) {
$files[] = $file;
}
*
* @note This used to purge old thumbnails by default as well, but doesn't anymore.
*/
- function purgeCache( $options = array() ) {
+ function purgeCache( $options = [] ) {
// Refresh metadata cache
$this->purgeMetadataCache();
// Purge CDN cache for this file
DeferredUpdates::addUpdate(
- new CdnCacheUpdate( array( $this->getUrl() ) ),
+ new CdnCacheUpdate( [ $this->getUrl() ] ),
DeferredUpdates::PRESEND
);
}
$files = $this->getThumbnails( $archiveName );
// Purge any custom thumbnail caches
- Hooks::run( 'LocalFilePurgeThumbnails', array( $this, $archiveName ) );
+ Hooks::run( 'LocalFilePurgeThumbnails', [ $this, $archiveName ] );
+ // Delete thumbnails
$dir = array_shift( $files );
$this->purgeThumbList( $dir, $files );
// Purge the CDN
- $urls = array();
+ $urls = [];
foreach ( $files as $file ) {
$urls[] = $this->getArchiveThumbUrl( $archiveName, $file );
}
* Delete cached transformed files for the current version only.
* @param array $options
*/
- public function purgeThumbnails( $options = array() ) {
- // Delete thumbnails
+ public function purgeThumbnails( $options = [] ) {
$files = $this->getThumbnails();
// Always purge all files from CDN regardless of handler filters
- $urls = array();
+ $urls = [];
foreach ( $files as $file ) {
$urls[] = $this->getThumbUrl( $file );
}
}
// Purge any custom thumbnail caches
- Hooks::run( 'LocalFilePurgeThumbnails', array( $this, false ) );
+ Hooks::run( 'LocalFilePurgeThumbnails', [ $this, false ] );
+ // Delete thumbnails
$dir = array_shift( $files );
$this->purgeThumbList( $dir, $files );
protected function purgeThumbList( $dir, $files ) {
$fileListDebug = strtr(
var_export( $files, true ),
- array( "\n" => '' )
+ [ "\n" => '' ]
);
wfDebug( __METHOD__ . ": $fileListDebug\n" );
- $purgeList = array();
+ $purgeList = [];
foreach ( $files as $file ) {
# Check that the base file name is part of the thumb name
# This is a basic sanity check to avoid erasing unrelated directories
*/
function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
$dbr = $this->repo->getSlaveDB();
- $tables = array( 'oldimage' );
+ $tables = [ 'oldimage' ];
$fields = OldLocalFile::selectFields();
- $conds = $opts = $join_conds = array();
+ $conds = $opts = $join_conds = [];
$eq = $inc ? '=' : '';
$conds[] = "oi_name = " . $dbr->addQuotes( $this->title->getDBkey() );
// Search backwards for time > x queries
$order = ( !$start && $end !== null ) ? 'ASC' : 'DESC';
$opts['ORDER BY'] = "oi_timestamp $order";
- $opts['USE INDEX'] = array( 'oldimage' => 'oi_name_timestamp' );
+ $opts['USE INDEX'] = [ 'oldimage' => 'oi_name_timestamp' ];
- Hooks::run( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
- &$conds, &$opts, &$join_conds ) );
+ Hooks::run( 'LocalFile::getHistory', [ &$this, &$tables, &$fields,
+ &$conds, &$opts, &$join_conds ] );
$res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
- $r = array();
+ $r = [];
foreach ( $res as $row ) {
$r[] = $this->repo->newFileFromRow( $row );
if ( $this->historyLine == 0 ) { // called for the first time, return line from cur
$this->historyRes = $dbr->select( 'image',
- array(
+ [
'*',
"'' AS oi_archive_name",
'0 as oi_deleted',
'img_sha1'
- ),
- array( 'img_name' => $this->title->getDBkey() ),
+ ],
+ [ 'img_name' => $this->title->getDBkey() ],
$fname
);
}
} elseif ( $this->historyLine == 1 ) {
$this->historyRes = $dbr->select( 'oldimage', '*',
- array( 'oi_name' => $this->title->getDBkey() ),
+ [ 'oi_name' => $this->title->getDBkey() ],
$fname,
- array( 'ORDER BY' => 'oi_timestamp DESC' )
+ [ 'ORDER BY' => 'oi_timestamp DESC' ]
);
}
$this->historyLine++;
/**
* Upload a file and record it in the DB
- * @param string $srcPath Source storage path, virtual URL, or filesystem path
+ * @param string|FSFile $src Source storage path, virtual URL, or filesystem path
* @param string $comment Upload description
* @param string $pageText Text to use for the new description page,
* if a new description page is created
* @return FileRepoStatus On success, the value member contains the
* archive name, or an empty string if it was a new file.
*/
- function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false,
- $timestamp = false, $user = null, $tags = array()
+ function upload( $src, $comment, $pageText, $flags = 0, $props = false,
+ $timestamp = false, $user = null, $tags = []
) {
global $wgContLang;
return $this->readOnlyFatalStatus();
}
+ $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
if ( !$props ) {
if ( $this->repo->isVirtualUrl( $srcPath )
|| FileBackend::isStoragePath( $srcPath )
}
}
- $options = array();
+ $options = [];
$handler = MediaHandler::getHandler( $props['mime'] );
if ( $handler ) {
$options['headers'] = $handler->getStreamHeaders( $props['metadata'] );
} else {
- $options['headers'] = array();
+ $options['headers'] = [];
}
// Trim spaces on user supplied text
// non-nicely (dangling multi-byte chars, non-truncated version in cache).
$comment = $wgContLang->truncate( $comment, 255 );
$this->lock(); // begin
- $status = $this->publish( $srcPath, $flags, $options );
+ $status = $this->publish( $src, $flags, $options );
if ( $status->successCount >= 2 ) {
// There will be a copy+(one of move,copy,store).
* @return bool
*/
function recordUpload2(
- $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = array()
+ $oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = []
) {
if ( is_null( $user ) ) {
global $wgUser;
# This avoids race conditions by locking the row until the commit, and also
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
$dbw->insert( 'image',
- array(
+ [
'img_name' => $this->getName(),
'img_size' => $this->size,
'img_width' => intval( $this->width ),
'img_user_text' => $user->getName(),
'img_metadata' => $dbw->encodeBlob( $this->metadata ),
'img_sha1' => $this->sha1
- ),
+ ],
__METHOD__,
'IGNORE'
);
$ltimestamp = $dbw->selectField(
'image',
'img_timestamp',
- array( 'img_name' => $this->getName() ),
+ [ 'img_name' => $this->getName() ],
__METHOD__,
- array( 'LOCK IN SHARE MODE' )
+ [ 'LOCK IN SHARE MODE' ]
);
$lUnixtime = $ltimestamp ? wfTimestamp( TS_UNIX, $ltimestamp ) : false;
# Avoid a timestamp that is not newer than the last version
# Collision, this is an update of a file
# Insert previous contents into oldimage
$dbw->insertSelect( 'oldimage', 'image',
- array(
+ [
'oi_name' => 'img_name',
'oi_archive_name' => $dbw->addQuotes( $oldver ),
'oi_size' => 'img_size',
'oi_major_mime' => 'img_major_mime',
'oi_minor_mime' => 'img_minor_mime',
'oi_sha1' => 'img_sha1'
- ),
- array( 'img_name' => $this->getName() ),
+ ],
+ [ 'img_name' => $this->getName() ],
__METHOD__
);
# Update the current image row
$dbw->update( 'image',
- array(
+ [
'img_size' => $this->size,
'img_width' => intval( $this->width ),
'img_height' => intval( $this->height ),
'img_user_text' => $user->getName(),
'img_metadata' => $dbw->encodeBlob( $this->metadata ),
'img_sha1' => $this->sha1
- ),
- array( 'img_name' => $this->getName() ),
+ ],
+ [ 'img_name' => $this->getName() ],
__METHOD__
);
}
// Allow people using the api to associate log entries with the upload.
// Log has a timestamp, but sometimes different from upload timestamp.
$logEntry->setParameters(
- array(
+ [
'img_sha1' => $this->sha1,
'img_timestamp' => $timestamp,
- )
+ ]
);
// Note we keep $logId around since during new image
// creation, page doesn't exist yet, so log_page = 0
$nullRevision->insertOn( $dbw );
Hooks::run(
'NewRevisionFromEditComplete',
- array( $wikiPage, $nullRevision, $nullRevision->getParentId(), $user )
+ [ $wikiPage, $nullRevision, $nullRevision->getParentId(), $user ]
);
$wikiPage->updateRevisionOn( $dbw, $nullRevision );
// Associate null revision id
# but setAssociatedRevId() wasn't called at that point yet...
$logParams = $logEntry->getParameters();
$logParams['associated_rev_id'] = $logEntry->getAssociatedRevId();
- $update = array( 'log_params' => LogEntryBase::makeParamBlob( $logParams ) );
+ $update = [ 'log_params' => LogEntryBase::makeParamBlob( $logParams ) ];
if ( $updateLogPage ) {
# Also log page, in case where we just created it above
$update['log_page'] = $updateLogPage;
$that->getRepo()->getMasterDB()->update(
'logging',
$update,
- array( 'log_id' => $logId ),
+ [ 'log_id' => $logId ],
__METHOD__
);
$that->getRepo()->getMasterDB()->insert(
'log_search',
- array(
+ [
'ls_field' => 'associated_rev_id',
'ls_value' => $logEntry->getAssociatedRevId(),
'ls_log_id' => $logId,
- ),
+ ],
__METHOD__
);
- # Now that the log entry is up-to-date, make an RC entry.
- $recentChange = $logEntry->publish( $logId );
-
+ # Add change tags, if any
if ( $tags ) {
- ChangeTags::addTags(
- $tags,
- $recentChange ? $recentChange->getAttribute( 'rc_id' ) : null,
- $logEntry->getAssociatedRevId(),
- $logId
- );
+ $logEntry->setTags( $tags );
}
+ # Now that the log entry is up-to-date, make an RC entry.
+ $logEntry->publish( $logId );
+
# Run hook for other updates (typically more cache purging)
- Hooks::run( 'FileUpload', array( $that, $reupload, !$newPageContent ) );
+ Hooks::run( 'FileUpload', [ $that, $reupload, !$newPageContent ] );
if ( $reupload ) {
# Delete old thumbnails
$that->purgeThumbnails();
# Remove the old file from the CDN cache
DeferredUpdates::addUpdate(
- new CdnCacheUpdate( array( $that->getUrl() ) ),
+ new CdnCacheUpdate( [ $that->getUrl() ] ),
DeferredUpdates::PRESEND
);
} else {
if ( !$reupload ) {
# This is a new file, so update the image count
- DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( 'images' => 1 ) ) );
+ DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => 1 ] ) );
}
# Invalidate cache for all pages using this file
* The archive name should be passed through to recordUpload for database
* registration.
*
- * @param string $srcPath Local filesystem path or virtual URL to the source image
+ * @param string|FSFile $src Local filesystem path or virtual URL to the source image
* @param int $flags A bitwise combination of:
* File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
* @param array $options Optional additional parameters
* @return FileRepoStatus On success, the value member contains the
* archive name, or an empty string if it was a new file.
*/
- function publish( $srcPath, $flags = 0, array $options = array() ) {
- return $this->publishTo( $srcPath, $this->getRel(), $flags, $options );
+ function publish( $src, $flags = 0, array $options = [] ) {
+ return $this->publishTo( $src, $this->getRel(), $flags, $options );
}
/**
* The archive name should be passed through to recordUpload for database
* registration.
*
- * @param string $srcPath Local filesystem path or virtual URL to the source image
+ * @param string|FSFile $src Local filesystem path or virtual URL to the source image
* @param string $dstRel Target relative path
* @param int $flags A bitwise combination of:
* File::DELETE_SOURCE Delete the source file, i.e. move rather than copy
* @return FileRepoStatus On success, the value member contains the
* archive name, or an empty string if it was a new file.
*/
- function publishTo( $srcPath, $dstRel, $flags = 0, array $options = array() ) {
+ function publishTo( $src, $dstRel, $flags = 0, array $options = [] ) {
+ $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
+
$repo = $this->getRepo();
if ( $repo->getReadOnlyReason() !== false ) {
return $this->readOnlyFatalStatus();
if ( $repo->hasSha1Storage() ) {
$sha1 = $repo->isVirtualUrl( $srcPath )
? $repo->getFileSha1( $srcPath )
- : File::sha1Base36( $srcPath );
+ : FSFile::getSha1Base36FromPath( $srcPath );
$dst = $repo->getBackend()->getPathForSHA1( $sha1 );
- $status = $repo->quickImport( $srcPath, $dst );
+ $status = $repo->quickImport( $src, $dst );
if ( $flags & File::DELETE_SOURCE ) {
unlink( $srcPath );
}
$this->unlock(); // done
if ( $status->isOK() ) {
- DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( 'images' => -1 ) ) );
+ DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => -1 ] ) );
}
// Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
);
// Purge the CDN
- $purgeUrls = array();
+ $purgeUrls = [];
foreach ( $archiveNames as $archiveName ) {
$purgeUrls[] = $this->getArchiveUrl( $archiveName );
}
}
DeferredUpdates::addUpdate(
- new CdnCacheUpdate( array( $this->getArchiveUrl( $archiveName ) ) ),
+ new CdnCacheUpdate( [ $this->getArchiveUrl( $archiveName ) ] ),
DeferredUpdates::PRESEND
);
* @param bool $unsuppress
* @return FileRepoStatus
*/
- function restore( $versions = array(), $unsuppress = false ) {
+ function restore( $versions = [], $unsuppress = false ) {
if ( $this->getRepo()->getReadOnlyReason() !== false ) {
return $this->readOnlyFatalStatus();
}
// itself gets it from elsewhere. To avoid repeating the DB lookups in such a case, we
// need to differentiate between null (uninitialized) and false (failed to load).
if ( $this->descriptionTouched === null ) {
- $cond = array(
+ $cond = [
'page_namespace' => $this->title->getNamespace(),
'page_title' => $this->title->getDBkey()
- );
+ ];
$touched = $this->repo->getSlaveDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ );
$this->descriptionTouched = $touched ? wfTimestamp( TS_MW, $touched ) : false;
}
if ( !wfReadOnly() && strval( $this->sha1 ) != '' ) {
$dbw = $this->repo->getMasterDB();
$dbw->update( 'image',
- array( 'img_sha1' => $this->sha1 ),
- array( 'img_name' => $this->getName() ),
+ [ 'img_sha1' => $this->sha1 ],
+ [ 'img_name' => $this->getName() ],
__METHOD__ );
$this->invalidateCache();
}
// SELECT FOR UPDATE prevents changes, not other SELECTs with FOR UPDATE.
// Also, that would cause contention on INSERT of similarly named rows.
$backend = $this->getRepo()->getBackend();
- $lockPaths = array( $this->getPath() ); // represents all versions of the file
+ $lockPaths = [ $this->getPath() ]; // represents all versions of the file
$status = $backend->lockFiles( $lockPaths, LockManager::LOCK_EX, 5 );
if ( !$status->isGood() ) {
throw new MWException( "Could not acquire lock for '{$this->getName()}.'" );
private $reason;
/** @var array */
- private $srcRels = array();
+ private $srcRels = [];
/** @var array */
- private $archiveUrls = array();
+ private $archiveUrls = [];
/** @var array Items to be processed in the deletion batch */
private $deletionBatch;
* @return array List of archive names from old versions
*/
public function addOlds() {
- $archiveNames = array();
+ $archiveNames = [];
$dbw = $this->file->repo->getMasterDB();
$result = $dbw->select( 'oldimage',
- array( 'oi_archive_name' ),
- array( 'oi_name' => $this->file->getName() ),
+ [ 'oi_archive_name' ],
+ [ 'oi_name' => $this->file->getName() ],
__METHOD__
);
$deleteCurrent = true;
}
- return array( $oldRels, $deleteCurrent );
+ return [ $oldRels, $deleteCurrent ];
}
/**
* @return array
*/
protected function getHashes() {
- $hashes = array();
+ $hashes = [];
list( $oldRels, $deleteCurrent ) = $this->getOldRels();
if ( $deleteCurrent ) {
$dbw = $this->file->repo->getMasterDB();
$res = $dbw->select(
'oldimage',
- array( 'oi_archive_name', 'oi_sha1' ),
- array( 'oi_archive_name' => array_keys( $oldRels ),
- 'oi_name' => $this->file->getName() ), // performance
+ [ 'oi_archive_name', 'oi_sha1' ],
+ [ 'oi_archive_name' => array_keys( $oldRels ),
+ 'oi_name' => $this->file->getName() ], // performance
__METHOD__
);
if ( $props['fileExists'] ) {
// Upgrade the oldimage row
$dbw->update( 'oldimage',
- array( 'oi_sha1' => $props['sha1'] ),
- array( 'oi_name' => $this->file->getName(), 'oi_archive_name' => $row->oi_archive_name ),
+ [ 'oi_sha1' => $props['sha1'] ],
+ [ 'oi_name' => $this->file->getName(), 'oi_archive_name' => $row->oi_archive_name ],
__METHOD__ );
$hashes[$row->oi_archive_name] = $props['sha1'];
} else {
}
if ( $deleteCurrent ) {
- $concat = $dbw->buildConcat( array( "img_sha1", $encExt ) );
- $where = array( 'img_name' => $this->file->getName() );
+ $concat = $dbw->buildConcat( [ "img_sha1", $encExt ] );
+ $where = [ 'img_name' => $this->file->getName() ];
$dbw->insertSelect( 'filearchive', 'image',
- array(
+ [
'fa_storage_group' => $encGroup,
'fa_storage_key' => $dbw->conditional(
- array( 'img_sha1' => '' ),
+ [ 'img_sha1' => '' ],
$dbw->addQuotes( '' ),
$concat
),
'fa_user_text' => 'img_user_text',
'fa_timestamp' => 'img_timestamp',
'fa_sha1' => 'img_sha1',
- ), $where, __METHOD__ );
+ ], $where, __METHOD__ );
}
if ( count( $oldRels ) ) {
- $concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) );
- $where = array(
+ $concat = $dbw->buildConcat( [ "oi_sha1", $encExt ] );
+ $where = [
'oi_name' => $this->file->getName(),
- 'oi_archive_name' => array_keys( $oldRels ) );
+ 'oi_archive_name' => array_keys( $oldRels ) ];
$dbw->insertSelect( 'filearchive', 'oldimage',
- array(
+ [
'fa_storage_group' => $encGroup,
'fa_storage_key' => $dbw->conditional(
- array( 'oi_sha1' => '' ),
+ [ 'oi_sha1' => '' ],
$dbw->addQuotes( '' ),
$concat
),
'fa_user_text' => 'oi_user_text',
'fa_timestamp' => 'oi_timestamp',
'fa_sha1' => 'oi_sha1',
- ), $where, __METHOD__ );
+ ], $where, __METHOD__ );
}
}
if ( count( $oldRels ) ) {
$dbw->delete( 'oldimage',
- array(
+ [
'oi_name' => $this->file->getName(),
'oi_archive_name' => array_keys( $oldRels )
- ), __METHOD__ );
+ ], __METHOD__ );
}
if ( $deleteCurrent ) {
- $dbw->delete( 'image', array( 'img_name' => $this->file->getName() ), __METHOD__ );
+ $dbw->delete( 'image', [ 'img_name' => $this->file->getName() ], __METHOD__ );
}
}
// Prepare deletion batch
$hashes = $this->getHashes();
- $this->deletionBatch = array();
+ $this->deletionBatch = [];
$ext = $this->file->getExtension();
$dotExt = $ext === '' ? '' : ".$ext";
$hash = $hashes[$name];
$key = $hash . $dotExt;
$dstRel = $repo->getDeletedHashPath( $key ) . $key;
- $this->deletionBatch[$name] = array( $srcRel, $dstRel );
+ $this->deletionBatch[$name] = [ $srcRel, $dstRel ];
}
}
* @return Status
*/
protected function removeNonexistentFiles( $batch ) {
- $files = $newBatch = array();
+ $files = $newBatch = [];
foreach ( $batch as $batchItem ) {
list( $src, ) = $batchItem;
*/
function __construct( File $file, $unsuppress = false ) {
$this->file = $file;
- $this->cleanupBatch = $this->ids = array();
- $this->ids = array();
+ $this->cleanupBatch = $this->ids = [];
+ $this->ids = [];
$this->unsuppress = $unsuppress;
}
$status = $this->file->repo->newGood();
$exists = (bool)$dbw->selectField( 'image', '1',
- array( 'img_name' => $this->file->getName() ),
+ [ 'img_name' => $this->file->getName() ],
__METHOD__,
// The lock() should already prevents changes, but this still may need
// to bypass any transaction snapshot. However, if lock() started the
// trx (which it probably did) then snapshot is post-lock and up-to-date.
- $lockOwnsTrx ? array() : array( 'LOCK IN SHARE MODE' )
+ $lockOwnsTrx ? [] : [ 'LOCK IN SHARE MODE' ]
);
// Fetch all or selected archived revisions for the file,
// sorted from the most recent to the oldest.
- $conditions = array( 'fa_name' => $this->file->getName() );
+ $conditions = [ 'fa_name' => $this->file->getName() ];
if ( !$this->all ) {
$conditions['fa_id'] = $this->ids;
ArchivedFile::selectFields(),
$conditions,
__METHOD__,
- array( 'ORDER BY' => 'fa_timestamp DESC' )
+ [ 'ORDER BY' => 'fa_timestamp DESC' ]
);
- $idsPresent = array();
- $storeBatch = array();
- $insertBatch = array();
+ $idsPresent = [];
+ $storeBatch = [];
+ $insertBatch = [];
$insertCurrent = false;
- $deleteIds = array();
+ $deleteIds = [];
$first = true;
- $archiveNames = array();
+ $archiveNames = [];
foreach ( $result as $row ) {
$idsPresent[] = $row->fa_id;
// Required for a new current revision; nice for older ones too. :)
$props = RepoGroup::singleton()->getFileProps( $deletedUrl );
} else {
- $props = array(
+ $props = [
'minor_mime' => $row->fa_minor_mime,
'major_mime' => $row->fa_major_mime,
'media_type' => $row->fa_media_type,
'metadata' => $row->fa_metadata
- );
+ ];
}
if ( $first && !$exists ) {
// This revision will be published as the new current version
$destRel = $this->file->getRel();
- $insertCurrent = array(
+ $insertCurrent = [
'img_name' => $row->fa_name,
'img_size' => $row->fa_size,
'img_width' => $row->fa_width,
'img_user_text' => $row->fa_user_text,
'img_timestamp' => $row->fa_timestamp,
'img_sha1' => $sha1
- );
+ ];
// The live (current) version cannot be hidden!
if ( !$this->unsuppress && $row->fa_deleted ) {
- $storeBatch[] = array( $deletedUrl, 'public', $destRel );
+ $storeBatch[] = [ $deletedUrl, 'public', $destRel ];
$this->cleanupBatch[] = $row->fa_storage_key;
}
} else {
$archiveNames[$archiveName] = true;
$destRel = $this->file->getArchiveRel( $archiveName );
- $insertBatch[] = array(
+ $insertBatch[] = [
'oi_name' => $row->fa_name,
'oi_archive_name' => $archiveName,
'oi_size' => $row->fa_size,
'oi_major_mime' => $props['major_mime'],
'oi_minor_mime' => $props['minor_mime'],
'oi_deleted' => $this->unsuppress ? 0 : $row->fa_deleted,
- 'oi_sha1' => $sha1 );
+ 'oi_sha1' => $sha1 ];
}
$deleteIds[] = $row->fa_id;
// private files can stay where they are
$status->successCount++;
} else {
- $storeBatch[] = array( $deletedUrl, 'public', $destRel );
+ $storeBatch[] = [ $deletedUrl, 'public', $destRel ];
$this->cleanupBatch[] = $row->fa_storage_key;
}
if ( $deleteIds ) {
$dbw->delete( 'filearchive',
- array( 'fa_id' => $deleteIds ),
+ [ 'fa_id' => $deleteIds ],
__METHOD__ );
}
if ( !$exists ) {
wfDebug( __METHOD__ . " restored {$status->successCount} items, creating a new current\n" );
- DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( 'images' => 1 ) ) );
+ DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => 1 ] ) );
$this->file->purgeEverything();
} else {
* @return Status
*/
protected function removeNonexistentFiles( $triplets ) {
- $files = $filteredTriplets = array();
+ $files = $filteredTriplets = [];
foreach ( $triplets as $file ) {
$files[$file[0]] = $file[0];
}
* @return array
*/
protected function removeNonexistentFromCleanup( $batch ) {
- $files = $newBatch = array();
+ $files = $newBatch = [];
$repo = $this->file->repo;
foreach ( $batch as $file ) {
* @param array $storeBatch
*/
protected function cleanupFailedBatch( $storeStatus, $storeBatch ) {
- $cleanupBatch = array();
+ $cleanupBatch = [];
foreach ( $storeStatus->success as $i => $success ) {
// Check if this item of the batch was successfully copied
if ( $success ) {
// Item was successfully copied and needs to be removed again
// Extract ($dstZone, $dstRel) from the batch
- $cleanupBatch[] = array( $storeBatch[$i][1], $storeBatch[$i][2] );
+ $cleanupBatch[] = [ $storeBatch[$i][1], $storeBatch[$i][2] ];
}
}
$this->file->repo->cleanupBatch( $cleanupBatch );
$this->newName = $this->file->repo->getNameFromTitle( $this->target );
$this->oldRel = $this->oldHash . $this->oldName;
$this->newRel = $this->newHash . $this->newName;
- $this->db = $file->getRepo()->getMasterDb();
+ $this->db = $file->getRepo()->getMasterDB();
}
/**
* Add the current image to the batch
*/
public function addCurrent() {
- $this->cur = array( $this->oldRel, $this->newRel );
+ $this->cur = [ $this->oldRel, $this->newRel ];
}
/**
*/
public function addOlds() {
$archiveBase = 'archive';
- $this->olds = array();
+ $this->olds = [];
$this->oldCount = 0;
- $archiveNames = array();
+ $archiveNames = [];
$result = $this->db->select( 'oldimage',
- array( 'oi_archive_name', 'oi_deleted' ),
- array( 'oi_name' => $this->oldName ),
+ [ 'oi_archive_name', 'oi_deleted' ],
+ [ 'oi_name' => $this->oldName ],
__METHOD__,
- array( 'LOCK IN SHARE MODE' ) // ignore snapshot
+ [ 'LOCK IN SHARE MODE' ] // ignore snapshot
);
foreach ( $result as $row ) {
continue;
}
- $this->olds[] = array(
+ $this->olds[] = [
"{$archiveBase}/{$this->oldHash}{$oldName}",
"{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
- );
+ ];
}
return $archiveNames;
// Update current image
$dbw->update(
'image',
- array( 'img_name' => $this->newName ),
- array( 'img_name' => $this->oldName ),
+ [ 'img_name' => $this->newName ],
+ [ 'img_name' => $this->oldName ],
__METHOD__
);
// Update old images
$dbw->update(
'oldimage',
- array(
+ [
'oi_name' => $this->newName,
'oi_archive_name = ' . $dbw->strreplace( 'oi_archive_name',
$dbw->addQuotes( $this->oldName ), $dbw->addQuotes( $this->newName ) ),
- ),
- array( 'oi_name' => $this->oldName ),
+ ],
+ [ 'oi_name' => $this->oldName ],
__METHOD__
);
* @return array
*/
protected function getMoveTriplets() {
- $moves = array_merge( array( $this->cur ), $this->olds );
- $triplets = array(); // The format is: (srcUrl, destZone, destUrl)
+ $moves = array_merge( [ $this->cur ], $this->olds );
+ $triplets = []; // The format is: (srcUrl, destZone, destUrl)
foreach ( $moves as $move ) {
// $move: (oldRelativePath, newRelativePath)
$srcUrl = $this->file->repo->getVirtualUrl() . '/public/' . rawurlencode( $move[0] );
- $triplets[] = array( $srcUrl, 'public', $move[1] );
+ $triplets[] = [ $srcUrl, 'public', $move[1] ];
wfDebugLog(
'imagemove',
"Generated move triplet for {$this->file->getName()}: {$srcUrl} :: public :: {$move[1]}"
* @return Status
*/
protected function removeNonexistentFiles( $triplets ) {
- $files = array();
+ $files = [];
foreach ( $triplets as $file ) {
$files[$file[0]] = $file[0];
$this->file->repo->getBackend()->getName() );
}
- $filteredTriplets = array();
+ $filteredTriplets = [];
foreach ( $triplets as $file ) {
if ( $result[$file[0]] ) {
$filteredTriplets[] = $file;
*/
protected function cleanupTarget( $triplets ) {
// Create dest pairs from the triplets
- $pairs = array();
+ $pairs = [];
foreach ( $triplets as $triplet ) {
// $triplet: (old source virtual URL, dst zone, dest rel)
- $pairs[] = array( $triplet[1], $triplet[2] );
+ $pairs[] = [ $triplet[1], $triplet[2] ];
}
$this->file->repo->cleanupBatch( $pairs );
*/
protected function cleanupSource( $triplets ) {
// Create source file names from the triplets
- $files = array();
+ $files = [];
foreach ( $triplets as $triplet ) {
$files[] = $triplet[0];
}