53 # The null default value is only here to avoid an E_STRICT
54 if ( $time ===
null ) {
55 throw new MWException( __METHOD__ .
' got null for $time parameter' );
70 return new static(
$title,
$repo,
null, $archiveName );
83 $file->loadFromRow( $row,
'oi_' );
103 $conds = [
'oi_sha1' =>
$sha1 ];
108 $fileQuery = static::getQueryInfo();
109 $row =
$dbr->selectRow(
110 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
113 return static::newFromRow( $row,
$repo );
138 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
142 'oldimage_actor' =>
'actor'
143 ] + $commentQuery[
'tables'],
158 'oi_user' =>
'oldimage_actor.actor_user',
159 'oi_user_text' =>
'oldimage_actor.actor_name'
160 ] + $commentQuery[
'fields'],
162 'oldimage_actor' => [
'JOIN',
'actor_id=oi_actor' ]
163 ] + $commentQuery[
'joins'],
166 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
170 if ( !in_array(
'omit-lazy', $options,
true ) ) {
172 $ret[
'fields'][] =
'oi_metadata';
189 $this->requestedTime = $time;
190 $this->archive_name = $archiveName;
191 if ( $time ===
null && $archiveName ===
null ) {
192 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
197 $this->archive_name = $row->{
"{$prefix}archive_name"};
198 $this->deleted = $row->{
"{$prefix}deleted"};
200 unset( $row->{
"{$prefix}archive_name"} );
201 unset( $row->{
"{$prefix}deleted"} );
202 parent::loadFromRow( $row, $prefix );
218 if ( !isset( $this->archive_name ) ) {
222 return $this->archive_name;
244 $this->dataLoaded =
true;
246 $dbr = ( $flags & self::READ_LATEST )
247 ? $this->repo->getPrimaryDB()
248 : $this->repo->getReplicaDB();
250 $conds = [
'oi_name' => $this->getName() ];
251 if ( $this->requestedTime ===
null ) {
252 $conds[
'oi_archive_name'] = $this->archive_name;
254 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
256 $fileQuery = static::getQueryInfo();
257 $row =
$dbr->selectRow(
258 $fileQuery[
'tables'],
259 $fileQuery[
'fields'],
262 [
'ORDER BY' =>
'oi_timestamp DESC' ],
266 $this->loadFromRow( $row,
'oi_' );
268 $this->fileExists =
false;
277 $this->extraDataLoaded =
true;
278 $dbr = $this->repo->getReplicaDB();
279 $conds = [
'oi_name' => $this->getName() ];
280 if ( $this->requestedTime ===
null ) {
281 $conds[
'oi_archive_name'] = $this->archive_name;
283 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
285 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
287 $row =
$dbr->selectRow(
288 $fileQuery[
'tables'],
289 $fileQuery[
'fields'],
292 [
'ORDER BY' =>
'oi_timestamp DESC' ],
297 $dbr = $this->repo->getPrimaryDB();
298 $row =
$dbr->selectRow(
299 $fileQuery[
'tables'],
300 $fileQuery[
'fields'],
303 [
'ORDER BY' =>
'oi_timestamp DESC' ],
309 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
310 $this->$name = $value;
313 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
322 $fields = parent::getCacheFields( $prefix );
323 $fields[] = $prefix .
'archive_name';
324 $fields[] = $prefix .
'deleted';
334 return $this->getArchiveRel( $this->getArchiveName() );
342 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
349 $this->loadFromFile();
351 # Don't destroy file info of missing files
352 if ( !$this->fileExists ) {
353 wfDebug( __METHOD__ .
": file does not exist, aborting" );
358 $dbw = $this->repo->getPrimaryDB();
359 list( $major, $minor ) = self::splitMime( $this->mime );
361 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
362 $dbw->update(
'oldimage',
364 'oi_size' => $this->size,
365 'oi_width' => $this->width,
366 'oi_height' => $this->height,
367 'oi_bits' => $this->bits,
368 'oi_media_type' => $this->media_type,
369 'oi_major_mime' => $major,
370 'oi_minor_mime' => $minor,
371 'oi_metadata' => $this->getMetadataForDb( $dbw ),
372 'oi_sha1' => $this->sha1,
374 'oi_name' => $this->getName(),
375 'oi_archive_name' => $this->archive_name ],
394 return ( $this->deleted & $field ) == $field;
404 return (
int)$this->deleted;
418 return RevisionRecord::userCanBitfield(
437 $archiveName = $this->getArchiveName();
438 $dstRel = $this->getArchiveRel( $archiveName );
439 $status = $this->publishTo( $srcPath, $dstRel );
441 if ( $status->isGood() &&
442 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
444 $status->fatal(
'filenotfound', $srcPath );
463 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
464 $dbw = $this->repo->getPrimaryDB();
466 $services = MediaWikiServices::getInstance();
467 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
468 $props = $mwProps->getPropsFromPath( $srcPath,
true );
469 if ( !$props[
'fileExists'] ) {
472 $this->setProps( $props );
474 $commentFields = $services->getCommentStore()
475 ->insert( $dbw,
'oi_description', $comment );
476 $actorId = $services->getActorNormalization()
477 ->acquireActorId( $user, $dbw );
478 $dbw->insert(
'oldimage',
480 'oi_name' => $this->getName(),
481 'oi_archive_name' => $archiveName,
482 'oi_size' => $props[
'size'],
483 'oi_width' => intval( $props[
'width'] ),
484 'oi_height' => intval( $props[
'height'] ),
485 'oi_bits' => $props[
'bits'],
486 'oi_actor' => $actorId,
487 'oi_timestamp' => $dbw->timestamp( $timestamp ),
488 'oi_metadata' => $this->getMetadataForDb( $dbw ),
489 'oi_media_type' => $props[
'media_type'],
490 'oi_major_mime' => $props[
'major_mime'],
491 'oi_minor_mime' => $props[
'minor_mime'],
492 'oi_sha1' => $props[
'sha1'],
493 ] + $commentFields, __METHOD__
507 $archiveName = $this->getArchiveName();
508 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
511 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 bool $repo
Some member variables can be lazy-initialised using __get().
Class to represent a local file in the wiki's own database.
string $timestamp
Upload timestamp.
string $sha1
SHA-1 base 36 content hash.
MimeMagic helper wrapper.
Class to represent a 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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.