51 # The null default value is only here to avoid an E_STRICT
52 if ( $time ===
null ) {
53 throw new MWException( __METHOD__ .
' got null for $time parameter' );
68 return new static(
$title,
$repo,
null, $archiveName );
81 $file->loadFromRow( $row,
'oi_' );
101 $conds = [
'oi_sha1' =>
$sha1 ];
106 $fileQuery = static::getQueryInfo();
107 $row =
$dbr->selectRow(
108 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
111 return static::newFromRow( $row,
$repo );
131 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
132 $actorQuery = ActorMigration::newMigration()->getJoin(
'oi_user' );
134 'tables' => [
'oldimage' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
148 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
149 'joins' => $commentQuery[
'joins'] + $actorQuery[
'joins'],
152 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
156 if ( !in_array(
'omit-lazy', $options,
true ) ) {
158 $ret[
'fields'][] =
'oi_metadata';
175 $this->requestedTime = $time;
176 $this->archive_name = $archiveName;
177 if ( $time ===
null && $archiveName ===
null ) {
178 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
195 if ( !isset( $this->archive_name ) ) {
221 $this->dataLoaded =
true;
223 $dbr = ( $flags & self::READ_LATEST )
224 ? $this->repo->getMasterDB()
225 : $this->repo->getReplicaDB();
227 $conds = [
'oi_name' => $this->
getName() ];
228 if ( $this->requestedTime ===
null ) {
231 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
233 $fileQuery = static::getQueryInfo();
234 $row =
$dbr->selectRow(
235 $fileQuery[
'tables'],
236 $fileQuery[
'fields'],
239 [
'ORDER BY' =>
'oi_timestamp DESC' ],
245 $this->fileExists =
false;
254 $this->extraDataLoaded =
true;
255 $dbr = $this->repo->getReplicaDB();
256 $conds = [
'oi_name' => $this->
getName() ];
257 if ( $this->requestedTime ===
null ) {
260 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
262 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
264 $row =
$dbr->selectRow(
265 $fileQuery[
'tables'],
266 $fileQuery[
'fields'],
269 [
'ORDER BY' =>
'oi_timestamp DESC' ],
274 $dbr = $this->repo->getMasterDB();
275 $row =
$dbr->selectRow(
276 $fileQuery[
'tables'],
277 $fileQuery[
'fields'],
280 [
'ORDER BY' =>
'oi_timestamp DESC' ],
287 $this->
$name = $value;
290 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
299 $fields = parent::getCacheFields( $prefix );
300 $fields[] = $prefix .
'archive_name';
301 $fields[] = $prefix .
'deleted';
328 # Don't destroy file info of missing files
329 if ( !$this->fileExists ) {
330 wfDebug( __METHOD__ .
": file does not exist, aborting" );
335 $dbw = $this->repo->getMasterDB();
338 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
339 $dbw->update(
'oldimage',
341 'oi_size' => $this->size,
342 'oi_width' => $this->width,
343 'oi_height' => $this->height,
344 'oi_bits' => $this->bits,
345 'oi_media_type' => $this->media_type,
346 'oi_major_mime' => $major,
347 'oi_minor_mime' => $minor,
348 'oi_metadata' => $this->metadata,
349 'oi_sha1' => $this->sha1,
352 'oi_archive_name' => $this->archive_name ],
365 return ( $this->deleted & $field ) == $field;
390 wfDeprecated( __METHOD__ .
' without passing a $user parameter',
'1.35' );
394 return RevisionRecord::userCanBitfield(
415 $status = $this->
publishTo( $srcPath, $dstRel );
417 if ( $status->isGood() &&
418 !$this->recordOldUpload( $srcPath, $archiveName,
$timestamp, $comment,
$user )
420 $status->fatal(
'filenotfound', $srcPath );
440 $dbw = $this->repo->getMasterDB();
442 $dstPath = $this->repo->getZonePath(
'public' ) .
'/' . $this->
getRel();
443 $props = $this->repo->getFileProps( $dstPath );
444 if ( !$props[
'fileExists'] ) {
448 $commentFields = MediaWikiServices::getInstance()->getCommentStore()
449 ->insert( $dbw,
'oi_description', $comment );
450 $actorFields = ActorMigration::newMigration()->getInsertValues( $dbw,
'oi_user',
$user );
451 $dbw->insert(
'oldimage',
454 'oi_archive_name' => $archiveName,
455 'oi_size' => $props[
'size'],
456 'oi_width' => intval( $props[
'width'] ),
457 'oi_height' => intval( $props[
'height'] ),
458 'oi_bits' => $props[
'bits'],
459 'oi_timestamp' => $dbw->timestamp(
$timestamp ),
460 'oi_metadata' => $props[
'metadata'],
461 'oi_media_type' => $props[
'media_type'],
462 'oi_major_mime' => $props[
'major_mime'],
463 'oi_minor_mime' => $props[
'minor_mime'],
464 'oi_sha1' => $props[
'sha1'],
465 ] + $commentFields + $actorFields, __METHOD__
480 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
483 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.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
getName()
Return the name of this file.
string $name
The name of a file from its title object.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
static splitMime( $mime)
Split an internet media type into its two components; if not a two-part name, set the minor type to '...
getArchiveRel( $suffix=false)
Get the path of an archived file relative to the public zone root Stable to override.
Class to represent a local file in the wiki's own database.
lock()
Start an atomic DB section and lock the image for update or increments a reference counter if the loc...
loadFromRow( $row, $prefix='img_')
Load file metadata from a DB result row Stable to override.
load( $flags=0)
Load file metadata from cache or DB, unless already loaded Stable to override.
loadFromFile()
Load metadata from the file itself.
string $timestamp
Upload timestamp.
publishTo( $src, $dstRel, $flags=0, array $options=[])
Move or copy a file to a specified location.
unlock()
Decrement the lock reference count and end the atomic section if it reaches zero.
string $sha1
SHA-1 base 36 content hash.
unprefixRow( $row, $prefix='img_')
int $deleted
Bitfield akin to rev_deleted.
Class to represent a file in the oldimage table.
static newFromArchiveName( $title, $repo, $archiveName)
Stable to override.
upgradeRow()
Stable to override.
recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user)
Record a file upload in the oldimage table, without adding log entries.
getCacheKey()
Stable to override.
static newFromRow( $row, $repo)
Stable to override.
uploadOld( $srcPath, $timestamp, $comment, $user)
Upload a file directly into archive.
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)
Stable to call.
loadFromDB( $flags=0)
Stable to override.
static newFromKey( $sha1, $repo, $timestamp=false)
Create a OldLocalFile from a SHA-1 key Do not call this except from inside a repo class.
getVisibility()
Returns bitfield value.
static newFromTitle( $title, $repo, $time=null)
Stable to override.
getArchiveName()
Stable to override.
string $archive_name
Archive name.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this image file,...
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.Stable to override string[...
string int $requestedTime
Timestamp.
loadExtraFromDB()
Load lazy file metadata from the DB Stable to override.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.