r83917 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83916‎ | r83917 | r83918 >
Date:16:28, 14 March 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
* Hook diff pages to provide more information about the message.
*: Useful for those who follow recent changes feeds in review purposes
* Removed remnants of the old version of this feature
* Small message tweaks, no need to repeat the message name everywhere
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)
  • /trunk/extensions/Translate/js/translationdisplay.js (deleted) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/js/translationdisplay.js
@@ -1,14 +0,0 @@
2 -$(document).ready( function() {
3 - $(".translationdisplay").hover(
4 - function() { $(this).addClass("translationdisplay-hover"); },
5 - function() { $(this).removeClass("translationdisplay-hover"); }
6 - );
7 - $("#tt1").click( function() {
8 - $("#tt1").hide();
9 - $("#tt2").show();
10 - });
11 - $("#tt2").click( function() {
12 - $("#tt2").hide();
13 - $("#tt1").show();
14 - });
15 -});
Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -417,21 +417,6 @@
418418 return $text;
419419 }
420420
421 - public static function injectTranslationDisplayJs( $parser, &$text, $state ) {
422 - if ( strpos( $text, 'translationdisplay' ) !== false ) {
423 - $output = $parser->getOutput();
424 - if ( method_exists( $output, 'addModules' ) ) {
425 - $output->addModules( 'translationdisplay' );
426 - } else {
427 - $file = TranslateUtils::assetPath( 'js/translationdisplay.js' );
428 - $script = Html::linkedScript( $file );
429 - // How to make sure jQuery is included??
430 - //$output->addHeadItem( $script, 'translationdisplay' );
431 - }
432 - }
433 - return true;
434 - }
435 -
436421 public static function translateMessageDocumentationLanguage( &$names, $code ) {
437422 global $wgTranslateDocumentationLanguageCode;
438423 if ( $wgTranslateDocumentationLanguageCode ) {
@@ -450,4 +435,29 @@
451436 }
452437 return true;
453438 }
 439+
 440+ public static function displayOnDiff( $de, $out ) {
 441+ $title = $de->getTitle();
 442+ $handle = new MessageHandle( $title );
 443+
 444+ if ( !$handle->exists() ) {
 445+ return true;
 446+ }
 447+
 448+ $de->loadNewText();
 449+ $out->setRevisionId( $de->mNewRev->getId() );
 450+
 451+ $th = new TranslationHelpers( $title );
 452+ $th->setEditMode( false );
 453+ $th->setTranslation( $de->mNewtext );
 454+ TranslateUtils::injectCSS();
 455+
 456+ $boxes = array();
 457+ $boxes[] = $th->getDocumentationBox();
 458+ $boxes[] = $th->getDefinitionBox();
 459+ $boxes[] = $th->getTranslationDisplayBox();
 460+ $output = Html::rawElement( 'div', array( 'class' => 'mw-sp-translate-edit-fields' ), implode( "\n\n", $boxes ) );
 461+ $out->addHtml( $output );
 462+ return false;
 463+ }
454464 }
Index: trunk/extensions/Translate/Translate.php
@@ -89,7 +89,6 @@
9090 $wgHooks['EditPageBeforeEditButtons'][] = 'TranslateEditAddons::buttonHack';
9191 $wgHooks['EditPage::showEditForm:fields'][] = 'TranslateEditAddons::keepFields';
9292 $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs';
93 -$wgHooks['ParserBeforeStrip'][] = 'TranslateEditAddons::injectTranslationDisplayJs';
9493 $wgHooks['LanguageGetTranslatedLanguageNames'][] = 'TranslateEditAddons::translateMessageDocumentationLanguage';
9594 $wgHooks['ArticlePrepareTextForEdit'][] = 'TranslateEditAddons::disablePreSaveTransform';
9695
@@ -109,6 +108,9 @@
110109 // Translation memory updates
111110 $wgHooks['ArticleSaveComplete'][] = 'TranslationMemoryUpdater::update';
112111
 112+// Translation display related
 113+$wgHooks['ArticleContentOnDiff'][] = 'TranslateEditAddons::displayOnDiff';
 114+
113115 // New rights
114116 $wgAvailableRights[] = 'translate';
115117 $wgAvailableRights[] = 'translate-import';
@@ -122,6 +124,7 @@
123125 );
124126 $wgResourceModules['translationdisplay'] = array(
125127 'scripts' => 'js/translationdisplay.js',
 128+ 'styles' => 'js/translationdisplay.css',
126129 'localBasePath' => dirname( __FILE__ ),
127130 'remoteExtPath' => 'Translate'
128131 );
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -44,6 +44,10 @@
4545 * suggestion directly into the text area, for example.
4646 */
4747 protected $textareaId = 'wpTextbox1';
 48+ /**
 49+ * Whether to include extra tools to aid translating.
 50+ */
 51+ protected $editMode = 'true';
4852
4953 /**
5054 * @param $title Title Title of a page that holds a translation.
@@ -106,7 +110,16 @@
107111 $this->textareaId = $id;
108112 }
109113
 114+
110115 /**
 116+ * Enable or disable extra help for editing.
 117+ * @param $mode Boolean
 118+ */
 119+ public function setEditMode( $mode = true ) {
 120+ $this->editMode = $mode;
 121+ }
 122+
 123+ /**
111124 * Gets the message definition.
112125 * @return String
113126 */
@@ -178,16 +191,7 @@
179192 */
180193 public function getBoxes( $suggestions = 'sync' ) {
181194 // Box filter
182 - $all = array(
183 - 'other-languages' => array( $this, 'getOtherLanguagesBox' ),
184 - 'translation-memory' => array( $this, 'getSuggestionBox' ),
185 - 'translation-diff' => array( $this, 'getPageDiff' ),
186 - 'page-translation' => array( $this, 'getTranslationPageDiff' ),
187 - 'separator' => array( $this, 'getSeparatorBox' ),
188 - 'documenation' => array( $this, 'getDocumentationBox' ),
189 - 'definition' => array( $this, 'getDefinitionBox' ),
190 - 'check' => array( $this, 'getCheckBox' ),
191 - );
 195+ $all = $this->getBoxNames();
192196
193197 if ( $suggestions === 'async' ) {
194198 $all['translation-memory'] = array( $this, 'getLazySuggestionBox' );
@@ -215,6 +219,19 @@
216220 }
217221 }
218222
 223+ public function getBoxNames() {
 224+ return array(
 225+ 'other-languages' => array( $this, 'getOtherLanguagesBox' ),
 226+ 'translation-memory' => array( $this, 'getSuggestionBox' ),
 227+ 'translation-diff' => array( $this, 'getPageDiff' ),
 228+ 'page-translation' => array( $this, 'getTranslationPageDiff' ),
 229+ 'separator' => array( $this, 'getSeparatorBox' ),
 230+ 'documentation' => array( $this, 'getDocumentationBox' ),
 231+ 'definition' => array( $this, 'getDefinitionBox' ),
 232+ 'check' => array( $this, 'getCheckBox' ),
 233+ );
 234+ }
 235+
219236 /**
220237 * Returns suggestions from a translation memory.
221238 * @return Html snippet which contains the suggestions.
@@ -299,7 +316,7 @@
300317 return $result;
301318 }
302319
303 - protected function getSuggestionBox( $async = false ) {
 320+ public function getSuggestionBox( $async = false ) {
304321 global $wgTranslateTranslationServices;
305322
306323 $boxes = array();
@@ -594,7 +611,7 @@
595612 return implode( "$divider\n", $suggestions );
596613 }
597614
598 - protected function getDefinitionBox() {
 615+ public function getDefinitionBox() {
599616 $en = $this->getDefinition();
600617 if ( $en === null ) {
601618 return null;
@@ -631,7 +648,22 @@
632649 return TranslateUtils::fieldset( $label, $msg, $class );
633650 }
634651
635 - protected function getCheckBox() {
 652+ public function getTranslationDisplayBox() {
 653+ $en = $this->getTranslation();
 654+ if ( $en === null ) {
 655+ return null;
 656+ }
 657+ $label = wfMsg( 'translate-edit-translation' );
 658+ $class = array( 'class' => 'mw-translate-edit-translation' );
 659+ $msg = Html::rawElement( 'span',
 660+ array( 'class' => 'mw-translate-edit-translationtext' ),
 661+ TranslateUtils::convertWhiteSpaceToHTML( $en )
 662+ );
 663+
 664+ return TranslateUtils::fieldset( $label, $msg, $class );
 665+ }
 666+
 667+ public function getCheckBox() {
636668 global $wgTranslateDocumentationLanguageCode;
637669
638670 $placeholder = Html::element( 'div', array( 'class' => 'mw-translate-messagechecks' ) );
@@ -680,7 +712,7 @@
681713 ) );
682714 }
683715
684 - protected function getOtherLanguagesBox() {
 716+ public function getOtherLanguagesBox() {
685717 global $wgLang;
686718
687719 $code = $this->targetLanguage;
@@ -746,12 +778,13 @@
747779
748780 $class = 'mw-sp-translate-edit-info';
749781
750 - if ( $info === null ) {
 782+ if ( $info !== null ) $info .= Html::element( 'hr' );
 783+ $info .= $this->formatGettextComments();
 784+
 785+ if ( strval( $info ) === '' ) {
751786 $info = wfMsg( 'translate-edit-no-information' );
752787 $class = 'mw-sp-translate-edit-noinfo';
753788 }
754 -
755 - $info .= $this->formatGettextComments();
756789 $class .= ' mw-sp-translate-message-documentation';
757790
758791 $contents = $wgOut->parse( $info );
@@ -759,7 +792,7 @@
760793 $contents = preg_replace( '~^<([a-z]+)>(.*)</\1>$~us', '\2', $contents );
761794
762795 return TranslateUtils::fieldset(
763 - wfMsgHtml( 'translate-edit-information', $edit , $page ), $contents, array( 'class' => $class )
 796+ wfMsgHtml( 'translate-edit-information', $edit, $page ), $contents, array( 'class' => $class )
764797 );
765798
766799 }
@@ -793,7 +826,7 @@
794827 }
795828 }
796829 }
797 - return "<hr />$out";
 830+ return "$out";
798831 }
799832 }
800833 }
@@ -999,15 +1032,18 @@
10001033 }
10011034
10021035 public function adder( $source ) {
1003 - $target = self::jQueryPathId( $this->getTextareaId() );
1004 - $source = self::jQueryPathId( $source );
1005 - $params = array(
1006 - 'onclick' => "jQuery($target).val(jQuery($source).text()).focus(); return false;",
1007 - 'href' => '#',
1008 - 'title' => wfMsg( 'translate-use-suggestion' )
1009 - );
 1036+ if ( !$this->editMode ) {
 1037+ return '';
 1038+ }
 1039+ $target = self::jQueryPathId( $this->getTextareaId() );
 1040+ $source = self::jQueryPathId( $source );
 1041+ $params = array(
 1042+ 'onclick' => "jQuery($target).val(jQuery($source).text()).focus(); return false;",
 1043+ 'href' => '#',
 1044+ 'title' => wfMsg( 'translate-use-suggestion' )
 1045+ );
10101046
1011 - return Html::element( 'a', $params, '↓' );
 1047+ return Html::element( 'a', $params, '↓' );
10121048 }
10131049
10141050 public function wrapInsert( $id, $text ) {
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -72,11 +72,12 @@
7373
7474 'translate-edit-title' => 'Edit "$1"',
7575 'translate-edit-definition' => 'Message definition',
 76+ 'translate-edit-translation' => 'Translation',
7677 'translate-edit-contribute' => 'contribute',
7778 'translate-edit-no-information' => "''This message has no documentation.''
7879 ''If you know where or how this message is used, you can help other translators by adding documentation to this message.''",
79 - 'translate-edit-information' => 'Information about message "$2" ($1)',
80 - 'translate-edit-in-other-languages' => 'Message "$1" in other languages',
 80+ 'translate-edit-information' => 'Information about message ($1)',
 81+ 'translate-edit-in-other-languages' => 'Message in other languages',
8182 'translate-edit-committed' => 'Current translation in software',
8283 'translate-edit-warnings' => 'Warnings about incomplete translations',
8384 'translate-edit-tmsugs' => 'Suggestions from translation memory',
@@ -87,10 +88,6 @@
8889 'translate-edit-tab-next' => '>>>',
8990 'translate-edit-tab-list' => 'Message list',
9091
91 - 'translate-edit-show-def' => 'Message definition',
92 - 'translate-edit-show-trans' => 'Translation',
93 - 'translate-edit-show-click' => 'Click to switch layout',
94 -
9592 'translate-magic-pagename' => 'Extended MediaWiki translation',
9693 'translate-magic-help' => 'You can translate special pages aliases, magic words and namespace names.
9794

Status & tagging log