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_' );
98 public static function newFromKey( $sha1, $repo, $timestamp =
false ) {
101 $conds = [
'oi_sha1' =>
$sha1 ];
103 $conds[
'oi_timestamp'] =
$dbr->timestamp( $timestamp );
106 $fileQuery = static::getQueryInfo();
107 $row =
$dbr->selectRow(
108 $fileQuery[
'tables'], $fileQuery[
'fields'], $conds, __METHOD__, [], $fileQuery[
'joins']
111 return static::newFromRow( $row,
$repo );
137 $commentQuery = MediaWikiServices::getInstance()->getCommentStore()->getJoin(
'oi_description' );
141 'oldimage_actor' =>
'actor'
142 ] + $commentQuery[
'tables'],
157 'oi_user' =>
'oldimage_actor.actor_user',
158 'oi_user_text' =>
'oldimage_actor.actor_name'
159 ] + $commentQuery[
'fields'],
161 'oldimage_actor' => [
'JOIN',
'actor_id=oi_actor' ]
162 ] + $commentQuery[
'joins'],
165 if ( in_array(
'omit-nonlazy', $options,
true ) ) {
169 if ( !in_array(
'omit-lazy', $options,
true ) ) {
171 $ret[
'fields'][] =
'oi_metadata';
188 $this->requestedTime = $time;
189 $this->archive_name = $archiveName;
190 if ( $time ===
null && $archiveName ===
null ) {
191 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
196 $this->archive_name = $row->{
"{$prefix}archive_name"};
197 $this->deleted = $row->{
"{$prefix}deleted"};
199 unset( $row->{
"{$prefix}archive_name"} );
200 unset( $row->{
"{$prefix}deleted"} );
201 parent::loadFromRow( $row, $prefix );
217 if ( !isset( $this->archive_name ) ) {
221 return $this->archive_name;
243 $this->dataLoaded =
true;
245 $dbr = ( $flags & self::READ_LATEST )
246 ? $this->repo->getPrimaryDB()
247 : $this->repo->getReplicaDB();
249 $conds = [
'oi_name' => $this->getName() ];
250 if ( $this->requestedTime ===
null ) {
251 $conds[
'oi_archive_name'] = $this->archive_name;
253 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
255 $fileQuery = static::getQueryInfo();
256 $row =
$dbr->selectRow(
257 $fileQuery[
'tables'],
258 $fileQuery[
'fields'],
261 [
'ORDER BY' =>
'oi_timestamp DESC' ],
265 $this->loadFromRow( $row,
'oi_' );
267 $this->fileExists =
false;
276 $this->extraDataLoaded =
true;
277 $dbr = $this->repo->getReplicaDB();
278 $conds = [
'oi_name' => $this->getName() ];
279 if ( $this->requestedTime ===
null ) {
280 $conds[
'oi_archive_name'] = $this->archive_name;
282 $conds[
'oi_timestamp'] =
$dbr->timestamp( $this->requestedTime );
284 $fileQuery = static::getQueryInfo( [
'omit-nonlazy' ] );
286 $row =
$dbr->selectRow(
287 $fileQuery[
'tables'],
288 $fileQuery[
'fields'],
291 [
'ORDER BY' =>
'oi_timestamp DESC' ],
296 $dbr = $this->repo->getPrimaryDB();
297 $row =
$dbr->selectRow(
298 $fileQuery[
'tables'],
299 $fileQuery[
'fields'],
302 [
'ORDER BY' =>
'oi_timestamp DESC' ],
308 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
309 $this->$name = $value;
312 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
321 $fields = parent::getCacheFields( $prefix );
322 $fields[] = $prefix .
'archive_name';
323 $fields[] = $prefix .
'deleted';
333 return $this->getArchiveRel( $this->getArchiveName() );
341 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
348 $this->loadFromFile();
350 # Don't destroy file info of missing files
351 if ( !$this->fileExists ) {
352 wfDebug( __METHOD__ .
": file does not exist, aborting" );
357 $dbw = $this->repo->getPrimaryDB();
358 [ $major, $minor ] = self::splitMime( $this->mime );
360 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
361 $dbw->update(
'oldimage',
363 'oi_size' => $this->size,
364 'oi_width' => $this->width,
365 'oi_height' => $this->height,
366 'oi_bits' => $this->bits,
367 'oi_media_type' => $this->media_type,
368 'oi_major_mime' => $major,
369 'oi_minor_mime' => $minor,
370 'oi_metadata' => $this->getMetadataForDb( $dbw ),
371 'oi_sha1' => $this->sha1,
373 'oi_name' => $this->getName(),
374 'oi_archive_name' => $this->archive_name ],
393 return ( $this->deleted & $field ) == $field;
403 return (
int)$this->deleted;
417 return RevisionRecord::userCanBitfield(
434 $archiveName = $this->getArchiveName();
435 $dstRel = $this->getArchiveRel( $archiveName );
436 $status = $this->publishTo( $srcPath, $dstRel );
438 if ( $status->isGood() &&
439 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
441 $status->fatal(
'filenotfound', $srcPath );
458 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
459 $dbw = $this->repo->getPrimaryDB();
461 $services = MediaWikiServices::getInstance();
462 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
463 $props = $mwProps->getPropsFromPath( $srcPath,
true );
464 if ( !$props[
'fileExists'] ) {
467 $this->setProps( $props );
469 $dbw->startAtomic( __METHOD__ );
470 $commentFields = $services->getCommentStore()
471 ->insert( $dbw,
'oi_description', $comment );
472 $actorId = $services->getActorNormalization()
473 ->acquireActorId( $user, $dbw );
474 $dbw->insert(
'oldimage',
476 'oi_name' => $this->getName(),
477 'oi_archive_name' => $archiveName,
478 'oi_size' => $props[
'size'],
479 'oi_width' => intval( $props[
'width'] ),
480 'oi_height' => intval( $props[
'height'] ),
481 'oi_bits' => $props[
'bits'],
482 'oi_actor' => $actorId,
483 'oi_timestamp' => $dbw->timestamp( $timestamp ),
484 'oi_metadata' => $this->getMetadataForDb( $dbw ),
485 'oi_media_type' => $props[
'media_type'],
486 'oi_major_mime' => $props[
'major_mime'],
487 'oi_minor_mime' => $props[
'minor_mime'],
488 'oi_sha1' => $props[
'sha1'],
489 ] + $commentFields, __METHOD__
491 $dbw->endAtomic( __METHOD__ );
504 $archiveName = $this->getArchiveName();
505 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
508 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 false $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.