fix some spacing
[lhc/web/wiklou.git] / includes / filerepo / file / OldLocalFile.php
index 967cb9f..4f27c8d 100644 (file)
@@ -42,7 +42,7 @@ class OldLocalFile extends LocalFile {
        static function newFromTitle( $title, $repo, $time = null ) {
                # The null default value is only here to avoid an E_STRICT
                if ( $time === null ) {
-                       throw new MWException( __METHOD__.' got null for $time parameter' );
+                       throw new MWException( __METHOD__ . ' got null for $time parameter' );
                }
                return new self( $title, $repo, $time, null );
        }
@@ -94,7 +94,7 @@ class OldLocalFile extends LocalFile {
                        return false;
                }
        }
-       
+
        /**
         * Fields in the oldimage table
         * @return array
@@ -132,7 +132,7 @@ class OldLocalFile extends LocalFile {
                $this->requestedTime = $time;
                $this->archive_name = $archiveName;
                if ( is_null( $time ) && is_null( $archiveName ) ) {
-                       throw new MWException( __METHOD__.': must specify at least one of $time or $archiveName' );
+                       throw new MWException( __METHOD__ . ': must specify at least one of $time or $archiveName' );
                }
        }
 
@@ -164,18 +164,19 @@ class OldLocalFile extends LocalFile {
         * @return bool
         */
        function isVisible() {
-               return $this->exists() && !$this->isDeleted(File::DELETED_FILE);
+               return $this->exists() && !$this->isDeleted( File::DELETED_FILE );
        }
 
        function loadFromDB() {
                wfProfileIn( __METHOD__ );
+
                $this->dataLoaded = true;
                $dbr = $this->repo->getSlaveDB();
                $conds = array( 'oi_name' => $this->getName() );
                if ( is_null( $this->requestedTime ) ) {
                        $conds['oi_archive_name'] = $this->archive_name;
                } else {
-                       $conds[] = 'oi_timestamp = ' . $dbr->addQuotes( $dbr->timestamp( $this->requestedTime ) );
+                       $conds['oi_timestamp'] = $dbr->timestamp( $this->requestedTime );
                }
                $row = $dbr->selectRow( 'oldimage', $this->getCacheFields( 'oi_' ),
                        $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
@@ -184,6 +185,42 @@ class OldLocalFile extends LocalFile {
                } else {
                        $this->fileExists = false;
                }
+
+               wfProfileOut( __METHOD__ );
+       }
+
+       /**
+        * Load lazy file metadata from the DB
+        */
+       protected function loadExtraFromDB() {
+               wfProfileIn( __METHOD__ );
+
+               $this->extraDataLoaded = true;
+               $dbr = $this->repo->getSlaveDB();
+               $conds = array( 'oi_name' => $this->getName() );
+               if ( is_null( $this->requestedTime ) ) {
+                       $conds['oi_archive_name'] = $this->archive_name;
+               } else {
+                       $conds['oi_timestamp'] = $dbr->timestamp( $this->requestedTime );
+               }
+               // In theory the file could have just been renamed/deleted...oh well
+               $row = $dbr->selectRow( 'oldimage', $this->getLazyCacheFields( 'oi_' ),
+                       $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
+
+               if ( !$row ) { // fallback to master
+                       $dbr = $this->repo->getMasterDB();
+                       $row = $dbr->selectRow( 'oldimage', $this->getLazyCacheFields( 'oi_' ),
+                               $conds, __METHOD__, array( 'ORDER BY' => 'oi_timestamp DESC' ) );
+               }
+
+               if ( $row ) {
+                       foreach ( $this->unprefixRow( $row, 'oi_' ) as $name => $value ) {
+                               $this->$name = $value;
+                       }
+               } else {
+                       throw new MWException( "Could not find data for image '{$this->archive_name}'." );
+               }
+
                wfProfileOut( __METHOD__ );
        }
 
@@ -218,7 +255,7 @@ class OldLocalFile extends LocalFile {
 
                # Don't destroy file info of missing files
                if ( !$this->fileExists ) {
-                       wfDebug( __METHOD__.": file does not exist, aborting\n" );
+                       wfDebug( __METHOD__ . ": file does not exist, aborting\n" );
                        wfProfileOut( __METHOD__ );
                        return;
                }
@@ -226,17 +263,18 @@ class OldLocalFile extends LocalFile {
                $dbw = $this->repo->getMasterDB();
                list( $major, $minor ) = self::splitMime( $this->mime );
 
-               wfDebug(__METHOD__.': upgrading '.$this->archive_name." to the current schema\n");
+               wfDebug( __METHOD__ . ': upgrading ' . $this->archive_name . " to the current schema\n" );
                $dbw->update( 'oldimage',
                        array(
-                               'oi_width' => $this->width,
-                               'oi_height' => $this->height,
-                               'oi_bits' => $this->bits,
+                               'oi_size'       => $this->size, // sanity
+                               'oi_width'      => $this->width,
+                               'oi_height'     => $this->height,
+                               'oi_bits'       => $this->bits,
                                'oi_media_type' => $this->media_type,
                                'oi_major_mime' => $major,
                                'oi_minor_mime' => $minor,
-                               'oi_metadata' => $this->metadata,
-                               'oi_sha1' => $this->sha1,
+                               'oi_metadata'   => $this->metadata,
+                               'oi_sha1'       => $this->sha1,
                        ), array(
                                'oi_name' => $this->getName(),
                                'oi_archive_name' => $this->archive_name ),
@@ -292,20 +330,20 @@ class OldLocalFile extends LocalFile {
         */
        function uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user, $flags = 0 ) {
                $this->lock();
-               
+
                $dstRel = 'archive/' . $this->getHashPath() . $archiveName;
                $status = $this->publishTo( $srcPath, $dstRel,
                        $flags & File::DELETE_SOURCE ? FileRepo::DELETE_SOURCE : 0
                );
-               
+
                if ( $status->isGood() ) {
                        if ( !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) ) {
                                $status->fatal( 'filenotfound', $srcPath );
                        }
                }
-               
+
                $this->unlock();
-               
+
                return $status;
        }