r101227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101226‎ | r101227 | r101228 >
Date:22:44, 28 October 2011
Author:aaron
Status:ok
Tags:
Comment:
MFT r100211 to fix bug 31962
Modified paths:
  • /branches/wmf/1.18wmf1/includes/filerepo/FileRepo.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/filerepo/LocalFile.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/filerepo/OldLocalFile.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/includes/filerepo/OldLocalFile.php
@@ -19,8 +19,9 @@
2020
2121 static function newFromTitle( $title, $repo, $time = null ) {
2222 # The null default value is only here to avoid an E_STRICT
23 - if( $time === null )
 23+ if ( $time === null ) {
2424 throw new MWException( __METHOD__.' got null for $time parameter' );
 25+ }
2526 return new self( $title, $repo, $time, null );
2627 }
2728
@@ -36,19 +37,25 @@
3738 }
3839
3940 /**
40 - * @param $sha1
 41+ * Create a OldLocalFile from a SHA-1 key
 42+ * Do not call this except from inside a repo class.
 43+ *
 44+ * @param $sha1 string base-36 SHA-1
4145 * @param $repo LocalRepo
42 - * @param bool $timestamp
 46+ * @param string|bool $timestamp MW_timestamp (optional)
 47+ *
4348 * @return bool|OldLocalFile
4449 */
4550 static function newFromKey( $sha1, $repo, $timestamp = false ) {
 51+ $dbr = $repo->getSlaveDB();
 52+
4653 $conds = array( 'oi_sha1' => $sha1 );
47 - if( $timestamp ) {
48 - $conds['oi_timestamp'] = $timestamp;
 54+ if ( $timestamp ) {
 55+ $conds['oi_timestamp'] = $dbr->timestamp( $timestamp );
4956 }
50 - $dbr = $repo->getSlaveDB();
 57+
5158 $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ );
52 - if( $row ) {
 59+ if ( $row ) {
5360 return self::newFromRow( $row, $repo );
5461 } else {
5562 return false;
Index: branches/wmf/1.18wmf1/includes/filerepo/LocalFile.php
@@ -95,22 +95,21 @@
9696 * Create a LocalFile from a SHA-1 key
9797 * Do not call this except from inside a repo class.
9898 *
99 - * @param $sha1 string
 99+ * @param $sha1 string base-36 SHA-1
100100 * @param $repo LocalRepo
101 - * @param $timestamp string
 101+ * @param string|bool $timestamp MW_timestamp (optional)
102102 *
103 - * @return LocalFile
 103+ * @return bool|LocalFile
104104 */
105105 static function newFromKey( $sha1, $repo, $timestamp = false ) {
106 - $conds = array( 'img_sha1' => $sha1 );
 106+ $dbr = $repo->getSlaveDB();
107107
 108+ $conds = array( 'img_sha1' => $sha1 );
108109 if ( $timestamp ) {
109 - $conds['img_timestamp'] = $timestamp;
 110+ $conds['img_timestamp'] = $dbr->timestamp( $timestamp );
110111 }
111112
112 - $dbr = $repo->getSlaveDB();
113113 $row = $dbr->selectRow( 'image', self::selectFields(), $conds, __METHOD__ );
114 -
115114 if ( $row ) {
116115 return self::newFromRow( $row, $repo );
117116 } else {
Index: branches/wmf/1.18wmf1/includes/filerepo/FileRepo.php
@@ -74,7 +74,7 @@
7575 * @return File
7676 */
7777 function newFile( $title, $time = false ) {
78 - if ( !($title instanceof Title) ) {
 78+ if ( !( $title instanceof Title ) ) {
7979 $title = Title::makeTitleSafe( NS_FILE, $title );
8080 if ( !is_object( $title ) ) {
8181 return null;
@@ -130,10 +130,10 @@
131131 if ( $time !== false ) {
132132 $img = $this->newFile( $title, $time );
133133 if ( $img && $img->exists() ) {
134 - if ( !$img->isDeleted(File::DELETED_FILE) ) {
 134+ if ( !$img->isDeleted( File::DELETED_FILE ) ) {
 135+ return $img; // always OK
 136+ } elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
135137 return $img;
136 - } elseif ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) {
137 - return $img;
138138 }
139139 }
140140 }
@@ -185,30 +185,6 @@
186186 }
187187
188188 /**
189 - * Create a new File object from the local repository
190 - * @param $sha1 Mixed: base 36 SHA-1 hash
191 - * @param $time Mixed: time at which the image was uploaded.
192 - * If this is specified, the returned object will be an
193 - * of the repository's old file class instead of a current
194 - * file. Repositories not supporting version control should
195 - * return false if this parameter is set.
196 - *
197 - * @return File
198 - */
199 - function newFileFromKey( $sha1, $time = false ) {
200 - if ( $time ) {
201 - if ( $this->oldFileFactoryKey ) {
202 - return call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
203 - }
204 - } else {
205 - if ( $this->fileFactoryKey ) {
206 - return call_user_func( $this->fileFactoryKey, $sha1, $this );
207 - }
208 - }
209 - return false;
210 - }
211 -
212 - /**
213189 * Find an instance of the file with this key, created at the specified time
214190 * Returns false if the file does not exist. Repositories not supporting
215191 * version control should return false if the time is specified.
@@ -219,22 +195,23 @@
220196 function findFileFromKey( $sha1, $options = array() ) {
221197 $time = isset( $options['time'] ) ? $options['time'] : false;
222198
223 - # First try the current version of the file to see if it precedes the timestamp
224 - $img = $this->newFileFromKey( $sha1 );
225 - if ( !$img ) {
226 - return false;
 199+ # First try to find a matching current version of a file...
 200+ if ( $this->fileFactoryKey ) {
 201+ $img = call_user_func( $this->fileFactoryKey, $sha1, $this, $time );
 202+ } else {
 203+ return false; // find-by-sha1 not supported
227204 }
228 - if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
 205+ if ( $img && $img->exists() ) {
229206 return $img;
230207 }
231 - # Now try an old version of the file
232 - if ( $time !== false ) {
233 - $img = $this->newFileFromKey( $sha1, $time );
 208+ # Now try to find a matching old version of a file...
 209+ if ( $time !== false && $this->oldFileFactoryKey ) { // find-by-sha1 supported?
 210+ $img = call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
234211 if ( $img && $img->exists() ) {
235 - if ( !$img->isDeleted(File::DELETED_FILE) ) {
 212+ if ( !$img->isDeleted( File::DELETED_FILE ) ) {
 213+ return $img; // always OK
 214+ } elseif ( !empty( $options['private'] ) && $img->userCan( File::DELETED_FILE ) ) {
236215 return $img;
237 - } elseif ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) {
238 - return $img;
239216 }
240217 }
241218 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100211* Removed newFileFromKey() which had a misleading description and a bug where...aaron04:06, 19 October 2011

Status & tagging log