Merge "Update README from [[mw:README]]"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 8824b66..f1f8af4 100644 (file)
@@ -913,7 +913,7 @@ class LocalFile extends File {
                $files = $this->getThumbnails( $archiveName );
 
                // Purge any custom thumbnail caches
-               wfRunHooks( 'LocalFilePurgeThumbnails', array( $this, $archiveName ) );
+               Hooks::run( 'LocalFilePurgeThumbnails', array( $this, $archiveName ) );
 
                $dir = array_shift( $files );
                $this->purgeThumbList( $dir, $files );
@@ -958,7 +958,7 @@ class LocalFile extends File {
                }
 
                // Purge any custom thumbnail caches
-               wfRunHooks( 'LocalFilePurgeThumbnails', array( $this, false ) );
+               Hooks::run( 'LocalFilePurgeThumbnails', array( $this, false ) );
 
                $dir = array_shift( $files );
                $this->purgeThumbList( $dir, $files );
@@ -1035,7 +1035,7 @@ class LocalFile extends File {
                $opts['ORDER BY'] = "oi_timestamp $order";
                $opts['USE INDEX'] = array( 'oldimage' => 'oi_name_timestamp' );
 
-               wfRunHooks( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
+               Hooks::run( 'LocalFile::getHistory', array( &$this, &$tables, &$fields,
                        &$conds, &$opts, &$join_conds ) );
 
                $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
@@ -1303,9 +1303,11 @@ class LocalFile extends File {
                );
                if ( $dbw->affectedRows() == 0 ) {
                        if ( $allowTimeKludge ) {
-                               # Use FOR UPDATE to ignore any transaction snapshotting
+                               # Use LOCK IN SHARE MODE to ignore any transaction snapshotting
                                $ltimestamp = $dbw->selectField( 'image', 'img_timestamp',
-                                       array( 'img_name' => $this->getName() ), __METHOD__, array( 'FOR UPDATE' ) );
+                                       array( 'img_name' => $this->getName() ),
+                                       __METHOD__,
+                                       array( 'LOCK IN SHARE MODE' ) );
                                $lUnixtime = $ltimestamp ? wfTimestamp( TS_UNIX, $ltimestamp ) : false;
                                # Avoid a timestamp that is not newer than the last version
                                # TODO: the image/oldimage tables should be like page/revision with an ID field
@@ -1421,7 +1423,7 @@ class LocalFile extends File {
                        if ( !is_null( $nullRevision ) ) {
                                $nullRevision->insertOn( $dbw );
 
-                               wfRunHooks( 'NewRevisionFromEditComplete', array( $wikiPage, $nullRevision, $latest, $user ) );
+                               Hooks::run( 'NewRevisionFromEditComplete', array( $wikiPage, $nullRevision, $latest, $user ) );
                                $wikiPage->updateRevisionOn( $dbw, $nullRevision );
                        }
                }
@@ -1482,7 +1484,7 @@ class LocalFile extends File {
 
                # Hooks, hooks, the magic of hooks...
                wfProfileIn( __METHOD__ . '-hooks' );
-               wfRunHooks( 'FileUpload', array( $this, $reupload, $descTitle->exists() ) );
+               Hooks::run( 'FileUpload', array( $this, $reupload, $descTitle->exists() ) );
                wfProfileOut( __METHOD__ . '-hooks' );
 
                # Invalidate cache for all pages using this file
@@ -1850,7 +1852,7 @@ class LocalFile extends File {
         * Start a transaction and lock the image for update
         * Increments a reference counter if the lock is already held
         * @throws MWException Throws an error if the lock was not acquired
-        * @return bool Success
+        * @return bool Whether the file lock owns/spawned the DB transaction
         */
        function lock() {
                $dbw = $this->repo->getMasterDB();
@@ -1877,7 +1879,7 @@ class LocalFile extends File {
 
                $this->markVolatile(); // file may change soon
 
-               return true;
+               return $this->lockedOwnTrx;
        }
 
        /**
@@ -2419,13 +2421,19 @@ class LocalFileRestoreBatch {
                        return $this->file->repo->newGood();
                }
 
-               $this->file->lock();
+               $lockOwnsTrx = $this->file->lock();
 
                $dbw = $this->file->repo->getMasterDB();
                $status = $this->file->repo->newGood();
 
                $exists = (bool)$dbw->selectField( 'image', '1',
-                       array( 'img_name' => $this->file->getName() ), __METHOD__, array( 'FOR UPDATE' ) );
+                       array( 'img_name' => $this->file->getName() ),
+                       __METHOD__,
+                       // The lock() should already prevents changes, but this still may need
+                       // to bypass any transaction snapshot. However, if lock() started the
+                       // trx (which it probably did) then snapshot is post-lock and up-to-date.
+                       $lockOwnsTrx ? array() : array( 'LOCK IN SHARE MODE' )
+               );
 
                // Fetch all or selected archived revisions for the file,
                // sorted from the most recent to the oldest.
@@ -2797,7 +2805,7 @@ class LocalFileMoveBatch {
                        array( 'oi_archive_name', 'oi_deleted' ),
                        array( 'oi_name' => $this->oldName ),
                        __METHOD__,
-                       array( 'FOR UPDATE' ) // ignore snapshot
+                       array( 'LOCK IN SHARE MODE' ) // ignore snapshot
                );
 
                foreach ( $result as $row ) {