Index: branches/wmf/1.18wmf1/includes/filerepo/OldLocalFile.php |
— | — | @@ -19,8 +19,9 @@ |
20 | 20 | |
21 | 21 | static function newFromTitle( $title, $repo, $time = null ) { |
22 | 22 | # The null default value is only here to avoid an E_STRICT |
23 | | - if( $time === null ) |
| 23 | + if ( $time === null ) { |
24 | 24 | throw new MWException( __METHOD__.' got null for $time parameter' ); |
| 25 | + } |
25 | 26 | return new self( $title, $repo, $time, null ); |
26 | 27 | } |
27 | 28 | |
— | — | @@ -36,19 +37,25 @@ |
37 | 38 | } |
38 | 39 | |
39 | 40 | /** |
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 |
41 | 45 | * @param $repo LocalRepo |
42 | | - * @param bool $timestamp |
| 46 | + * @param string|bool $timestamp MW_timestamp (optional) |
| 47 | + * |
43 | 48 | * @return bool|OldLocalFile |
44 | 49 | */ |
45 | 50 | static function newFromKey( $sha1, $repo, $timestamp = false ) { |
| 51 | + $dbr = $repo->getSlaveDB(); |
| 52 | + |
46 | 53 | $conds = array( 'oi_sha1' => $sha1 ); |
47 | | - if( $timestamp ) { |
48 | | - $conds['oi_timestamp'] = $timestamp; |
| 54 | + if ( $timestamp ) { |
| 55 | + $conds['oi_timestamp'] = $dbr->timestamp( $timestamp ); |
49 | 56 | } |
50 | | - $dbr = $repo->getSlaveDB(); |
| 57 | + |
51 | 58 | $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ ); |
52 | | - if( $row ) { |
| 59 | + if ( $row ) { |
53 | 60 | return self::newFromRow( $row, $repo ); |
54 | 61 | } else { |
55 | 62 | return false; |
Index: branches/wmf/1.18wmf1/includes/filerepo/LocalFile.php |
— | — | @@ -95,22 +95,21 @@ |
96 | 96 | * Create a LocalFile from a SHA-1 key |
97 | 97 | * Do not call this except from inside a repo class. |
98 | 98 | * |
99 | | - * @param $sha1 string |
| 99 | + * @param $sha1 string base-36 SHA-1 |
100 | 100 | * @param $repo LocalRepo |
101 | | - * @param $timestamp string |
| 101 | + * @param string|bool $timestamp MW_timestamp (optional) |
102 | 102 | * |
103 | | - * @return LocalFile |
| 103 | + * @return bool|LocalFile |
104 | 104 | */ |
105 | 105 | static function newFromKey( $sha1, $repo, $timestamp = false ) { |
106 | | - $conds = array( 'img_sha1' => $sha1 ); |
| 106 | + $dbr = $repo->getSlaveDB(); |
107 | 107 | |
| 108 | + $conds = array( 'img_sha1' => $sha1 ); |
108 | 109 | if ( $timestamp ) { |
109 | | - $conds['img_timestamp'] = $timestamp; |
| 110 | + $conds['img_timestamp'] = $dbr->timestamp( $timestamp ); |
110 | 111 | } |
111 | 112 | |
112 | | - $dbr = $repo->getSlaveDB(); |
113 | 113 | $row = $dbr->selectRow( 'image', self::selectFields(), $conds, __METHOD__ ); |
114 | | - |
115 | 114 | if ( $row ) { |
116 | 115 | return self::newFromRow( $row, $repo ); |
117 | 116 | } else { |
Index: branches/wmf/1.18wmf1/includes/filerepo/FileRepo.php |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | * @return File |
76 | 76 | */ |
77 | 77 | function newFile( $title, $time = false ) { |
78 | | - if ( !($title instanceof Title) ) { |
| 78 | + if ( !( $title instanceof Title ) ) { |
79 | 79 | $title = Title::makeTitleSafe( NS_FILE, $title ); |
80 | 80 | if ( !is_object( $title ) ) { |
81 | 81 | return null; |
— | — | @@ -130,10 +130,10 @@ |
131 | 131 | if ( $time !== false ) { |
132 | 132 | $img = $this->newFile( $title, $time ); |
133 | 133 | 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 ) ) { |
135 | 137 | return $img; |
136 | | - } elseif ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) { |
137 | | - return $img; |
138 | 138 | } |
139 | 139 | } |
140 | 140 | } |
— | — | @@ -185,30 +185,6 @@ |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
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 | | - /** |
213 | 189 | * Find an instance of the file with this key, created at the specified time |
214 | 190 | * Returns false if the file does not exist. Repositories not supporting |
215 | 191 | * version control should return false if the time is specified. |
— | — | @@ -219,22 +195,23 @@ |
220 | 196 | function findFileFromKey( $sha1, $options = array() ) { |
221 | 197 | $time = isset( $options['time'] ) ? $options['time'] : false; |
222 | 198 | |
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 |
227 | 204 | } |
228 | | - if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) { |
| 205 | + if ( $img && $img->exists() ) { |
229 | 206 | return $img; |
230 | 207 | } |
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 ); |
234 | 211 | 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 ) ) { |
236 | 215 | return $img; |
237 | | - } elseif ( !empty( $options['private'] ) && $img->userCan(File::DELETED_FILE) ) { |
238 | | - return $img; |
239 | 216 | } |
240 | 217 | } |
241 | 218 | } |