54 public static function newFromTitle( $title, $repo, $time =
null ) {
55 # The null default value is only here to avoid an E_STRICT
56 if ( $time ===
null ) {
57 throw new InvalidArgumentException( __METHOD__ .
' got null for $time parameter' );
72 return new static(
$title,
$repo,
null, $archiveName );
84 $file =
new static(
$title,
$repo,
null, $row->oi_archive_name );
85 $file->loadFromRow( $row,
'oi_' );
102 public static function newFromKey( $sha1, $repo, $timestamp =
false ) {
103 $dbr =
$repo->getReplicaDB();
104 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $dbr );
106 $queryBuilder->where( [
'oi_sha1' =>
$sha1 ] );
108 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $timestamp ) ] );
111 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
113 return static::newFromRow( $row,
$repo );
140 $dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase();
141 $queryInfo = FileSelectQueryBuilder::newForOldFile( $dbr, $options )->getQueryInfo();
143 'tables' => $queryInfo[
'tables'],
144 'fields' => $queryInfo[
'fields'],
145 'joins' => $queryInfo[
'join_conds'],
157 public function __construct( $title, $repo, $time, $archiveName ) {
159 $this->requestedTime = $time;
160 $this->archive_name = $archiveName;
161 if ( $time ===
null && $archiveName ===
null ) {
162 throw new LogicException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
167 $this->archive_name = $row->{
"{$prefix}archive_name"};
168 $this->deleted = $row->{
"{$prefix}deleted"};
170 unset( $row->{
"{$prefix}archive_name"} );
171 unset( $row->{
"{$prefix}deleted"} );
172 parent::loadFromRow( $row, $prefix );
188 if ( !isset( $this->archive_name ) ) {
192 return $this->archive_name;
214 $this->dataLoaded =
true;
216 $dbr = ( $flags & IDBAccessObject::READ_LATEST )
217 ? $this->repo->getPrimaryDB()
218 : $this->repo->getReplicaDB();
219 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr, [] );
220 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
222 $this->loadFromRow( $row,
'oi_' );
224 $this->fileExists =
false;
233 $this->extraDataLoaded =
true;
234 $dbr = $this->repo->getReplicaDB();
235 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
238 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
241 $dbr = $this->repo->getPrimaryDB();
242 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
243 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
247 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
248 $this->$name = $value;
251 throw new RuntimeException(
"Could not find data for image '{$this->archive_name}'." );
255 private function buildQueryBuilderForLoad(
IReadableDatabase $dbr, $options = [
'omit-nonlazy' ] ) {
256 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $dbr, $options );
257 $queryBuilder->where( [
'oi_name' => $this->getName() ] )
258 ->orderBy(
'oi_timestamp', SelectQueryBuilder::SORT_DESC );
259 if ( $this->requestedTime ===
null ) {
260 $queryBuilder->andWhere( [
'oi_archive_name' => $this->archive_name ] );
262 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $this->requestedTime ) ] );
264 return $queryBuilder;
272 $fields = parent::getCacheFields( $prefix );
273 $fields[] = $prefix .
'archive_name';
274 $fields[] = $prefix .
'deleted';
284 return $this->getArchiveRel( $this->getArchiveName() );
292 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
299 $this->loadFromFile();
301 # Don't destroy file info of missing files
302 if ( !$this->fileExists ) {
303 wfDebug( __METHOD__ .
": file does not exist, aborting" );
308 $dbw = $this->repo->getPrimaryDB();
309 [ $major, $minor ] = self::splitMime( $this->mime );
311 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
312 $dbw->newUpdateQueryBuilder()
313 ->update(
'oldimage' )
315 'oi_size' => $this->size,
316 'oi_width' => $this->width,
317 'oi_height' => $this->height,
318 'oi_bits' => $this->bits,
319 'oi_media_type' => $this->media_type,
320 'oi_major_mime' => $major,
321 'oi_minor_mime' => $minor,
322 'oi_metadata' => $this->getMetadataForDb( $dbw ),
323 'oi_sha1' => $this->sha1,
326 'oi_name' => $this->getName(),
327 'oi_archive_name' => $this->archive_name,
329 ->caller( __METHOD__ )->execute();
346 return ( $this->deleted & $field ) == $field;
356 return (
int)$this->deleted;
370 return RevisionRecord::userCanBitfield(
387 $archiveName = $this->getArchiveName();
388 $dstRel = $this->getArchiveRel( $archiveName );
389 $status = $this->publishTo( $srcPath, $dstRel );
391 if ( $status->isGood() &&
392 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
394 $status->fatal(
'filenotfound', $srcPath );
411 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
412 $dbw = $this->repo->getPrimaryDB();
414 $services = MediaWikiServices::getInstance();
415 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
416 $props = $mwProps->getPropsFromPath( $srcPath,
true );
417 if ( !$props[
'fileExists'] ) {
420 $this->setProps( $props );
422 $dbw->startAtomic( __METHOD__ );
423 $commentFields = $services->getCommentStore()
424 ->insert( $dbw,
'oi_description', $comment );
425 $actorId = $services->getActorNormalization()
426 ->acquireActorId( $user, $dbw );
427 $dbw->newInsertQueryBuilder()
428 ->insertInto(
'oldimage' )
430 'oi_name' => $this->getName(),
431 'oi_archive_name' => $archiveName,
432 'oi_size' => $props[
'size'],
433 'oi_width' => intval( $props[
'width'] ),
434 'oi_height' => intval( $props[
'height'] ),
435 'oi_bits' => $props[
'bits'],
436 'oi_actor' => $actorId,
437 'oi_timestamp' => $dbw->timestamp( $timestamp ),
438 'oi_metadata' => $this->getMetadataForDb( $dbw ),
439 'oi_media_type' => $props[
'media_type'],
440 'oi_major_mime' => $props[
'major_mime'],
441 'oi_minor_mime' => $props[
'minor_mime'],
442 'oi_sha1' => $props[
'sha1'],
444 ->caller( __METHOD__ )->execute();
445 $dbw->endAtomic( __METHOD__ );
458 $archiveName = $this->getArchiveName();
459 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
462 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().
Title string false $title
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.