Merge "resources: Move QUnit to resources/lib/qunitjs"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 10 Feb 2015 15:06:01 +0000 (15:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 10 Feb 2015 15:06:01 +0000 (15:06 +0000)
autoload.php
composer.json
includes/Import.php
maintenance/Maintenance.php
resources/Resources.php
resources/src/mediawiki/mediawiki.js
resources/src/mediawiki/mediawiki.startUp.js [new file with mode: 0644]
thumb.php

index a44d279..d78b0ff 100644 (file)
@@ -535,6 +535,7 @@ $wgAutoloadLocalClasses = array(
        'ImageQueryPage' => __DIR__ . '/includes/specialpage/ImageQueryPage.php',
        'ImportReporter' => __DIR__ . '/includes/specials/SpecialImport.php',
        'ImportSiteScripts' => __DIR__ . '/maintenance/importSiteScripts.php',
+       'ImportSource' => __DIR__ . '/includes/Import.php',
        'ImportStreamSource' => __DIR__ . '/includes/Import.php',
        'ImportStringSource' => __DIR__ . '/includes/Import.php',
        'ImportTitleFactory' => __DIR__ . '/includes/title/ImportTitleFactory.php',
index bae3b55..94bec94 100644 (file)
@@ -27,7 +27,7 @@
        },
        "require-dev": {
                "justinrainbow/json-schema": "~1.3",
-               "phpunit/phpunit": "*"
+               "phpunit/phpunit": "~4.5"
        },
        "suggest": {
                "ext-fileinfo": "*",
index 9d1bbc0..36028ea 100644 (file)
@@ -45,10 +45,10 @@ class WikiImporter {
 
        /**
         * Creates an ImportXMLReader drawing from the source provided
-        * @param ImportStreamSource $source
+        * @param ImportSource $source
         * @param Config $config
         */
-       function __construct( ImportStreamSource $source, Config $config = null ) {
+       function __construct( ImportSource $source, Config $config = null ) {
                $this->reader = new XMLReader();
                if ( !$config ) {
                        wfDeprecated( __METHOD__ . ' without a Config instance', '1.25' );
@@ -967,10 +967,10 @@ class UploadSourceAdapter {
        private $mPosition;
 
        /**
-        * @param ImportStreamSource $source
+        * @param ImportSource $source
         * @return string
         */
-       static function registerSource( ImportStreamSource $source ) {
+       static function registerSource( ImportSource $source ) {
                $id = wfRandomString();
 
                self::$sourceRegistrations[$id] = $source;
@@ -1708,6 +1708,30 @@ class WikiRevision {
 
 }
 
+/**
+ * Source interface for XML import.
+ */
+interface ImportSource {
+
+       /**
+        * Indicates whether the end of the input has been reached.
+        * Will return true after a finite number of calls to readChunk.
+        *
+        * @return bool true if there is no more input, false otherwise.
+        */
+       function atEnd();
+
+       /**
+        * Return a chunk of the input, as a (possibly empty) string.
+        * When the end of input is reached, readChunk() returns false.
+        * If atEnd() returns false, readChunk() will return a string.
+        * If atEnd() returns true, readChunk() will return false.
+        *
+        * @return bool|string
+        */
+       function readChunk();
+}
+
 /**
  * Used for importing XML dumps where the content of the dump is in a string.
  * This class is ineffecient, and should only be used for small dumps.
@@ -1715,7 +1739,7 @@ class WikiRevision {
  *
  * @ingroup SpecialPage
  */
-class ImportStringSource {
+class ImportStringSource implements ImportSource {
        function __construct( $string ) {
                $this->mString = $string;
                $this->mRead = false;
@@ -1744,7 +1768,7 @@ class ImportStringSource {
  * Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
  * @ingroup SpecialPage
  */
-class ImportStreamSource {
+class ImportStreamSource implements ImportSource {
        function __construct( $handle ) {
                $this->mHandle = $handle;
        }
index 9b98b20..af14bb3 100644 (file)
@@ -1207,7 +1207,13 @@ abstract class Maintenance {
                }
 
                if ( $isatty && function_exists( 'readline' ) ) {
-                       return readline( $prompt );
+                       $resp = readline( $prompt );
+                       if ( $resp === null ) {
+                               // Workaround for https://github.com/facebook/hhvm/issues/4776
+                               return false;
+                       } else {
+                               return $resp;
+                       }
                } else {
                        if ( $isatty ) {
                                $st = self::readlineEmulation( $prompt );
index dadd673..233485c 100644 (file)
@@ -765,7 +765,10 @@ return array(
        /* MediaWiki */
 
        'mediawiki' => array(
-               'scripts' => 'resources/src/mediawiki/mediawiki.js',
+               'scripts' => array(
+                       'resources/src/mediawiki/mediawiki.js',
+                       'resources/src/mediawiki/mediawiki.startUp.js',
+               ),
                'debugScripts' => 'resources/src/mediawiki/mediawiki.log.js',
                'raw' => true,
                'targets' => array( 'desktop', 'mobile' ),
index bed5cb5..98a2f6a 100644 (file)
 
        // Attach to window and globally alias
        window.mw = window.mediaWiki = mw;
-
-       // Auto-register from pre-loaded startup scripts
-       if ( $.isFunction( window.startUp ) ) {
-               window.startUp();
-               window.startUp = undefined;
-       }
-
 }( jQuery ) );
diff --git a/resources/src/mediawiki/mediawiki.startUp.js b/resources/src/mediawiki/mediawiki.startUp.js
new file mode 100644 (file)
index 0000000..8032aa2
--- /dev/null
@@ -0,0 +1,12 @@
+/**
+ * Auto-register from pre-loaded startup scripts
+ * @ignore (this line will make JSDuck happy)
+ */
+( function ( $ ) {
+       'use strict';
+
+       if ( $.isFunction( window.startUp ) ) {
+               window.startUp();
+               window.startUp = undefined;
+       }
+}( jQuery ) );
index 88314bc..28f22fd 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -321,6 +321,7 @@ function wfStreamThumb( array $params ) {
 
        // Check for thumbnail generation errors...
        $msg = wfMessage( 'thumbnail_error' );
+       $errorCode = 500;
        if ( !$thumb ) {
                $errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform() returned false' )->escaped();
        } elseif ( $thumb->isError() ) {
@@ -330,10 +331,11 @@ function wfStreamThumb( array $params ) {
        } elseif ( $thumb->fileIsSource() ) {
                $errorMsg = $msg->
                        rawParams( 'Image was not scaled, is the requested width bigger than the source?' )->escaped();
+               $errorCode = 400;
        }
 
        if ( $errorMsg !== false ) {
-               wfThumbError( 500, $errorMsg );
+               wfThumbError( $errorCode, $errorMsg );
        } else {
                // Stream the file if there were no errors
                $thumb->streamFile( $headers );
@@ -545,7 +547,9 @@ function wfThumbError( $status, $msg ) {
 
        header( 'Cache-Control: no-cache' );
        header( 'Content-Type: text/html; charset=utf-8' );
-       if ( $status == 404 ) {
+       if ( $status == 400 ) {
+               header( 'HTTP/1.1 400 Bad request' );
+       } elseif ( $status == 404 ) {
                header( 'HTTP/1.1 404 Not found' );
        } elseif ( $status == 403 ) {
                header( 'HTTP/1.1 403 Forbidden' );