Merge "Force $wgCategoryCollation to be uppercase in tests"
[lhc/web/wiklou.git] / includes / specials / SpecialJavaScriptTest.php
index c971949..84e3cb7 100644 (file)
@@ -1,5 +1,29 @@
 <?php
-
+/**
+ * Implements Special:JavaScriptTest
+ *
+ * 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 SpecialPage
+ */
+
+/**
+ * @ingroup SpecialPage
+ */
 class SpecialJavaScriptTest extends SpecialPage {
 
        /**
@@ -16,19 +40,11 @@ class SpecialJavaScriptTest extends SpecialPage {
        }
 
        public function execute( $par ) {
-               global $wgEnableJavaScriptTest;
-
                $out = $this->getOutput();
 
                $this->setHeaders();
                $out->disallowUserJs();
 
-               // Abort early if we're disabled
-               if ( $wgEnableJavaScriptTest !== true ) {
-                       $out->addWikiMsg( 'javascripttest-disabled' );
-                       return;
-               }
-
                $out->addModules( 'mediawiki.special.javaScriptTest' );
 
                // Determine framework
@@ -37,26 +53,24 @@ class SpecialJavaScriptTest extends SpecialPage {
 
                // No framework specified
                if ( $par == '' ) {
-                       $out->setPagetitle( wfMsg( 'javascripttest' ) );
+                       $out->setPageTitle( $this->msg( 'javascripttest' ) );
                        $summary = $this->wrapSummaryHtml(
-                               wfMsg( 'javascripttest-pagetext-noframework' ) . $this->getFrameworkListHtml(),
+                               $this->msg( 'javascripttest-pagetext-noframework' )->escaped() . $this->getFrameworkListHtml(),
                                'noframework'
                        );
                        $out->addHtml( $summary );
 
                // Matched! Display proper title and initialize the framework
                } elseif ( isset( self::$frameworks[$framework] ) ) {
-                       $out->setPagetitle( wfMsg( 'javascripttest-title', wfMsg( "javascripttest-$framework-name" ) ) );
-                       $out->setSubtitle(
-                               wfMessage( 'javascripttest-backlink' )->rawParams( Linker::linkKnown( $this->getTitle() ) )->escaped()
-                       );
+                       $out->setPageTitle( $this->msg( 'javascripttest-title', $this->msg( "javascripttest-$framework-name" )->plain() ) );
+                       $out->setSubtitle( $this->msg( 'javascripttest-backlink' )->rawParams( Linker::linkKnown( $this->getTitle() ) ) );
                        $this->{self::$frameworks[$framework]}();
 
                // Framework not found, display error
                } else {
-                       $out->setPagetitle( wfMsg( 'javascripttest' ) );
+                       $out->setPageTitle( $this->msg( 'javascripttest' ) );
                        $summary = $this->wrapSummaryHtml( '<p class="error">'
-                               . wfMsg( 'javascripttest-pagetext-unknownframework', $par )
+                               . $this->msg( 'javascripttest-pagetext-unknownframework', $par )->escaped()
                                . '</p>'
                                . $this->getFrameworkListHtml(),
                                'unknownframework'
@@ -75,11 +89,11 @@ class SpecialJavaScriptTest extends SpecialPage {
                        $list .= Html::rawElement(
                                'li',
                                array(),
-                               Linker::link( $this->getTitle( $framework ), wfMsg( "javascripttest-$framework-name" ) )
+                               Linker::link( $this->getTitle( $framework ), $this->msg( "javascripttest-$framework-name" )->escaped() )
                        );
                }
                $list .= '</ul>';
-               $msg = wfMessage( 'javascripttest-pagetext-frameworks' )->rawParams( $list )->parseAsBlock();
+               $msg = $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )->parseAsBlock();
 
                return $msg;
        }
@@ -90,6 +104,8 @@ class SpecialJavaScriptTest extends SpecialPage {
         * be thrown.
         * @param $html String: The raw HTML.
         * @param $state String: State, one of 'noframework', 'unknownframework' or 'frameworkfound'
+        * @throws MWException
+        * @return string
         */
        private function wrapSummaryHtml( $html, $state ) {
                $validStates = array( 'noframework', 'unknownframework', 'frameworkfound' );
@@ -114,25 +130,31 @@ class SpecialJavaScriptTest extends SpecialPage {
                $qunitTestModules = $out->getResourceLoader()->getTestModuleNames( 'qunit' );
                $out->addModules( $qunitTestModules );
 
-               $summary = wfMessage( 'javascripttest-qunit-intro' )
+               $summary = $this->msg( 'javascripttest-qunit-intro' )
                        ->params( $wgJavaScriptTestConfig['qunit']['documentation'] )
                        ->parseAsBlock();
-               $header = wfMessage( 'javascripttest-qunit-heading' )->escaped();
+               $header = $this->msg( 'javascripttest-qunit-heading' )->escaped();
+               $userDir = $this->getLanguage()->getDir();
 
                $baseHtml = <<<HTML
-<div id="qunit-header">$header</div>
+<div class="mw-content-ltr">
+<div id="qunit-header"><span dir="$userDir">$header</span></div>
 <div id="qunit-banner"></div>
 <div id="qunit-testrunner-toolbar"></div>
 <div id="qunit-userAgent"></div>
 <ol id="qunit-tests"></ol>
+<div id="qunit-fixture">test markup, will be hidden</div>
+</div>
 HTML;
                $out->addHtml( $this->wrapSummaryHtml( $summary, 'frameworkfound' ) . $baseHtml );
 
-       }
+               // 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();
 
-       public function isListed(){
-               global $wgEnableJavaScriptTest;
-               return $wgEnableJavaScriptTest === true;
+               // Used in ./tests/qunit/data/testrunner.js, see also documentation of
+               // $wgJavaScriptTestConfig in DefaultSettings.php
+               $out->addJsConfigVars( 'QUnitTestSwarmInjectJSPath', $wgJavaScriptTestConfig['qunit']['testswarm-injectjs'] );
        }
-
 }