53 public static function newFromTitle( $title, $repo, $time =
null ) {
54 # The null default value is only here to avoid an E_STRICT
55 if ( $time ===
null ) {
56 throw new InvalidArgumentException( __METHOD__ .
' got null for $time parameter' );
71 return new static(
$title,
$repo,
null, $archiveName );
83 $file =
new static(
$title,
$repo,
null, $row->oi_archive_name );
84 $file->loadFromRow( $row,
'oi_' );
101 public static function newFromKey( $sha1, $repo, $timestamp =
false ) {
102 $dbr =
$repo->getReplicaDB();
103 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $dbr );
105 $queryBuilder->where( [
'oi_sha1' =>
$sha1 ] );
107 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $timestamp ) ] );
110 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
112 return static::newFromRow( $row,
$repo );
139 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
140 $queryInfo = FileSelectQueryBuilder::newForOldFile( $dbr, $options )->getQueryInfo();
142 'tables' => $queryInfo[
'tables'],
143 'fields' => $queryInfo[
'fields'],
144 'joins' => $queryInfo[
'join_conds'],
156 public function __construct( $title, $repo, $time, $archiveName ) {
158 $this->requestedTime = $time;
159 $this->archive_name = $archiveName;
160 if ( $time ===
null && $archiveName ===
null ) {
161 throw new LogicException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
166 $this->archive_name = $row->{
"{$prefix}archive_name"};
167 $this->deleted = $row->{
"{$prefix}deleted"};
169 unset( $row->{
"{$prefix}archive_name"} );
170 unset( $row->{
"{$prefix}deleted"} );
171 parent::loadFromRow( $row, $prefix );
187 if ( !isset( $this->archive_name ) ) {
191 return $this->archive_name;
213 $this->dataLoaded =
true;
215 $dbr = ( $flags & IDBAccessObject::READ_LATEST )
216 ? $this->repo->getPrimaryDB()
217 : $this->repo->getReplicaDB();
218 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr, [] );
219 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
221 $this->loadFromRow( $row,
'oi_' );
223 $this->fileExists =
false;
232 $this->extraDataLoaded =
true;
233 $dbr = $this->repo->getReplicaDB();
234 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
237 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
240 $dbr = $this->repo->getPrimaryDB();
241 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
242 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
246 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
247 $this->$name = $value;
250 throw new RuntimeException(
"Could not find data for image '{$this->archive_name}'." );
254 private function buildQueryBuilderForLoad(
IReadableDatabase $dbr, $options = [
'omit-nonlazy' ] ) {
255 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $dbr, $options );
256 $queryBuilder->where( [
'oi_name' => $this->getName() ] )
257 ->orderBy(
'oi_timestamp', SelectQueryBuilder::SORT_DESC );
258 if ( $this->requestedTime ===
null ) {
259 $queryBuilder->andWhere( [
'oi_archive_name' => $this->archive_name ] );
261 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $this->requestedTime ) ] );
263 return $queryBuilder;
271 $fields = parent::getCacheFields( $prefix );
272 $fields[] = $prefix .
'archive_name';
273 $fields[] = $prefix .
'deleted';
283 return $this->getArchiveRel( $this->getArchiveName() );
291 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
298 $this->loadFromFile();
300 # Don't destroy file info of missing files
301 if ( !$this->fileExists ) {
302 wfDebug( __METHOD__ .
": file does not exist, aborting" );
307 $dbw = $this->repo->getPrimaryDB();
308 [ $major, $minor ] = self::splitMime( $this->mime );
310 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
311 $dbw->newUpdateQueryBuilder()
312 ->update(
'oldimage' )
314 'oi_size' => $this->size,
315 'oi_width' => $this->width,
316 'oi_height' => $this->height,
317 'oi_bits' => $this->bits,
318 'oi_media_type' => $this->media_type,
319 'oi_major_mime' => $major,
320 'oi_minor_mime' => $minor,
321 'oi_metadata' => $this->getMetadataForDb( $dbw ),
322 'oi_sha1' => $this->sha1,
325 'oi_name' => $this->getName(),
326 'oi_archive_name' => $this->archive_name,
328 ->caller( __METHOD__ )->execute();
345 return ( $this->deleted & $field ) == $field;
355 return (
int)$this->deleted;
369 return RevisionRecord::userCanBitfield(
386 $archiveName = $this->getArchiveName();
387 $dstRel = $this->getArchiveRel( $archiveName );
388 $status = $this->publishTo( $srcPath, $dstRel );
390 if ( $status->isGood() &&
391 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
393 $status->fatal(
'filenotfound', $srcPath );
410 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
411 $dbw = $this->repo->getPrimaryDB();
413 $services = MediaWikiServices::getInstance();
414 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
415 $props = $mwProps->getPropsFromPath( $srcPath,
true );
416 if ( !$props[
'fileExists'] ) {
419 $this->setProps( $props );
421 $dbw->startAtomic( __METHOD__ );
422 $commentFields = $services->getCommentStore()
423 ->insert( $dbw,
'oi_description', $comment );
424 $actorId = $services->getActorNormalization()
425 ->acquireActorId( $user, $dbw );
426 $dbw->newInsertQueryBuilder()
427 ->insertInto(
'oldimage' )
429 'oi_name' => $this->getName(),
430 'oi_archive_name' => $archiveName,
431 'oi_size' => $props[
'size'],
432 'oi_width' => intval( $props[
'width'] ),
433 'oi_height' => intval( $props[
'height'] ),
434 'oi_bits' => $props[
'bits'],
435 'oi_actor' => $actorId,
436 'oi_timestamp' => $dbw->timestamp( $timestamp ),
437 'oi_metadata' => $this->getMetadataForDb( $dbw ),
438 'oi_media_type' => $props[
'media_type'],
439 'oi_major_mime' => $props[
'major_mime'],
440 'oi_minor_mime' => $props[
'minor_mime'],
441 'oi_sha1' => $props[
'sha1'],
443 ->caller( __METHOD__ )->execute();
444 $dbw->endAtomic( __METHOD__ );
457 $archiveName = $this->getArchiveName();
458 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
461 return parent::exists();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
FileRepo LocalRepo ForeignAPIRepo false $repo
Some member variables can be lazy-initialised using __get().
Title string false $title
Local file in the wiki's own database.
string $sha1
SHA-1 base 36 content hash.
MimeMagic helper wrapper.
Old file in the oldimage table.
static newFromArchiveName( $title, $repo, $archiveName)
recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user)
Record a file upload in the oldimage table, without adding log entries.
uploadOld( $srcPath, $timestamp, $comment, UserIdentity $user)
Upload a file directly into archive.
static newFromRow( $row, $repo)
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
__construct( $title, $repo, $time, $archiveName)
reserializeMetadata()
Write the metadata back to the database with the current serialization format.
static newFromKey( $sha1, $repo, $timestamp=false)
Create a OldLocalFile from a SHA-1 key Do not call this except from inside a repo class.
loadFromRow( $row, $prefix='img_')
Load file metadata from a DB result row.
getVisibility()
Returns bitfield value.
static newFromTitle( $title, $repo, $time=null)
string $archive_name
Archive name.
exists()
If archive name is an empty string, then file does not "exist".
getCacheFields( $prefix='img_')
Returns the list of object properties that are included as-is in the cache.to override string[] 1....
userCan( $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this image file,...
string int $requestedTime
Timestamp.
loadExtraFromDB()
Load lazy file metadata from the DB.