Merge "Remove the $wgHandheldStyle config variable entirely"
[lhc/web/wiklou.git] / includes / specials / SpecialJavaScriptTest.php
index f7e81ee..f79fdd7 100644 (file)
@@ -1,7 +1,24 @@
 <?php
 /**
- * @ingroup SpecialPage
+ * 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
  */
 
 /**
@@ -23,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
@@ -46,24 +55,28 @@ class SpecialJavaScriptTest extends SpecialPage {
                if ( $par == '' ) {
                        $out->setPageTitle( $this->msg( 'javascripttest' ) );
                        $summary = $this->wrapSummaryHtml(
-                               $this->msg( 'javascripttest-pagetext-noframework' )->escaped() . $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( $this->msg( 'javascripttest-title', $this->msg( "javascripttest-$framework-name" )->plain() ) );
-                       $out->setSubtitle( $this->msg( 'javascripttest-backlink' )->rawParams( Linker::linkKnown( $this->getTitle() ) ) );
+                       // Matched! Display proper title and initialize the framework
+                       $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 {
+                       // Framework not found, display error
                        $out->setPageTitle( $this->msg( 'javascripttest' ) );
-                       $summary = $this->wrapSummaryHtml( '<p class="error">'
-                               . $this->msg( 'javascripttest-pagetext-unknownframework', $par )->escaped()
-                               . '</p>'
-                               . $this->getFrameworkListHtml(),
+                       $summary = $this->wrapSummaryHtml(
+                               '<p class="error">' .
+                                       $this->msg( 'javascripttest-pagetext-unknownframework', $par )->escaped() .
+                                       '</p>' .
+                                       $this->getFrameworkListHtml(),
                                'unknownframework'
                        );
                        $out->addHtml( $summary );
@@ -71,40 +84,48 @@ class SpecialJavaScriptTest extends SpecialPage {
        }
 
        /**
-        * Get a list of frameworks (including introduction paragraph and links to the framework run pages)
-        * @return String: HTML
+        * 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 => $initFn ) {
+               foreach ( self::$frameworks as $framework => $initFn ) {
                        $list .= Html::rawElement(
                                'li',
                                array(),
-                               Linker::link( $this->getTitle( $framework ), $this->msg( "javascripttest-$framework-name" )->escaped() )
+                               Linker::link(
+                                       $this->getTitle( $framework ),
+                                       $this->msg( "javascripttest-$framework-name" )->escaped()
+                               )
                        );
                }
                $list .= '</ul>';
-               $msg = $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )->parseAsBlock();
 
-               return $msg;
+               return $this->msg( 'javascripttest-pagetext-frameworks' )->rawParams( $list )
+                       ->parseAsBlock();
        }
 
        /**
         * Function to wrap the summary.
         * It must be given a valid state as a second parameter or an exception will
         * be thrown.
-        * @param $html String: The raw HTML.
-        * @param $state String: State, one of 'noframework', 'unknownframework' or 'frameworkfound'
+        * @param string $html The raw HTML.
+        * @param string $state State, one of 'noframework', 'unknownframework' or 'frameworkfound'
+        * @throws MWException
         * @return string
         */
        private function wrapSummaryHtml( $html, $state ) {
                $validStates = array( 'noframework', 'unknownframework', 'frameworkfound' );
-               if( !in_array( $state, $validStates ) ) {
+
+               if ( !in_array( $state, $validStates ) ) {
                        throw new MWException( __METHOD__
                                . ' given an invalid state. Must be one of "'
-                               . join( '", "', $validStates) . '".'
+                               . join( '", "', $validStates ) . '".'
                        );
                }
+
                return "<div id=\"mw-javascripttest-summary\" class=\"mw-javascripttest-$state\">$html</div>";
        }
 
@@ -145,12 +166,13 @@ HTML;
 
                // Used in ./tests/qunit/data/testrunner.js, see also documentation of
                // $wgJavaScriptTestConfig in DefaultSettings.php
-               $out->addJsConfigVars( 'QUnitTestSwarmInjectJSPath', $wgJavaScriptTestConfig['qunit']['testswarm-injectjs'] );
+               $out->addJsConfigVars(
+                       'QUnitTestSwarmInjectJSPath',
+                       $wgJavaScriptTestConfig['qunit']['testswarm-injectjs']
+               );
        }
 
-       public function isListed(){
-               global $wgEnableJavaScriptTest;
-               return $wgEnableJavaScriptTest === true;
+       protected function getGroupName() {
+               return 'other';
        }
-
 }