23use InvalidArgumentException;
63 # The null default value is only here to avoid an E_STRICT
64 if ( $time ===
null ) {
65 throw new InvalidArgumentException( __METHOD__ .
' got null for $time parameter' );
80 return new static(
$title,
$repo,
null, $archiveName );
92 $file =
new static(
$title,
$repo,
null, $row->oi_archive_name );
93 $file->loadFromRow( $row,
'oi_' );
111 $dbr =
$repo->getReplicaDB();
114 $queryBuilder->where( [
'oi_sha1' =>
$sha1 ] );
116 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $timestamp ) ] );
119 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
121 return static::newFromRow( $row,
$repo );
152 'tables' => $queryInfo[
'tables'],
153 'fields' => $queryInfo[
'fields'],
154 'joins' => $queryInfo[
'join_conds'],
168 $this->requestedTime = $time;
169 $this->archive_name = $archiveName;
170 if ( $time ===
null && $archiveName ===
null ) {
171 throw new LogicException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
176 $this->archive_name = $row->{
"{$prefix}archive_name"};
177 $this->deleted = $row->{
"{$prefix}deleted"};
179 unset( $row->{
"{$prefix}archive_name"} );
180 unset( $row->{
"{$prefix}deleted"} );
181 parent::loadFromRow( $row, $prefix );
197 if ( $this->archive_name ===
null ) {
201 return $this->archive_name;
215 return $this->exists() && !$this->isDeleted( File::DELETED_FILE );
223 $this->dataLoaded =
true;
225 $dbr = ( $flags & IDBAccessObject::READ_LATEST )
226 ? $this->repo->getPrimaryDB()
227 : $this->repo->getReplicaDB();
228 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr, [] );
229 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
231 $this->loadFromRow( $row,
'oi_' );
233 $this->fileExists =
false;
242 $this->extraDataLoaded =
true;
243 $dbr = $this->repo->getReplicaDB();
244 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
247 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
250 $dbr = $this->repo->getPrimaryDB();
251 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
252 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
256 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
257 $this->$name = $value;
260 throw new RuntimeException(
"Could not find data for image '{$this->archive_name}'." );
264 private function buildQueryBuilderForLoad(
268 $queryBuilder->
where( [
'oi_name' => $this->getName() ] )
269 ->orderBy(
'oi_timestamp', SelectQueryBuilder::SORT_DESC );
270 if ( $this->requestedTime ===
null ) {
271 $queryBuilder->andWhere( [
'oi_archive_name' => $this->archive_name ] );
273 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $this->requestedTime ) ] );
275 return $queryBuilder;
283 $fields = parent::getCacheFields( $prefix );
284 $fields[] = $prefix .
'archive_name';
285 $fields[] = $prefix .
'deleted';
295 return $this->getArchiveRel( $this->getArchiveName() );
303 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
310 $this->loadFromFile();
312 # Don't destroy file info of missing files
313 if ( !$this->fileExists ) {
314 wfDebug( __METHOD__ .
": file does not exist, aborting" );
319 $dbw = $this->repo->getPrimaryDB();
320 [ $major, $minor ] = self::splitMime( $this->mime );
321 $metadata = $this->getMetadataForDb( $dbw );
323 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
324 $dbw->newUpdateQueryBuilder()
325 ->update(
'oldimage' )
327 'oi_size' => $this->size,
328 'oi_width' => $this->width,
329 'oi_height' => $this->height,
330 'oi_bits' => $this->bits,
331 'oi_media_type' => $this->media_type,
332 'oi_major_mime' => $major,
333 'oi_minor_mime' => $minor,
334 'oi_metadata' => $metadata,
335 'oi_sha1' => $this->sha1,
338 'oi_name' => $this->getName(),
339 'oi_archive_name' => $this->archive_name,
341 ->caller( __METHOD__ )->execute();
343 $migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
344 MainConfigNames::FileSchemaMigrationStage
347 $dbw->newUpdateQueryBuilder()
348 ->update(
'filerevision' )
350 'fr_size' => $this->size,
351 'fr_width' => $this->width,
352 'fr_height' => $this->height,
353 'fr_bits' => $this->bits,
354 'fr_metadata' => $metadata,
355 'fr_sha1' => $this->sha1,
358 'fr_file' => $this->acquireFileIdFromName(),
359 'fr_archive_name' => $this->archive_name,
361 ->caller( __METHOD__ )->execute();
379 return ( $this->deleted & $field ) == $field;
389 return (
int)$this->deleted;
403 return RevisionRecord::userCanBitfield(
420 $archiveName = $this->getArchiveName();
421 $dstRel = $this->getArchiveRel( $archiveName );
422 $status = $this->publishTo( $srcPath, $dstRel );
424 if ( $status->isGood() &&
425 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
427 $status->fatal(
'filenotfound', $srcPath );
444 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
445 $dbw = $this->repo->getPrimaryDB();
447 $services = MediaWikiServices::getInstance();
448 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
449 $props = $mwProps->getPropsFromPath( $srcPath,
true );
450 if ( !$props[
'fileExists'] ) {
453 $this->setProps( $props );
455 $dbw->startAtomic( __METHOD__ );
457 $commentFields = $services->getCommentStore()
458 ->insert( $dbw,
'oi_description', $comment );
459 $actorId = $services->getActorNormalization()
460 ->acquireActorId( $user, $dbw );
461 $dbw->newInsertQueryBuilder()
462 ->insertInto(
'oldimage' )
464 'oi_name' => $this->getName(),
465 'oi_archive_name' => $archiveName,
466 'oi_size' => $props[
'size'],
467 'oi_width' => intval( $props[
'width'] ),
468 'oi_height' => intval( $props[
'height'] ),
469 'oi_bits' => $props[
'bits'],
470 'oi_actor' => $actorId,
471 'oi_timestamp' => $dbw->timestamp( $timestamp ),
472 'oi_metadata' => $this->getMetadataForDb( $dbw ),
473 'oi_media_type' => $props[
'media_type'],
474 'oi_major_mime' => $props[
'major_mime'],
475 'oi_minor_mime' => $props[
'minor_mime'],
476 'oi_sha1' => $props[
'sha1'],
478 ->caller( __METHOD__ )->execute();
480 $migrationStage = MediaWikiServices::getInstance()->getMainConfig()->get(
481 MainConfigNames::FileSchemaMigrationStage
484 $commentFields = $services->getCommentStore()
485 ->insert( $dbw,
'fr_description', $comment );
486 $dbw->newInsertQueryBuilder()
487 ->insertInto(
'filerevision' )
490 'fr_file' => $this->acquireFileIdFromName(),
491 'fr_size' => $this->size,
492 'fr_width' => intval( $this->width ),
493 'fr_height' => intval( $this->height ),
494 'fr_bits' => $this->bits,
495 'fr_actor' => $actorId,
497 'fr_timestamp' => $dbw->timestamp( $timestamp ),
498 'fr_metadata' => $this->getMetadataForDb( $dbw ),
499 'fr_sha1' => $this->sha1
501 ->caller( __METHOD__ )->execute();
504 $dbw->endAtomic( __METHOD__ );
517 $archiveName = $this->getArchiveName();
518 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
521 return parent::exists();
526class_alias( OldLocalFile::class,
'OldLocalFile' );
const SCHEMA_COMPAT_WRITE_NEW
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
MimeMagic helper wrapper.
A class containing constants representing the names of configuration variables.