r22474 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22473‎ | r22474 | r22475 >
Date:11:06, 27 May 2007
Author:tstarling
Status:old
Tags:
Comment:
Bug fixes
Modified paths:
  • /branches/filerepo-work/phase3/includes/filerepo/FSRepo.php (modified) (history)
  • /branches/filerepo-work/phase3/includes/filerepo/LocalFile.php (modified) (history)

Diff [purge]

Index: branches/filerepo-work/phase3/includes/filerepo/LocalFile.php
@@ -76,7 +76,12 @@
7777 // Check if the key existed and belongs to this version of MediaWiki
7878 if ( isset($cachedValues['version']) && ( $cachedValues['version'] == MW_FILE_VERSION ) ) {
7979 wfDebug( "Pulling file metadata from cache key $key\n" );
80 - $this->loadFromRow( $cachedValues, '' );
 80+ $this->fileExists = $cachedValues['fileExists'];
 81+ if ( $this->fileExists ) {
 82+ unset( $cachedValues['version'] );
 83+ unset( $cachedValues['fileExists'] );
 84+ $this->loadFromRow( $cachedValues, '' );
 85+ }
8186 }
8287 if ( $this->dataLoaded ) {
8388 wfIncrStats( 'image_cache_hit' );
@@ -100,8 +105,11 @@
101106 }
102107 $fields = $this->getCacheFields( '' );
103108 $cache = array( 'version' => MW_FILE_VERSION );
104 - foreach ( $fields as $field ) {
105 - $cache[$field] = $this->$field;
 109+ $cache['fileExists'] = $this->fileExists;
 110+ if ( $this->fileExists ) {
 111+ foreach ( $fields as $field ) {
 112+ $cache[$field] = $this->$field;
 113+ }
106114 }
107115
108116 $wgMemc->set( $key, $cache, 60 * 60 * 24 * 7 ); // A week
@@ -120,6 +128,7 @@
121129 $magic=& MimeMagic::singleton();
122130
123131 $this->mime = $magic->guessMimeType($path,true);
 132+ list( $this->major_mime, $this->minor_mime ) = self::splitMime( $this->mime );
124133 $this->media_type = $magic->getMediaType($path,$this->mime);
125134 $handler = MediaHandler::getHandler( $this->mime );
126135
@@ -168,7 +177,7 @@
169178 static $fields = array( 'size', 'width', 'height', 'bits', 'media_type',
170179 'major_mime', 'minor_mime', 'metadata', 'timestamp' );
171180 static $results = array();
172 - if ( $prefix = '' ) {
 181+ if ( $prefix == '' ) {
173182 return $fields;
174183 }
175184 if ( !isset( $results[$prefix] ) ) {
@@ -176,9 +185,9 @@
177186 foreach ( $fields as $field ) {
178187 $prefixedFields[] = $prefix . $field;
179188 }
180 - $fields[$prefix] = $prefixedFields;
 189+ $results[$prefix] = $prefixedFields;
181190 }
182 - return $fields[$prefix];
 191+ return $results[$prefix];
183192 }
184193
185194 /**
@@ -192,6 +201,7 @@
193202 $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
194203 array( 'img_name' => $this->getName() ), __METHOD__ );
195204 if ( $row ) {
 205+ $this->fileExists = true;
196206 $this->decodeRow( $row );
197207 $this->loadFromRow( $row );
198208 // Check for rows from a previous schema, quietly upgrade them
@@ -207,7 +217,7 @@
208218
209219 function decodeRow( &$row, $prefix = 'img_' ) {
210220 $tsName = $prefix . 'timestamp';
211 - $row->$tsName = wfTimestamp( $row->$tsName );
 221+ $row->$tsName = wfTimestamp( TS_MW, $row->$tsName );
212222 }
213223
214224 function encodeRow( &$row, $db, $prefix = 'img_' ) {
@@ -237,7 +247,6 @@
238248 }
239249 $this->mime = $this->major_mime.'/'.$this->minor_mime;
240250 }
241 - $this->fileExists = true;
242251 $this->dataLoaded = true;
243252 }
244253
Index: branches/filerepo-work/phase3/includes/filerepo/FSRepo.php
@@ -62,6 +62,9 @@
6363 */
6464 function findFile( $title, $time = false ) {
6565 $img = $this->newFile( $title );
 66+ if ( !$img ) {
 67+ return false;
 68+ }
6669 if ( $img->exists() && $img->getTimestamp() <= $time ) {
6770 return $img;
6871 }