r105743 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105742‎ | r105743 | r105744 >
Date:02:06, 10 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* More documentation cleanups
* Added checkContainerName() to restrict container names
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php
@@ -156,7 +156,7 @@
157157 * $params include:
158158 * dir : storage directory
159159 *
160 - * @param Array $params
 160+ * @param $params Array
161161 * @return Status
162162 */
163163 abstract public function prepare( array $params );
@@ -173,7 +173,7 @@
174174 * noAccess : try to deny file access
175175 * noListing : try to deny file listing
176176 *
177 - * @param Array $params
 177+ * @param $params Array
178178 * @return Status
179179 */
180180 abstract public function secure( array $params );
@@ -185,7 +185,7 @@
186186 * $params include:
187187 * dir : storage directory
188188 *
189 - * @param Array $params
 189+ * @param $params Array
190190 * @return Status
191191 */
192192 abstract public function clean( array $params );
@@ -196,7 +196,7 @@
197197 * $params include:
198198 * src : source storage path
199199 *
200 - * @param Array $params
 200+ * @param $params Array
201201 * @return bool
202202 */
203203 abstract public function fileExists( array $params );
@@ -208,7 +208,7 @@
209209 * $params include:
210210 * src : source storage path
211211 *
212 - * @param Array $params
 212+ * @param $params Array
213213 * @return string|false Hash string or false on failure
214214 */
215215 abstract public function getFileHash( array $params );
@@ -226,7 +226,7 @@
227227 * $params include:
228228 * src : source storage path
229229 *
230 - * @param Array $params
 230+ * @param $params Array
231231 * @return string|false TS_MW timestamp or false on failure
232232 */
233233 abstract public function getFileTimestamp( array $params );
@@ -238,7 +238,7 @@
239239 * $params include:
240240 * src : source storage path
241241 *
242 - * @param Array $params
 242+ * @param $params Array
243243 * @return Array
244244 */
245245 abstract public function getFileProps( array $params );
@@ -253,7 +253,7 @@
254254 * src : source storage path
255255 * headers : additional HTTP headers to send on success
256256 *
257 - * @param Array $params
 257+ * @param $params Array
258258 * @return Status
259259 */
260260 abstract public function streamFile( array $params );
@@ -286,7 +286,7 @@
287287 * $params include:
288288 * src : source storage path
289289 *
290 - * @param Array $params
 290+ * @param $params Array
291291 * @return FSFile|null Returns null on failure
292292 */
293293 public function getLocalReference( array $params ) {
@@ -300,7 +300,7 @@
301301 * $params include:
302302 * src : source storage path
303303 *
304 - * @param Array $params
 304+ * @param $params Array
305305 * @return TempFSFile|null Returns null on failure
306306 */
307307 abstract public function getLocalCopy( array $params );
@@ -365,7 +365,7 @@
366366 * dst : destination storage path
367367 * overwriteDest : do nothing and pass if an identical file exists at destination
368368 *
369 - * @param Array $params
 369+ * @param $params Array
370370 * @return Status
371371 */
372372 abstract public function store( array $params );
@@ -378,7 +378,7 @@
379379 * dst : destination storage path
380380 * overwriteDest : do nothing and pass if an identical file exists at destination
381381 *
382 - * @param Array $params
 382+ * @param $params Array
383383 * @return Status
384384 */
385385 abstract public function copy( array $params );
@@ -392,7 +392,7 @@
393393 * dst : destination storage path
394394 * overwriteDest : do nothing and pass if an identical file exists at destination
395395 *
396 - * @param Array $params
 396+ * @param $params Array
397397 * @return Status
398398 */
399399 public function move( array $params ) {
@@ -405,7 +405,7 @@
406406 * $params include:
407407 * src : source storage path
408408 *
409 - * @param Array $params
 409+ * @param $params Array
410410 * @return Status
411411 */
412412 abstract public function delete( array $params );
@@ -418,7 +418,7 @@
419419 * dst : destination storage path
420420 * overwriteDest : do nothing and pass if an identical file exists at destination
421421 *
422 - * @param Array $params
 422+ * @param $params Array
423423 * @return Status
424424 */
425425 abstract public function concatenate( array $params );
@@ -431,7 +431,7 @@
432432 * dst : destination storage path
433433 * overwriteDest : do nothing and pass if an identical file exists at destination
434434 *
435 - * @param Array $params
 435+ * @param $params Array
436436 * @return Status
437437 */
438438 abstract public function create( array $params );
@@ -457,7 +457,7 @@
458458 * src : source storage path
459459 * dst : destination storage path
460460 *
461 - * @param Array $params
 461+ * @param $params Array
462462 * @return bool
463463 */
464464 public function canMove( array $params ) {
@@ -521,8 +521,8 @@
522522 * The result must have the same number of items as the input.
523523 * An exception is thrown if an unsupported operation is requested.
524524 *
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
527527 * @throws MWException
528528 */
529529 final public function getOperations( array $ops ) {
@@ -675,7 +675,9 @@
676676 $relPath = $this->resolveContainerPath( $container, $relPath );
677677 if ( $relPath !== null ) { // valid
678678 $container = $this->fullContainerName( $container );
679 - return array( $container, $relPath ); // (container, path)
 679+ if ( $this->checkContainerName( $container ) ) {
 680+ return array( $container, $relPath ); // (container, path)
 681+ }
680682 }
681683 }
682684 }
@@ -724,7 +726,22 @@
725727 }
726728
727729 /**
 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+ /**
728744 * Resolve a storage path relative to a particular container.
 745+ * This should also check if the path is allowed by the backend.
729746 * This is for internal use for backends, such as encoding or
730747 * perhaps getting absolute paths (e.g. FS based backends).
731748 *

Status & tagging log