fix some spacing
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index c08d192..d9ba4e4 100644 (file)
@@ -36,7 +36,7 @@ define( 'MW_FILE_VERSION', 9 );
  * never name a file class explictly outside of the repo class. Instead use the
  * repo's factory functions to generate file objects, for example:
  *
- * RepoGroup::singleton()->getLocalRepo()->newFile($title);
+ * RepoGroup::singleton()->getLocalRepo()->newFile( $title );
  *
  * The convenience functions wfLocalFile() and wfFindFile() should be sufficient
  * in most cases.
@@ -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
                        }
                }
@@ -398,7 +399,7 @@ class LocalFile extends File {
 
                // Sanity check prefix once
                if ( substr( key( $array ), 0, $prefixLength ) !== $prefix ) {
-                       throw new MWException( __METHOD__ .  ': incorrect $prefix parameter' );
+                       throw new MWException( __METHOD__ . ': incorrect $prefix parameter' );
                }
 
                $decoded = array();
@@ -737,7 +738,7 @@ class LocalFile extends File {
                        // Directory where file should be
                        // This happened occasionally due to broken migration code in 1.5
                        // Rename to broken-*
-                       for ( $i = 0; $i < 100 ; $i++ ) {
+                       for ( $i = 0; $i < 100; $i++ ) {
                                $broken = $this->repo->getZonePath( 'public' ) . "/broken-$i-$thumbName";
                                if ( !file_exists( $broken ) ) {
                                        rename( $thumbPath, $broken );
@@ -901,7 +902,7 @@ class LocalFile extends File {
        protected function purgeThumbList( $dir, $files ) {
                $fileListDebug = strtr(
                        var_export( $files, true ),
-                       array("\n"=>'')
+                       array( "\n" => '' )
                );
                wfDebug( __METHOD__ . ": $fileListDebug\n" );
 
@@ -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;
        }
@@ -1285,7 +1291,7 @@ class LocalFile extends File {
                                $log->getRcComment(),
                                false
                        );
-                       if (!is_null($nullRevision)) {
+                       if ( !is_null( $nullRevision ) ) {
                                $nullRevision->insertOn( $dbw );
 
                                wfRunHooks( 'NewRevisionFromEditComplete', array( $wikiPage, $nullRevision, $latest, $user ) );
@@ -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;
        }
 
        /**
@@ -2128,7 +2139,9 @@ class LocalFileRestoreBatch {
                        $conditions[] = 'fa_id IN (' . $dbw->makeList( $this->ids ) . ')';
                }
 
-               $result = $dbw->select( 'filearchive', '*',
+               $result = $dbw->select(
+                       'filearchive',
+                       ArchivedFile::selectFields(),
                        $conditions,
                        __METHOD__,
                        array( 'ORDER BY' => 'fa_timestamp DESC' )
@@ -2380,7 +2393,7 @@ class LocalFileRestoreBatch {
        /**
         * Delete unused files in the deleted zone.
         * This should be called from outside the transaction in which execute() was called.
-        * @return FileRepoStatus|void
+        * @return FileRepoStatus
         */
        function cleanup() {
                if ( !$this->cleanupBatch ) {
@@ -2621,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)