Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / filerepo / backend / FileOp.php
index d134edd..d9fbafd 100644 (file)
@@ -438,10 +438,18 @@ abstract class FileOp {
  *     overwriteSame : override any existing file at destination
  */
 class StoreFileOp extends FileOp {
+
+       /**
+        * @return array
+        */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) );
        }
 
+       /**
+        * @param $predicates array
+        * @return Status
+        */
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if the source file exists on the file system
@@ -450,10 +458,13 @@ class StoreFileOp extends FileOp {
                        return $status;
                // Check if the source file is too big
                } elseif ( filesize( $this->params['src'] ) > $this->backend->maxFileSizeInternal() ) {
+                       $status->fatal( 'backend-fail-maxsize',
+                               $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
@@ -467,6 +478,9 @@ class StoreFileOp extends FileOp {
                return $status; // safe to call attempt()
        }
 
+       /**
+        * @return Status
+        */
        protected function doAttempt() {
                // Store the file at the destination
                if ( !$this->destSameAsSource ) {
@@ -475,6 +489,9 @@ class StoreFileOp extends FileOp {
                return Status::newGood();
        }
 
+       /**
+        * @return bool|string
+        */
        protected function getSourceSha1Base36() {
                wfSuppressWarnings();
                $hash = sha1_file( $this->params['src'] );
@@ -507,10 +524,13 @@ class CreateFileOp extends FileOp {
                $status = Status::newGood();
                // Check if the source data is too big
                if ( strlen( $this->getParam( 'content' ) ) > $this->backend->maxFileSizeInternal() ) {
+                       $status->fatal( 'backend-fail-maxsize',
+                               $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
                        return $status;
                }
@@ -524,6 +544,9 @@ class CreateFileOp extends FileOp {
                return $status; // safe to call attempt()
        }
 
+       /**
+        * @return Status
+        */
        protected function doAttempt() {
                if ( !$this->destSameAsSource ) {
                        // Create the file at the destination
@@ -532,10 +555,16 @@ class CreateFileOp extends FileOp {
                return Status::newGood();
        }
 
+       /**
+        * @return bool|String
+        */
        protected function getSourceSha1Base36() {
                return wfBaseConvert( sha1( $this->params['content'] ), 16, 36, 31 );
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsChanged() {
                return array( $this->params['dst'] );
        }
@@ -550,10 +579,18 @@ class CreateFileOp extends FileOp {
  *     overwriteSame : override any existing file at destination
  */
 class CopyFileOp extends FileOp {
+
+       /**
+        * @return array
+        */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) );
        }
 
+       /**
+        * @param $predicates array
+        * @return Status
+        */
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if the source file exists
@@ -562,6 +599,7 @@ class CopyFileOp extends FileOp {
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-copy', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
@@ -575,6 +613,9 @@ class CopyFileOp extends FileOp {
                return $status; // safe to call attempt()
        }
 
+       /**
+        * @return Status
+        */
        protected function doAttempt() {
                // Do nothing if the src/dst paths are the same
                if ( $this->params['src'] !== $this->params['dst'] ) {
@@ -586,10 +627,16 @@ class CopyFileOp extends FileOp {
                return Status::newGood();
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsRead() {
                return array( $this->params['src'] );
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsChanged() {
                return array( $this->params['dst'] );
        }
@@ -604,10 +651,17 @@ class CopyFileOp extends FileOp {
  *     overwriteSame : override any existing file at destination
  */
 class MoveFileOp extends FileOp {
+       /**
+        * @return array
+        */
        protected function allowedParams() {
                return array( array( 'src', 'dst' ), array( 'overwrite', 'overwriteSame' ) );
        }
 
+       /**
+        * @param $predicates array
+        * @return Status
+        */
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if the source file exists
@@ -616,6 +670,7 @@ class MoveFileOp extends FileOp {
                        return $status;
                // Check if a file can be placed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-move', $this->params['src'], $this->params['dst'] );
                        return $status;
                }
@@ -631,6 +686,9 @@ class MoveFileOp extends FileOp {
                return $status; // safe to call attempt()
        }
 
+       /**
+        * @return Status
+        */
        protected function doAttempt() {
                // Do nothing if the src/dst paths are the same
                if ( $this->params['src'] !== $this->params['dst'] ) {
@@ -646,10 +704,16 @@ class MoveFileOp extends FileOp {
                return Status::newGood();
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsRead() {
                return array( $this->params['src'] );
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsChanged() {
                return array( $this->params['src'], $this->params['dst'] );
        }
@@ -662,12 +726,19 @@ class MoveFileOp extends FileOp {
  *     ignoreMissingSource : don't return an error if the file does not exist
  */
 class DeleteFileOp extends FileOp {
+       /**
+        * @return array
+        */
        protected function allowedParams() {
                return array( array( 'src' ), array( 'ignoreMissingSource' ) );
        }
 
        protected $needsDelete = true;
 
+       /**
+        * @param array $predicates
+        * @return Status
+        */
        protected function doPrecheck( array &$predicates ) {
                $status = Status::newGood();
                // Check if the source file exists
@@ -684,6 +755,9 @@ class DeleteFileOp extends FileOp {
                return $status; // safe to call attempt()
        }
 
+       /**
+        * @return Status
+        */
        protected function doAttempt() {
                if ( $this->needsDelete ) {
                        // Delete the source file
@@ -692,6 +766,9 @@ class DeleteFileOp extends FileOp {
                return Status::newGood();
        }
 
+       /**
+        * @return array
+        */
        protected function doStoragePathsChanged() {
                return array( $this->params['src'] );
        }