Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -156,7 +156,7 @@ |
157 | 157 | * $params include: |
158 | 158 | * dir : storage directory |
159 | 159 | * |
160 | | - * @param Array $params |
| 160 | + * @param $params Array |
161 | 161 | * @return Status |
162 | 162 | */ |
163 | 163 | abstract public function prepare( array $params ); |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | * noAccess : try to deny file access |
175 | 175 | * noListing : try to deny file listing |
176 | 176 | * |
177 | | - * @param Array $params |
| 177 | + * @param $params Array |
178 | 178 | * @return Status |
179 | 179 | */ |
180 | 180 | abstract public function secure( array $params ); |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | * $params include: |
187 | 187 | * dir : storage directory |
188 | 188 | * |
189 | | - * @param Array $params |
| 189 | + * @param $params Array |
190 | 190 | * @return Status |
191 | 191 | */ |
192 | 192 | abstract public function clean( array $params ); |
— | — | @@ -196,7 +196,7 @@ |
197 | 197 | * $params include: |
198 | 198 | * src : source storage path |
199 | 199 | * |
200 | | - * @param Array $params |
| 200 | + * @param $params Array |
201 | 201 | * @return bool |
202 | 202 | */ |
203 | 203 | abstract public function fileExists( array $params ); |
— | — | @@ -208,7 +208,7 @@ |
209 | 209 | * $params include: |
210 | 210 | * src : source storage path |
211 | 211 | * |
212 | | - * @param Array $params |
| 212 | + * @param $params Array |
213 | 213 | * @return string|false Hash string or false on failure |
214 | 214 | */ |
215 | 215 | abstract public function getFileHash( array $params ); |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | * $params include: |
228 | 228 | * src : source storage path |
229 | 229 | * |
230 | | - * @param Array $params |
| 230 | + * @param $params Array |
231 | 231 | * @return string|false TS_MW timestamp or false on failure |
232 | 232 | */ |
233 | 233 | abstract public function getFileTimestamp( array $params ); |
— | — | @@ -238,7 +238,7 @@ |
239 | 239 | * $params include: |
240 | 240 | * src : source storage path |
241 | 241 | * |
242 | | - * @param Array $params |
| 242 | + * @param $params Array |
243 | 243 | * @return Array |
244 | 244 | */ |
245 | 245 | abstract public function getFileProps( array $params ); |
— | — | @@ -253,7 +253,7 @@ |
254 | 254 | * src : source storage path |
255 | 255 | * headers : additional HTTP headers to send on success |
256 | 256 | * |
257 | | - * @param Array $params |
| 257 | + * @param $params Array |
258 | 258 | * @return Status |
259 | 259 | */ |
260 | 260 | abstract public function streamFile( array $params ); |
— | — | @@ -286,7 +286,7 @@ |
287 | 287 | * $params include: |
288 | 288 | * src : source storage path |
289 | 289 | * |
290 | | - * @param Array $params |
| 290 | + * @param $params Array |
291 | 291 | * @return FSFile|null Returns null on failure |
292 | 292 | */ |
293 | 293 | public function getLocalReference( array $params ) { |
— | — | @@ -300,7 +300,7 @@ |
301 | 301 | * $params include: |
302 | 302 | * src : source storage path |
303 | 303 | * |
304 | | - * @param Array $params |
| 304 | + * @param $params Array |
305 | 305 | * @return TempFSFile|null Returns null on failure |
306 | 306 | */ |
307 | 307 | abstract public function getLocalCopy( array $params ); |
— | — | @@ -365,7 +365,7 @@ |
366 | 366 | * dst : destination storage path |
367 | 367 | * overwriteDest : do nothing and pass if an identical file exists at destination |
368 | 368 | * |
369 | | - * @param Array $params |
| 369 | + * @param $params Array |
370 | 370 | * @return Status |
371 | 371 | */ |
372 | 372 | abstract public function store( array $params ); |
— | — | @@ -378,7 +378,7 @@ |
379 | 379 | * dst : destination storage path |
380 | 380 | * overwriteDest : do nothing and pass if an identical file exists at destination |
381 | 381 | * |
382 | | - * @param Array $params |
| 382 | + * @param $params Array |
383 | 383 | * @return Status |
384 | 384 | */ |
385 | 385 | abstract public function copy( array $params ); |
— | — | @@ -392,7 +392,7 @@ |
393 | 393 | * dst : destination storage path |
394 | 394 | * overwriteDest : do nothing and pass if an identical file exists at destination |
395 | 395 | * |
396 | | - * @param Array $params |
| 396 | + * @param $params Array |
397 | 397 | * @return Status |
398 | 398 | */ |
399 | 399 | public function move( array $params ) { |
— | — | @@ -405,7 +405,7 @@ |
406 | 406 | * $params include: |
407 | 407 | * src : source storage path |
408 | 408 | * |
409 | | - * @param Array $params |
| 409 | + * @param $params Array |
410 | 410 | * @return Status |
411 | 411 | */ |
412 | 412 | abstract public function delete( array $params ); |
— | — | @@ -418,7 +418,7 @@ |
419 | 419 | * dst : destination storage path |
420 | 420 | * overwriteDest : do nothing and pass if an identical file exists at destination |
421 | 421 | * |
422 | | - * @param Array $params |
| 422 | + * @param $params Array |
423 | 423 | * @return Status |
424 | 424 | */ |
425 | 425 | abstract public function concatenate( array $params ); |
— | — | @@ -431,7 +431,7 @@ |
432 | 432 | * dst : destination storage path |
433 | 433 | * overwriteDest : do nothing and pass if an identical file exists at destination |
434 | 434 | * |
435 | | - * @param Array $params |
| 435 | + * @param $params Array |
436 | 436 | * @return Status |
437 | 437 | */ |
438 | 438 | abstract public function create( array $params ); |
— | — | @@ -457,7 +457,7 @@ |
458 | 458 | * src : source storage path |
459 | 459 | * dst : destination storage path |
460 | 460 | * |
461 | | - * @param Array $params |
| 461 | + * @param $params Array |
462 | 462 | * @return bool |
463 | 463 | */ |
464 | 464 | public function canMove( array $params ) { |
— | — | @@ -521,8 +521,8 @@ |
522 | 522 | * The result must have the same number of items as the input. |
523 | 523 | * An exception is thrown if an unsupported operation is requested. |
524 | 524 | * |
525 | | - * @param Array $ops Same format as doOperations() |
526 | | - * @return Array |
| 525 | + * @param $ops Array Same format as doOperations() |
| 526 | + * @return Array List of FileOp objects |
527 | 527 | * @throws MWException |
528 | 528 | */ |
529 | 529 | final public function getOperations( array $ops ) { |
— | — | @@ -675,7 +675,9 @@ |
676 | 676 | $relPath = $this->resolveContainerPath( $container, $relPath ); |
677 | 677 | if ( $relPath !== null ) { // valid |
678 | 678 | $container = $this->fullContainerName( $container ); |
679 | | - return array( $container, $relPath ); // (container, path) |
| 679 | + if ( $this->checkContainerName( $container ) ) { |
| 680 | + return array( $container, $relPath ); // (container, path) |
| 681 | + } |
680 | 682 | } |
681 | 683 | } |
682 | 684 | } |
— | — | @@ -724,7 +726,22 @@ |
725 | 727 | } |
726 | 728 | |
727 | 729 | /** |
| 730 | + * Check if a container name is allowed by the backend. |
| 731 | + * Subclasses can override this to be more restrictive. |
| 732 | + * |
| 733 | + * @param $container string |
| 734 | + * @return bool |
| 735 | + */ |
| 736 | + protected function checkContainerName( $container ) { |
| 737 | + // This accounts for Swift and S3 restrictions. Also note |
| 738 | + // that these urlencode to the same string, which is useful |
| 739 | + // since the Swift size limit is *after* URL encoding. |
| 740 | + return preg_match( '/^[a-zA-Z._-]{1,256}$/u', $container ); |
| 741 | + } |
| 742 | + |
| 743 | + /** |
728 | 744 | * Resolve a storage path relative to a particular container. |
| 745 | + * This should also check if the path is allowed by the backend. |
729 | 746 | * This is for internal use for backends, such as encoding or |
730 | 747 | * perhaps getting absolute paths (e.g. FS based backends). |
731 | 748 | * |