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_' );
100 $conds = [
'oi_sha1' =>
$sha1 ];
105 $fileQuery = static::getQueryInfo();
106 $row =
$dbr->selectRow(
107 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
110 return static::newFromRow( $row,
$repo );
135 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
139 'oldimage_actor' =>
'actor'
140 ] + $commentQuery[
'tables'],
155 'oi_user' =>
'oldimage_actor.actor_user',
156 'oi_user_text' =>
'oldimage_actor.actor_name'
157 ] + $commentQuery[
'fields'],
159 'oldimage_actor' => [
'JOIN',
'actor_id=oi_actor' ]
160 ] + $commentQuery[
'joins'],
163 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
167 if ( !in_array(
'omit-lazy', $options,
true ) ) {
169 $ret[
'fields'][] =
'oi_metadata';
186 $this->requestedTime = $time;
187 $this->archive_name = $archiveName;
188 if ( $time ===
null && $archiveName ===
null ) {
189 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
194 $this->archive_name = $row->{
"{$prefix}archive_name"};
195 $this->deleted = $row->{
"{$prefix}deleted"};
197 unset( $row->{
"{$prefix}archive_name"} );
198 unset( $row->{
"{$prefix}deleted"} );
199 parent::loadFromRow( $row, $prefix );
215 if ( !isset( $this->archive_name ) ) {
219 return $this->archive_name;
241 $this->dataLoaded =
true;
243 $dbr = ( $flags & self::READ_LATEST )
244 ? $this->repo->getPrimaryDB()
245 : $this->repo->getReplicaDB();
247 $conds = [
'oi_name' => $this->getName() ];
248 if ( $this->requestedTime ===
null ) {
249 $conds[
'oi_archive_name'] = $this->archive_name;
251 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
253 $fileQuery = static::getQueryInfo();
254 $row =
$dbr->selectRow(
255 $fileQuery[
'tables'],
256 $fileQuery[
'fields'],
259 [
'ORDER BY' =>
'oi_timestamp DESC' ],
263 $this->loadFromRow( $row,
'oi_' );
265 $this->fileExists =
false;
274 $this->extraDataLoaded =
true;
275 $dbr = $this->repo->getReplicaDB();
276 $conds = [
'oi_name' => $this->getName() ];
277 if ( $this->requestedTime ===
null ) {
278 $conds[
'oi_archive_name'] = $this->archive_name;
280 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
282 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
284 $row =
$dbr->selectRow(
285 $fileQuery[
'tables'],
286 $fileQuery[
'fields'],
289 [
'ORDER BY' =>
'oi_timestamp DESC' ],
294 $dbr = $this->repo->getPrimaryDB();
295 $row =
$dbr->selectRow(
296 $fileQuery[
'tables'],
297 $fileQuery[
'fields'],
300 [
'ORDER BY' =>
'oi_timestamp DESC' ],
306 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
307 $this->$name = $value;
310 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
319 $fields = parent::getCacheFields( $prefix );
320 $fields[] = $prefix .
'archive_name';
321 $fields[] = $prefix .
'deleted';
331 return $this->getArchiveRel( $this->getArchiveName() );
339 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
346 $this->loadFromFile();
348 # Don't destroy file info of missing files
349 if ( !$this->fileExists ) {
350 wfDebug( __METHOD__ .
": file does not exist, aborting" );
355 $dbw = $this->repo->getPrimaryDB();
356 list( $major, $minor ) = self::splitMime( $this->mime );
358 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
359 $dbw->update(
'oldimage',
361 'oi_size' => $this->size,
362 'oi_width' => $this->width,
363 'oi_height' => $this->height,
364 'oi_bits' => $this->bits,
365 'oi_media_type' => $this->media_type,
366 'oi_major_mime' => $major,
367 'oi_minor_mime' => $minor,
368 'oi_metadata' => $this->getMetadataForDb( $dbw ),
369 'oi_sha1' => $this->sha1,
371 'oi_name' => $this->getName(),
372 'oi_archive_name' => $this->archive_name ],
391 return ( $this->deleted & $field ) == $field;
401 return (
int)$this->deleted;
415 return RevisionRecord::userCanBitfield(
432 $archiveName = $this->getArchiveName();
433 $dstRel = $this->getArchiveRel( $archiveName );
434 $status = $this->publishTo( $srcPath, $dstRel );
436 if ( $status->isGood() &&
437 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
439 $status->fatal(
'filenotfound', $srcPath );
456 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
457 $dbw = $this->repo->getPrimaryDB();
459 $services = MediaWikiServices::getInstance();
460 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
461 $props = $mwProps->getPropsFromPath( $srcPath,
true );
462 if ( !$props[
'fileExists'] ) {
465 $this->setProps( $props );
467 $dbw->startAtomic( __METHOD__ );
468 $commentFields = $services->getCommentStore()
469 ->insert( $dbw,
'oi_description', $comment );
470 $actorId = $services->getActorNormalization()
471 ->acquireActorId( $user, $dbw );
472 $dbw->insert(
'oldimage',
474 'oi_name' => $this->getName(),
475 'oi_archive_name' => $archiveName,
476 'oi_size' => $props[
'size'],
477 'oi_width' => intval( $props[
'width'] ),
478 'oi_height' => intval( $props[
'height'] ),
479 'oi_bits' => $props[
'bits'],
480 'oi_actor' => $actorId,
481 'oi_timestamp' => $dbw->timestamp( $timestamp ),
482 'oi_metadata' => $this->getMetadataForDb( $dbw ),
483 'oi_media_type' => $props[
'media_type'],
484 'oi_major_mime' => $props[
'major_mime'],
485 'oi_minor_mime' => $props[
'minor_mime'],
486 'oi_sha1' => $props[
'sha1'],
487 ] + $commentFields, __METHOD__
489 $dbw->endAtomic( __METHOD__ );
502 $archiveName = $this->getArchiveName();
503 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
506 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 $timestamp
Upload timestamp.
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.Stability: stableto overri...
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.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.