Reorganise the functions doing wfProfileOut and returning on all if branches.
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index dc32a29..b5c65e5 100644 (file)
@@ -235,6 +235,14 @@ abstract class UploadBase {
                return $this->mFileSize;
        }
 
+       /**
+        * Get the base 36 SHA1 of the file
+        * @return string
+        */
+       protected function getTempFileSha1Base36() {
+               return FSFile::getSha1Base36FromPath( $this->mTempPath );
+       }
+
        /**
         * @param $srcPath String: the source path
         * @return string the real path if it was a virtual URL
@@ -546,7 +554,9 @@ abstract class UploadBase {
        }
 
        /**
-        * Check for non fatal problems with the file
+        * Check for non fatal problems with the file.
+        *
+        * This should not assume that mTempPath is set.
         *
         * @return Array of warnings
         */
@@ -594,7 +604,7 @@ abstract class UploadBase {
                }
 
                // Check dupes against existing files
-               $hash = FSFile::getSha1Base36FromPath( $this->mTempPath );
+               $hash = $this->getTempFileSha1Base36();
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
                $title = $this->getTitle();
                // Remove all matches against self
@@ -1224,27 +1234,22 @@ abstract class UploadBase {
                        }
                }
 
+               /* NB: AV_NO_VIRUS is 0 but AV_SCAN_FAILED is false,
+                * so we need the strict equalities === and thus can't use a switch here
+                */
                if ( $mappedCode === AV_SCAN_FAILED ) {
                        # scan failed (code was mapped to false by $exitCodeMap)
                        wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" );
 
-                       if ( $wgAntivirusRequired ) {
-                               wfProfileOut( __METHOD__ );
-                               return wfMessage( 'virus-scanfailed', array( $exitCode ) )->text();
-                       } else {
-                               wfProfileOut( __METHOD__ );
-                               return null;
-                       }
+                       $output = $wgAntivirusRequired ? wfMessage( 'virus-scanfailed', array( $exitCode ) )->text() : null;
                } elseif ( $mappedCode === AV_SCAN_ABORTED ) {
                        # scan failed because filetype is unknown (probably imune)
                        wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" );
-                       wfProfileOut( __METHOD__ );
-                       return null;
+                       $output = null;
                } elseif ( $mappedCode === AV_NO_VIRUS ) {
                        # no virus found
                        wfDebug( __METHOD__ . ": file passed virus scan.\n" );
-                       wfProfileOut( __METHOD__ );
-                       return false;
+                       $output = false;
                } else {
                        $output = trim( $output );
 
@@ -1260,9 +1265,10 @@ abstract class UploadBase {
                        }
 
                        wfDebug( __METHOD__ . ": FOUND VIRUS! scanner feedback: $output \n" );
-                       wfProfileOut( __METHOD__ );
-                       return $output;
                }
+
+               wfProfileOut( __METHOD__ );
+               return $output;
        }
 
        /**