6 * Bump this number when serialized cache records may be incompatible.
8 define( 'MW_FILE_VERSION', 7 );
11 * Class to represent a local file in the wiki's own database
13 * Provides methods to retrieve paths (physical, logical, URL),
14 * to generate image thumbnails or for uploading.
16 * Note that only the repo object knows what its file class is called. You should
17 * never name a file class explictly outside of the repo class. Instead use the
18 * repo's factory functions to generate file objects, for example:
20 * RepoGroup::singleton()->getLocalRepo()->newFile($title);
22 * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
25 * @addtogroup FileRepo
27 class LocalFile
extends File
32 var $fileExists, # does the file file exist on disk? (loadFromXxx)
33 $historyLine, # Number of line to return by nextHistoryLine() (constructor)
34 $historyRes, # result of the query for the file's history (nextHistoryLine)
37 $bits, # --- returned by getimagesize (loadFromXxx)
39 $media_type, # MEDIATYPE_xxx (bitmap, drawing, audio...)
40 $mime, # MIME type, determined by MimeMagic::guessMimeType
41 $major_mime, # Major mime type
42 $minor_mime, # Minor mime type
43 $size, # Size in bytes (loadFromXxx)
44 $metadata, # Handler-specific metadata
45 $timestamp, # Upload timestamp
46 $sha1, # SHA-1 base 36 content hash
47 $user, $user_text, # User, who uploaded the file
48 $description, # Description of current revision of the file
49 $dataLoaded, # Whether or not all this has been loaded from the database (loadFromXxx)
50 $upgraded, # Whether the row was upgraded on load
51 $locked, # True if the image row is locked
52 $deleted; # Bitfield akin to rev_deleted
57 * Create a LocalFile from a title
58 * Do not call this except from inside a repo class.
60 static function newFromTitle( $title, $repo ) {
61 return new self( $title, $repo );
65 * Create a LocalFile from a title
66 * Do not call this except from inside a repo class.
68 static function newFromRow( $row, $repo ) {
69 $title = Title
::makeTitle( NS_IMAGE
, $row->img_name
);
70 $file = new self( $title, $repo );
71 $file->loadFromRow( $row );
77 * Do not call this except from inside a repo class.
79 function __construct( $title, $repo ) {
80 if( !is_object( $title ) ) {
81 throw new MWException( __CLASS__
.' constructor given bogus title.' );
83 parent
::__construct( $title, $repo );
85 $this->historyLine
= 0;
86 $this->historyRes
= null;
87 $this->dataLoaded
= false;
91 * Get the memcached key
93 function getCacheKey() {
94 $hashedName = md5($this->getName());
95 return wfMemcKey( 'file', $hashedName );
99 * Try to load file metadata from memcached. Returns true on success.
101 function loadFromCache() {
103 wfProfileIn( __METHOD__
);
104 $this->dataLoaded
= false;
105 $key = $this->getCacheKey();
109 $cachedValues = $wgMemc->get( $key );
111 // Check if the key existed and belongs to this version of MediaWiki
112 if ( isset($cachedValues['version']) && ( $cachedValues['version'] == MW_FILE_VERSION
) ) {
113 wfDebug( "Pulling file metadata from cache key $key\n" );
114 $this->fileExists
= $cachedValues['fileExists'];
115 if ( $this->fileExists
) {
116 $this->setProps( $cachedValues );
118 $this->dataLoaded
= true;
120 if ( $this->dataLoaded
) {
121 wfIncrStats( 'image_cache_hit' );
123 wfIncrStats( 'image_cache_miss' );
126 wfProfileOut( __METHOD__
);
127 return $this->dataLoaded
;
131 * Save the file metadata to memcached
133 function saveToCache() {
136 $key = $this->getCacheKey();
140 $fields = $this->getCacheFields( '' );
141 $cache = array( 'version' => MW_FILE_VERSION
);
142 $cache['fileExists'] = $this->fileExists
;
143 if ( $this->fileExists
) {
144 foreach ( $fields as $field ) {
145 $cache[$field] = $this->$field;
149 $wgMemc->set( $key, $cache, 60 * 60 * 24 * 7 ); // A week
153 * Load metadata from the file itself
155 function loadFromFile() {
156 $this->setProps( self
::getPropsFromPath( $this->getPath() ) );
159 function getCacheFields( $prefix = 'img_' ) {
160 static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
161 'major_mime', 'minor_mime', 'metadata', 'timestamp', 'sha1', 'user', 'user_text', 'description' );
162 static $results = array();
163 if ( $prefix == '' ) {
166 if ( !isset( $results[$prefix] ) ) {
167 $prefixedFields = array();
168 foreach ( $fields as $field ) {
169 $prefixedFields[] = $prefix . $field;
171 $results[$prefix] = $prefixedFields;
173 return $results[$prefix];
177 * Load file metadata from the DB
179 function loadFromDB() {
180 # Polymorphic function name to distinguish foreign and local fetches
181 $fname = get_class( $this ) . '::' . __FUNCTION__
;
182 wfProfileIn( $fname );
184 # Unconditionally set loaded=true, we don't want the accessors constantly rechecking
185 $this->dataLoaded
= true;
187 $dbr = $this->repo
->getMasterDB();
189 $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
190 array( 'img_name' => $this->getName() ), $fname );
192 $this->loadFromRow( $row );
194 $this->fileExists
= false;
197 wfProfileOut( $fname );
201 * Decode a row from the database (either object or array) to an array
202 * with timestamps and MIME types decoded, and the field prefix removed.
204 function decodeRow( $row, $prefix = 'img_' ) {
205 $array = (array)$row;
206 $prefixLength = strlen( $prefix );
207 // Sanity check prefix once
208 if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
209 throw new MWException( __METHOD__
. ': incorrect $prefix parameter' );
212 foreach ( $array as $name => $value ) {
213 $decoded[substr( $name, $prefixLength )] = $value;
215 $decoded['timestamp'] = wfTimestamp( TS_MW
, $decoded['timestamp'] );
216 if ( empty( $decoded['major_mime'] ) ) {
217 $decoded['mime'] = "unknown/unknown";
219 if (!$decoded['minor_mime']) {
220 $decoded['minor_mime'] = "unknown";
222 $decoded['mime'] = $decoded['major_mime'].'/'.$decoded['minor_mime'];
224 # Trim zero padding from char/binary field
225 $decoded['sha1'] = rtrim( $decoded['sha1'], "\0" );
230 * Load file metadata from a DB result row
232 function loadFromRow( $row, $prefix = 'img_' ) {
233 $this->dataLoaded
= true;
234 $array = $this->decodeRow( $row, $prefix );
235 foreach ( $array as $name => $value ) {
236 $this->$name = $value;
238 $this->fileExists
= true;
239 // Check if the file is hidden...
240 if( $this->isDeleted(File
::DELETED_FILE
) ) {
241 $this->fileExists
= false; // treat as not existing
243 // Check for rows from a previous schema, quietly upgrade them
244 $this->maybeUpgradeRow();
249 * Load file metadata from cache or DB, unless already loaded
252 if ( !$this->dataLoaded
) {
253 if ( !$this->loadFromCache() ) {
255 $this->saveToCache();
257 $this->dataLoaded
= true;
262 * Upgrade a row if it needs it
264 function maybeUpgradeRow() {
265 if ( wfReadOnly() ) {
268 if ( is_null($this->media_type
) ||
269 $this->mime
== 'image/svg'
272 $this->upgraded
= true;
274 $handler = $this->getHandler();
275 if ( $handler && !$handler->isMetadataValid( $this, $this->metadata
) ) {
277 $this->upgraded
= true;
282 function getUpgraded() {
283 return $this->upgraded
;
287 * Fix assorted version-related problems with the image row by reloading it from the file
289 function upgradeRow() {
290 wfProfileIn( __METHOD__
);
292 $this->loadFromFile();
294 # Don't destroy file info of missing files
295 if ( !$this->fileExists
) {
296 wfDebug( __METHOD__
.": file does not exist, aborting\n" );
299 $dbw = $this->repo
->getMasterDB();
300 list( $major, $minor ) = self
::splitMime( $this->mime
);
302 if ( wfReadOnly() ) {
305 wfDebug(__METHOD__
.': upgrading '.$this->getName()." to the current schema\n");
307 $dbw->update( 'image',
309 'img_width' => $this->width
,
310 'img_height' => $this->height
,
311 'img_bits' => $this->bits
,
312 'img_media_type' => $this->media_type
,
313 'img_major_mime' => $major,
314 'img_minor_mime' => $minor,
315 'img_metadata' => $this->metadata
,
316 'img_sha1' => $this->sha1
,
317 ), array( 'img_name' => $this->getName() ),
320 $this->saveToCache();
321 wfProfileOut( __METHOD__
);
325 * Set properties in this object to be equal to those given in the
326 * associative array $info. Only cacheable fields can be set.
328 * If 'mime' is given, it will be split into major_mime/minor_mime.
329 * If major_mime/minor_mime are given, $this->mime will also be set.
331 function setProps( $info ) {
332 $this->dataLoaded
= true;
333 $fields = $this->getCacheFields( '' );
334 $fields[] = 'fileExists';
335 foreach ( $fields as $field ) {
336 if ( isset( $info[$field] ) ) {
337 $this->$field = $info[$field];
340 // Fix up mime fields
341 if ( isset( $info['major_mime'] ) ) {
342 $this->mime
= "{$info['major_mime']}/{$info['minor_mime']}";
343 } elseif ( isset( $info['mime'] ) ) {
344 list( $this->major_mime
, $this->minor_mime
) = self
::splitMime( $this->mime
);
348 /** splitMime inherited */
349 /** getName inherited */
350 /** getTitle inherited */
351 /** getURL inherited */
352 /** getViewURL inherited */
353 /** getPath inherited */
354 /** isVisible inhereted */
357 * Return the width of the image
359 * Returns false on error
362 function getWidth( $page = 1 ) {
364 if ( $this->isMultipage() ) {
365 $dim = $this->getHandler()->getPageDimensions( $this, $page );
367 return $dim['width'];
377 * Return the height of the image
379 * Returns false on error
382 function getHeight( $page = 1 ) {
384 if ( $this->isMultipage() ) {
385 $dim = $this->getHandler()->getPageDimensions( $this, $page );
387 return $dim['height'];
392 return $this->height
;
397 * Returns ID or name of user who uploaded the file
399 * @param $type string 'text' or 'id'
401 function getUser($type='text') {
403 if( $type == 'text' ) {
404 return $this->user_text
;
405 } elseif( $type == 'id' ) {
411 * Get handler-specific metadata
413 function getMetadata() {
415 return $this->metadata
;
419 * Return the size of the image file, in bytes
428 * Returns the mime type of the file.
430 function getMimeType() {
436 * Return the type of the media in the file.
437 * Use the value returned by this function with the MEDIATYPE_xxx constants.
439 function getMediaType() {
441 return $this->media_type
;
444 /** canRender inherited */
445 /** mustRender inherited */
446 /** allowInlineDisplay inherited */
447 /** isSafeFile inherited */
448 /** isTrustedFile inherited */
451 * Returns true if the file file exists on disk.
452 * @return boolean Whether file file exist on disk.
457 return $this->fileExists
;
460 /** getTransformScript inherited */
461 /** getUnscaledThumb inherited */
462 /** thumbName inherited */
463 /** createThumb inherited */
464 /** getThumbnail inherited */
465 /** transform inherited */
468 * Fix thumbnail files from 1.4 or before, with extreme prejudice
470 function migrateThumbFile( $thumbName ) {
471 $thumbDir = $this->getThumbPath();
472 $thumbPath = "$thumbDir/$thumbName";
473 if ( is_dir( $thumbPath ) ) {
474 // Directory where file should be
475 // This happened occasionally due to broken migration code in 1.5
476 // Rename to broken-*
477 for ( $i = 0; $i < 100 ; $i++
) {
478 $broken = $this->repo
->getZonePath('public') . "/broken-$i-$thumbName";
479 if ( !file_exists( $broken ) ) {
480 rename( $thumbPath, $broken );
484 // Doesn't exist anymore
487 if ( is_file( $thumbDir ) ) {
488 // File where directory should be
490 // Doesn't exist anymore
495 /** getHandler inherited */
496 /** iconThumb inherited */
497 /** getLastError inherited */
500 * Get all thumbnail names previously generated for this file
502 function getThumbnails() {
503 if ( $this->isHashed() ) {
506 $dir = $this->getThumbPath();
508 if ( is_dir( $dir ) ) {
509 $handle = opendir( $dir );
512 while ( false !== ( $file = readdir($handle) ) ) {
513 if ( $file{0} != '.' ) {
528 * Refresh metadata in memcached, but don't touch thumbnails or squid
530 function purgeMetadataCache() {
532 $this->saveToCache();
533 $this->purgeHistory();
537 * Purge the shared history (OldLocalFile) cache
539 function purgeHistory() {
541 $hashedName = md5($this->getName());
542 $oldKey = wfMemcKey( 'oldfile', $hashedName );
543 $wgMemc->delete( $oldKey );
547 * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid
549 function purgeCache() {
550 // Refresh metadata cache
551 $this->purgeMetadataCache();
554 $this->purgeThumbnails();
556 // Purge squid cache for this file
557 wfPurgeSquidServers( array( $this->getURL() ) );
561 * Delete cached transformed files
563 function purgeThumbnails() {
566 $files = $this->getThumbnails();
567 $dir = $this->getThumbPath();
569 foreach ( $files as $file ) {
570 # Check that the base file name is part of the thumb name
571 # This is a basic sanity check to avoid erasing unrelated directories
572 if ( strpos( $file, $this->getName() ) !== false ) {
573 $url = $this->getThumbUrl( $file );
575 @unlink
( "$dir/$file" );
581 wfPurgeSquidServers( $urls );
585 /** purgeDescription inherited */
586 /** purgeEverything inherited */
588 function getHistory($limit = null, $start = null, $end = null) {
589 $dbr = $this->repo
->getSlaveDB();
590 $conds = $opts = array();
591 $conds[] = "oi_name = " . $dbr->addQuotes( $this->title
->getDBKey() );
592 if( $start !== null ) {
593 $conds[] = "oi_timestamp <= " . $dbr->addQuotes( $dbr->timestamp( $start ) );
595 if( $end !== null ) {
596 $conds[] = "oi_timestamp >= " . $dbr->addQuotes( $dbr->timestamp( $end ) );
599 $opts['LIMIT'] = $limit;
601 $opts['ORDER BY'] = 'oi_timestamp DESC';
602 $res = $dbr->select('oldimage', '*', $conds, __METHOD__
, $opts);
604 while( $row = $dbr->fetchObject($res) ) {
605 $r[] = OldLocalFile
::newFromRow($row, $this->repo
);
611 * Return the history of this file, line by line.
612 * starts with current version, then old versions.
613 * uses $this->historyLine to check which line to return:
614 * 0 return line for current version
615 * 1 query for old versions, return first one
616 * 2, ... return next old version from above query
620 function nextHistoryLine() {
621 # Polymorphic function name to distinguish foreign and local fetches
622 $fname = get_class( $this ) . '::' . __FUNCTION__
;
624 $dbr = $this->repo
->getSlaveDB();
626 if ( $this->historyLine
== 0 ) {// called for the first time, return line from cur
627 $this->historyRes
= $dbr->select( 'image',
630 "'' AS oi_archive_name",
634 array( 'img_name' => $this->title
->getDBkey() ),
637 if ( 0 == $dbr->numRows( $this->historyRes
) ) {
638 $dbr->freeResult($this->historyRes
);
639 $this->historyRes
= null;
642 } else if ( $this->historyLine
== 1 ) {
643 $dbr->freeResult($this->historyRes
);
644 $this->historyRes
= $dbr->select( 'oldimage', '*',
645 array( 'oi_name' => $this->title
->getDBkey() ),
647 array( 'ORDER BY' => 'oi_timestamp DESC' )
650 $this->historyLine ++
;
652 return $dbr->fetchObject( $this->historyRes
);
656 * Reset the history pointer to the first element of the history
659 function resetHistory() {
660 $this->historyLine
= 0;
661 if (!is_null($this->historyRes
)) {
662 $this->repo
->getSlaveDB()->freeResult($this->historyRes
);
663 $this->historyRes
= null;
667 /** getFullPath inherited */
668 /** getHashPath inherited */
669 /** getRel inherited */
670 /** getUrlRel inherited */
671 /** getArchiveRel inherited */
672 /** getThumbRel inherited */
673 /** getArchivePath inherited */
674 /** getThumbPath inherited */
675 /** getArchiveUrl inherited */
676 /** getThumbUrl inherited */
677 /** getArchiveVirtualUrl inherited */
678 /** getThumbVirtualUrl inherited */
679 /** isHashed inherited */
682 * Upload a file and record it in the DB
683 * @param string $srcPath Source path or virtual URL
684 * @param string $comment Upload description
685 * @param string $pageText Text to use for the new description page, if a new description page is created
686 * @param integer $flags Flags for publish()
687 * @param array $props File properties, if known. This can be used to reduce the
688 * upload time when uploading virtual URLs for which the file info
690 * @param string $timestamp Timestamp for img_timestamp, or false to use the current time
692 * @return FileRepoStatus object. On success, the value member contains the
693 * archive name, or an empty string if it was a new file.
695 function upload( $srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false ) {
697 $status = $this->publish( $srcPath, $flags );
699 if ( !$this->recordUpload2( $status->value
, $comment, $pageText, $props, $timestamp ) ) {
700 $status->fatal( 'filenotfound', $srcPath );
708 * Record a file upload in the upload log and the image table
709 * @deprecated use upload()
711 function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
712 $watch = false, $timestamp = false )
714 $pageText = UploadForm
::getInitialPageText( $desc, $license, $copyStatus, $source );
715 if ( !$this->recordUpload2( $oldver, $desc, $pageText ) ) {
720 $wgUser->addWatch( $this->getTitle() );
727 * Record a file upload in the upload log and the image table
729 function recordUpload2( $oldver, $comment, $pageText, $props = false, $timestamp = false )
733 $dbw = $this->repo
->getMasterDB();
736 $props = $this->repo
->getFileProps( $this->getVirtualUrl() );
738 $props['description'] = $comment;
739 $props['user'] = $wgUser->getID();
740 $props['user_text'] = $wgUser->getName();
741 $props['timestamp'] = wfTimestamp( TS_MW
);
742 $this->setProps( $props );
744 // Delete thumbnails and refresh the metadata cache
745 $this->purgeThumbnails();
746 $this->saveToCache();
747 wfPurgeSquidServers( array( $this->getURL() ) );
749 // Fail now if the file isn't there
750 if ( !$this->fileExists
) {
751 wfDebug( __METHOD__
.": File ".$this->getPath()." went missing!\n" );
756 if ( $timestamp === false ) {
757 $timestamp = $dbw->timestamp();
760 # Test to see if the row exists using INSERT IGNORE
761 # This avoids race conditions by locking the row until the commit, and also
762 # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
763 $dbw->insert( 'image',
765 'img_name' => $this->getName(),
766 'img_size'=> $this->size
,
767 'img_width' => intval( $this->width
),
768 'img_height' => intval( $this->height
),
769 'img_bits' => $this->bits
,
770 'img_media_type' => $this->media_type
,
771 'img_major_mime' => $this->major_mime
,
772 'img_minor_mime' => $this->minor_mime
,
773 'img_timestamp' => $timestamp,
774 'img_description' => $comment,
775 'img_user' => $wgUser->getID(),
776 'img_user_text' => $wgUser->getName(),
777 'img_metadata' => $this->metadata
,
778 'img_sha1' => $this->sha1
784 if( $dbw->affectedRows() == 0 ) {
787 # Collision, this is an update of a file
788 # Insert previous contents into oldimage
789 $dbw->insertSelect( 'oldimage', 'image',
791 'oi_name' => 'img_name',
792 'oi_archive_name' => $dbw->addQuotes( $oldver ),
793 'oi_size' => 'img_size',
794 'oi_width' => 'img_width',
795 'oi_height' => 'img_height',
796 'oi_bits' => 'img_bits',
797 'oi_timestamp' => 'img_timestamp',
798 'oi_description' => 'img_description',
799 'oi_user' => 'img_user',
800 'oi_user_text' => 'img_user_text',
801 'oi_metadata' => 'img_metadata',
802 'oi_media_type' => 'img_media_type',
803 'oi_major_mime' => 'img_major_mime',
804 'oi_minor_mime' => 'img_minor_mime',
805 'oi_sha1' => 'img_sha1'
806 ), array( 'img_name' => $this->getName() ), __METHOD__
809 # Update the current image row
810 $dbw->update( 'image',
812 'img_size' => $this->size
,
813 'img_width' => intval( $this->width
),
814 'img_height' => intval( $this->height
),
815 'img_bits' => $this->bits
,
816 'img_media_type' => $this->media_type
,
817 'img_major_mime' => $this->major_mime
,
818 'img_minor_mime' => $this->minor_mime
,
819 'img_timestamp' => $timestamp,
820 'img_description' => $comment,
821 'img_user' => $wgUser->getID(),
822 'img_user_text' => $wgUser->getName(),
823 'img_metadata' => $this->metadata
,
824 'img_sha1' => $this->sha1
825 ), array( /* WHERE */
826 'img_name' => $this->getName()
831 # Update the image count
832 $site_stats = $dbw->tableName( 'site_stats' );
833 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", __METHOD__
);
836 $descTitle = $this->getTitle();
837 $article = new Article( $descTitle );
840 $log = new LogPage( 'upload' );
841 $action = $reupload ?
'overwrite' : 'upload';
842 $log->addEntry( $action, $descTitle, $comment );
844 if( $descTitle->exists() ) {
845 # Create a null revision
846 $nullRevision = Revision
::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
847 $nullRevision->insertOn( $dbw );
848 $article->updateRevisionOn( $dbw, $nullRevision );
850 # Invalidate the cache for the description page
851 $descTitle->invalidateCache();
852 $descTitle->purgeSquid();
854 // New file; create the description page.
855 // There's already a log entry, so don't make a second RC entry
856 $article->doEdit( $pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC
);
859 # Hooks, hooks, the magic of hooks...
860 wfRunHooks( 'FileUpload', array( $this ) );
862 # Commit the transaction now, in case something goes wrong later
863 # The most important thing is that files don't get lost, especially archives
864 $dbw->immediateCommit();
866 # Invalidate cache for all pages using this file
867 $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
874 * Move or copy a file to its public location. If a file exists at the
875 * destination, move it to an archive. Returns the archive name on success
876 * or an empty string if it was a new file, and a wikitext-formatted
877 * WikiError object on failure.
879 * The archive name should be passed through to recordUpload for database
882 * @param string $sourcePath Local filesystem path to the source image
883 * @param integer $flags A bitwise combination of:
884 * File::DELETE_SOURCE Delete the source file, i.e. move
886 * @return FileRepoStatus object. On success, the value member contains the
887 * archive name, or an empty string if it was a new file.
889 function publish( $srcPath, $flags = 0 ) {
891 $dstRel = $this->getRel();
892 $archiveName = gmdate( 'YmdHis' ) . '!'. $this->getName();
893 $archiveRel = 'archive/' . $this->getHashPath() . $archiveName;
894 $flags = $flags & File
::DELETE_SOURCE ? LocalRepo
::DELETE_SOURCE
: 0;
895 $status = $this->repo
->publish( $srcPath, $dstRel, $archiveRel, $flags );
896 if ( $status->value
== 'new' ) {
899 $status->value
= $archiveName;
905 /** getLinksTo inherited */
906 /** getExifData inherited */
907 /** isLocal inherited */
908 /** wasDeleted inherited */
911 * Delete all versions of the file.
913 * Moves the files into an archive directory (or deletes them)
914 * and removes the database rows.
916 * Cache purging is done; logging is caller's responsibility.
920 * @return FileRepoStatus object.
922 function delete( $reason, $suppress = false ) {
924 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
925 $batch->addCurrent();
927 # Get old version relative paths
928 $dbw = $this->repo
->getMasterDB();
929 $result = $dbw->select( 'oldimage',
930 array( 'oi_archive_name' ),
931 array( 'oi_name' => $this->getName() ) );
932 while ( $row = $dbw->fetchObject( $result ) ) {
933 $batch->addOld( $row->oi_archive_name
);
935 $status = $batch->execute();
939 $site_stats = $dbw->tableName( 'site_stats' );
940 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images-1", __METHOD__
);
941 $this->purgeEverything();
949 * Delete an old version of the file.
951 * Moves the file into an archive directory (or deletes it)
952 * and removes the database row.
954 * Cache purging is done; logging is caller's responsibility.
958 * @throws MWException or FSException on database or filestore failure
959 * @return FileRepoStatus object.
961 function deleteOld( $archiveName, $reason, $suppress=false ) {
963 $batch = new LocalFileDeleteBatch( $this, $reason, $suppress );
964 $batch->addOld( $archiveName );
965 $status = $batch->execute();
968 $this->purgeDescription();
969 $this->purgeHistory();
975 * Restore all or specified deleted revisions to the given file.
976 * Permissions and logging are left to the caller.
978 * May throw database exceptions on error.
980 * @param $versions set of record ids of deleted items to restore,
981 * or empty to restore all revisions.
983 * @return FileRepoStatus
985 function restore( $versions = array(), $unsuppress = false ) {
986 $batch = new LocalFileRestoreBatch( $this, $unsuppress );
990 $batch->addIds( $versions );
992 $status = $batch->execute();
993 if ( !$status->ok
) {
997 $cleanupStatus = $batch->cleanup();
998 $cleanupStatus->successCount
= 0;
999 $cleanupStatus->failCount
= 0;
1000 $status->merge( $cleanupStatus );
1004 /** isMultipage inherited */
1005 /** pageCount inherited */
1006 /** scaleHeight inherited */
1007 /** getImageSize inherited */
1010 * Get the URL of the file description page.
1012 function getDescriptionUrl() {
1013 return $this->title
->getLocalUrl();
1017 * Get the HTML text of the description page
1018 * This is not used by ImagePage for local files, since (among other things)
1019 * it skips the parser cache.
1021 function getDescriptionText() {
1023 $revision = Revision
::newFromTitle( $this->title
);
1024 if ( !$revision ) return false;
1025 $text = $revision->getText();
1026 if ( !$text ) return false;
1027 $html = $wgParser->parse( $text, new ParserOptions
);
1031 function getDescription() {
1033 return $this->description
;
1036 function getTimestamp() {
1038 return $this->timestamp
;
1041 function getSha1() {
1043 // Initialise now if necessary
1044 if ( $this->sha1
== '' && $this->fileExists
) {
1045 $this->sha1
= File
::sha1Base36( $this->getPath() );
1046 if ( strval( $this->sha1
) != '' ) {
1047 $dbw = $this->repo
->getMasterDB();
1048 $dbw->update( 'image',
1049 array( 'img_sha1' => $this->sha1
),
1050 array( 'img_name' => $this->getName() ),
1052 $this->saveToCache();
1060 * Start a transaction and lock the image for update
1061 * Increments a reference counter if the lock is already held
1062 * @return boolean True if the image exists, false otherwise
1065 $dbw = $this->repo
->getMasterDB();
1066 if ( !$this->locked
) {
1070 return $dbw->selectField( 'image', '1', array( 'img_name' => $this->getName() ), __METHOD__
);
1074 * Decrement the lock reference count. If the reference count is reduced to zero, commits
1075 * the transaction and thereby releases the image lock.
1078 if ( $this->locked
) {
1080 if ( !$this->locked
) {
1081 $dbw = $this->repo
->getMasterDB();
1088 * Roll back the DB transaction and mark the image unlocked
1090 function unlockAndRollback() {
1091 $this->locked
= false;
1092 $dbw = $this->repo
->getMasterDB();
1095 } // LocalFile class
1097 #------------------------------------------------------------------------------
1100 * Backwards compatibility class
1102 class Image
extends LocalFile
{
1103 function __construct( $title ) {
1104 $repo = RepoGroup
::singleton()->getLocalRepo();
1105 parent
::__construct( $title, $repo );
1109 * Wrapper for wfFindFile(), for backwards-compatibility only
1110 * Do not use in core code.
1113 static function newFromTitle( $title, $time = false ) {
1114 $img = wfFindFile( $title, $time );
1116 $img = wfLocalFile( $title );
1122 * Wrapper for wfFindFile(), for backwards-compatibility only.
1123 * Do not use in core code.
1125 * @param string $name name of the image, used to create a title object using Title::makeTitleSafe
1126 * @return image object or null if invalid title
1129 static function newFromName( $name ) {
1130 $title = Title
::makeTitleSafe( NS_IMAGE
, $name );
1131 if ( is_object( $title ) ) {
1132 $img = wfFindFile( $title );
1134 $img = wfLocalFile( $title );
1143 * Return the URL of an image, provided its name.
1145 * Backwards-compatibility for extensions.
1146 * Note that fromSharedDirectory will only use the shared path for files
1147 * that actually exist there now, and will return local paths otherwise.
1149 * @param string $name Name of the image, without the leading "Image:"
1150 * @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
1151 * @return string URL of $name image
1154 static function imageUrl( $name, $fromSharedDirectory = false ) {
1156 if( $fromSharedDirectory ) {
1157 $image = wfFindFile( $name );
1160 $image = wfLocalFile( $name );
1162 return $image->getUrl();
1166 #------------------------------------------------------------------------------
1169 * Helper class for file deletion
1171 class LocalFileDeleteBatch
{
1172 var $file, $reason, $srcRels = array(), $archiveUrls = array(), $deletionBatch, $suppress;
1175 function __construct( File
$file, $reason = '', $suppress = false ) {
1176 $this->file
= $file;
1177 $this->reason
= $reason;
1178 $this->suppress
= $suppress;
1179 $this->status
= $file->repo
->newGood();
1182 function addCurrent() {
1183 $this->srcRels
['.'] = $this->file
->getRel();
1186 function addOld( $oldName ) {
1187 $this->srcRels
[$oldName] = $this->file
->getArchiveRel( $oldName );
1188 $this->archiveUrls
[] = $this->file
->getArchiveUrl( $oldName );
1191 function getOldRels() {
1192 if ( !isset( $this->srcRels
['.'] ) ) {
1193 $oldRels =& $this->srcRels
;
1194 $deleteCurrent = false;
1196 $oldRels = $this->srcRels
;
1197 unset( $oldRels['.'] );
1198 $deleteCurrent = true;
1200 return array( $oldRels, $deleteCurrent );
1203 /*protected*/ function getHashes() {
1205 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
1206 if ( $deleteCurrent ) {
1207 $hashes['.'] = $this->file
->getSha1();
1209 if ( count( $oldRels ) ) {
1210 $dbw = $this->file
->repo
->getMasterDB();
1211 $res = $dbw->select( 'oldimage', array( 'oi_archive_name', 'oi_sha1' ),
1212 'oi_archive_name IN(' . $dbw->makeList( array_keys( $oldRels ) ) . ')',
1214 while ( $row = $dbw->fetchObject( $res ) ) {
1215 if ( rtrim( $row->oi_sha1
, "\0" ) === '' ) {
1216 // Get the hash from the file
1217 $oldUrl = $this->file
->getArchiveVirtualUrl( $row->oi_archive_name
);
1218 $props = $this->file
->repo
->getFileProps( $oldUrl );
1219 if ( $props['fileExists'] ) {
1220 // Upgrade the oldimage row
1221 $dbw->update( 'oldimage',
1222 array( 'oi_sha1' => $props['sha1'] ),
1223 array( 'oi_name' => $this->file
->getName(), 'oi_archive_name' => $row->oi_archive_name
),
1225 $hashes[$row->oi_archive_name
] = $props['sha1'];
1227 $hashes[$row->oi_archive_name
] = false;
1230 $hashes[$row->oi_archive_name
] = $row->oi_sha1
;
1234 $missing = array_diff_key( $this->srcRels
, $hashes );
1235 foreach ( $missing as $name => $rel ) {
1236 $this->status
->error( 'filedelete-old-unregistered', $name );
1238 foreach ( $hashes as $name => $hash ) {
1240 $this->status
->error( 'filedelete-missing', $this->srcRels
[$name] );
1241 unset( $hashes[$name] );
1248 function doDBInserts() {
1250 $dbw = $this->file
->repo
->getMasterDB();
1251 $encTimestamp = $dbw->addQuotes( $dbw->timestamp() );
1252 $encUserId = $dbw->addQuotes( $wgUser->getId() );
1253 $encReason = $dbw->addQuotes( $this->reason
);
1254 $encGroup = $dbw->addQuotes( 'deleted' );
1255 $ext = $this->file
->getExtension();
1256 $dotExt = $ext === '' ?
'' : ".$ext";
1257 $encExt = $dbw->addQuotes( $dotExt );
1258 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
1260 // Bitfields to further suppress the content
1261 if ( $this->suppress
) {
1263 // This should be 15...
1264 $bitfield |
= Revision
::DELETED_TEXT
;
1265 $bitfield |
= Revision
::DELETED_COMMENT
;
1266 $bitfield |
= Revision
::DELETED_USER
;
1267 $bitfield |
= Revision
::DELETED_RESTRICTED
;
1269 $bitfield = 'oi_deleted';
1272 if ( $deleteCurrent ) {
1273 $concat = $dbw->buildConcat( array( "img_sha1", $encExt ) );
1274 $where = array( 'img_name' => $this->file
->getName() );
1275 $dbw->insertSelect( 'filearchive', 'image',
1277 'fa_storage_group' => $encGroup,
1278 'fa_storage_key' => "CASE WHEN img_sha1='' THEN '' ELSE $concat END",
1279 'fa_deleted_user' => $encUserId,
1280 'fa_deleted_timestamp' => $encTimestamp,
1281 'fa_deleted_reason' => $encReason,
1282 'fa_deleted' => $this->suppress ?
$bitfield : 0,
1284 'fa_name' => 'img_name',
1285 'fa_archive_name' => 'NULL',
1286 'fa_size' => 'img_size',
1287 'fa_width' => 'img_width',
1288 'fa_height' => 'img_height',
1289 'fa_metadata' => 'img_metadata',
1290 'fa_bits' => 'img_bits',
1291 'fa_media_type' => 'img_media_type',
1292 'fa_major_mime' => 'img_major_mime',
1293 'fa_minor_mime' => 'img_minor_mime',
1294 'fa_description' => 'img_description',
1295 'fa_user' => 'img_user',
1296 'fa_user_text' => 'img_user_text',
1297 'fa_timestamp' => 'img_timestamp'
1298 ), $where, __METHOD__
);
1301 if ( count( $oldRels ) ) {
1302 $concat = $dbw->buildConcat( array( "oi_sha1", $encExt ) );
1304 'oi_name' => $this->file
->getName(),
1305 'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')' );
1306 $dbw->insertSelect( 'filearchive', 'oldimage',
1308 'fa_storage_group' => $encGroup,
1309 'fa_storage_key' => "CASE WHEN oi_sha1='' THEN '' ELSE $concat END",
1310 'fa_deleted_user' => $encUserId,
1311 'fa_deleted_timestamp' => $encTimestamp,
1312 'fa_deleted_reason' => $encReason,
1313 'fa_deleted' => $this->suppress ?
$bitfield : 'oi_deleted',
1315 'fa_name' => 'oi_name',
1316 'fa_archive_name' => 'oi_archive_name',
1317 'fa_size' => 'oi_size',
1318 'fa_width' => 'oi_width',
1319 'fa_height' => 'oi_height',
1320 'fa_metadata' => 'oi_metadata',
1321 'fa_bits' => 'oi_bits',
1322 'fa_media_type' => 'oi_media_type',
1323 'fa_major_mime' => 'oi_major_mime',
1324 'fa_minor_mime' => 'oi_minor_mime',
1325 'fa_description' => 'oi_description',
1326 'fa_user' => 'oi_user',
1327 'fa_user_text' => 'oi_user_text',
1328 'fa_timestamp' => 'oi_timestamp',
1329 'fa_deleted' => $bitfield
1330 ), $where, __METHOD__
);
1334 function doDBDeletes() {
1335 $dbw = $this->file
->repo
->getMasterDB();
1336 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
1337 if ( count( $oldRels ) ) {
1338 $dbw->delete( 'oldimage',
1340 'oi_name' => $this->file
->getName(),
1341 'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')'
1344 if ( $deleteCurrent ) {
1345 $dbw->delete( 'image', array( 'img_name' => $this->file
->getName() ), __METHOD__
);
1350 * Run the transaction
1352 function execute() {
1353 global $wgUser, $wgUseSquid;
1354 wfProfileIn( __METHOD__
);
1356 $this->file
->lock();
1357 // Leave private files alone
1358 $privateFiles = array();
1359 list( $oldRels, $deleteCurrent ) = $this->getOldRels();
1360 $dbw = $this->file
->repo
->getMasterDB();
1361 if( !empty( $oldRels ) ) {
1362 $res = $dbw->select( 'oldimage',
1363 array( 'oi_archive_name' ),
1364 array( 'oi_name' => $this->file
->getName(),
1365 'oi_archive_name IN (' . $dbw->makeList( array_keys($oldRels) ) . ')',
1366 'oi_deleted & ' . File
::DELETED_FILE
=> File
::DELETED_FILE
),
1368 while( $row = $dbw->fetchObject( $res ) ) {
1369 $privateFiles[$row->oi_archive_name
] = 1;
1372 // Prepare deletion batch
1373 $hashes = $this->getHashes();
1374 $this->deletionBatch
= array();
1375 $ext = $this->file
->getExtension();
1376 $dotExt = $ext === '' ?
'' : ".$ext";
1377 foreach ( $this->srcRels
as $name => $srcRel ) {
1378 // Skip files that have no hash (missing source).
1379 // Keep private files where they are.
1380 if ( isset($hashes[$name]) && !array_key_exists($name,$privateFiles) ) {
1381 $hash = $hashes[$name];
1382 $key = $hash . $dotExt;
1383 $dstRel = $this->file
->repo
->getDeletedHashPath( $key ) . $key;
1384 $this->deletionBatch
[$name] = array( $srcRel, $dstRel );
1388 // Lock the filearchive rows so that the files don't get deleted by a cleanup operation
1389 // We acquire this lock by running the inserts now, before the file operations.
1391 // This potentially has poor lock contention characteristics -- an alternative
1392 // scheme would be to insert stub filearchive entries with no fa_name and commit
1393 // them in a separate transaction, then run the file ops, then update the fa_name fields.
1394 $this->doDBInserts();
1396 // Execute the file deletion batch
1397 $status = $this->file
->repo
->deleteBatch( $this->deletionBatch
);
1398 if ( !$status->isGood() ) {
1399 $this->status
->merge( $status );
1402 if ( !$this->status
->ok
) {
1403 // Critical file deletion error
1404 // Roll back inserts, release lock and abort
1405 // TODO: delete the defunct filearchive rows if we are using a non-transactional DB
1406 $this->file
->unlockAndRollback();
1407 return $this->status
;
1411 if ( $wgUseSquid ) {
1413 foreach ( $this->srcRels
as $srcRel ) {
1414 $urlRel = str_replace( '%2F', '/', rawurlencode( $srcRel ) );
1415 $urls[] = $this->file
->repo
->getZoneUrl( 'public' ) . '/' . $urlRel;
1417 SquidUpdate
::purge( $urls );
1420 // Delete image/oldimage rows
1421 $this->doDBDeletes();
1423 // Commit and return
1424 $this->file
->unlock();
1425 wfProfileOut( __METHOD__
);
1426 return $this->status
;
1430 #------------------------------------------------------------------------------
1433 * Helper class for file undeletion
1435 class LocalFileRestoreBatch
{
1436 var $file, $cleanupBatch, $ids, $all, $unsuppress = false;
1438 function __construct( File
$file, $unsuppress = false ) {
1439 $this->file
= $file;
1440 $this->cleanupBatch
= $this->ids
= array();
1441 $this->ids
= array();
1442 $this->unsuppress
= $unsuppress;
1448 function addId( $fa_id ) {
1449 $this->ids
[] = $fa_id;
1453 * Add a whole lot of files by ID
1455 function addIds( $ids ) {
1456 $this->ids
= array_merge( $this->ids
, $ids );
1460 * Add all revisions of the file
1467 * Run the transaction, except the cleanup batch.
1468 * The cleanup batch should be run in a separate transaction, because it locks different
1469 * rows and there's no need to keep the image row locked while it's acquiring those locks
1470 * The caller may have its own transaction open.
1471 * So we save the batch and let the caller call cleanup()
1473 function execute() {
1474 global $wgUser, $wgLang;
1475 if ( !$this->all
&& !$this->ids
) {
1477 return $this->file
->repo
->newGood();
1480 $exists = $this->file
->lock();
1481 $dbw = $this->file
->repo
->getMasterDB();
1482 $status = $this->file
->repo
->newGood();
1484 // Fetch all or selected archived revisions for the file,
1485 // sorted from the most recent to the oldest.
1486 $conditions = array( 'fa_name' => $this->file
->getName() );
1488 $conditions[] = 'fa_id IN (' . $dbw->makeList( $this->ids
) . ')';
1491 $result = $dbw->select( 'filearchive', '*',
1494 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
1496 $idsPresent = array();
1497 $storeBatch = array();
1498 $insertBatch = array();
1499 $insertCurrent = false;
1500 $deleteIds = array();
1502 $archiveNames = array();
1503 while( $row = $dbw->fetchObject( $result ) ) {
1504 $idsPresent[] = $row->fa_id
;
1506 if ( $row->fa_name
!= $this->file
->getName() ) {
1507 $status->error( 'undelete-filename-mismatch', $wgLang->timeanddate( $row->fa_timestamp
) );
1508 $status->failCount++
;
1511 if ( $row->fa_storage_key
== '' ) {
1512 // Revision was missing pre-deletion
1513 $status->error( 'undelete-bad-store-key', $wgLang->timeanddate( $row->fa_timestamp
) );
1514 $status->failCount++
;
1518 $deletedRel = $this->file
->repo
->getDeletedHashPath( $row->fa_storage_key
) . $row->fa_storage_key
;
1519 $deletedUrl = $this->file
->repo
->getVirtualUrl() . '/deleted/' . $deletedRel;
1521 $sha1 = substr( $row->fa_storage_key
, 0, strcspn( $row->fa_storage_key
, '.' ) );
1523 if ( strlen( $sha1 ) == 32 && $sha1[0] == '0' ) {
1524 $sha1 = substr( $sha1, 1 );
1527 if( is_null( $row->fa_major_mime
) ||
$row->fa_major_mime
== 'unknown'
1528 ||
is_null( $row->fa_minor_mime
) ||
$row->fa_minor_mime
== 'unknown'
1529 ||
is_null( $row->fa_media_type
) ||
$row->fa_media_type
== 'UNKNOWN'
1530 ||
is_null( $row->fa_metadata
) ) {
1531 // Refresh our metadata
1532 // Required for a new current revision; nice for older ones too. :)
1533 $props = RepoGroup
::singleton()->getFileProps( $deletedUrl );
1536 'minor_mime' => $row->fa_minor_mime
,
1537 'major_mime' => $row->fa_major_mime
,
1538 'media_type' => $row->fa_media_type
,
1539 'metadata' => $row->fa_metadata
);
1542 if ( $first && !$exists ) {
1543 // The live (current) version cannot be hidden!
1544 if( !$this->unsuppress
&& $row->fa_deleted
) {
1545 $this->file
->unlock();
1548 // This revision will be published as the new current version
1549 $destRel = $this->file
->getRel();
1550 $insertCurrent = array(
1551 'img_name' => $row->fa_name
,
1552 'img_size' => $row->fa_size
,
1553 'img_width' => $row->fa_width
,
1554 'img_height' => $row->fa_height
,
1555 'img_metadata' => $props['metadata'],
1556 'img_bits' => $row->fa_bits
,
1557 'img_media_type' => $props['media_type'],
1558 'img_major_mime' => $props['major_mime'],
1559 'img_minor_mime' => $props['minor_mime'],
1560 'img_description' => $row->fa_description
,
1561 'img_user' => $row->fa_user
,
1562 'img_user_text' => $row->fa_user_text
,
1563 'img_timestamp' => $row->fa_timestamp
,
1564 'img_sha1' => $sha1);
1566 $archiveName = $row->fa_archive_name
;
1567 if( $archiveName == '' ) {
1568 // This was originally a current version; we
1569 // have to devise a new archive name for it.
1570 // Format is <timestamp of archiving>!<name>
1571 $timestamp = wfTimestamp( TS_UNIX
, $row->fa_deleted_timestamp
);
1573 $archiveName = wfTimestamp( TS_MW
, $timestamp ) . '!' . $row->fa_name
;
1575 } while ( isset( $archiveNames[$archiveName] ) );
1577 $archiveNames[$archiveName] = true;
1578 $destRel = $this->file
->getArchiveRel( $archiveName );
1579 $insertBatch[] = array(
1580 'oi_name' => $row->fa_name
,
1581 'oi_archive_name' => $archiveName,
1582 'oi_size' => $row->fa_size
,
1583 'oi_width' => $row->fa_width
,
1584 'oi_height' => $row->fa_height
,
1585 'oi_bits' => $row->fa_bits
,
1586 'oi_description' => $row->fa_description
,
1587 'oi_user' => $row->fa_user
,
1588 'oi_user_text' => $row->fa_user_text
,
1589 'oi_timestamp' => $row->fa_timestamp
,
1590 'oi_metadata' => $props['metadata'],
1591 'oi_media_type' => $props['media_type'],
1592 'oi_major_mime' => $props['major_mime'],
1593 'oi_minor_mime' => $props['minor_mime'],
1594 'oi_deleted' => $this->unsuppress ?
0 : $row->fa_deleted
,
1595 'oi_sha1' => $sha1 );
1598 $deleteIds[] = $row->fa_id
;
1599 if( !$this->unsuppress
&& $row->fa_deleted
& File
::DELETED_FILE
) {
1600 // private files can stay where they are
1602 $storeBatch[] = array( $deletedUrl, 'public', $destRel );
1603 $this->cleanupBatch
[] = $row->fa_storage_key
;
1609 // Add a warning to the status object for missing IDs
1610 $missingIds = array_diff( $this->ids
, $idsPresent );
1611 foreach ( $missingIds as $id ) {
1612 $status->error( 'undelete-missing-filearchive', $id );
1615 // Run the store batch
1616 // Use the OVERWRITE_SAME flag to smooth over a common error
1617 $storeStatus = $this->file
->repo
->storeBatch( $storeBatch, FileRepo
::OVERWRITE_SAME
);
1618 $status->merge( $storeStatus );
1620 if ( !$status->ok
) {
1621 // Store batch returned a critical error -- this usually means nothing was stored
1622 // Stop now and return an error
1623 $this->file
->unlock();
1627 // Run the DB updates
1628 // Because we have locked the image row, key conflicts should be rare.
1629 // If they do occur, we can roll back the transaction at this time with
1630 // no data loss, but leaving unregistered files scattered throughout the
1632 // This is not ideal, which is why it's important to lock the image row.
1633 if ( $insertCurrent ) {
1634 $dbw->insert( 'image', $insertCurrent, __METHOD__
);
1636 if ( $insertBatch ) {
1637 $dbw->insert( 'oldimage', $insertBatch, __METHOD__
);
1640 $dbw->delete( 'filearchive',
1641 array( 'fa_id IN (' . $dbw->makeList( $deleteIds ) . ')' ),
1645 if( $status->successCount
> 0 ) {
1647 wfDebug( __METHOD__
." restored {$status->successCount} items, creating a new current\n" );
1649 // Update site_stats
1650 $site_stats = $dbw->tableName( 'site_stats' );
1651 $dbw->query( "UPDATE $site_stats SET ss_images=ss_images+1", __METHOD__
);
1653 $this->file
->purgeEverything();
1655 wfDebug( __METHOD__
." restored {$status->successCount} as archived versions\n" );
1656 $this->file
->purgeDescription();
1657 $this->file
->purgeHistory();
1660 $this->file
->unlock();
1665 * Delete unused files in the deleted zone.
1666 * This should be called from outside the transaction in which execute() was called.
1668 function cleanup() {
1669 if ( !$this->cleanupBatch
) {
1670 return $this->file
->repo
->newGood();
1672 $status = $this->file
->repo
->cleanupDeletedBatch( $this->cleanupBatch
);