Merge "Revert "merged master"" into Wikidata
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index a4de98a..6ef3be2 100644 (file)
@@ -1,6 +1,28 @@
 <?php
 /**
- * @defgroup Upload
+ * Base class for the backend of file upload.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Upload
+ */
+
+/**
+ * @defgroup Upload Upload related
  */
 
 /**
@@ -41,6 +63,10 @@ abstract class UploadBase {
        const WINDOWS_NONASCII_FILENAME = 13;
        const FILENAME_TOO_LONG = 14;
 
+       /**
+        * @param $error int
+        * @return string
+        */
        public function getVerificationErrorCode( $error ) {
                $code_to_status = array(self::EMPTY_FILE => 'empty-file',
                                                                self::FILE_TOO_LARGE => 'file-too-large',
@@ -143,6 +169,7 @@ abstract class UploadBase {
 
        /**
         * Check whether a request if valid for this handler
+        * @param $request
         * @return bool
         */
        public static function isValidRequest( $request ) {
@@ -165,7 +192,7 @@ abstract class UploadBase {
         * @param $tempPath string the temporary path
         * @param $fileSize int the file size
         * @param $removeTempFile bool (false) remove the temporary file?
-        * @return null
+        * @throws MWException
         */
        public function initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile = false ) {
                $this->mDesiredDestName = $name;
@@ -208,7 +235,7 @@ abstract class UploadBase {
 
        /**
         * @param $srcPath String: the source path
-        * @return stringthe real path if it was a virtual URL
+        * @return string the real path if it was a virtual URL
         */
        function getRealPath( $srcPath ) {
                wfProfileIn( __METHOD__ );
@@ -592,6 +619,9 @@ abstract class UploadBase {
         * Really perform the upload. Stores the file in the local repo, watches
         * if necessary and runs the UploadComplete hook.
         *
+        * @param $comment
+        * @param $pageText
+        * @param $watch
         * @param $user User
         *
         * @return Status indicating the whether the upload succeeded.
@@ -736,7 +766,7 @@ abstract class UploadBase {
        /**
         * Return the local file and initializes if necessary.
         *
-        * @return LocalFile
+        * @return LocalFile|null
         */
        public function getLocalFile() {
                if( is_null( $this->mLocalFile ) ) {
@@ -808,6 +838,7 @@ abstract class UploadBase {
         * earlier pseudo-'extensions' to determine type and execute
         * scripts, so the blacklist needs to check them all.
         *
+        * @param $filename string
         * @return array
         */
        public static function splitExtensions( $filename ) {
@@ -1006,6 +1037,10 @@ abstract class UploadBase {
                return false;
        }
 
+       /**
+        * @param $filename string
+        * @return bool
+        */
        protected function detectScriptInSvg( $filename ) {
                $check = new XmlTypeCheck( $filename, array( $this, 'checkSvgScriptCallback' ) );
                return $check->filterMatch;
@@ -1013,6 +1048,8 @@ abstract class UploadBase {
 
        /**
         * @todo Replace this with a whitelist filter!
+        * @param $element string
+        * @param $attribs array
         * @return bool
         */
        public function checkSvgScriptCallback( $element, $attribs ) {
@@ -1112,6 +1149,10 @@ abstract class UploadBase {
                return false; //No scripts detected
        }
 
+       /**
+        * @param $name string
+        * @return string
+        */
        private function stripXmlNamespace( $name ) {
                // 'http://www.w3.org/2000/svg:script' -> 'script'
                $parts = explode( ':', strtolower( $name ) );
@@ -1143,7 +1184,7 @@ abstract class UploadBase {
                        $wgOut->wrapWikiMsg( "<div class=\"error\">\n$1\n</div>",
                                array( 'virus-badscanner', $wgAntivirus ) );
                        wfProfileOut( __METHOD__ );
-                       return wfMsg( 'virus-unknownscanner' ) . " $wgAntivirus";
+                       return wfMessage( 'virus-unknownscanner' )->text() . " $wgAntivirus";
                }
 
                # look up scanner configuration
@@ -1363,6 +1404,7 @@ abstract class UploadBase {
 
        /**
         * Helper function that checks whether the filename looks like a thumbnail
+        * @param $filename string
         * @return bool
         */
        public static function isThumbName( $filename ) {
@@ -1426,13 +1468,20 @@ abstract class UploadBase {
                return $info;
        }
 
-
+       /**
+        * @param $error array
+        * @return Status
+        */
        public function convertVerifyErrorToStatus( $error ) {
                $code = $error['status'];
                unset( $code['status'] );
                return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
        }
 
+       /**
+        * @param $forType null|string
+        * @return int
+        */
        public static function getMaxUploadSize( $forType = null ) {
                global $wgMaxUploadSize;