49 # The null default value is only here to avoid an E_STRICT
50 if ( $time ===
null ) {
51 throw new MWException( __METHOD__ .
' got null for $time parameter' );
64 return new static(
$title,
$repo,
null, $archiveName );
75 $file->loadFromRow( $row,
'oi_' );
93 $conds = [
'oi_sha1' =>
$sha1 ];
98 $fileQuery = static::getQueryInfo();
99 $row =
$dbr->selectRow(
100 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
103 return static::newFromRow( $row,
$repo );
121 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
122 $actorQuery = ActorMigration::newMigration()->getJoin(
'oi_user' );
124 'tables' => [
'oldimage' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
138 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
139 'joins' => $commentQuery[
'joins'] + $actorQuery[
'joins'],
142 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
146 if ( !in_array(
'omit-lazy', $options,
true ) ) {
148 $ret[
'fields'][] =
'oi_metadata';
163 $this->requestedTime = $time;
164 $this->archive_name = $archiveName;
165 if ( is_null( $time ) && is_null( $archiveName ) ) {
166 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
181 if ( !isset( $this->archive_name ) ) {
203 $this->dataLoaded =
true;
205 $dbr = ( $flags & self::READ_LATEST )
206 ? $this->repo->getMasterDB()
207 : $this->repo->getReplicaDB();
209 $conds = [
'oi_name' => $this->
getName() ];
210 if ( is_null( $this->requestedTime ) ) {
213 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
215 $fileQuery = static::getQueryInfo();
216 $row =
$dbr->selectRow(
217 $fileQuery[
'tables'],
218 $fileQuery[
'fields'],
221 [
'ORDER BY' =>
'oi_timestamp DESC' ],
227 $this->fileExists =
false;
235 $this->extraDataLoaded =
true;
236 $dbr = $this->repo->getReplicaDB();
237 $conds = [
'oi_name' => $this->
getName() ];
238 if ( is_null( $this->requestedTime ) ) {
241 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
243 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
245 $row =
$dbr->selectRow(
246 $fileQuery[
'tables'],
247 $fileQuery[
'fields'],
250 [
'ORDER BY' =>
'oi_timestamp DESC' ],
255 $dbr = $this->repo->getMasterDB();
256 $row =
$dbr->selectRow(
257 $fileQuery[
'tables'],
258 $fileQuery[
'fields'],
261 [
'ORDER BY' =>
'oi_timestamp DESC' ],
268 $this->
$name = $value;
271 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
277 $fields = parent::getCacheFields( $prefix );
278 $fields[] = $prefix .
'archive_name';
279 $fields[] = $prefix .
'deleted';
301 # Don't destroy file info of missing files
302 if ( !$this->fileExists ) {
303 wfDebug( __METHOD__ .
": file does not exist, aborting\n" );
308 $dbw = $this->repo->getMasterDB();
311 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema\n" );
312 $dbw->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->metadata,
322 'oi_sha1' => $this->sha1,
325 'oi_archive_name' => $this->archive_name ],
338 return ( $this->deleted & $field ) == $field;
362 return Revision::userCanBitfield( $this->deleted, $field,
$user );
379 $status = $this->
publishTo( $srcPath, $dstRel );
381 if ( $status->isGood() &&
382 !$this->recordOldUpload( $srcPath, $archiveName,
$timestamp, $comment,
$user )
384 $status->fatal(
'filenotfound', $srcPath );
403 $dbw = $this->repo->getMasterDB();
405 $dstPath = $this->repo->getZonePath(
'public' ) .
'/' . $this->
getRel();
406 $props = $this->repo->getFileProps( $dstPath );
407 if ( !$props[
'fileExists'] ) {
411 $commentFields = MediaWikiServices::getInstance()->getCommentStore()
412 ->insert( $dbw,
'oi_description', $comment );
413 $actorFields = ActorMigration::newMigration()->getInsertValues( $dbw,
'oi_user',
$user );
414 $dbw->insert(
'oldimage',
417 'oi_archive_name' => $archiveName,
418 'oi_size' => $props[
'size'],
419 'oi_width' => intval( $props[
'width'] ),
420 'oi_height' => intval( $props[
'height'] ),
421 'oi_bits' => $props[
'bits'],
422 'oi_timestamp' => $dbw->timestamp(
$timestamp ),
423 'oi_metadata' => $props[
'metadata'],
424 'oi_media_type' => $props[
'media_type'],
425 'oi_major_mime' => $props[
'major_mime'],
426 'oi_minor_mime' => $props[
'minor_mime'],
427 'oi_sha1' => $props[
'sha1'],
428 ] + $commentFields + $actorFields, __METHOD__
443 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
446 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.
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.
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.
load( $flags=0)
Load file metadata from cache or DB, unless already loaded.
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)
upgradeRow()
Fix assorted version-related problems with the image row by reloading it from the file.
recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user)
Record a file upload in the oldimage table, without adding log entries.
static newFromRow( $row, $repo)
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)
loadFromDB( $flags=0)
Load file metadata from the DB.
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)
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.string[] 1....
string int $requestedTime
Timestamp.
loadExtraFromDB()
Load lazy file metadata from the DB.
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.