Index: trunk/extensions/JS2Support/ScriptLoaderOutputPage.php |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | // Add script without grouping |
70 | 70 | $this->addScript( Html::linkedScript( wfAppendQuery( $path, $wgStyleVersion ) ) ); |
71 | 71 | } |
72 | | - |
| 72 | + |
73 | 73 | /** |
74 | 74 | * Gets the class name From an internal wiki title link |
75 | 75 | * @param $path String: script include path |
— | — | @@ -161,7 +161,7 @@ |
162 | 162 | $scripts .= "\n" . $this->mScripts; |
163 | 163 | return $scripts; |
164 | 164 | } |
165 | | - |
| 165 | + |
166 | 166 | /** |
167 | 167 | * Add a className to an output Bucket |
168 | 168 | */ |
— | — | @@ -171,7 +171,7 @@ |
172 | 172 | } |
173 | 173 | $this->mScriptLoaderClassList[ $type ][ $bucket ][] = $className; |
174 | 174 | } |
175 | | - |
| 175 | + |
176 | 176 | /** |
177 | 177 | * Set the embed options for a given bucketKey |
178 | 178 | * @param $bucketKey String: the bucketkey to apply the options to. |
— | — | @@ -179,7 +179,7 @@ |
180 | 180 | protected function setClassBucketOptions( $bucketKey, $options ){ |
181 | 181 | $this->mScriptLoaderBucketOptions[ $bucketKey ] = $options; |
182 | 182 | } |
183 | | - |
| 183 | + |
184 | 184 | /** |
185 | 185 | * Get class bucket options |
186 | 186 | */ |
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | } |
191 | 191 | return array(); |
192 | 192 | } |
193 | | - |
| 193 | + |
194 | 194 | /** |
195 | 195 | * Add a local or specified stylesheet, with the given media options. |
196 | 196 | * Meant primarily for internal use... |
— | — | @@ -255,7 +255,7 @@ |
256 | 256 | // Else use normal styles output: |
257 | 257 | $this->styles[ $style ] = $options; |
258 | 258 | } |
259 | | - |
| 259 | + |
260 | 260 | /** |
261 | 261 | * Build a set of <link>s for the stylesheets specified in the $this->styles array. |
262 | 262 | * These will be applied to various media & IE conditionals. |
— | — | @@ -318,7 +318,7 @@ |
319 | 319 | //Now re-append any scripts that got added prior to the includeJQuery call |
320 | 320 | $this->mScripts = $this->mScripts . $postScripts; |
321 | 321 | } |
322 | | - |
| 322 | + |
323 | 323 | /** |
324 | 324 | * Get style sheets grouped by "media", "condition" & "bucket" attributes |
325 | 325 | * call getLinkedScriptLoaderCss for each group |
— | — | @@ -337,7 +337,7 @@ |
338 | 338 | } |
339 | 339 | return $s; |
340 | 340 | } |
341 | | - |
| 341 | + |
342 | 342 | /** |
343 | 343 | * Get the linked css script-loader calls |
344 | 344 | * @param Array $stylesAry Array of style sheets to be added. |
— | — | @@ -347,7 +347,7 @@ |
348 | 348 | $stylesString = implode( ',', $stylesAry ); |
349 | 349 | |
350 | 350 | $url = wfScript( self::$mScriptLoaderPath ) . |
351 | | - "?class={$stylesString}&" . $this->getURIDparam( $stylesAry ). "&ctype=css"; |
| 351 | + "?class={$stylesString}&" . $this->getURIDparam( $stylesAry ). "&format=css"; |
352 | 352 | |
353 | 353 | // Check for the media option: |
354 | 354 | if( isset( $options['media'] ) && $options['media']!='' ){ |
— | — | @@ -363,7 +363,7 @@ |
364 | 364 | |
365 | 365 | return $link; |
366 | 366 | } |
367 | | - |
| 367 | + |
368 | 368 | /** |
369 | 369 | * Adds the script loader to mScripts |
370 | 370 | */ |
— | — | @@ -381,7 +381,7 @@ |
382 | 382 | } |
383 | 383 | return $s; |
384 | 384 | } |
385 | | - |
| 385 | + |
386 | 386 | /** |
387 | 387 | * Get the <script> tag which will invoke the script loader |
388 | 388 | * @param $classAry A class array |
— | — | @@ -401,72 +401,82 @@ |
402 | 402 | * @param $type 'js' or 'css' for type of head item being included |
403 | 403 | * @return boolean False if the class wasn't found, True on success |
404 | 404 | */ |
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') { |
406 | 412 | global $wgDebugJavaScript, $wgScriptLoaderNamedPaths, $IP, |
407 | 413 | $wgEnableScriptLoader, $wgStyleVersion, $wgScriptPath, $wgStylePath, |
408 | 414 | $wgUser; |
409 | 415 | |
| 416 | + if( !$this->mScriptLoader ){ |
| 417 | + $this->mScriptLoader = new jsScriptLoader(); |
| 418 | + } |
| 419 | + |
410 | 420 | // Check for wikiTitle: |
411 | 421 | if ( substr( $className, 0, 3 ) == 'WT:' ) { |
412 | 422 | if( $wgEnableScriptLoader ) { |
413 | 423 | // Add to the mScriptLoaderClassList list |
414 | 424 | $this->addClassToOutputBucket( $className, $scriptRequestBucket, $type); |
| 425 | + return true; |
415 | 426 | } else { |
| 427 | + |
416 | 428 | $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; |
417 | 429 | $titlePage = substr( $className, 3 ); |
418 | 430 | $titleArg = ''; |
| 431 | + |
419 | 432 | // Deal with arguments after the "|" syntax |
420 | 433 | if( stripos( $titlePage, "|") !== false ) { |
421 | 434 | $parts = explode( '|', $titlePage ); |
422 | 435 | $titlePage = $parts[0]; |
423 | 436 | $titleArg = '&' . $parts[1]; |
424 | 437 | } |
| 438 | + // Check script-loader for msg text |
425 | 439 | $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 | + ) |
429 | 443 | ); |
430 | 444 | } |
431 | | - // Done with addScriptClass used className as wikiTitle |
432 | | - return true; |
433 | | - } |
434 | 445 | |
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 |
459 | 447 | |
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 |
463 | 455 | } |
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 ) ) ); |
467 | 473 | } |
468 | 474 | } |
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 | + } |
471 | 481 | } |
472 | 482 | |
473 | 483 | /** |
Index: trunk/extensions/JS2Support/JS2Support.php |
— | — | @@ -84,9 +84,10 @@ |
85 | 85 | */ |
86 | 86 | $wgHooks['MakeGlobalVariablesScript'][] = 'js2SupportAddJSVars'; |
87 | 87 | function js2SupportAddJSVars( &$vars ) { |
88 | | - $vars = array_merge( $vars, |
| 88 | + global $wgExtensionAssetsPath; |
| 89 | + $vars = array_merge( $vars, |
89 | 90 | array( |
90 | | - 'wgScriptLoaderLocation' => $wgExtensionAssetsPath . 'JS2Support/mwScriptLoader.php' |
| 91 | + 'wgScriptLoaderLocation' => $wgExtensionAssetsPath . 'JS2Support/mwScriptLoader.php' |
91 | 92 | ) |
92 | 93 | ); |
93 | 94 | return true; |
— | — | @@ -180,5 +181,3 @@ |
181 | 182 | * on every request. |
182 | 183 | */ |
183 | 184 | $wgDebugJavaScript = false; |
184 | | - |
185 | | - |