* Fix assorted version-related problems with the image row by reloading it from the file
*/
function upgradeRow() {
- $this->lock(); // begin
+ $this->lock();
$this->loadFromFile();
$this->invalidateCache();
- $this->unlock(); // done
+ $this->unlock();
$this->upgraded = true; // avoid rework/retries
}
* (This doesn't check $user's permissions.)
* @param bool $createNullRevision Set to false to avoid creation of a null revision on file
* upload, see T193621
+ * @param bool $revert If this file upload is a revert
* @return Status On success, the value member contains the
* archive name, or an empty string if it was a new file.
*/
function upload( $src, $comment, $pageText, $flags = 0, $props = false,
$timestamp = false, $user = null, $tags = [],
- $createNullRevision = true
+ $createNullRevision = true, $revert = false
) {
if ( $this->getRepo()->getReadOnlyReason() !== false ) {
return $this->readOnlyFatalStatus();
$srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
if ( !$props ) {
- if ( $this->repo->isVirtualUrl( $srcPath )
+ if ( FileRepo::isVirtualUrl( $srcPath )
|| FileBackend::isStoragePath( $srcPath )
) {
$props = $this->repo->getFileProps( $srcPath );
// Trim spaces on user supplied text
$comment = trim( $comment );
- $this->lock(); // begin
+ $this->lock();
$status = $this->publish( $src, $flags, $options );
if ( $status->successCount >= 2 ) {
$timestamp,
$user,
$tags,
- $createNullRevision
+ $createNullRevision,
+ $revert
);
if ( !$uploadStatus->isOK() ) {
if ( $uploadStatus->hasMessage( 'filenotfound' ) ) {
}
}
- $this->unlock(); // done
-
+ $this->unlock();
return $status;
}
* @param string[] $tags
* @param bool $createNullRevision Set to false to avoid creation of a null revision on file
* upload, see T193621
+ * @param bool $revert If this file upload is a revert
* @return Status
*/
function recordUpload2(
$oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = [],
- $createNullRevision = true
+ $createNullRevision = true, $revert = false
) {
- global $wgCommentTableSchemaMigrationStage, $wgActorTableSchemaMigrationStage;
+ global $wgActorTableSchemaMigrationStage;
if ( is_null( $user ) ) {
global $wgUser;
'oi_width' => 'img_width',
'oi_height' => 'img_height',
'oi_bits' => 'img_bits',
+ 'oi_description_id' => 'img_description_id',
'oi_timestamp' => 'img_timestamp',
'oi_metadata' => 'img_metadata',
'oi_media_type' => 'img_media_type',
];
$joins = [];
- if ( $wgCommentTableSchemaMigrationStage <= MIGRATION_WRITE_BOTH ) {
- $fields['oi_description'] = 'img_description';
- }
- if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
- $fields['oi_description_id'] = 'img_description_id';
- }
-
- if ( $wgCommentTableSchemaMigrationStage !== MIGRATION_OLD &&
- $wgCommentTableSchemaMigrationStage !== MIGRATION_NEW
- ) {
- // Upgrade any rows that are still old-style. Otherwise an upgrade
- // might be missed if a deletion happens while the migration script
- // is running.
- $res = $dbw->select(
- [ 'image' ],
- [ 'img_name', 'img_description' ],
- [
- 'img_name' => $this->getName(),
- 'img_description_id' => 0,
- ],
- __METHOD__
- );
- foreach ( $res as $row ) {
- $imgFields = $commentStore->insert( $dbw, 'img_description', $row->img_description );
- $dbw->update(
- 'image',
- $imgFields,
- [ 'img_name' => $row->img_name ],
- __METHOD__
- );
- }
- }
-
if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
$fields['oi_user'] = 'img_user';
$fields['oi_user_text'] = 'img_user_text';
$wikiPage = new WikiFilePage( $descTitle );
$wikiPage->setFile( $this );
+ // Determine log action. If reupload is done by reverting, use a special log_action.
+ if ( $revert === true ) {
+ $logAction = 'revert';
+ } elseif ( $reupload === true ) {
+ $logAction = 'overwrite';
+ } else {
+ $logAction = 'upload';
+ }
// Add the log entry...
- $logEntry = new ManualLogEntry( 'upload', $reupload ? 'overwrite' : 'upload' );
+ $logEntry = new ManualLogEntry( 'upload', $logAction );
$logEntry->setTimestamp( $this->timestamp );
$logEntry->setPerformer( $user );
$logEntry->setComment( $comment );
return $this->readOnlyFatalStatus();
}
- $this->lock(); // begin
+ $this->lock();
$archiveName = wfTimestamp( TS_MW ) . '!' . $this->getName();
$archiveRel = $this->getArchiveRel( $archiveName );
if ( $repo->hasSha1Storage() ) {
- $sha1 = $repo->isVirtualUrl( $srcPath )
+ $sha1 = FileRepo::isVirtualUrl( $srcPath )
? $repo->getFileSha1( $srcPath )
: FSFile::getSha1Base36FromPath( $srcPath );
/** @var FileBackendDBRepoWrapper $wrapperBackend */
}
}
- $this->unlock(); // done
-
+ $this->unlock();
return $status;
}
wfDebugLog( 'imagemove', "Got request to move {$this->name} to " . $target->getText() );
$batch = new LocalFileMoveBatch( $this, $target );
- $this->lock(); // begin
+ $this->lock();
$batch->addCurrent();
$archiveNames = $batch->addOlds();
$status = $batch->execute();
- $this->unlock(); // done
+ $this->unlock();
wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
$batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
- $this->lock(); // begin
+ $this->lock();
$batch->addCurrent();
// Get old version relative paths
$archiveNames = $batch->addOlds();
$status = $batch->execute();
- $this->unlock(); // done
+ $this->unlock();
if ( $status->isOK() ) {
DeferredUpdates::addUpdate( SiteStatsUpdate::factory( [ 'images' => -1 ] ) );
$batch = new LocalFileDeleteBatch( $this, $reason, $suppress, $user );
- $this->lock(); // begin
+ $this->lock();
$batch->addOld( $archiveName );
$status = $batch->execute();
- $this->unlock(); // done
+ $this->unlock();
$this->purgeOldThumbnails( $archiveName );
if ( $status->isOK() ) {
$batch = new LocalFileRestoreBatch( $this, $unsuppress );
- $this->lock(); // begin
+ $this->lock();
if ( !$versions ) {
$batch->addAll();
} else {
$cleanupStatus->failCount = 0;
$status->merge( $cleanupStatus );
}
- $this->unlock(); // done
+ $this->unlock();
return $status;
}
$this->load();
// Initialise now if necessary
if ( $this->sha1 == '' && $this->fileExists ) {
- $this->lock(); // begin
+ $this->lock();
$this->sha1 = $this->repo->getFileSha1( $this->getPath() );
if ( !wfReadOnly() && strval( $this->sha1 ) != '' ) {
$this->invalidateCache();
}
- $this->unlock(); // done
+ $this->unlock();
}
return $this->sha1;
}
protected function doDBInserts() {
- global $wgCommentTableSchemaMigrationStage, $wgActorTableSchemaMigrationStage;
+ global $wgActorTableSchemaMigrationStage;
$now = time();
$dbw = $this->file->repo->getMasterDB();
'fa_media_type' => 'img_media_type',
'fa_major_mime' => 'img_major_mime',
'fa_minor_mime' => 'img_minor_mime',
+ 'fa_description_id' => 'img_description_id',
'fa_timestamp' => 'img_timestamp',
'fa_sha1' => 'img_sha1'
];
$commentStore->insert( $dbw, 'fa_deleted_reason', $this->reason )
);
- if ( $wgCommentTableSchemaMigrationStage <= MIGRATION_WRITE_BOTH ) {
- $fields['fa_description'] = 'img_description';
- }
- if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
- $fields['fa_description_id'] = 'img_description_id';
- }
-
- if ( $wgCommentTableSchemaMigrationStage !== MIGRATION_OLD &&
- $wgCommentTableSchemaMigrationStage !== MIGRATION_NEW
- ) {
- // Upgrade any rows that are still old-style. Otherwise an upgrade
- // might be missed if a deletion happens while the migration script
- // is running.
- $res = $dbw->select(
- [ 'image' ],
- [ 'img_name', 'img_description' ],
- [
- 'img_name' => $this->file->getName(),
- 'img_description_id' => 0,
- ],
- __METHOD__
- );
- foreach ( $res as $row ) {
- $imgFields = $commentStore->insert( $dbw, 'img_description', $row->img_description );
- $dbw->update(
- 'image',
- $imgFields,
- [ 'img_name' => $row->img_name ],
- __METHOD__
- );
- }
- }
-
if ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_OLD ) {
$fields['fa_user'] = 'img_user';
$fields['fa_user_text'] = 'img_user_text';
$status = $repo->newGood();
$destFile = wfLocalFile( $this->target );
- $this->file->lock(); // begin
+ $this->file->lock();
$destFile->lock(); // quickly fail if destination is not available
$triplets = $this->getMoveTriplets();
"{$statusDb->successCount} successes, {$statusDb->failCount} failures" );
$destFile->unlock();
- $this->file->unlock(); // done
+ $this->file->unlock();
// Everything went ok, remove the source files
$this->cleanupSource( $triplets );