Revised design of Special:Userlogin
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index 9d756f8..34af8ca 100644 (file)
@@ -70,17 +70,18 @@ abstract class UploadBase {
         * @return string
         */
        public function getVerificationErrorCode( $error ) {
-               $code_to_status = array(self::EMPTY_FILE => 'empty-file',
-                                                               self::FILE_TOO_LARGE => 'file-too-large',
-                                                               self::FILETYPE_MISSING => 'filetype-missing',
-                                                               self::FILETYPE_BADTYPE => 'filetype-banned',
-                                                               self::MIN_LENGTH_PARTNAME => 'filename-tooshort',
-                                                               self::ILLEGAL_FILENAME => 'illegal-filename',
-                                                               self::OVERWRITE_EXISTING_FILE => 'overwrite',
-                                                               self::VERIFICATION_ERROR => 'verification-error',
-                                                               self::HOOK_ABORTED => 'hookaborted',
-                                                               self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
-                                                               self::FILENAME_TOO_LONG => 'filename-toolong',
+               $code_to_status = array(
+                       self::EMPTY_FILE => 'empty-file',
+                       self::FILE_TOO_LARGE => 'file-too-large',
+                       self::FILETYPE_MISSING => 'filetype-missing',
+                       self::FILETYPE_BADTYPE => 'filetype-banned',
+                       self::MIN_LENGTH_PARTNAME => 'filename-tooshort',
+                       self::ILLEGAL_FILENAME => 'illegal-filename',
+                       self::OVERWRITE_EXISTING_FILE => 'overwrite',
+                       self::VERIFICATION_ERROR => 'verification-error',
+                       self::HOOK_ABORTED => 'hookaborted',
+                       self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
+                       self::FILENAME_TOO_LONG => 'filename-toolong',
                );
                if( isset( $code_to_status[$error] ) ) {
                        return $code_to_status[$error];
@@ -108,7 +109,7 @@ abstract class UploadBase {
        /**
         * Returns true if the user can use this upload module or else a string
         * identifying the missing permission.
-        * Can be overriden by subclasses.
+        * Can be overridden by subclasses.
         *
         * @param $user User
         * @return bool
@@ -190,10 +191,10 @@ abstract class UploadBase {
 
        /**
         * Initialize the path information
-        * @param $name string the desired destination name
-        * @param $tempPath string the temporary path
-        * @param $fileSize int the file size
-        * @param $removeTempFile bool (false) remove the temporary file?
+        * @param string $name the desired destination name
+        * @param string $tempPath the temporary path
+        * @param int $fileSize the file size
+        * @param bool $removeTempFile (false) remove the temporary file?
         * @throws MWException
         */
        public function initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile = false ) {
@@ -244,7 +245,7 @@ abstract class UploadBase {
        }
 
        /**
-        * @param $srcPath String: the source path
+        * @param string $srcPath the source path
         * @return string the real path if it was a virtual URL
         */
        function getRealPath( $srcPath ) {
@@ -252,7 +253,7 @@ abstract class UploadBase {
                $repo = RepoGroup::singleton()->getLocalRepo();
                if ( $repo->isVirtualUrl( $srcPath ) ) {
                        // @TODO: just make uploads work with storage paths
-                       // UploadFromStash loads files via virtuals URLs
+                       // UploadFromStash loads files via virtual URLs
                        $tmpFile = $repo->getLocalCopy( $srcPath );
                        $tmpFile->bind( $this ); // keep alive with $this
                        wfProfileOut( __METHOD__ );
@@ -330,7 +331,7 @@ abstract class UploadBase {
         * @return mixed true if valid, otherwise and array with 'status'
         * and other keys
         **/
-       protected function validateName() {
+       public function validateName() {
                $nt = $this->getTitle();
                if( is_null( $nt ) ) {
                        $result = array( 'status' => $this->mTitleError );
@@ -353,14 +354,14 @@ abstract class UploadBase {
        /**
         * Verify the mime type
         *
-        * @param $mime string representing the mime
+        * @param string $mime representing the mime
         * @return mixed true if the file is verified, an array otherwise
         */
        protected function verifyMimeType( $mime ) {
                global $wgVerifyMimeType;
                wfProfileIn( __METHOD__ );
                if ( $wgVerifyMimeType ) {
-                       wfDebug ( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n" );
+                       wfDebug( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n" );
                        global $wgMimeTypeBlacklist;
                        if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
                                wfProfileOut( __METHOD__ );
@@ -704,8 +705,6 @@ abstract class UploadBase {
                }
                $this->mFilteredName = $nt->getDBkey();
 
-
-
                /**
                 * We'll want to blacklist against *any* 'extension', and use
                 * only the final one for the whitelist.
@@ -733,7 +732,6 @@ abstract class UploadBase {
                                        $ext = array( $this->mFinalExtension );
                                }
                        }
-
                }
 
                /* Don't allow users to override the blacklist (check file extension) */
@@ -887,8 +885,8 @@ abstract class UploadBase {
        /**
         * Checks if the mime type of the uploaded file matches the file extension.
         *
-        * @param $mime String: the mime type of the uploaded file
-        * @param $extension String: the filename extension that the file is to be served with
+        * @param string $mime the mime type of the uploaded file
+        * @param string $extension the filename extension that the file is to be served with
         * @return Boolean
         */
        public static function verifyExtension( $mime, $extension ) {
@@ -928,9 +926,9 @@ abstract class UploadBase {
         * potentially harmful. The present implementation will produce false
         * positives in some situations.
         *
-        * @param $file String: pathname to the temporary upload file
-        * @param $mime String: the mime type of the file
-        * @param $extension String: the extension of the file
+        * @param string $file pathname to the temporary upload file
+        * @param string $mime the mime type of the file
+        * @param string $extension the extension of the file
         * @return Boolean: true if the file contains something looking like embedded scripts
         */
        public static function detectScript( $file, $mime, $extension ) {
@@ -970,7 +968,7 @@ abstract class UploadBase {
 
                $chunk = trim( $chunk );
 
-               # @todo FIXME: Convert from UTF-16 if necessarry!
+               # @todo FIXME: Convert from UTF-16 if necessary!
                wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" );
 
                # check for HTML doctype
@@ -1103,13 +1101,13 @@ abstract class UploadBase {
                                return true;
                        }
 
-                       # href with embeded svg as target
+                       # href with embedded svg as target
                        if( $stripped == 'href' && preg_match( '!data:[^,]*image/svg[^,]*,!sim', $value ) ) {
                                wfDebug( __METHOD__ . ": Found href to embedded svg \"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" );
                                return true;
                        }
 
-                       # href with embeded (text/xml) svg as target
+                       # href with embedded (text/xml) svg as target
                        if( $stripped == 'href' && preg_match( '!data:[^,]*text/xml[^,]*,!sim', $value ) ) {
                                wfDebug( __METHOD__ . ": Found href to embedded svg \"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" );
                                return true;
@@ -1123,19 +1121,18 @@ abstract class UploadBase {
 
                        # use set to add href attribute to parent element
                        if( $strippedElement == 'set' && $stripped == 'attributename' && strpos( $value, 'href' ) !== false ) {
-                               wfDebug( __METHOD__ . ": Found svg setting href attibute '$value' in uploaded file.\n" );
+                               wfDebug( __METHOD__ . ": Found svg setting href attribute '$value' in uploaded file.\n" );
                                return true;
                        }
 
                        # use set to add a remote / data / script target to an element
-                       if( $strippedElement == 'set' && $stripped == 'to' &&  preg_match( '!(http|https|data|script):!sim', $value ) ) {
-                               wfDebug( __METHOD__ . ": Found svg setting attibute to '$value' in uploaded file.\n" );
+                       if( $strippedElement == 'set' && $stripped == 'to' && preg_match( '!(http|https|data|script):!sim', $value ) ) {
+                               wfDebug( __METHOD__ . ": Found svg setting attribute to '$value' in uploaded file.\n" );
                                return true;
                        }
 
-
                        # use handler attribute with remote / data / script
-                       if( $stripped == 'handler' &&  preg_match( '!(http|https|data|script):!sim', $value ) ) {
+                       if( $stripped == 'handler' && preg_match( '!(http|https|data|script):!sim', $value ) ) {
                                wfDebug( __METHOD__ . ": Found svg setting handler with remote/data/script '$attrib'='$value' in uploaded file.\n" );
                                return true;
                        }
@@ -1177,7 +1174,7 @@ abstract class UploadBase {
         * This relies on the $wgAntivirus and $wgAntivirusSetup variables.
         * $wgAntivirusRequired may be used to deny upload if the scan fails.
         *
-        * @param $file String: pathname to the temporary upload file
+        * @param string $file pathname to the temporary upload file
         * @return mixed false if not virus is found, NULL if the scan fails or is disabled,
         *         or a string containing feedback from the virus scanner if a virus was found.
         *         If textual feedback is missing but a virus was found, this function returns true.
@@ -1305,7 +1302,7 @@ abstract class UploadBase {
         * Check if a user is the last uploader
         *
         * @param $user User object
-        * @param $img String: image name
+        * @param string $img image name
         * @return Boolean
         */
        public static function userCanReUpload( User $user, $img ) {
@@ -1381,10 +1378,10 @@ abstract class UploadBase {
                $similarFiles = RepoGroup::singleton()->getLocalRepo()->findFilesByPrefix(
                                "{$partname}.", 1 );
                if ( count( $similarFiles ) ) {
-                       return array(\r
-                               'warning' => 'exists-normalized',\r
-                               'file' => $file,\r
-                               'normalizedFile' => $similarFiles[0],\r
+                       return array(
+                               'warning' => 'exists-normalized',
+                               'file' => $file,
+                               'normalizedFile' => $similarFiles[0],
                        );
                }
 
@@ -1408,7 +1405,6 @@ abstract class UploadBase {
                        }
                }
 
-
                foreach( self::getFilenamePrefixBlacklist() as $prefix ) {
                        if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
                                return array(