r76163 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76162‎ | r76163 | r76164 >
Date:23:25, 5 November 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Fix javascript inclusion
Modified paths:
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -418,9 +418,6 @@
419419 list( $key, $code, $group ) = self::getKeyCodeGroup( $article->getTitle() );
420420 if ( !$group ) return true;
421421
422 - global $wgOut;
423 - $wgOut->addScriptFile( TranslateUtils::assetPath( 'js/translationdisplay.js' ) );
424 -
425422 $def = self::preserveWhitespaces( $group->getMessage( $key, 'en' ) );
426423 $content = self::preserveWhitespaces( $content );
427424
@@ -452,4 +449,19 @@
453450 $text = str_replace( "\n", '<br />', $text );
454451 return $text;
455452 }
 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+ }
456468 }
Index: trunk/extensions/Translate/Translate.php
@@ -91,6 +91,7 @@
9292 $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields';
9393 $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs';
9494 $wgHooks['ArticleAfterFetchContent'][] = 'TranslateEditAddons::customDisplay';
 95+$wgHooks['ParserBeforeStrip'][] = 'TranslateEditAddons::injectTranslationDisplayJs';
9596
9697 // Custom preferences
9798 $wgDefaultUserOptions['translate'] = 0;
@@ -422,10 +423,16 @@
423424 # Startup code
424425 function efTranslateResources( &$resourceLoader ) {
425426 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+);
430437 return true;
431438 }
432439

Status & tagging log