Merge "Don't try to verify XML well-formedness for partial SVG uploads"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 6 Nov 2014 18:50:29 +0000 (18:50 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 6 Nov 2014 18:50:29 +0000 (18:50 +0000)
1  2 
includes/upload/UploadBase.php

@@@ -424,7 -424,7 +424,7 @@@ abstract class UploadBase 
         * @return mixed True of the file is verified, array otherwise.
         */
        protected function verifyFile() {
-               global $wgVerifyMimeType;
+               global $wgVerifyMimeType, $wgDisableUploadScriptChecks;
                wfProfileIn( __METHOD__ );
  
                $status = $this->verifyPartialFile();
                        }
                }
  
+               # check for htmlish code and javascript
+               if ( !$wgDisableUploadScriptChecks ) {
+                       if ( $this->mFinalExtension == 'svg' || $mime == 'image/svg+xml' ) {
+                               $svgStatus = $this->detectScriptInSvg( $this->mTempPath, false );
+                               if ( $svgStatus !== false ) {
+                                       wfProfileOut( __METHOD__ );
+                                       return $svgStatus;
+                               }
+                       }
+               }
                $handler = MediaHandler::getHandler( $mime );
                if ( $handler ) {
                        $handlerStatus = $handler->verifyUpload( $this->mTempPath );
                                return array( 'uploadscripted' );
                        }
                        if ( $this->mFinalExtension == 'svg' || $mime == 'image/svg+xml' ) {
-                               $svgStatus = $this->detectScriptInSvg( $this->mTempPath );
+                               $svgStatus = $this->detectScriptInSvg( $this->mTempPath, true );
                                if ( $svgStatus !== false ) {
                                        wfProfileOut( __METHOD__ );
  
                $sizes = $wgUploadThumbnailRenderMap;
                rsort( $sizes );
  
 +              $file = $this->getLocalFile();
 +
                foreach ( $sizes as $size ) {
 -                      $jobs[] = new ThumbnailRenderJob( $this->getLocalFile()->getTitle(), array(
 -                              'transformParams' => array( 'width' => $size ),
 -                      ) );
 +                      if ( $file->isVectorized()
 +                              || $file->getWidth() > $size ) {
 +                                      $jobs[] = new ThumbnailRenderJob( $file->getTitle(), array(
 +                                              'transformParams' => array( 'width' => $size ),
 +                                      ) );
 +                      }
                }
  
 -              JobQueueGroup::singleton()->push( $jobs );
 +              if ( $jobs ) {
 +                      JobQueueGroup::singleton()->push( $jobs );
 +              }
        }
  
        /**
  
        /**
         * @param string $filename
+        * @param bool $partial
         * @return mixed False of the file is verified (does not contain scripts), array otherwise.
         */
-       protected function detectScriptInSvg( $filename ) {
+       protected function detectScriptInSvg( $filename, $partial ) {
                $this->mSVGNSError = false;
                $check = new XmlTypeCheck(
                        $filename,
                );
                if ( $check->wellFormed !== true ) {
                        // Invalid xml (bug 58553)
-                       return array( 'uploadinvalidxml' );
+                       // But only when non-partial (bug 65724)
+                       return $partial ? false : array( 'uploadinvalidxml' );
                } elseif ( $check->filterMatch ) {
                        if ( $this->mSVGNSError ) {
                                return array( 'uploadscriptednamespace', $this->mSVGNSError );