Remove skin mode of Special:JavaScriptTest
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 31 Mar 2016 20:18:14 +0000 (21:18 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 31 Mar 2016 20:20:19 +0000 (21:20 +0100)
Leaving behind only the so-called "plain" mode.

Also removed related unused messages (follows-up 6b758fc).

The execute() method continues to enforce 404 Not Found for arbitrary
subpage urls so that we keep the door open to add other sub resources or
test frameworks in the future.

Bug: T131389
Change-Id: I4c22666fb98e54c47ed1b4d12776af6fc43ee473

includes/specials/SpecialJavaScriptTest.php
languages/i18n/en.json
languages/i18n/qqq.json

index 37dba53..5d36a3c 100644 (file)
  * @ingroup SpecialPage
  */
 class SpecialJavaScriptTest extends SpecialPage {
-       /**
-        * @var array Supported frameworks.
-        */
-       private static $frameworks = [
-               'qunit',
-       ];
 
        public function __construct() {
                parent::__construct( 'JavaScriptTest' );
@@ -42,102 +36,33 @@ class SpecialJavaScriptTest extends SpecialPage {
                $this->setHeaders();
                $out->disallowUserJs();
 
-               if ( $par === null ) {
-                       // No framework specified
-                       // If only one framework is configured, redirect to it. Otherwise display a list.
-                       if ( count( self::$frameworks ) === 1 ) {
-                               $out->redirect( $this->getPageTitle( self::$frameworks[0] . '/plain' )->getLocalURL() );
-                               return;
-                       }
-                       $out->setStatusCode( 404 );
-                       $out->setPageTitle( $this->msg( 'javascripttest' ) );
-                       $out->addHTML(
-                               $this->msg( 'javascripttest-pagetext-noframework' )->parseAsBlock()
-                               . $this->getFrameworkListHtml()
-                       );
-                       return;
-               }
-
-               // Determine framework and mode
-               $pars = explode( '/', $par, 2 );
-
-               $framework = $pars[0];
-               if ( !in_array( $framework, self::$frameworks ) ) {
-                       // Framework not found
-                       $out->setStatusCode( 404 );
-                       $out->addHTML(
-                               '<div class="error">'
-                               . $this->msg( 'javascripttest-pagetext-unknownframework' )
-                                       ->plaintextParams( $par )->parseAsBlock()
-                               . '</div>'
-                               . $this->getFrameworkListHtml()
-                       );
-                       return;
-               }
-
                // This special page is disabled by default ($wgEnableJavaScriptTest), and contains
                // no sensitive data. In order to allow TestSwarm to embed it into a test client window,
                // we need to allow iframing of this page.
                $out->allowClickjacking();
-               if ( count( self::$frameworks ) !== 1 ) {
-                       // If there's only one framework, don't set the subtitle since it
-                       // is going to redirect back to this page
-                       $out->setSubtitle(
-                               $this->msg( 'javascripttest-backlink' )
-                                       ->rawParams( Linker::linkKnown( $this->getPageTitle() ) )
-                       );
-               }
 
-               // Custom actions
-               if ( isset( $pars[1] ) ) {
-                       $action = $pars[1];
-                       if ( !in_array( $action, [ 'export', 'plain' ] ) ) {
-                               $out->setStatusCode( 404 );
-                               $out->addHTML(
-                                       '<div class="error">'
-                                       . $this->msg( 'javascripttest-pagetext-unknownaction' )
-                                               ->plaintextParams( $action )->parseAsBlock()
-                                       . '</div>'
-                               );
-                               return;
-                       }
-                       $method = $action . ucfirst( $framework );
-                       $this->$method();
+               // Sub resource: Internal JavaScript export bundle for QUnit
+               if ( $par === 'qunit/export' ) {
+                       $this->exportQUnit();
                        return;
                }
 
-               $method = 'view' . ucfirst( $framework );
-               $this->$method();
-               $out->setPageTitle( $this->msg(
-                       'javascripttest-title',
-                       // Messages: javascripttest-qunit-name
-                       $this->msg( "javascripttest-$framework-name" )->plain()
-               ) );
-       }
-
-       /**
-        * Get a list of frameworks (including introduction paragraph and links
-        * to the framework run pages)
-        *
-        * @return string HTML
-        */
-       private function getFrameworkListHtml() {
-               $list = '<ul>';
-               foreach ( self::$frameworks as $framework ) {
-                       $list .= Html::rawElement(
-                               'li',
-                               [],
-                               Linker::link(
-                                       $this->getPageTitle( $framework ),
-                                       // Message: javascripttest-qunit-name
-                                       $this->msg( "javascripttest-$framework-name" )->escaped()
-                               )
-                       );
+               // Regular view: QUnit test runner
+               // (Support "/qunit" and "/qunit/plain" for backwards compatibility)
+               if ( $par === null || $par === '' || $par === 'qunit' || $par === 'qunit/plain' ) {
+                       $this->plainQUnit();
+                       return;
                }
-               $list .= '</ul>';
 
-               return $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )
-                       ->parseAsBlock();
+               // Unknown action
+               $out->setStatusCode( 404 );
+               $out->setPageTitle( $this->msg( 'javascripttest' ) );
+               $out->addHTML(
+                       '<div class="error">'
+                       . $this->msg( 'javascripttest-pagetext-unknownaction' )
+                               ->plaintextParams( $par )->parseAsBlock()
+                       . '</div>'
+               );
        }
 
        /**
@@ -152,37 +77,6 @@ class SpecialJavaScriptTest extends SpecialPage {
                return "<div id=\"mw-javascripttest-summary\">$summary</div>";
        }
 
-       /**
-        * Run the test suite on the Special page.
-        *
-        * Rendered by OutputPage and Skin.
-        */
-       private function viewQUnit() {
-               $out = $this->getOutput();
-
-               $modules = $out->getResourceLoader()->getTestModuleNames( 'qunit' );
-
-               $baseHtml = <<<HTML
-<div class="mw-content-ltr">
-<div id="qunit"></div>
-</div>
-HTML;
-
-               $out->addHTML( $this->getSummaryHtml() . $baseHtml );
-
-               // The testrunner configures QUnit and essentially depends on it. However, test suites
-               // are reusable in environments that preload QUnit (or a compatibility interface to
-               // another framework). Therefore we have to load it ourselves.
-               $out->addHTML( ResourceLoader::makeInlineScript(
-                       Xml::encodeJsCall( 'mw.loader.using', [
-                               [ 'jquery.qunit', 'jquery.qunit.completenessTest' ],
-                               new XmlJsCode(
-                                       'function () {' . Xml::encodeJsCall( 'mw.loader.load', [ $modules ] ) . '}'
-                               )
-                       ] )
-               ) );
-       }
-
        /**
         * Generate self-sufficient JavaScript payload to run the tests elsewhere.
         *
index b7c0ac6..579e9b8 100644 (file)
        "import-logentry-interwiki": "transwikied $1",
        "import-logentry-interwiki-detail": "$1 {{PLURAL:$1|revision|revisions}} imported from $2",
        "javascripttest": "JavaScript testing",
-       "javascripttest-backlink": "< $1",
-       "javascripttest-title": "$1",
-       "javascripttest-pagetext-noframework": "This page is reserved for running JavaScript tests.",
-       "javascripttest-pagetext-unknownframework": "Unknown testing framework \"$1\".",
        "javascripttest-pagetext-unknownaction": "Unknown action \"$1\".",
-       "javascripttest-pagetext-frameworks": "Please choose one of the following testing frameworks: $1",
-       "javascripttest-pagetext-skins": "Choose a skin to run the tests with:",
-       "javascripttest-qunit-name": "QUnit",
        "javascripttest-qunit-intro": "See [$1 testing documentation] on mediawiki.org.",
        "accesskey-pt-userpage": ".",
        "accesskey-pt-anonuserpage": ".",
index 379fe79..28c02cb 100644 (file)
        "import-logentry-interwiki": "{{ignored}}This is a ''logentry'' message only used on IRC. Parameters:\n* $1 - page title",
        "import-logentry-interwiki-detail": "Used as success message and log entry. Parameters:\n* $1 - number of succeeded revisions\n* $2 - interwiki name\nSee also:\n* {{msg-mw|Import-logentry-upload-detail}}",
        "javascripttest": "Title of the special page [[Special:JavaScriptTest]].\n\nSee also:\n* {{msg-mw|Javascripttest|title}}\n* {{msg-mw|Javascripttest-pagetext-noframework|summary}}\n* {{msg-mw|Javascripttest-pagetext-unknownframework|error message}}",
-       "javascripttest-backlink": "{{optional}}\nUsed as subtitle in [[Special:JavaScriptTest]]. Parameters:\n* $1 - page title",
-       "javascripttest-title": "{{Ignore}}",
-       "javascripttest-pagetext-noframework": "Used as summary when no framework specified.\n\nSee also:\n* {{msg-mw|Javascripttest|title}}\n* {{msg-mw|Javascripttest-pagetext-noframework|summary}}\n* {{msg-mw|Javascripttest-pagetext-unknownframework|error message}}",
-       "javascripttest-pagetext-unknownframework": "Error message when given framework ID is not found. Parameters:\n* $1 - the ID of the framework\nSee also:\n* {{msg-mw|Javascripttest|title}}\n* {{msg-mw|Javascripttest-pagetext-noframework|summary}}\n* {{msg-mw|Javascripttest-pagetext-unknownframework|error message}}",
        "javascripttest-pagetext-unknownaction": "Error message when url specifies an unknown action. Parameters:\n* $1 - the action specified in the url.",
-       "javascripttest-pagetext-frameworks": "Parameters:\n* $1 - frameworks list which contain a link text {{msg-mw|Javascripttest-qunit-name}}",
-       "javascripttest-pagetext-skins": "Used as label in [[Special:JavaScriptTest]].",
-       "javascripttest-qunit-name": "{{Ignore}}",
        "javascripttest-qunit-intro": "Used as summary. Parameters:\n* $1 - the configured URL to the documentation\nSee also:\n* {{msg-mw|Javascripttest-qunit-heading}}",
        "accesskey-pt-userpage": "{{doc-accesskey}}\nSee also:\n<!--* username-->\n* {{msg-mw|Accesskey-pt-userpage}}\n* {{msg-mw|Tooltip-pt-userpage}}",
        "accesskey-pt-anonuserpage": "{{doc-accesskey}}",