fix some spacing
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index ee49448..d9ba4e4 100644 (file)
@@ -71,6 +71,7 @@ class LocalFile extends File {
                $extraDataLoaded,  # Whether or not lazy-loaded data has been loaded from the database
                $upgraded,         # Whether the row was upgraded on load
                $locked,           # True if the image row is locked
+               $lockedOwnTrx,     # True if the image row is locked with a lock initiated transaction
                $missing,          # True if file is not present in file system. Not to be cached in memcached
                $deleted;          # Bitfield akin to rev_deleted
 
@@ -265,7 +266,7 @@ class LocalFile extends File {
                // If the cache value gets to large it will not fit in memcached and nothing will
                // get cached at all, causing master queries for any file access.
                foreach ( $this->getLazyCacheFields( '' ) as $field ) {
-                       if ( isset( $cache[$field] ) && strlen( $cache[$field] ) > 100*1024 ) {
+                       if ( isset( $cache[$field] ) && strlen( $cache[$field] ) > 100 * 1024 ) {
                                unset( $cache[$field] ); // don't let the value get too big
                        }
                }
@@ -1119,20 +1120,25 @@ class LocalFile extends File {
         * @param $source string
         * @param $watch bool
         * @param $timestamp string|bool
+        * @param $user User object or null to use $wgUser
         * @return bool
         */
        function recordUpload( $oldver, $desc, $license = '', $copyStatus = '', $source = '',
-               $watch = false, $timestamp = false )
+               $watch = false, $timestamp = false, User $user = null )
        {
+               if ( !$user ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
+
                $pageText = SpecialUpload::getInitialPageText( $desc, $license, $copyStatus, $source );
 
-               if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp ) ) {
+               if ( !$this->recordUpload2( $oldver, $desc, $pageText, false, $timestamp, $user ) ) {
                        return false;
                }
 
                if ( $watch ) {
-                       global $wgUser;
-                       $wgUser->addWatch( $this->getTitle() );
+                       $user->addWatch( $this->getTitle() );
                }
                return true;
        }
@@ -1669,7 +1675,10 @@ class LocalFile extends File {
                $dbw = $this->repo->getMasterDB();
 
                if ( !$this->locked ) {
-                       $dbw->begin( __METHOD__ );
+                       if ( !$dbw->trxLevel() ) {
+                               $dbw->begin( __METHOD__ );
+                               $this->lockedOwnTrx = true;
+                       }
                        $this->locked++;
                }
 
@@ -1684,9 +1693,10 @@ class LocalFile extends File {
        function unlock() {
                if ( $this->locked ) {
                        --$this->locked;
-                       if ( !$this->locked ) {
+                       if ( !$this->locked && $this->lockedOwnTrx ) {
                                $dbw = $this->repo->getMasterDB();
                                $dbw->commit( __METHOD__ );
+                               $this->lockedOwnTrx = false;
                        }
                }
        }
@@ -1698,6 +1708,7 @@ class LocalFile extends File {
                $this->locked = false;
                $dbw = $this->repo->getMasterDB();
                $dbw->rollback( __METHOD__ );
+               $this->lockedOwnTrx = false;
        }
 
        /**
@@ -2623,7 +2634,7 @@ class LocalFileMoveBatch {
         */
        function getMoveTriplets() {
                $moves = array_merge( array( $this->cur ), $this->olds );
-               $triplets = array();    // The format is: (srcUrl, destZone, destUrl)
+               $triplets = array(); // The format is: (srcUrl, destZone, destUrl)
 
                foreach ( $moves as $move ) {
                        // $move: (oldRelativePath, newRelativePath)