r65634 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65633‎ | r65634 | r65635 >
Date:20:52, 28 April 2010
Author:dale
Status:deferred
Tags:
Comment:
* updated addScriptClass function in script-loader outputPage
Modified paths:
  • /trunk/extensions/JS2Support/JS2Support.php (modified) (history)
  • /trunk/extensions/JS2Support/ScriptLoaderOutputPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php
@@ -68,7 +68,7 @@
6969 // Add script without grouping
7070 $this->addScript( Html::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) );
7171 }
72 -
 72+
7373 /**
7474 * Gets the class name From an internal wiki title link
7575 * @param $path String: script include path
@@ -161,7 +161,7 @@
162162 $scripts .= "\n" . $this->mScripts;
163163 return $scripts;
164164 }
165 -
 165+
166166 /**
167167 * Add a className to an output Bucket
168168 */
@@ -171,7 +171,7 @@
172172 }
173173 $this->mScriptLoaderClassList[ $type ][ $bucket ][] = $className;
174174 }
175 -
 175+
176176 /**
177177 * Set the embed options for a given bucketKey
178178 * @param $bucketKey String: the bucketkey to apply the options to.
@@ -179,7 +179,7 @@
180180 protected function setClassBucketOptions( $bucketKey, $options ){
181181 $this->mScriptLoaderBucketOptions[ $bucketKey ] = $options;
182182 }
183 -
 183+
184184 /**
185185 * Get class bucket options
186186 */
@@ -189,7 +189,7 @@
190190 }
191191 return array();
192192 }
193 -
 193+
194194 /**
195195 * Add a local or specified stylesheet, with the given media options.
196196 * Meant primarily for internal use...
@@ -255,7 +255,7 @@
256256 // Else use normal styles output:
257257 $this->styles[ $style ] = $options;
258258 }
259 -
 259+
260260 /**
261261 * Build a set of <link>s for the stylesheets specified in the $this->styles array.
262262 * These will be applied to various media & IE conditionals.
@@ -318,7 +318,7 @@
319319 //Now re-append any scripts that got added prior to the includeJQuery call
320320 $this->mScripts = $this->mScripts . $postScripts;
321321 }
322 -
 322+
323323 /**
324324 * Get style sheets grouped by "media", "condition" & "bucket" attributes
325325 * call getLinkedScriptLoaderCss for each group
@@ -337,7 +337,7 @@
338338 }
339339 return $s;
340340 }
341 -
 341+
342342 /**
343343 * Get the linked css script-loader calls
344344 * @param Array $stylesAry Array of style sheets to be added.
@@ -347,7 +347,7 @@
348348 $stylesString = implode( ',', $stylesAry );
349349
350350 $url = wfScript( self::$mScriptLoaderPath ) .
351 - "?class={$stylesString}&" . $this->getURIDparam( $stylesAry ). "&ctype=css";
 351+ "?class={$stylesString}&" . $this->getURIDparam( $stylesAry ). "&format=css";
352352
353353 // Check for the media option:
354354 if( isset( $options['media'] ) && $options['media']!='' ){
@@ -363,7 +363,7 @@
364364
365365 return $link;
366366 }
367 -
 367+
368368 /**
369369 * Adds the script loader to mScripts
370370 */
@@ -381,7 +381,7 @@
382382 }
383383 return $s;
384384 }
385 -
 385+
386386 /**
387387 * Get the <script> tag which will invoke the script loader
388388 * @param $classAry A class array
@@ -401,72 +401,82 @@
402402 * @param $type 'js' or 'css' for type of head item being included
403403 * @return boolean False if the class wasn't found, True on success
404404 */
405 - function addScriptClass( $className, $scriptRequestBucket = 'page' , $type='js') {
 405+/**
 406+ * @param $className String Name of the class
 407+ * @param $scriptRequestBucket Name of bucket for the class
 408+ * @param $type 'js' or 'css' for type of head item being included
 409+ * @return boolean False if the class wasn't found, True on success
 410+ */
 411+function addScriptClass( $className, $scriptRequestBucket = 'page' , $type='js') {
406412 global $wgDebugJavaScript, $wgScriptLoaderNamedPaths, $IP,
407413 $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath,
408414 $wgUser;
409415
 416+ if( !$this->mScriptLoader ){
 417+ $this->mScriptLoader = new jsScriptLoader();
 418+ }
 419+
410420 // Check for wikiTitle:
411421 if ( substr( $className, 0, 3 ) == 'WT:' ) {
412422 if( $wgEnableScriptLoader ) {
413423 // Add to the mScriptLoaderClassList list
414424 $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type);
 425+ return true;
415426 } else {
 427+
416428 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
417429 $titlePage = substr( $className, 3 );
418430 $titleArg = '';
 431+
419432 // Deal with arguments after the "|" syntax
420433 if( stripos( $titlePage, "|") !== false ) {
421434 $parts = explode( '|', $titlePage );
422435 $titlePage = $parts[0];
423436 $titleArg = '&' . $parts[1];
424437 }
 438+ // Check script-loader for msg text
425439 $this->addScriptFile(
426 - Skin::makeUrl( $titlePage,
427 - "action=raw$jsCache&gen=js$titleArg"
428 - )
 440+ Skin::makeUrl( $titlePage,
 441+ "action=raw$jsCache&gen=js$titleArg"
 442+ )
429443 );
430444 }
431 - // Done with addScriptClass used className as wikiTitle
432 - return true;
433 - }
434445
435 - // Get js or css path:
436 - $path = jsScriptLoader::getPathFromClass( $className );
437 - if( $path == false ){
438 - // NOTE:: could throw an error here
439 - //print "could not find: $className\n";
440 - wfDebug( __METHOD__ . ' scriptLoader could not find class: ' . $className );
441 - return false; // could not find the class
442 - }
443 - // Valid path add it to script-loader or "link" directly
444 - if( $wgEnableScriptLoader ) {
445 - // Register it with the script loader
446 - $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type );
447 - } else {
448 - // Source the script directly
449 - $prefix = "skins/common/";
450 - if( substr( $path, 0, 1 ) == '/' ) {
451 - // Straight path
452 - } elseif( substr( $path, 0, strlen( $prefix ) ) == $prefix ) {
453 - // Respect $wgStypePath
454 - $path = "{$wgStylePath}/common/" . substr( $path, strlen( $prefix ) );
455 - } else {
456 - $path = $wgScriptPath . '/' . $path;
457 - }
458 - $this->addScript( Html::linkedScript( $path . "?" . $this->getURIDparam( $className ) ) );
 446+ } else { //dealing with a file not WikiText
459447
460 - // Merge in language text for non-script loader scripts
461 - if( !$this->mScriptLoader ){
462 - $this->mScriptLoader = new jsScriptLoader();
 448+ // Get js or css path:
 449+ $path = jsScriptLoader::getPathFromClass( $className );
 450+ if( $path == false ){
 451+ // NOTE:: could throw an error here
 452+ //print "could not find: $className\n";
 453+ wfDebug( __METHOD__ . ' scriptLoader could not find class: ' . $className );
 454+ return false; // could not find the class
463455 }
464 - $inlineMsg = $this->mScriptLoader->getInlineMsgFromClass( $className );
465 - if( $inlineMsg != '' ){
466 - $this->addScript( Html::inlineScript( $inlineMsg ));
 456+ // Valid path add it to script-loader or "link" directly
 457+ if( $wgEnableScriptLoader ) {
 458+ // Register it with the script loader
 459+ $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type );
 460+ return true;
 461+ } else {
 462+ // Source the script directly
 463+ $prefix = "skins/common/";
 464+ if( substr( $path, 0, 1 ) == '/' ) {
 465+ // Straight path
 466+ } elseif( substr( $path, 0, strlen( $prefix ) ) == $prefix ) {
 467+ // Respect $wgStypePath
 468+ $path = "{$wgStylePath}/common/" . substr( $path, strlen( $prefix ) );
 469+ } else {
 470+ $path = $wgScriptPath . '/' . $path;
 471+ }
 472+ $this->addScript( Html::linkedScript( $path . "?" . $this->getURIDparam( $className ) ) );
467473 }
468474 }
469 - return true;
470 -
 475+ // Included script without script-loader
 476+ // Generate the localized msgs inline since we can't rely on scriptloader to localize
 477+ $inlineMsg = $this->mScriptLoader->getInlineMsgFromClass( $className );
 478+ if( $inlineMsg != '' ) {
 479+ $this->addScript( Html::inlineScript( $inlineMsg ) );
 480+ }
471481 }
472482
473483 /**
Index: trunk/extensions/JS2Support/JS2Support.php
@@ -84,9 +84,10 @@
8585 */
8686 $wgHooks['MakeGlobalVariablesScript'][] = 'js2SupportAddJSVars';
8787 function js2SupportAddJSVars( &$vars ) {
88 - $vars = array_merge( $vars,
 88+ global $wgExtensionAssetsPath;
 89+ $vars = array_merge( $vars,
8990 array(
90 - 'wgScriptLoaderLocation' => $wgExtensionAssetsPath . 'JS2Support/mwScriptLoader.php'
 91+ 'wgScriptLoaderLocation' => $wgExtensionAssetsPath . 'JS2Support/mwScriptLoader.php'
9192 )
9293 );
9394 return true;
@@ -180,5 +181,3 @@
181182 * on every request.
182183 */
183184 $wgDebugJavaScript = false;
184 -
185 -

Status & tagging log