Removed old HTMLCacheUpdateJob b/c code
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index f1f8af4..699c915 100644 (file)
@@ -109,6 +109,9 @@ class LocalFile extends File {
        /** @var string Description of current revision of the file */
        private $description;
 
+       /** @var string TS_MW timestamp of the last change of the file description */
+       private $descriptionTouched;
+
        /** @var bool Whether the row was upgraded on load */
        private $upgraded;
 
@@ -247,13 +250,11 @@ class LocalFile extends File {
        function loadFromCache() {
                global $wgMemc;
 
-               wfProfileIn( __METHOD__ );
                $this->dataLoaded = false;
                $this->extraDataLoaded = false;
                $key = $this->getCacheKey();
 
                if ( !$key ) {
-                       wfProfileOut( __METHOD__ );
 
                        return false;
                }
@@ -280,8 +281,6 @@ class LocalFile extends File {
                        wfIncrStats( 'image_cache_miss' );
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $this->dataLoaded;
        }
 
@@ -382,9 +381,7 @@ class LocalFile extends File {
         * @param int $flags
         */
        function loadFromDB( $flags = 0 ) {
-               # Polymorphic function name to distinguish foreign and local fetches
                $fname = get_class( $this ) . '::' . __FUNCTION__;
-               wfProfileIn( $fname );
 
                # Unconditionally set loaded=true, we don't want the accessors constantly rechecking
                $this->dataLoaded = true;
@@ -402,8 +399,6 @@ class LocalFile extends File {
                } else {
                        $this->fileExists = false;
                }
-
-               wfProfileOut( $fname );
        }
 
        /**
@@ -411,9 +406,7 @@ class LocalFile extends File {
         * This covers fields that are sometimes not cached.
         */
        protected function loadExtraFromDB() {
-               # Polymorphic function name to distinguish foreign and local fetches
                $fname = get_class( $this ) . '::' . __FUNCTION__;
-               wfProfileIn( $fname );
 
                # Unconditionally set loaded=true, we don't want the accessors constantly rechecking
                $this->extraDataLoaded = true;
@@ -428,11 +421,8 @@ class LocalFile extends File {
                                $this->$name = $value;
                        }
                } else {
-                       wfProfileOut( $fname );
                        throw new MWException( "Could not find data for image '{$this->getName()}'." );
                }
-
-               wfProfileOut( $fname );
        }
 
        /**
@@ -587,7 +577,6 @@ class LocalFile extends File {
         * Fix assorted version-related problems with the image row by reloading it from the file
         */
        function upgradeRow() {
-               wfProfileIn( __METHOD__ );
 
                $this->lock(); // begin
 
@@ -597,7 +586,6 @@ class LocalFile extends File {
                if ( !$this->fileExists ) {
                        $this->unlock();
                        wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
-                       wfProfileOut( __METHOD__ );
 
                        return;
                }
@@ -607,7 +595,6 @@ class LocalFile extends File {
 
                if ( wfReadOnly() ) {
                        $this->unlock();
-                       wfProfileOut( __METHOD__ );
 
                        return;
                }
@@ -633,7 +620,6 @@ class LocalFile extends File {
 
                $this->unlock(); // done
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -672,7 +658,7 @@ class LocalFile extends File {
        /** getURL inherited */
        /** getViewURL inherited */
        /** getPath inherited */
-       /** isVisible inhereted */
+       /** isVisible inherited */
 
        /**
         * @return bool
@@ -889,7 +875,6 @@ class LocalFile extends File {
         * @note This used to purge old thumbnails by default as well, but doesn't anymore.
         */
        function purgeCache( $options = array() ) {
-               wfProfileIn( __METHOD__ );
                // Refresh metadata cache
                $this->purgeMetadataCache();
 
@@ -898,7 +883,6 @@ class LocalFile extends File {
 
                // Purge squid cache for this file
                SquidUpdate::purge( array( $this->getURL() ) );
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -907,7 +891,6 @@ class LocalFile extends File {
         */
        function purgeOldThumbnails( $archiveName ) {
                global $wgUseSquid;
-               wfProfileIn( __METHOD__ );
 
                // Get a list of old thumbnails and URLs
                $files = $this->getThumbnails( $archiveName );
@@ -927,7 +910,6 @@ class LocalFile extends File {
                        SquidUpdate::purge( $urls );
                }
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -936,7 +918,6 @@ class LocalFile extends File {
         */
        function purgeThumbnails( $options = array() ) {
                global $wgUseSquid;
-               wfProfileIn( __METHOD__ );
 
                // Delete thumbnails
                $files = $this->getThumbnails();
@@ -968,7 +949,6 @@ class LocalFile extends File {
                        SquidUpdate::purge( $urls );
                }
 
-               wfProfileOut( __METHOD__ );
        }
 
        /**
@@ -1146,7 +1126,6 @@ class LocalFile extends File {
                }
 
                if ( !$props ) {
-                       wfProfileIn( __METHOD__ . '-getProps' );
                        if ( $this->repo->isVirtualUrl( $srcPath )
                                || FileBackend::isStoragePath( $srcPath )
                        ) {
@@ -1154,7 +1133,6 @@ class LocalFile extends File {
                        } else {
                                $props = FSFile::getPropsFromPath( $srcPath );
                        }
-                       wfProfileOut( __METHOD__ . '-getProps' );
                }
 
                $options = array();
@@ -1236,7 +1214,6 @@ class LocalFile extends File {
        function recordUpload2( $oldver, $comment, $pageText, $props = false, $timestamp = false,
                $user = null
        ) {
-               wfProfileIn( __METHOD__ );
 
                if ( is_null( $user ) ) {
                        global $wgUser;
@@ -1247,9 +1224,7 @@ class LocalFile extends File {
                $dbw->begin( __METHOD__ );
 
                if ( !$props ) {
-                       wfProfileIn( __METHOD__ . '-getProps' );
                        $props = $this->repo->getFileProps( $this->getVirtualUrl() );
-                       wfProfileOut( __METHOD__ . '-getProps' );
                }
 
                # Imports or such might force a certain timestamp; otherwise we generate
@@ -1271,7 +1246,6 @@ class LocalFile extends File {
                if ( !$this->fileExists ) {
                        wfDebug( __METHOD__ . ": File " . $this->getRel() . " went missing!\n" );
                        $dbw->rollback( __METHOD__ );
-                       wfProfileOut( __METHOD__ );
 
                        return false;
                }
@@ -1406,12 +1380,14 @@ class LocalFile extends File {
                        // Page exists, do RC entry now (otherwise we wait for later).
                        $logEntry->publish( $logId );
                }
-               wfProfileIn( __METHOD__ . '-edit' );
 
                if ( $exists ) {
                        # Create a null revision
                        $latest = $descTitle->getLatestRevID();
-                       $editSummary = LogFormatter::newFromEntry( $logEntry )->getPlainActionText();
+                       // Use own context to get the action text in content language
+                       $formatter = LogFormatter::newFromEntry( $logEntry );
+                       $formatter->setContext( RequestContext::newExtraneousContext( $descTitle ) );
+                       $editSummary = $formatter->getPlainActionText();
 
                        $nullRevision = Revision::newNullRevision(
                                $dbw,
@@ -1470,22 +1446,16 @@ class LocalFile extends File {
                        $dbw->commit( __METHOD__ ); // commit before anything bad can happen
                }
 
-               wfProfileOut( __METHOD__ . '-edit' );
-
                if ( $reupload ) {
                        # Delete old thumbnails
-                       wfProfileIn( __METHOD__ . '-purge' );
                        $this->purgeThumbnails();
-                       wfProfileOut( __METHOD__ . '-purge' );
 
                        # Remove the old file from the squid cache
                        SquidUpdate::purge( array( $this->getURL() ) );
                }
 
                # Hooks, hooks, the magic of hooks...
-               wfProfileIn( __METHOD__ . '-hooks' );
                Hooks::run( 'FileUpload', array( $this, $reupload, $descTitle->exists() ) );
-               wfProfileOut( __METHOD__ . '-hooks' );
 
                # Invalidate cache for all pages using this file
                $update = new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' );
@@ -1494,8 +1464,6 @@ class LocalFile extends File {
                        LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' );
                }
 
-               wfProfileOut( __METHOD__ );
-
                return true;
        }
 
@@ -1812,6 +1780,22 @@ class LocalFile extends File {
                return $this->timestamp;
        }
 
+       /**
+        * @return bool|string
+        */
+       public function getDescriptionTouched() {
+               // The DB lookup might return false, e.g. if the file was just deleted, or the shared DB repo
+               // itself gets it from elsewhere. To avoid repeating the DB lookups in such a case, we
+               // need to differentiate between null (uninitialized) and false (failed to load).
+               if ( $this->descriptionTouched === null ) {
+                       $cond = array( 'page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey() );
+                       $touched = $this->repo->getSlaveDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ );
+                       $this->descriptionTouched = $touched ? wfTimestamp( TS_MW, $touched ) : false;
+               }
+
+               return $this->descriptionTouched;
+       }
+
        /**
         * @return string
         */
@@ -1987,7 +1971,7 @@ class LocalFileDeleteBatch {
        /** @var array Items to be processed in the deletion batch */
        private $deletionBatch;
 
-       /** @var bool Wether to suppress all suppressable fields when deleting */
+       /** @var bool Whether to suppress all suppressable fields when deleting */
        private $suppress;
 
        /** @var FileRepoStatus */
@@ -2240,26 +2224,9 @@ class LocalFileDeleteBatch {
         * @return FileRepoStatus
         */
        function execute() {
-               wfProfileIn( __METHOD__ );
 
                $this->file->lock();
-               // Leave private files alone
-               $privateFiles = array();
-               list( $oldRels, ) = $this->getOldRels();
-               $dbw = $this->file->repo->getMasterDB();
 
-               if ( !empty( $oldRels ) ) {
-                       $res = $dbw->select( 'oldimage',
-                               array( 'oi_archive_name' ),
-                               array( 'oi_name' => $this->file->getName(),
-                                       'oi_archive_name' => array_keys( $oldRels ),
-                                       $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE ),
-                               __METHOD__ );
-
-                       foreach ( $res as $row ) {
-                               $privateFiles[$row->oi_archive_name] = 1;
-                       }
-               }
                // Prepare deletion batch
                $hashes = $this->getHashes();
                $this->deletionBatch = array();
@@ -2267,9 +2234,8 @@ class LocalFileDeleteBatch {
                $dotExt = $ext === '' ? '' : ".$ext";
 
                foreach ( $this->srcRels as $name => $srcRel ) {
-                       // Skip files that have no hash (missing source).
-                       // Keep private files where they are.
-                       if ( isset( $hashes[$name] ) && !array_key_exists( $name, $privateFiles ) ) {
+                       // Skip files that have no hash (e.g. missing DB record, or sha1 field and file source)
+                       if ( isset( $hashes[$name] ) ) {
                                $hash = $hashes[$name];
                                $key = $hash . $dotExt;
                                $dstRel = $this->file->repo->getDeletedHashPath( $key ) . $key;
@@ -2286,6 +2252,7 @@ class LocalFileDeleteBatch {
                $this->doDBInserts();
 
                // Removes non-existent file from the batch, so we don't get errors.
+               // This also handles files in the 'deleted' zone deleted via revision deletion.
                $checkStatus = $this->removeNonexistentFiles( $this->deletionBatch );
                if ( !$checkStatus->isGood() ) {
                        $this->status->merge( $checkStatus );
@@ -2305,7 +2272,6 @@ class LocalFileDeleteBatch {
                        // Roll back inserts, release lock and abort
                        // TODO: delete the defunct filearchive rows if we are using a non-transactional DB
                        $this->file->unlockAndRollback();
-                       wfProfileOut( __METHOD__ );
 
                        return $this->status;
                }
@@ -2315,7 +2281,6 @@ class LocalFileDeleteBatch {
 
                // Commit and return
                $this->file->unlock();
-               wfProfileOut( __METHOD__ );
 
                return $this->status;
        }
@@ -2368,7 +2333,7 @@ class LocalFileRestoreBatch {
        /** @var bool Add all revisions of the file */
        private $all;
 
-       /** @var bool Wether to remove all settings for suppressed fields */
+       /** @var bool Whether to remove all settings for suppressed fields */
        private $unsuppress = false;
 
        /**