Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -418,9 +418,6 @@ |
419 | 419 | list( $key, $code, $group ) = self::getKeyCodeGroup( $article->getTitle() ); |
420 | 420 | if ( !$group ) return true; |
421 | 421 | |
422 | | - global $wgOut; |
423 | | - $wgOut->addScriptFile( TranslateUtils::assetPath( 'js/translationdisplay.js' ) ); |
424 | | - |
425 | 422 | $def = self::preserveWhitespaces( $group->getMessage( $key, 'en' ) ); |
426 | 423 | $content = self::preserveWhitespaces( $content ); |
427 | 424 | |
— | — | @@ -452,4 +449,19 @@ |
453 | 450 | $text = str_replace( "\n", '<br />', $text ); |
454 | 451 | return $text; |
455 | 452 | } |
| 453 | + |
| 454 | + public static function injectTranslationDisplayJs( $parser, &$text, $state ) { |
| 455 | + if ( strpos( $text, 'translationdisplay' ) !== false ) { |
| 456 | + $output = $parser->getOutput(); |
| 457 | + if ( method_exists( $output, 'addModules' ) ) { |
| 458 | + $output->addModules( 'translationdisplay' ); |
| 459 | + } else { |
| 460 | + $file = TranslateUtils::assetPath( 'js/translationdisplay.js' ); |
| 461 | + $script = Html::linkedScript( $file ); |
| 462 | + // How to make sure jQuery is included?? |
| 463 | + //$output->addHeadItem( $script, 'translationdisplay' ); |
| 464 | + } |
| 465 | + } |
| 466 | + return true; |
| 467 | + } |
456 | 468 | } |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields'; |
93 | 93 | $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs'; |
94 | 94 | $wgHooks['ArticleAfterFetchContent'][] = 'TranslateEditAddons::customDisplay'; |
| 95 | +$wgHooks['ParserBeforeStrip'][] = 'TranslateEditAddons::injectTranslationDisplayJs'; |
95 | 96 | |
96 | 97 | // Custom preferences |
97 | 98 | $wgDefaultUserOptions['translate'] = 0; |
— | — | @@ -422,10 +423,16 @@ |
423 | 424 | # Startup code |
424 | 425 | function efTranslateResources( &$resourceLoader ) { |
425 | 426 | global $wgExtensionAssetsPath; |
426 | | - $resourceLoader->register( array( 'translate-css' => |
427 | | - new ResourceLoaderFileModule( array( 'styles' => 'Translate.css' ), |
428 | | - dirname( __FILE__ ), "$wgExtensionAssetsPath/Translate" ) |
429 | | - ) ); |
| 427 | + $resourceLoader->register( |
| 428 | + array( |
| 429 | + 'translate-css' => |
| 430 | + new ResourceLoaderFileModule( array( 'styles' => 'Translate.css' ), |
| 431 | + dirname( __FILE__ ), "$wgExtensionAssetsPath/Translate" ), |
| 432 | + 'translationdisplay' => |
| 433 | + new ResourceLoaderFileModule( array( 'scripts' => 'translationdisplay.js' ), |
| 434 | + dirname( __FILE__ ) . '/js' , "$wgExtensionAssetsPath/Translate/js" ), |
| 435 | + ) |
| 436 | +); |
430 | 437 | return true; |
431 | 438 | } |
432 | 439 | |