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 MWException( __METHOD__ .
' got null for $time parameter' );
72 return new static(
$title,
$repo,
null, $archiveName );
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()->getDBLoadBalancerFactory()->getReplicaDatabase();
141 $queryInfo = FileSelectQueryBuilder::newForOldFile( $dbr, $options )->getQueryInfo();
143 'tables' => $queryInfo[
'tables'],
144 'fields' => $queryInfo[
'fields'],
145 'joins' => $queryInfo[
'join_conds'],
158 public function __construct( $title, $repo, $time, $archiveName ) {
160 $this->requestedTime = $time;
161 $this->archive_name = $archiveName;
162 if ( $time ===
null && $archiveName ===
null ) {
163 throw new MWException( __METHOD__ .
': must specify at least one of $time or $archiveName' );
168 $this->archive_name = $row->{
"{$prefix}archive_name"};
169 $this->deleted = $row->{
"{$prefix}deleted"};
171 unset( $row->{
"{$prefix}archive_name"} );
172 unset( $row->{
"{$prefix}deleted"} );
173 parent::loadFromRow( $row, $prefix );
189 if ( !isset( $this->archive_name ) ) {
193 return $this->archive_name;
215 $this->dataLoaded =
true;
217 $dbr = ( $flags & self::READ_LATEST )
218 ? $this->repo->getPrimaryDB()
219 : $this->repo->getReplicaDB();
220 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr, [] );
221 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
223 $this->loadFromRow( $row,
'oi_' );
225 $this->fileExists =
false;
234 $this->extraDataLoaded =
true;
235 $dbr = $this->repo->getReplicaDB();
236 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
239 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
242 $dbr = $this->repo->getPrimaryDB();
243 $queryBuilder = $this->buildQueryBuilderForLoad( $dbr );
244 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
248 foreach ( $this->unprefixRow( $row,
'oi_' ) as $name => $value ) {
249 $this->$name = $value;
252 throw new MWException(
"Could not find data for image '{$this->archive_name}'." );
256 private function buildQueryBuilderForLoad(
IReadableDatabase $dbr, $options = [
'omit-nonlazy' ] ) {
257 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $dbr, $options );
258 $queryBuilder->where( [
'oi_name' => $this->getName() ] )
259 ->orderBy(
'oi_timestamp', SelectQueryBuilder::SORT_DESC );
260 if ( $this->requestedTime ===
null ) {
261 $queryBuilder->andWhere( [
'oi_archive_name' => $this->archive_name ] );
263 $queryBuilder->andWhere( [
'oi_timestamp' => $dbr->
timestamp( $this->requestedTime ) ] );
265 return $queryBuilder;
273 $fields = parent::getCacheFields( $prefix );
274 $fields[] = $prefix .
'archive_name';
275 $fields[] = $prefix .
'deleted';
285 return $this->getArchiveRel( $this->getArchiveName() );
293 return $this->getArchiveRel( rawurlencode( $this->getArchiveName() ) );
300 $this->loadFromFile();
302 # Don't destroy file info of missing files
303 if ( !$this->fileExists ) {
304 wfDebug( __METHOD__ .
": file does not exist, aborting" );
309 $dbw = $this->repo->getPrimaryDB();
310 [ $major, $minor ] = self::splitMime( $this->mime );
312 wfDebug( __METHOD__ .
': upgrading ' . $this->archive_name .
" to the current schema" );
313 $dbw->newUpdateQueryBuilder()
314 ->update(
'oldimage' )
316 'oi_size' => $this->size,
317 'oi_width' => $this->width,
318 'oi_height' => $this->height,
319 'oi_bits' => $this->bits,
320 'oi_media_type' => $this->media_type,
321 'oi_major_mime' => $major,
322 'oi_minor_mime' => $minor,
323 'oi_metadata' => $this->getMetadataForDb( $dbw ),
324 'oi_sha1' => $this->sha1,
327 'oi_name' => $this->getName(),
328 'oi_archive_name' => $this->archive_name,
330 ->caller( __METHOD__ )->execute();
347 return ( $this->deleted & $field ) == $field;
357 return (
int)$this->deleted;
371 return RevisionRecord::userCanBitfield(
388 $archiveName = $this->getArchiveName();
389 $dstRel = $this->getArchiveRel( $archiveName );
390 $status = $this->publishTo( $srcPath, $dstRel );
392 if ( $status->isGood() &&
393 !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user )
395 $status->fatal(
'filenotfound', $srcPath );
412 protected function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) {
413 $dbw = $this->repo->getPrimaryDB();
415 $services = MediaWikiServices::getInstance();
416 $mwProps =
new MWFileProps( $services->getMimeAnalyzer() );
417 $props = $mwProps->getPropsFromPath( $srcPath,
true );
418 if ( !$props[
'fileExists'] ) {
421 $this->setProps( $props );
423 $dbw->startAtomic( __METHOD__ );
424 $commentFields = $services->getCommentStore()
425 ->insert( $dbw,
'oi_description', $comment );
426 $actorId = $services->getActorNormalization()
427 ->acquireActorId( $user, $dbw );
428 $dbw->newInsertQueryBuilder()
429 ->insertInto(
'oldimage' )
431 'oi_name' => $this->getName(),
432 'oi_archive_name' => $archiveName,
433 'oi_size' => $props[
'size'],
434 'oi_width' => intval( $props[
'width'] ),
435 'oi_height' => intval( $props[
'height'] ),
436 'oi_bits' => $props[
'bits'],
437 'oi_actor' => $actorId,
438 'oi_timestamp' => $dbw->timestamp( $timestamp ),
439 'oi_metadata' => $this->getMetadataForDb( $dbw ),
440 'oi_media_type' => $props[
'media_type'],
441 'oi_major_mime' => $props[
'major_mime'],
442 'oi_minor_mime' => $props[
'minor_mime'],
443 'oi_sha1' => $props[
'sha1'],
445 ->caller( __METHOD__ )->execute();
446 $dbw->endAtomic( __METHOD__ );
459 $archiveName = $this->getArchiveName();
460 if ( $archiveName ===
'' || !is_string( $archiveName ) ) {
463 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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.