From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- includes/specials/SpecialJavaScriptTest.php | 142 ++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 includes/specials/SpecialJavaScriptTest.php (limited to 'includes/specials/SpecialJavaScriptTest.php') diff --git a/includes/specials/SpecialJavaScriptTest.php b/includes/specials/SpecialJavaScriptTest.php new file mode 100644 index 00000000..d7e1655f --- /dev/null +++ b/includes/specials/SpecialJavaScriptTest.php @@ -0,0 +1,142 @@ + 'initQUnitTesting', + ); + + public function __construct() { + parent::__construct( 'JavaScriptTest' ); + } + + 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 + $pars = explode( '/', $par ); + $framework = strtolower( $pars[0] ); + + // No framework specified + if ( $par == '' ) { + $out->setPagetitle( wfMsgHtml( 'javascripttest' ) ); + $summary = $this->wrapSummaryHtml( + wfMsgHtml( 'javascripttest-pagetext-noframework' ) . $this->getFrameworkListHtml(), + 'noframework' + ); + $out->addHtml( $summary ); + + // Matched! Display proper title and initialize the framework + } elseif ( isset( self::$frameworks[$framework] ) ) { + $out->setPagetitle( wfMsgHtml( 'javascripttest-title', wfMsgHtml( "javascripttest-$framework-name" ) ) ); + $out->setSubtitle( + wfMessage( 'javascripttest-backlink' )->rawParams( Linker::linkKnown( $this->getTitle() ) )->escaped() + ); + $this->{self::$frameworks[$framework]}(); + + // Framework not found, display error + } else { + $out->setPagetitle( wfMsgHtml( 'javascripttest' ) ); + $summary = $this->wrapSummaryHtml( '

' + . wfMsgHtml( 'javascripttest-pagetext-unknownframework', $par ) + . '

' + . $this->getFrameworkListHtml(), + 'unknownframework' + ); + $out->addHtml( $summary ); + } + } + + /** + * Get a list of frameworks (including introduction paragraph and links to the framework run pages) + * @return String: HTML + */ + private function getFrameworkListHtml() { + $list = ''; + $msg = wfMessage( 'javascripttest-pagetext-frameworks' )->rawParams( $list )->parseAsBlock(); + + return $msg; + } + + /** + * 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' + */ + private function wrapSummaryHtml( $html, $state ) { + $validStates = array( 'noframework', 'unknownframework', 'frameworkfound' ); + if( !in_array( $state, $validStates ) ) { + throw new MWException( __METHOD__ + . ' given an invalid state. Must be one of "' + . join( '", "', $validStates) . '".' + ); + } + return "
$html
"; + } + + /** + * Initialize the page for QUnit. + */ + private function initQUnitTesting() { + global $wgJavaScriptTestConfig, $wgLang; + + $out = $this->getOutput(); + + $out->addModules( 'mediawiki.tests.qunit.testrunner' ); + $qunitTestModules = $out->getResourceLoader()->getTestModuleNames( 'qunit' ); + $out->addModules( $qunitTestModules ); + + $summary = wfMessage( 'javascripttest-qunit-intro' ) + ->params( $wgJavaScriptTestConfig['qunit']['documentation'] ) + ->parseAsBlock(); + $header = wfMessage( 'javascripttest-qunit-heading' )->escaped(); + $userDir = $wgLang->getDir(); + + $baseHtml = << +
$header
+
+
+
+
    +
    test markup, will be hidden
    + +HTML; + $out->addHtml( $this->wrapSummaryHtml( $summary, 'frameworkfound' ) . $baseHtml ); + + } + + public function isListed(){ + global $wgEnableJavaScriptTest; + return $wgEnableJavaScriptTest === true; + } + +} -- cgit v1.2.3-54-g00ecf