ea953e01882a55ac119fa55d1200bc183b8c9732
[lhc/web/wiklou.git] / includes / filebackend / FileBackend.php
1 <?php
2 /**
3 * @defgroup FileBackend File backend
4 *
5 * File backend is used to interact with file storage systems,
6 * such as the local file system, NFS, or cloud storage systems.
7 */
8
9 /**
10 * Base class for all file backends.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
26 *
27 * @file
28 * @ingroup FileBackend
29 * @author Aaron Schulz
30 */
31
32 /**
33 * @brief Base class for all file backend classes (including multi-write backends).
34 *
35 * This class defines the methods as abstract that subclasses must implement.
36 * Outside callers can assume that all backends will have these functions.
37 *
38 * All "storage paths" are of the format "mwstore://<backend>/<container>/<path>".
39 * The "backend" portion is unique name for MediaWiki to refer to a backend, while
40 * the "container" portion is a top-level directory of the backend. The "path" portion
41 * is a relative path that uses UNIX file system (FS) notation, though any particular
42 * backend may not actually be using a local filesystem. Therefore, the relative paths
43 * are only virtual.
44 *
45 * Backend contents are stored under wiki-specific container names by default.
46 * Global (qualified) backends are achieved by configuring the "wiki ID" to a constant.
47 * For legacy reasons, the FSFileBackend class allows manually setting the paths of
48 * containers to ones that do not respect the "wiki ID".
49 *
50 * In key/value (object) stores, containers are the only hierarchy (the rest is emulated).
51 * FS-based backends are somewhat more restrictive due to the existence of real
52 * directory files; a regular file cannot have the same name as a directory. Other
53 * backends with virtual directories may not have this limitation. Callers should
54 * store files in such a way that no files and directories are under the same path.
55 *
56 * In general, this class allows for callers to access storage through the same
57 * interface, without regard to the underlying storage system. However, calling code
58 * must follow certain patterns and be aware of certain things to ensure compatibility:
59 * - a) Always call prepare() on the parent directory before trying to put a file there;
60 * key/value stores only need the container to exist first, but filesystems need
61 * all the parent directories to exist first (prepare() is aware of all this)
62 * - b) Always call clean() on a directory when it might become empty to avoid empty
63 * directory buildup on filesystems; key/value stores never have empty directories,
64 * so doing this helps preserve consistency in both cases
65 * - c) Likewise, do not rely on the existence of empty directories for anything;
66 * calling directoryExists() on a path that prepare() was previously called on
67 * will return false for key/value stores if there are no files under that path
68 * - d) Never alter the resulting FSFile returned from getLocalReference(), as it could
69 * either be a copy of the source file in /tmp or the original source file itself
70 * - e) Use a file layout that results in never attempting to store files over directories
71 * or directories over files; key/value stores allow this but filesystems do not
72 * - f) Use ASCII file names (e.g. base32, IDs, hashes) to avoid Unicode issues in Windows
73 * - g) Do not assume that move operations are atomic (difficult with key/value stores)
74 * - h) Do not assume that file stat or read operations always have immediate consistency;
75 * various methods have a "latest" flag that should always be used if up-to-date
76 * information is required (this trades performance for correctness as needed)
77 * - i) Do not assume that directory listings have immediate consistency
78 *
79 * Methods of subclasses should avoid throwing exceptions at all costs.
80 * As a corollary, external dependencies should be kept to a minimum.
81 *
82 * @ingroup FileBackend
83 * @since 1.19
84 */
85 abstract class FileBackend {
86 /** @var string Unique backend name */
87 protected $name;
88
89 /** @var string Unique wiki name */
90 protected $wikiId;
91
92 /** @var string Read-only explanation message */
93 protected $readOnly;
94
95 /** @var string When to do operations in parallel */
96 protected $parallelize;
97
98 /** @var int How many operations can be done in parallel */
99 protected $concurrency;
100
101 /** @var LockManager */
102 protected $lockManager;
103
104 /** @var FileJournal */
105 protected $fileJournal;
106
107 /**
108 * Create a new backend instance from configuration.
109 * This should only be called from within FileBackendGroup.
110 *
111 * @param array $config Parameters include:
112 * - name : The unique name of this backend.
113 * This should consist of alphanumberic, '-', and '_' characters.
114 * This name should not be changed after use (e.g. with journaling).
115 * Note that the name is *not* used in actual container names.
116 * - wikiId : Prefix to container names that is unique to this backend.
117 * It should only consist of alphanumberic, '-', and '_' characters.
118 * This ID is what avoids collisions if multiple logical backends
119 * use the same storage system, so this should be set carefully.
120 * - lockManager : LockManager object to use for any file locking.
121 * If not provided, then no file locking will be enforced.
122 * - fileJournal : FileJournal object to use for logging changes to files.
123 * If not provided, then change journaling will be disabled.
124 * - readOnly : Write operations are disallowed if this is a non-empty string.
125 * It should be an explanation for the backend being read-only.
126 * - parallelize : When to do file operations in parallel (when possible).
127 * Allowed values are "implicit", "explicit" and "off".
128 * - concurrency : How many file operations can be done in parallel.
129 * @throws MWException
130 */
131 public function __construct( array $config ) {
132 $this->name = $config['name'];
133 if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) {
134 throw new MWException( "Backend name `{$this->name}` is invalid." );
135 }
136 $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_"
137 $this->lockManager = isset( $config['lockManager'] )
138 ? $config['lockManager']
139 : new NullLockManager( array() );
140 $this->fileJournal = isset( $config['fileJournal'] )
141 ? $config['fileJournal']
142 : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $this->name );
143 $this->readOnly = isset( $config['readOnly'] )
144 ? (string)$config['readOnly']
145 : '';
146 $this->parallelize = isset( $config['parallelize'] )
147 ? (string)$config['parallelize']
148 : 'off';
149 $this->concurrency = isset( $config['concurrency'] )
150 ? (int)$config['concurrency']
151 : 50;
152 }
153
154 /**
155 * Get the unique backend name.
156 * We may have multiple different backends of the same type.
157 * For example, we can have two Swift backends using different proxies.
158 *
159 * @return string
160 */
161 final public function getName() {
162 return $this->name;
163 }
164
165 /**
166 * Get the wiki identifier used for this backend (possibly empty).
167 * Note that this might *not* be in the same format as wfWikiID().
168 *
169 * @return string
170 * @since 1.20
171 */
172 final public function getWikiId() {
173 return $this->wikiId;
174 }
175
176 /**
177 * Check if this backend is read-only
178 *
179 * @return bool
180 */
181 final public function isReadOnly() {
182 return ( $this->readOnly != '' );
183 }
184
185 /**
186 * Get an explanatory message if this backend is read-only
187 *
188 * @return string|bool Returns false if the backend is not read-only
189 */
190 final public function getReadOnlyReason() {
191 return ( $this->readOnly != '' ) ? $this->readOnly : false;
192 }
193
194 /**
195 * This is the main entry point into the backend for write operations.
196 * Callers supply an ordered list of operations to perform as a transaction.
197 * Files will be locked, the stat cache cleared, and then the operations attempted.
198 * If any serious errors occur, all attempted operations will be rolled back.
199 *
200 * $ops is an array of arrays. The outer array holds a list of operations.
201 * Each inner array is a set of key value pairs that specify an operation.
202 *
203 * Supported operations and their parameters. The supported actions are:
204 * - create
205 * - store
206 * - copy
207 * - move
208 * - delete
209 * - describe (since 1.21)
210 * - null
211 *
212 * a) Create a new file in storage with the contents of a string
213 * @code
214 * array(
215 * 'op' => 'create',
216 * 'dst' => <storage path>,
217 * 'content' => <string of new file contents>,
218 * 'overwrite' => <boolean>,
219 * 'overwriteSame' => <boolean>,
220 * 'headers' => <HTTP header name/value map> # since 1.21
221 * );
222 * @endcode
223 *
224 * b) Copy a file system file into storage
225 * @code
226 * array(
227 * 'op' => 'store',
228 * 'src' => <file system path>,
229 * 'dst' => <storage path>,
230 * 'overwrite' => <boolean>,
231 * 'overwriteSame' => <boolean>,
232 * 'headers' => <HTTP header name/value map> # since 1.21
233 * )
234 * @endcode
235 *
236 * c) Copy a file within storage
237 * @code
238 * array(
239 * 'op' => 'copy',
240 * 'src' => <storage path>,
241 * 'dst' => <storage path>,
242 * 'overwrite' => <boolean>,
243 * 'overwriteSame' => <boolean>,
244 * 'ignoreMissingSource' => <boolean>, # since 1.21
245 * 'headers' => <HTTP header name/value map> # since 1.21
246 * )
247 * @endcode
248 *
249 * d) Move a file within storage
250 * @code
251 * array(
252 * 'op' => 'move',
253 * 'src' => <storage path>,
254 * 'dst' => <storage path>,
255 * 'overwrite' => <boolean>,
256 * 'overwriteSame' => <boolean>,
257 * 'ignoreMissingSource' => <boolean>, # since 1.21
258 * 'headers' => <HTTP header name/value map> # since 1.21
259 * )
260 * @endcode
261 *
262 * e) Delete a file within storage
263 * @code
264 * array(
265 * 'op' => 'delete',
266 * 'src' => <storage path>,
267 * 'ignoreMissingSource' => <boolean>
268 * )
269 * @endcode
270 *
271 * f) Update metadata for a file within storage
272 * @code
273 * array(
274 * 'op' => 'describe',
275 * 'src' => <storage path>,
276 * 'headers' => <HTTP header name/value map>
277 * )
278 * @endcode
279 *
280 * g) Do nothing (no-op)
281 * @code
282 * array(
283 * 'op' => 'null',
284 * )
285 * @endcode
286 *
287 * Boolean flags for operations (operation-specific):
288 * - ignoreMissingSource : The operation will simply succeed and do
289 * nothing if the source file does not exist.
290 * - overwrite : Any destination file will be overwritten.
291 * - overwriteSame : If a file already exists at the destination with the
292 * same contents, then do nothing to the destination file
293 * instead of giving an error. This does not compare headers.
294 * This option is ignored if 'overwrite' is already provided.
295 * - headers : If supplied, the result of merging these headers with any
296 * existing source file headers (replacing conflicting ones)
297 * will be set as the destination file headers. Headers are
298 * deleted if their value is set to the empty string. When a
299 * file has headers they are included in responses to GET and
300 * HEAD requests to the backing store for that file.
301 * Header values should be no larger than 255 bytes, except for
302 * Content-Disposition. The system might ignore or truncate any
303 * headers that are too long to store (exact limits will vary).
304 * Backends that don't support metadata ignore this. (since 1.21)
305 *
306 * $opts is an associative of boolean flags, including:
307 * - force : Operation precondition errors no longer trigger an abort.
308 * Any remaining operations are still attempted. Unexpected
309 * failures may still cause remaining operations to be aborted.
310 * - nonLocking : No locks are acquired for the operations.
311 * This can increase performance for non-critical writes.
312 * This has no effect unless the 'force' flag is set.
313 * - nonJournaled : Don't log this operation batch in the file journal.
314 * This limits the ability of recovery scripts.
315 * - parallelize : Try to do operations in parallel when possible.
316 * - bypassReadOnly : Allow writes in read-only mode. (since 1.20)
317 * - preserveCache : Don't clear the process cache before checking files.
318 * This should only be used if all entries in the process
319 * cache were added after the files were already locked. (since 1.20)
320 *
321 * @remarks Remarks on locking:
322 * File system paths given to operations should refer to files that are
323 * already locked or otherwise safe from modification from other processes.
324 * Normally these files will be new temp files, which should be adequate.
325 *
326 * @par Return value:
327 *
328 * This returns a Status, which contains all warnings and fatals that occurred
329 * during the operation. The 'failCount', 'successCount', and 'success' members
330 * will reflect each operation attempted.
331 *
332 * The status will be "OK" unless:
333 * - a) unexpected operation errors occurred (network partitions, disk full...)
334 * - b) significant operation errors occurred and 'force' was not set
335 *
336 * @param array $ops List of operations to execute in order
337 * @param array $opts Batch operation options
338 * @return Status
339 */
340 final public function doOperations( array $ops, array $opts = array() ) {
341 if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
342 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
343 }
344 if ( !count( $ops ) ) {
345 return Status::newGood(); // nothing to do
346 }
347 if ( empty( $opts['force'] ) ) { // sanity
348 unset( $opts['nonLocking'] );
349 }
350 foreach ( $ops as &$op ) {
351 if ( isset( $op['disposition'] ) ) { // b/c (MW 1.20)
352 $op['headers']['Content-Disposition'] = $op['disposition'];
353 }
354 }
355 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
356 return $this->doOperationsInternal( $ops, $opts );
357 }
358
359 /**
360 * @see FileBackend::doOperations()
361 */
362 abstract protected function doOperationsInternal( array $ops, array $opts );
363
364 /**
365 * Same as doOperations() except it takes a single operation.
366 * If you are doing a batch of operations that should either
367 * all succeed or all fail, then use that function instead.
368 *
369 * @see FileBackend::doOperations()
370 *
371 * @param array $op Operation
372 * @param array $opts Operation options
373 * @return Status
374 */
375 final public function doOperation( array $op, array $opts = array() ) {
376 return $this->doOperations( array( $op ), $opts );
377 }
378
379 /**
380 * Performs a single create operation.
381 * This sets $params['op'] to 'create' and passes it to doOperation().
382 *
383 * @see FileBackend::doOperation()
384 *
385 * @param array $params Operation parameters
386 * @param array $opts Operation options
387 * @return Status
388 */
389 final public function create( array $params, array $opts = array() ) {
390 return $this->doOperation( array( 'op' => 'create' ) + $params, $opts );
391 }
392
393 /**
394 * Performs a single store operation.
395 * This sets $params['op'] to 'store' and passes it to doOperation().
396 *
397 * @see FileBackend::doOperation()
398 *
399 * @param array $params Operation parameters
400 * @param array $opts Operation options
401 * @return Status
402 */
403 final public function store( array $params, array $opts = array() ) {
404 return $this->doOperation( array( 'op' => 'store' ) + $params, $opts );
405 }
406
407 /**
408 * Performs a single copy operation.
409 * This sets $params['op'] to 'copy' and passes it to doOperation().
410 *
411 * @see FileBackend::doOperation()
412 *
413 * @param array $params Operation parameters
414 * @param array $opts Operation options
415 * @return Status
416 */
417 final public function copy( array $params, array $opts = array() ) {
418 return $this->doOperation( array( 'op' => 'copy' ) + $params, $opts );
419 }
420
421 /**
422 * Performs a single move operation.
423 * This sets $params['op'] to 'move' and passes it to doOperation().
424 *
425 * @see FileBackend::doOperation()
426 *
427 * @param array $params Operation parameters
428 * @param array $opts Operation options
429 * @return Status
430 */
431 final public function move( array $params, array $opts = array() ) {
432 return $this->doOperation( array( 'op' => 'move' ) + $params, $opts );
433 }
434
435 /**
436 * Performs a single delete operation.
437 * This sets $params['op'] to 'delete' and passes it to doOperation().
438 *
439 * @see FileBackend::doOperation()
440 *
441 * @param array $params Operation parameters
442 * @param array $opts Operation options
443 * @return Status
444 */
445 final public function delete( array $params, array $opts = array() ) {
446 return $this->doOperation( array( 'op' => 'delete' ) + $params, $opts );
447 }
448
449 /**
450 * Performs a single describe operation.
451 * This sets $params['op'] to 'describe' and passes it to doOperation().
452 *
453 * @see FileBackend::doOperation()
454 *
455 * @param array $params Operation parameters
456 * @param array $opts Operation options
457 * @return Status
458 * @since 1.21
459 */
460 final public function describe( array $params, array $opts = array() ) {
461 return $this->doOperation( array( 'op' => 'describe' ) + $params, $opts );
462 }
463
464 /**
465 * Perform a set of independent file operations on some files.
466 *
467 * This does no locking, nor journaling, and possibly no stat calls.
468 * Any destination files that already exist will be overwritten.
469 * This should *only* be used on non-original files, like cache files.
470 *
471 * Supported operations and their parameters:
472 * - create
473 * - store
474 * - copy
475 * - move
476 * - delete
477 * - describe (since 1.21)
478 * - null
479 *
480 * a) Create a new file in storage with the contents of a string
481 * @code
482 * array(
483 * 'op' => 'create',
484 * 'dst' => <storage path>,
485 * 'content' => <string of new file contents>,
486 * 'headers' => <HTTP header name/value map> # since 1.21
487 * )
488 * @endcode
489 *
490 * b) Copy a file system file into storage
491 * @code
492 * array(
493 * 'op' => 'store',
494 * 'src' => <file system path>,
495 * 'dst' => <storage path>,
496 * 'headers' => <HTTP header name/value map> # since 1.21
497 * )
498 * @endcode
499 *
500 * c) Copy a file within storage
501 * @code
502 * array(
503 * 'op' => 'copy',
504 * 'src' => <storage path>,
505 * 'dst' => <storage path>,
506 * 'ignoreMissingSource' => <boolean>, # since 1.21
507 * 'headers' => <HTTP header name/value map> # since 1.21
508 * )
509 * @endcode
510 *
511 * d) Move a file within storage
512 * @code
513 * array(
514 * 'op' => 'move',
515 * 'src' => <storage path>,
516 * 'dst' => <storage path>,
517 * 'ignoreMissingSource' => <boolean>, # since 1.21
518 * 'headers' => <HTTP header name/value map> # since 1.21
519 * )
520 * @endcode
521 *
522 * e) Delete a file within storage
523 * @code
524 * array(
525 * 'op' => 'delete',
526 * 'src' => <storage path>,
527 * 'ignoreMissingSource' => <boolean>
528 * )
529 * @endcode
530 *
531 * f) Update metadata for a file within storage
532 * @code
533 * array(
534 * 'op' => 'describe',
535 * 'src' => <storage path>,
536 * 'headers' => <HTTP header name/value map>
537 * )
538 * @endcode
539 *
540 * g) Do nothing (no-op)
541 * @code
542 * array(
543 * 'op' => 'null',
544 * )
545 * @endcode
546 *
547 * @par Boolean flags for operations (operation-specific):
548 * - ignoreMissingSource : The operation will simply succeed and do
549 * nothing if the source file does not exist.
550 * - headers : If supplied with a header name/value map, the backend will
551 * reply with these headers when GETs/HEADs of the destination
552 * file are made. Header values should be smaller than 256 bytes.
553 * Content-Disposition headers can be longer, though the system
554 * might ignore or truncate ones that are too long to store.
555 * Existing headers will remain, but these will replace any
556 * conflicting previous headers, and headers will be removed
557 * if they are set to an empty string.
558 * Backends that don't support metadata ignore this. (since 1.21)
559 *
560 * $opts is an associative of boolean flags, including:
561 * - bypassReadOnly : Allow writes in read-only mode (since 1.20)
562 *
563 * @par Return value:
564 * This returns a Status, which contains all warnings and fatals that occurred
565 * during the operation. The 'failCount', 'successCount', and 'success' members
566 * will reflect each operation attempted for the given files. The status will be
567 * considered "OK" as long as no fatal errors occurred.
568 *
569 * @param array $ops Set of operations to execute
570 * @param array $opts Batch operation options
571 * @return Status
572 * @since 1.20
573 */
574 final public function doQuickOperations( array $ops, array $opts = array() ) {
575 if ( empty( $opts['bypassReadOnly'] ) && $this->isReadOnly() ) {
576 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
577 }
578 if ( !count( $ops ) ) {
579 return Status::newGood(); // nothing to do
580 }
581 foreach ( $ops as &$op ) {
582 $op['overwrite'] = true; // avoids RTTs in key/value stores
583 if ( isset( $op['disposition'] ) ) { // b/c (MW 1.20)
584 $op['headers']['Content-Disposition'] = $op['disposition'];
585 }
586 }
587 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
588 return $this->doQuickOperationsInternal( $ops );
589 }
590
591 /**
592 * @see FileBackend::doQuickOperations()
593 * @since 1.20
594 */
595 abstract protected function doQuickOperationsInternal( array $ops );
596
597 /**
598 * Same as doQuickOperations() except it takes a single operation.
599 * If you are doing a batch of operations, then use that function instead.
600 *
601 * @see FileBackend::doQuickOperations()
602 *
603 * @param array $op Operation
604 * @return Status
605 * @since 1.20
606 */
607 final public function doQuickOperation( array $op ) {
608 return $this->doQuickOperations( array( $op ) );
609 }
610
611 /**
612 * Performs a single quick create operation.
613 * This sets $params['op'] to 'create' and passes it to doQuickOperation().
614 *
615 * @see FileBackend::doQuickOperation()
616 *
617 * @param array $params Operation parameters
618 * @return Status
619 * @since 1.20
620 */
621 final public function quickCreate( array $params ) {
622 return $this->doQuickOperation( array( 'op' => 'create' ) + $params );
623 }
624
625 /**
626 * Performs a single quick store operation.
627 * This sets $params['op'] to 'store' and passes it to doQuickOperation().
628 *
629 * @see FileBackend::doQuickOperation()
630 *
631 * @param array $params Operation parameters
632 * @return Status
633 * @since 1.20
634 */
635 final public function quickStore( array $params ) {
636 return $this->doQuickOperation( array( 'op' => 'store' ) + $params );
637 }
638
639 /**
640 * Performs a single quick copy operation.
641 * This sets $params['op'] to 'copy' and passes it to doQuickOperation().
642 *
643 * @see FileBackend::doQuickOperation()
644 *
645 * @param array $params Operation parameters
646 * @return Status
647 * @since 1.20
648 */
649 final public function quickCopy( array $params ) {
650 return $this->doQuickOperation( array( 'op' => 'copy' ) + $params );
651 }
652
653 /**
654 * Performs a single quick move operation.
655 * This sets $params['op'] to 'move' and passes it to doQuickOperation().
656 *
657 * @see FileBackend::doQuickOperation()
658 *
659 * @param array $params Operation parameters
660 * @return Status
661 * @since 1.20
662 */
663 final public function quickMove( array $params ) {
664 return $this->doQuickOperation( array( 'op' => 'move' ) + $params );
665 }
666
667 /**
668 * Performs a single quick delete operation.
669 * This sets $params['op'] to 'delete' and passes it to doQuickOperation().
670 *
671 * @see FileBackend::doQuickOperation()
672 *
673 * @param array $params Operation parameters
674 * @return Status
675 * @since 1.20
676 */
677 final public function quickDelete( array $params ) {
678 return $this->doQuickOperation( array( 'op' => 'delete' ) + $params );
679 }
680
681 /**
682 * Performs a single quick describe operation.
683 * This sets $params['op'] to 'describe' and passes it to doQuickOperation().
684 *
685 * @see FileBackend::doQuickOperation()
686 *
687 * @param array $params Operation parameters
688 * @return Status
689 * @since 1.21
690 */
691 final public function quickDescribe( array $params ) {
692 return $this->doQuickOperation( array( 'op' => 'describe' ) + $params );
693 }
694
695 /**
696 * Concatenate a list of storage files into a single file system file.
697 * The target path should refer to a file that is already locked or
698 * otherwise safe from modification from other processes. Normally,
699 * the file will be a new temp file, which should be adequate.
700 *
701 * @param array $params Operation parameters, include:
702 * - srcs : ordered source storage paths (e.g. chunk1, chunk2, ...)
703 * - dst : file system path to 0-byte temp file
704 * - parallelize : try to do operations in parallel when possible
705 * @return Status
706 */
707 abstract public function concatenate( array $params );
708
709 /**
710 * Prepare a storage directory for usage.
711 * This will create any required containers and parent directories.
712 * Backends using key/value stores only need to create the container.
713 *
714 * The 'noAccess' and 'noListing' parameters works the same as in secure(),
715 * except they are only applied *if* the directory/container had to be created.
716 * These flags should always be set for directories that have private files.
717 * However, setting them is not guaranteed to actually do anything.
718 * Additional server configuration may be needed to achieve the desired effect.
719 *
720 * @param array $params Parameters include:
721 * - dir : storage directory
722 * - noAccess : try to deny file access (since 1.20)
723 * - noListing : try to deny file listing (since 1.20)
724 * - bypassReadOnly : allow writes in read-only mode (since 1.20)
725 * @return Status
726 */
727 final public function prepare( array $params ) {
728 if ( empty( $params['bypassReadOnly'] ) && $this->isReadOnly() ) {
729 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
730 }
731 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
732 return $this->doPrepare( $params );
733 }
734
735 /**
736 * @see FileBackend::prepare()
737 */
738 abstract protected function doPrepare( array $params );
739
740 /**
741 * Take measures to block web access to a storage directory and
742 * the container it belongs to. FS backends might add .htaccess
743 * files whereas key/value store backends might revoke container
744 * access to the storage user representing end-users in web requests.
745 *
746 * This is not guaranteed to actually make files or listings publically hidden.
747 * Additional server configuration may be needed to achieve the desired effect.
748 *
749 * @param array $params Parameters include:
750 * - dir : storage directory
751 * - noAccess : try to deny file access
752 * - noListing : try to deny file listing
753 * - bypassReadOnly : allow writes in read-only mode (since 1.20)
754 * @return Status
755 */
756 final public function secure( array $params ) {
757 if ( empty( $params['bypassReadOnly'] ) && $this->isReadOnly() ) {
758 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
759 }
760 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
761 return $this->doSecure( $params );
762 }
763
764 /**
765 * @see FileBackend::secure()
766 */
767 abstract protected function doSecure( array $params );
768
769 /**
770 * Remove measures to block web access to a storage directory and
771 * the container it belongs to. FS backends might remove .htaccess
772 * files whereas key/value store backends might grant container
773 * access to the storage user representing end-users in web requests.
774 * This essentially can undo the result of secure() calls.
775 *
776 * This is not guaranteed to actually make files or listings publically viewable.
777 * Additional server configuration may be needed to achieve the desired effect.
778 *
779 * @param array $params Parameters include:
780 * - dir : storage directory
781 * - access : try to allow file access
782 * - listing : try to allow file listing
783 * - bypassReadOnly : allow writes in read-only mode (since 1.20)
784 * @return Status
785 * @since 1.20
786 */
787 final public function publish( array $params ) {
788 if ( empty( $params['bypassReadOnly'] ) && $this->isReadOnly() ) {
789 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
790 }
791 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
792 return $this->doPublish( $params );
793 }
794
795 /**
796 * @see FileBackend::publish()
797 */
798 abstract protected function doPublish( array $params );
799
800 /**
801 * Delete a storage directory if it is empty.
802 * Backends using key/value stores may do nothing unless the directory
803 * is that of an empty container, in which case it will be deleted.
804 *
805 * @param array $params Parameters include:
806 * - dir : storage directory
807 * - recursive : recursively delete empty subdirectories first (since 1.20)
808 * - bypassReadOnly : allow writes in read-only mode (since 1.20)
809 * @return Status
810 */
811 final public function clean( array $params ) {
812 if ( empty( $params['bypassReadOnly'] ) && $this->isReadOnly() ) {
813 return Status::newFatal( 'backend-fail-readonly', $this->name, $this->readOnly );
814 }
815 $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
816 return $this->doClean( $params );
817 }
818
819 /**
820 * @see FileBackend::clean()
821 */
822 abstract protected function doClean( array $params );
823
824 /**
825 * Enter file operation scope.
826 * This just makes PHP ignore user aborts/disconnects until the return
827 * value leaves scope. This returns null and does nothing in CLI mode.
828 *
829 * @return ScopedCallback|null
830 */
831 final protected function getScopedPHPBehaviorForOps() {
832 if ( PHP_SAPI != 'cli' ) { // http://bugs.php.net/bug.php?id=47540
833 $old = ignore_user_abort( true ); // avoid half-finished operations
834 return new ScopedCallback( function () use ( $old ) {
835 ignore_user_abort( $old );
836 } );
837 }
838
839 return null;
840 }
841
842 /**
843 * Check if a file exists at a storage path in the backend.
844 * This returns false if only a directory exists at the path.
845 *
846 * @param array $params Parameters include:
847 * - src : source storage path
848 * - latest : use the latest available data
849 * @return bool|null Returns null on failure
850 */
851 abstract public function fileExists( array $params );
852
853 /**
854 * Get the last-modified timestamp of the file at a storage path.
855 *
856 * @param array $params Parameters include:
857 * - src : source storage path
858 * - latest : use the latest available data
859 * @return string|bool TS_MW timestamp or false on failure
860 */
861 abstract public function getFileTimestamp( array $params );
862
863 /**
864 * Get the contents of a file at a storage path in the backend.
865 * This should be avoided for potentially large files.
866 *
867 * @param array $params Parameters include:
868 * - src : source storage path
869 * - latest : use the latest available data
870 * @return string|bool Returns false on failure
871 */
872 final public function getFileContents( array $params ) {
873 $contents = $this->getFileContentsMulti(
874 array( 'srcs' => array( $params['src'] ) ) + $params );
875
876 return $contents[$params['src']];
877 }
878
879 /**
880 * Like getFileContents() except it takes an array of storage paths
881 * and returns a map of storage paths to strings (or null on failure).
882 * The map keys (paths) are in the same order as the provided list of paths.
883 *
884 * @see FileBackend::getFileContents()
885 *
886 * @param array $params Parameters include:
887 * - srcs : list of source storage paths
888 * - latest : use the latest available data
889 * - parallelize : try to do operations in parallel when possible
890 * @return array Map of (path name => string or false on failure)
891 * @since 1.20
892 */
893 abstract public function getFileContentsMulti( array $params );
894
895 /**
896 * Get the size (bytes) of a file at a storage path in the backend.
897 *
898 * @param array $params Parameters include:
899 * - src : source storage path
900 * - latest : use the latest available data
901 * @return int|bool Returns false on failure
902 */
903 abstract public function getFileSize( array $params );
904
905 /**
906 * Get quick information about a file at a storage path in the backend.
907 * If the file does not exist, then this returns false.
908 * Otherwise, the result is an associative array that includes:
909 * - mtime : the last-modified timestamp (TS_MW)
910 * - size : the file size (bytes)
911 * Additional values may be included for internal use only.
912 *
913 * @param array $params Parameters include:
914 * - src : source storage path
915 * - latest : use the latest available data
916 * @return array|bool|null Returns null on failure
917 */
918 abstract public function getFileStat( array $params );
919
920 /**
921 * Get a SHA-1 hash of the file at a storage path in the backend.
922 *
923 * @param array $params Parameters include:
924 * - src : source storage path
925 * - latest : use the latest available data
926 * @return string|bool Hash string or false on failure
927 */
928 abstract public function getFileSha1Base36( array $params );
929
930 /**
931 * Get the properties of the file at a storage path in the backend.
932 * This gives the result of FSFile::getProps() on a local copy of the file.
933 *
934 * @param array $params Parameters include:
935 * - src : source storage path
936 * - latest : use the latest available data
937 * @return array Returns FSFile::placeholderProps() on failure
938 */
939 abstract public function getFileProps( array $params );
940
941 /**
942 * Stream the file at a storage path in the backend.
943 * If the file does not exists, an HTTP 404 error will be given.
944 * Appropriate HTTP headers (Status, Content-Type, Content-Length)
945 * will be sent if streaming began, while none will be sent otherwise.
946 * Implementations should flush the output buffer before sending data.
947 *
948 * @param array $params Parameters include:
949 * - src : source storage path
950 * - headers : list of additional HTTP headers to send on success
951 * - latest : use the latest available data
952 * @return Status
953 */
954 abstract public function streamFile( array $params );
955
956 /**
957 * Returns a file system file, identical to the file at a storage path.
958 * The file returned is either:
959 * - a) A local copy of the file at a storage path in the backend.
960 * The temporary copy will have the same extension as the source.
961 * - b) An original of the file at a storage path in the backend.
962 * Temporary files may be purged when the file object falls out of scope.
963 *
964 * Write operations should *never* be done on this file as some backends
965 * may do internal tracking or may be instances of FileBackendMultiWrite.
966 * In that later case, there are copies of the file that must stay in sync.
967 * Additionally, further calls to this function may return the same file.
968 *
969 * @param array $params Parameters include:
970 * - src : source storage path
971 * - latest : use the latest available data
972 * @return FSFile|null Returns null on failure
973 */
974 final public function getLocalReference( array $params ) {
975 $fsFiles = $this->getLocalReferenceMulti(
976 array( 'srcs' => array( $params['src'] ) ) + $params );
977
978 return $fsFiles[$params['src']];
979 }
980
981 /**
982 * Like getLocalReference() except it takes an array of storage paths
983 * and returns a map of storage paths to FSFile objects (or null on failure).
984 * The map keys (paths) are in the same order as the provided list of paths.
985 *
986 * @see FileBackend::getLocalReference()
987 *
988 * @param array $params Parameters include:
989 * - srcs : list of source storage paths
990 * - latest : use the latest available data
991 * - parallelize : try to do operations in parallel when possible
992 * @return array Map of (path name => FSFile or null on failure)
993 * @since 1.20
994 */
995 abstract public function getLocalReferenceMulti( array $params );
996
997 /**
998 * Get a local copy on disk of the file at a storage path in the backend.
999 * The temporary copy will have the same file extension as the source.
1000 * Temporary files may be purged when the file object falls out of scope.
1001 *
1002 * @param array $params Parameters include:
1003 * - src : source storage path
1004 * - latest : use the latest available data
1005 * @return TempFSFile|null Returns null on failure
1006 */
1007 final public function getLocalCopy( array $params ) {
1008 $tmpFiles = $this->getLocalCopyMulti(
1009 array( 'srcs' => array( $params['src'] ) ) + $params );
1010
1011 return $tmpFiles[$params['src']];
1012 }
1013
1014 /**
1015 * Like getLocalCopy() except it takes an array of storage paths and
1016 * returns a map of storage paths to TempFSFile objects (or null on failure).
1017 * The map keys (paths) are in the same order as the provided list of paths.
1018 *
1019 * @see FileBackend::getLocalCopy()
1020 *
1021 * @param array $params Parameters include:
1022 * - srcs : list of source storage paths
1023 * - latest : use the latest available data
1024 * - parallelize : try to do operations in parallel when possible
1025 * @return array Map of (path name => TempFSFile or null on failure)
1026 * @since 1.20
1027 */
1028 abstract public function getLocalCopyMulti( array $params );
1029
1030 /**
1031 * Return an HTTP URL to a given file that requires no authentication to use.
1032 * The URL may be pre-authenticated (via some token in the URL) and temporary.
1033 * This will return null if the backend cannot make an HTTP URL for the file.
1034 *
1035 * This is useful for key/value stores when using scripts that seek around
1036 * large files and those scripts (and the backend) support HTTP Range headers.
1037 * Otherwise, one would need to use getLocalReference(), which involves loading
1038 * the entire file on to local disk.
1039 *
1040 * @param array $params Parameters include:
1041 * - src : source storage path
1042 * - ttl : lifetime (seconds) if pre-authenticated; default is 1 day
1043 * @return string|null
1044 * @since 1.21
1045 */
1046 abstract public function getFileHttpUrl( array $params );
1047
1048 /**
1049 * Check if a directory exists at a given storage path.
1050 * Backends using key/value stores will check if the path is a
1051 * virtual directory, meaning there are files under the given directory.
1052 *
1053 * Storage backends with eventual consistency might return stale data.
1054 *
1055 * @param array $params Parameters include:
1056 * - dir : storage directory
1057 * @return bool|null Returns null on failure
1058 * @since 1.20
1059 */
1060 abstract public function directoryExists( array $params );
1061
1062 /**
1063 * Get an iterator to list *all* directories under a storage directory.
1064 * If the directory is of the form "mwstore://backend/container",
1065 * then all directories in the container will be listed.
1066 * If the directory is of form "mwstore://backend/container/dir",
1067 * then all directories directly under that directory will be listed.
1068 * Results will be storage directories relative to the given directory.
1069 *
1070 * Storage backends with eventual consistency might return stale data.
1071 *
1072 * Failures during iteration can result in FileBackendError exceptions (since 1.22).
1073 *
1074 * @param array $params Parameters include:
1075 * - dir : storage directory
1076 * - topOnly : only return direct child dirs of the directory
1077 * @return Traversable|Array|null Returns null on failure
1078 * @since 1.20
1079 */
1080 abstract public function getDirectoryList( array $params );
1081
1082 /**
1083 * Same as FileBackend::getDirectoryList() except only lists
1084 * directories that are immediately under the given directory.
1085 *
1086 * Storage backends with eventual consistency might return stale data.
1087 *
1088 * Failures during iteration can result in FileBackendError exceptions (since 1.22).
1089 *
1090 * @param array $params Parameters include:
1091 * - dir : storage directory
1092 * @return Traversable|Array|null Returns null on failure
1093 * @since 1.20
1094 */
1095 final public function getTopDirectoryList( array $params ) {
1096 return $this->getDirectoryList( array( 'topOnly' => true ) + $params );
1097 }
1098
1099 /**
1100 * Get an iterator to list *all* stored files under a storage directory.
1101 * If the directory is of the form "mwstore://backend/container",
1102 * then all files in the container will be listed.
1103 * If the directory is of form "mwstore://backend/container/dir",
1104 * then all files under that directory will be listed.
1105 * Results will be storage paths relative to the given directory.
1106 *
1107 * Storage backends with eventual consistency might return stale data.
1108 *
1109 * Failures during iteration can result in FileBackendError exceptions (since 1.22).
1110 *
1111 * @param array $params Parameters include:
1112 * - dir : storage directory
1113 * - topOnly : only return direct child files of the directory (since 1.20)
1114 * - adviseStat : set to true if stat requests will be made on the files (since 1.22)
1115 * @return Traversable|Array|null Returns null on failure
1116 */
1117 abstract public function getFileList( array $params );
1118
1119 /**
1120 * Same as FileBackend::getFileList() except only lists
1121 * files that are immediately under the given directory.
1122 *
1123 * Storage backends with eventual consistency might return stale data.
1124 *
1125 * Failures during iteration can result in FileBackendError exceptions (since 1.22).
1126 *
1127 * @param array $params Parameters include:
1128 * - dir : storage directory
1129 * - adviseStat : set to true if stat requests will be made on the files (since 1.22)
1130 * @return Traversable|Array|null Returns null on failure
1131 * @since 1.20
1132 */
1133 final public function getTopFileList( array $params ) {
1134 return $this->getFileList( array( 'topOnly' => true ) + $params );
1135 }
1136
1137 /**
1138 * Preload persistent file stat and property cache into in-process cache.
1139 * This should be used when stat calls will be made on a known list of a many files.
1140 *
1141 * @param array $paths Storage paths
1142 */
1143 public function preloadCache( array $paths ) {
1144 }
1145
1146 /**
1147 * Invalidate any in-process file stat and property cache.
1148 * If $paths is given, then only the cache for those files will be cleared.
1149 *
1150 * @param array $paths Storage paths (optional)
1151 */
1152 public function clearCache( array $paths = null ) {
1153 }
1154
1155 /**
1156 * Lock the files at the given storage paths in the backend.
1157 * This will either lock all the files or none (on failure).
1158 *
1159 * Callers should consider using getScopedFileLocks() instead.
1160 *
1161 * @param array $paths Storage paths
1162 * @param int $type LockManager::LOCK_* constant
1163 * @return Status
1164 */
1165 final public function lockFiles( array $paths, $type ) {
1166 $paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
1167
1168 return $this->lockManager->lock( $paths, $type );
1169 }
1170
1171 /**
1172 * Unlock the files at the given storage paths in the backend.
1173 *
1174 * @param array $paths Storage paths
1175 * @param int $type LockManager::LOCK_* constant
1176 * @return Status
1177 */
1178 final public function unlockFiles( array $paths, $type ) {
1179 $paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
1180
1181 return $this->lockManager->unlock( $paths, $type );
1182 }
1183
1184 /**
1185 * Lock the files at the given storage paths in the backend.
1186 * This will either lock all the files or none (on failure).
1187 * On failure, the status object will be updated with errors.
1188 *
1189 * Once the return value goes out scope, the locks will be released and
1190 * the status updated. Unlock fatals will not change the status "OK" value.
1191 *
1192 * @see ScopedLock::factory()
1193 *
1194 * @param array $paths List of storage paths or map of lock types to path lists
1195 * @param int|string $type LockManager::LOCK_* constant or "mixed"
1196 * @param Status $status Status to update on lock/unlock
1197 * @return ScopedLock|null Returns null on failure
1198 */
1199 final public function getScopedFileLocks( array $paths, $type, Status $status ) {
1200 if ( $type === 'mixed' ) {
1201 foreach ( $paths as &$typePaths ) {
1202 $typePaths = array_map( 'FileBackend::normalizeStoragePath', $typePaths );
1203 }
1204 } else {
1205 $paths = array_map( 'FileBackend::normalizeStoragePath', $paths );
1206 }
1207
1208 return ScopedLock::factory( $this->lockManager, $paths, $type, $status );
1209 }
1210
1211 /**
1212 * Get an array of scoped locks needed for a batch of file operations.
1213 *
1214 * Normally, FileBackend::doOperations() handles locking, unless
1215 * the 'nonLocking' param is passed in. This function is useful if you
1216 * want the files to be locked for a broader scope than just when the
1217 * files are changing. For example, if you need to update DB metadata,
1218 * you may want to keep the files locked until finished.
1219 *
1220 * @see FileBackend::doOperations()
1221 *
1222 * @param array $ops List of file operations to FileBackend::doOperations()
1223 * @param Status $status Status to update on lock/unlock
1224 * @return array List of ScopedFileLocks or null values
1225 * @since 1.20
1226 */
1227 abstract public function getScopedLocksForOps( array $ops, Status $status );
1228
1229 /**
1230 * Get the root storage path of this backend.
1231 * All container paths are "subdirectories" of this path.
1232 *
1233 * @return string Storage path
1234 * @since 1.20
1235 */
1236 final public function getRootStoragePath() {
1237 return "mwstore://{$this->name}";
1238 }
1239
1240 /**
1241 * Get the storage path for the given container for this backend
1242 *
1243 * @param string $container Container name
1244 * @return string Storage path
1245 * @since 1.21
1246 */
1247 final public function getContainerStoragePath( $container ) {
1248 return $this->getRootStoragePath() . "/{$container}";
1249 }
1250
1251 /**
1252 * Get the file journal object for this backend
1253 *
1254 * @return FileJournal
1255 */
1256 final public function getJournal() {
1257 return $this->fileJournal;
1258 }
1259
1260 /**
1261 * Check if a given path is a "mwstore://" path.
1262 * This does not do any further validation or any existence checks.
1263 *
1264 * @param string $path
1265 * @return bool
1266 */
1267 final public static function isStoragePath( $path ) {
1268 return ( strpos( $path, 'mwstore://' ) === 0 );
1269 }
1270
1271 /**
1272 * Split a storage path into a backend name, a container name,
1273 * and a relative file path. The relative path may be the empty string.
1274 * This does not do any path normalization or traversal checks.
1275 *
1276 * @param string $storagePath
1277 * @return array (backend, container, rel object) or (null, null, null)
1278 */
1279 final public static function splitStoragePath( $storagePath ) {
1280 if ( self::isStoragePath( $storagePath ) ) {
1281 // Remove the "mwstore://" prefix and split the path
1282 $parts = explode( '/', substr( $storagePath, 10 ), 3 );
1283 if ( count( $parts ) >= 2 && $parts[0] != '' && $parts[1] != '' ) {
1284 if ( count( $parts ) == 3 ) {
1285 return $parts; // e.g. "backend/container/path"
1286 } else {
1287 return array( $parts[0], $parts[1], '' ); // e.g. "backend/container"
1288 }
1289 }
1290 }
1291
1292 return array( null, null, null );
1293 }
1294
1295 /**
1296 * Normalize a storage path by cleaning up directory separators.
1297 * Returns null if the path is not of the format of a valid storage path.
1298 *
1299 * @param string $storagePath
1300 * @return string|null
1301 */
1302 final public static function normalizeStoragePath( $storagePath ) {
1303 list( $backend, $container, $relPath ) = self::splitStoragePath( $storagePath );
1304 if ( $relPath !== null ) { // must be for this backend
1305 $relPath = self::normalizeContainerPath( $relPath );
1306 if ( $relPath !== null ) {
1307 return ( $relPath != '' )
1308 ? "mwstore://{$backend}/{$container}/{$relPath}"
1309 : "mwstore://{$backend}/{$container}";
1310 }
1311 }
1312
1313 return null;
1314 }
1315
1316 /**
1317 * Get the parent storage directory of a storage path.
1318 * This returns a path like "mwstore://backend/container",
1319 * "mwstore://backend/container/...", or null if there is no parent.
1320 *
1321 * @param string $storagePath
1322 * @return string|null
1323 */
1324 final public static function parentStoragePath( $storagePath ) {
1325 $storagePath = dirname( $storagePath );
1326 list( , , $rel ) = self::splitStoragePath( $storagePath );
1327
1328 return ( $rel === null ) ? null : $storagePath;
1329 }
1330
1331 /**
1332 * Get the final extension from a storage or FS path
1333 *
1334 * @param string $path
1335 * @return string
1336 */
1337 final public static function extensionFromPath( $path ) {
1338 $i = strrpos( $path, '.' );
1339
1340 return strtolower( $i ? substr( $path, $i + 1 ) : '' );
1341 }
1342
1343 /**
1344 * Check if a relative path has no directory traversals
1345 *
1346 * @param string $path
1347 * @return bool
1348 * @since 1.20
1349 */
1350 final public static function isPathTraversalFree( $path ) {
1351 return ( self::normalizeContainerPath( $path ) !== null );
1352 }
1353
1354 /**
1355 * Build a Content-Disposition header value per RFC 6266.
1356 *
1357 * @param string $type One of (attachment, inline)
1358 * @param string $filename Suggested file name (should not contain slashes)
1359 * @throws MWException
1360 * @return string
1361 * @since 1.20
1362 */
1363 final public static function makeContentDisposition( $type, $filename = '' ) {
1364 $parts = array();
1365
1366 $type = strtolower( $type );
1367 if ( !in_array( $type, array( 'inline', 'attachment' ) ) ) {
1368 throw new MWException( "Invalid Content-Disposition type '$type'." );
1369 }
1370 $parts[] = $type;
1371
1372 if ( strlen( $filename ) ) {
1373 $parts[] = "filename*=UTF-8''" . rawurlencode( basename( $filename ) );
1374 }
1375
1376 return implode( ';', $parts );
1377 }
1378
1379 /**
1380 * Validate and normalize a relative storage path.
1381 * Null is returned if the path involves directory traversal.
1382 * Traversal is insecure for FS backends and broken for others.
1383 *
1384 * This uses the same traversal protection as Title::secureAndSplit().
1385 *
1386 * @param string $path Storage path relative to a container
1387 * @return string|null
1388 */
1389 final protected static function normalizeContainerPath( $path ) {
1390 // Normalize directory separators
1391 $path = strtr( $path, '\\', '/' );
1392 // Collapse any consecutive directory separators
1393 $path = preg_replace( '![/]{2,}!', '/', $path );
1394 // Remove any leading directory separator
1395 $path = ltrim( $path, '/' );
1396 // Use the same traversal protection as Title::secureAndSplit()
1397 if ( strpos( $path, '.' ) !== false ) {
1398 if (
1399 $path === '.' ||
1400 $path === '..' ||
1401 strpos( $path, './' ) === 0 ||
1402 strpos( $path, '../' ) === 0 ||
1403 strpos( $path, '/./' ) !== false ||
1404 strpos( $path, '/../' ) !== false
1405 ) {
1406 return null;
1407 }
1408 }
1409
1410 return $path;
1411 }
1412 }
1413
1414 /**
1415 * @ingroup FileBackend
1416 * @since 1.22
1417 */
1418 class FileBackendError extends MWException {
1419 }