Remove not needed global imports in BitmapHandler
[lhc/web/wiklou.git] / includes / filebackend / FSFileBackend.php
index 2b18443..07370ad 100644 (file)
@@ -90,6 +90,10 @@ class FSFileBackend extends FileBackendStore {
                }
        }
 
+       public function getFeatures() {
+               return !wfIsWindows() ? FileBackend::ATTR_UNICODE_PATHS : 0;
+       }
+
        protected function resolveContainerPath( $container, $relStoragePath ) {
                // Check that container has a root directory
                if ( isset( $this->containerPaths[$container] ) || isset( $this->basePath ) ) {
@@ -209,7 +213,13 @@ class FSFileBackend extends FileBackendStore {
                                wfEscapeShellArg( $this->cleanPathSlashes( $tempFile->getPath() ) ),
                                wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
                        ) );
-                       $status->value = new FSFileOpHandle( $this, $params, 'Create', $cmd, $dest );
+                       $handler = function ( $errors, Status $status, array $params, $cmd ) {
+                               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+                                       $status->fatal( 'backend-fail-create', $params['dst'] );
+                                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+                               }
+                       };
+                       $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
                        $tempFile->bind( $status->value );
                } else { // immediate write
                        $this->trapWarnings();
@@ -226,16 +236,6 @@ class FSFileBackend extends FileBackendStore {
                return $status;
        }
 
-       /**
-        * @see FSFileBackend::doExecuteOpHandlesInternal()
-        */
-       protected function getResponseCreate( $errors, Status $status, array $params, $cmd ) {
-               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
-                       $status->fatal( 'backend-fail-create', $params['dst'] );
-                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
-               }
-       }
-
        protected function doStoreInternal( array $params ) {
                $status = Status::newGood();
 
@@ -252,7 +252,13 @@ class FSFileBackend extends FileBackendStore {
                                wfEscapeShellArg( $this->cleanPathSlashes( $params['src'] ) ),
                                wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
                        ) );
-                       $status->value = new FSFileOpHandle( $this, $params, 'Store', $cmd, $dest );
+                       $handler = function ( $errors, Status $status, array $params, $cmd ) {
+                               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+                                       $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
+                                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+                               }
+                       };
+                       $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
                } else { // immediate write
                        $this->trapWarnings();
                        $ok = copy( $params['src'], $dest );
@@ -273,16 +279,6 @@ class FSFileBackend extends FileBackendStore {
                return $status;
        }
 
-       /**
-        * @see FSFileBackend::doExecuteOpHandlesInternal()
-        */
-       protected function getResponseStore( $errors, Status $status, array $params, $cmd ) {
-               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
-                       $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
-                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
-               }
-       }
-
        protected function doCopyInternal( array $params ) {
                $status = Status::newGood();
 
@@ -314,7 +310,13 @@ class FSFileBackend extends FileBackendStore {
                                wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
                                wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
                        ) );
-                       $status->value = new FSFileOpHandle( $this, $params, 'Copy', $cmd, $dest );
+                       $handler = function ( $errors, Status $status, array $params, $cmd ) {
+                               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+                                       $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
+                                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+                               }
+                       };
+                       $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
                } else { // immediate write
                        $this->trapWarnings();
                        $ok = ( $source === $dest ) ? true : copy( $source, $dest );
@@ -337,16 +339,6 @@ class FSFileBackend extends FileBackendStore {
                return $status;
        }
 
-       /**
-        * @see FSFileBackend::doExecuteOpHandlesInternal()
-        */
-       protected function getResponseCopy( $errors, Status $status, array $params, $cmd ) {
-               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
-                       $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
-                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
-               }
-       }
-
        protected function doMoveInternal( array $params ) {
                $status = Status::newGood();
 
@@ -378,7 +370,13 @@ class FSFileBackend extends FileBackendStore {
                                wfEscapeShellArg( $this->cleanPathSlashes( $source ) ),
                                wfEscapeShellArg( $this->cleanPathSlashes( $dest ) )
                        ) );
-                       $status->value = new FSFileOpHandle( $this, $params, 'Move', $cmd );
+                       $handler = function ( $errors, Status $status, array $params, $cmd ) {
+                               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+                                       $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
+                                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+                               }
+                       };
+                       $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd );
                } else { // immediate write
                        $this->trapWarnings();
                        $ok = ( $source === $dest ) ? true : rename( $source, $dest );
@@ -394,16 +392,6 @@ class FSFileBackend extends FileBackendStore {
                return $status;
        }
 
-       /**
-        * @see FSFileBackend::doExecuteOpHandlesInternal()
-        */
-       protected function getResponseMove( $errors, Status $status, array $params, $cmd ) {
-               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
-                       $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] );
-                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
-               }
-       }
-
        protected function doDeleteInternal( array $params ) {
                $status = Status::newGood();
 
@@ -427,7 +415,13 @@ class FSFileBackend extends FileBackendStore {
                                wfIsWindows() ? 'DEL' : 'unlink',
                                wfEscapeShellArg( $this->cleanPathSlashes( $source ) )
                        ) );
-                       $status->value = new FSFileOpHandle( $this, $params, 'Copy', $cmd );
+                       $handler = function ( $errors, Status $status, array $params, $cmd ) {
+                               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
+                                       $status->fatal( 'backend-fail-delete', $params['src'] );
+                                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
+                               }
+                       };
+                       $status->value = new FSFileOpHandle( $this, $params, $handler, $cmd );
                } else { // immediate write
                        $this->trapWarnings();
                        $ok = unlink( $source );
@@ -442,16 +436,6 @@ class FSFileBackend extends FileBackendStore {
                return $status;
        }
 
-       /**
-        * @see FSFileBackend::doExecuteOpHandlesInternal()
-        */
-       protected function getResponseDelete( $errors, Status $status, array $params, $cmd ) {
-               if ( $errors !== '' && !( wfIsWindows() && $errors[0] === " " ) ) {
-                       $status->fatal( 'backend-fail-delete', $params['src'] );
-                       trigger_error( "$cmd\n$errors", E_USER_WARNING ); // command output
-               }
-       }
-
        /**
         * @param string $fullCont
         * @param string $dirRel
@@ -467,10 +451,13 @@ class FSFileBackend extends FileBackendStore {
                // Create the directory and its parents as needed...
                $this->trapWarnings();
                if ( !wfMkdirParents( $dir ) ) {
+                       wfDebugLog( 'FSFileBackend', __METHOD__ . ": cannot create directory $dir" );
                        $status->fatal( 'directorycreateerror', $params['dir'] ); // fails on races
                } elseif ( !is_writable( $dir ) ) {
+                       wfDebugLog( 'FSFileBackend', __METHOD__ . ": directory $dir is read-only" );
                        $status->fatal( 'directoryreadonlyerror', $params['dir'] );
                } elseif ( !is_readable( $dir ) ) {
+                       wfDebugLog( 'FSFileBackend', __METHOD__ . ": directory $dir is not readable" );
                        $status->fatal( 'directorynotreadableerror', $params['dir'] );
                }
                $this->untrapWarnings();
@@ -694,6 +681,11 @@ class FSFileBackend extends FileBackendStore {
                return false;
        }
 
+       /**
+        * @param FileBackendStoreOpHandle[] $fileOpHandles
+        *
+        * @return Status[]
+        */
        protected function doExecuteOpHandlesInternal( array $fileOpHandles ) {
                $statuses = array();
 
@@ -712,8 +704,8 @@ class FSFileBackend extends FileBackendStore {
 
                foreach ( $fileOpHandles as $index => $fileOpHandle ) {
                        $status = Status::newGood();
-                       $function = 'getResponse' . $fileOpHandle->call;
-                       $this->$function( $errs[$index], $status, $fileOpHandle->params, $fileOpHandle->cmd );
+                       $function = $fileOpHandle->call;
+                       $function( $errs[$index], $status, $fileOpHandle->params, $fileOpHandle->cmd );
                        $statuses[$index] = $status;
                        if ( $status->isOK() && $fileOpHandle->chmodPath ) {
                                $this->chmod( $fileOpHandle->chmodPath );
@@ -808,7 +800,7 @@ class FSFileOpHandle extends FileBackendStoreOpHandle {
        /**
         * @param FSFileBackend $backend
         * @param array $params
-        * @param string $call
+        * @param callable $call
         * @param string $cmd
         * @param int|null $chmodPath
         */
@@ -844,7 +836,7 @@ abstract class FSFileBackendList implements Iterator {
        protected $params = array();
 
        /**
-        * @param string $dir file system directory
+        * @param string $dir File system directory
         * @param array $params
         */
        public function __construct( $dir, array $params ) {
@@ -865,7 +857,7 @@ abstract class FSFileBackendList implements Iterator {
        /**
         * Return an appropriate iterator object to wrap
         *
-        * @param string $dir file system directory
+        * @param string $dir File system directory
         * @return Iterator
         */
        protected function initIterator( $dir ) {