* (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 );
$timestamp,
$user,
$tags,
- $createNullRevision
+ $createNullRevision,
+ $revert
);
if ( !$uploadStatus->isOK() ) {
if ( $uploadStatus->hasMessage( 'filenotfound' ) ) {
* @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 );
$archiveRel = $this->getArchiveRel( $archiveName );
if ( $repo->hasSha1Storage() ) {
- $sha1 = $repo->isVirtualUrl( $srcPath )
+ $sha1 = FileRepo::isVirtualUrl( $srcPath )
? $repo->getFileSha1( $srcPath )
: FSFile::getSha1Base36FromPath( $srcPath );
/** @var FileBackendDBRepoWrapper $wrapperBackend */
}
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';