50 # The null default value is only here to avoid an E_STRICT
51 if ( $time ===
null ) {
52 throw new MWException( __METHOD__ .
' got null for $time parameter' );
67 return new static(
$title,
$repo,
null, $archiveName );
80 $file->loadFromRow( $row,
'oi_' );
97 public static function newFromKey( $sha1, $repo, $timestamp =
false ) {
100 $conds = [
'oi_sha1' =>
$sha1 ];
102 $conds[
'oi_timestamp'] =
$dbr->timestamp( $timestamp );
105 $fileQuery = static::getQueryInfo();
106 $row =
$dbr->selectRow(
107 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
110 return static::newFromRow( $row,
$repo );
136 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
140 'oldimage_actor' =>
'actor'
141 ] + $commentQuery[
'tables'],
156 'oi_user' =>
'oldimage_actor.actor_user',
157 'oi_user_text' =>
'oldimage_actor.actor_name'
158 ] + $commentQuery[
'fields'],
160 'oldimage_actor' => [
'JOIN',
'actor_id=oi_actor' ]
161 ] + $commentQuery[
'joins'],
164 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
168 if ( !in_array(
'omit-lazy', $options,
true ) ) {
170 $ret[
'fields'][] =
'oi_metadata';
187 $this->requestedTime = $time;
188 $this->archive_name = $archiveName;
189 if ( $time ===
null && $archiveName ===
null ) {
190 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
195 $this->archive_name = $row->{
"{$prefix}archive_name"};
196 $this->deleted = $row->{
"{$prefix}deleted"};
198 unset( $row->{
"{$prefix}archive_name"} );
199 unset( $row->{
"{$prefix}deleted"} );
200 parent::loadFromRow( $row, $prefix );
216 if ( !isset( $this->archive_name ) ) {
220 return $this->archive_name;
242 $this->dataLoaded =
true;
244 $dbr = ( $flags & self::READ_LATEST )
245 ? $this->repo->getPrimaryDB()
246 : $this->repo->getReplicaDB();
248 $conds = [
'oi_name' => $this->getName() ];
249 if ( $this->requestedTime ===
null ) {
250 $conds[
'oi_archive_name'] = $this->archive_name;
252 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
254 $fileQuery = static::getQueryInfo();
255 $row =
$dbr->selectRow(
256 $fileQuery[
'tables'],
257 $fileQuery[
'fields'],
260 [
'ORDER BY' =>
'oi_timestamp DESC' ],
264 $this->loadFromRow( $row,
'oi_' );
266 $this->fileExists =
false;
275 $this->extraDataLoaded =
true;
276 $dbr = $this->repo->getReplicaDB();
277 $conds = [
'oi_name' => $this->getName() ];
278 if ( $this->requestedTime ===
null ) {
279 $conds[
'oi_archive_name'] = $this->archive_name;
281 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
283 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
285 $row =
$dbr->selectRow(
286 $fileQuery[
'tables'],
287 $fileQuery[
'fields'],
290 [
'ORDER BY' =>
'oi_timestamp DESC' ],
295 $dbr = $this->repo->getPrimaryDB();
296 $row =
$dbr->selectRow(
297 $fileQuery[
'tables'],
298 $fileQuery[
'fields'],
301 [
'ORDER BY' =>
'oi_timestamp DESC' ],
307 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
308 $this->$name = $value;
311 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
320 $fields = parent::getCacheFields( $prefix );
321 $fields[] = $prefix .
'archive_name';
322 $fields[] = $prefix .
'deleted';
332 return $this->getArchiveRel( $this->getArchiveName() );
340 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
347 $this->loadFromFile();
349 # Don't destroy file info of missing files
350 if ( !$this->fileExists ) {
351 wfDebug( __METHOD__ .
": file does not exist, aborting" );
356 $dbw = $this->repo->getPrimaryDB();
357 list( $major, $minor ) = self::splitMime( $this->mime );
359 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
360 $dbw->update(
'oldimage',
362 'oi_size' => $this->size,
363 'oi_width' => $this->width,
364 'oi_height' => $this->height,
365 'oi_bits' => $this->bits,
366 'oi_media_type' => $this->media_type,
367 'oi_major_mime' => $major,
368 'oi_minor_mime' => $minor,
369 'oi_metadata' => $this->getMetadataForDb( $dbw ),
370 'oi_sha1' => $this->sha1,
372 'oi_name' => $this->getName(),
373 'oi_archive_name' => $this->archive_name ],
392 return ( $this->deleted & $field ) == $field;
402 return (
int)$this->deleted;
416 return RevisionRecord::userCanBitfield(
433 $archiveName = $this->getArchiveName();
434 $dstRel = $this->getArchiveRel( $archiveName );
435 $status = $this->publishTo( $srcPath, $dstRel );
437 if ( $status->isGood() &&
438 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
440 $status->fatal(
'filenotfound', $srcPath );
457 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
458 $dbw = $this->repo->getPrimaryDB();
460 $services = MediaWikiServices::getInstance();
461 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
462 $props = $mwProps->getPropsFromPath( $srcPath,
true );
463 if ( !$props[
'fileExists'] ) {
466 $this->setProps( $props );
468 $dbw->startAtomic( __METHOD__ );
469 $commentFields = $services->getCommentStore()
470 ->insert( $dbw,
'oi_description', $comment );
471 $actorId = $services->getActorNormalization()
472 ->acquireActorId( $user, $dbw );
473 $dbw->insert(
'oldimage',
475 'oi_name' => $this->getName(),
476 'oi_archive_name' => $archiveName,
477 'oi_size' => $props[
'size'],
478 'oi_width' => intval( $props[
'width'] ),
479 'oi_height' => intval( $props[
'height'] ),
480 'oi_bits' => $props[
'bits'],
481 'oi_actor' => $actorId,
482 'oi_timestamp' => $dbw->timestamp( $timestamp ),
483 'oi_metadata' => $this->getMetadataForDb( $dbw ),
484 'oi_media_type' => $props[
'media_type'],
485 'oi_major_mime' => $props[
'major_mime'],
486 'oi_minor_mime' => $props[
'minor_mime'],
487 'oi_sha1' => $props[
'sha1'],
488 ] + $commentFields, __METHOD__
490 $dbw->endAtomic( __METHOD__ );
503 $archiveName = $this->getArchiveName();
504 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
507 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().
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.