r107568 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107567‎ | r107568 | r107569 >
Date:13:09, 29 December 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Sneaking in a new feature for comments: show more information about the latest change of translations when using the recent translations group
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/resources/ext.translate.quickedit.css (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -211,6 +211,10 @@
212212 return (string) call_user_func( $all['check'] );
213213 }
214214
 215+ if ( $this->group instanceof RecentMessageGroup ) {
 216+ $all['last-diff'] = array( $this, 'getLastDiff' );
 217+ }
 218+
215219 $boxes = array();
216220 foreach ( $all as $type => $cb ) {
217221 $box = call_user_func( $cb );
@@ -981,6 +985,57 @@
982986 return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) );
983987 }
984988
 989+ protected function getLastDiff() {
 990+ // Shortcuts
 991+ $title = $this->title;
 992+ $latestRevId = $title->getLatestRevID();
 993+ $previousRevId = $title->getPreviousRevisionID( $latestRevId );
 994+
 995+ $latestRev = Revision::newFromTitle( $title, $latestRevId );
 996+ $previousRev = Revision::newFromTitle( $title, $previousRevId );
 997+
 998+ $diffText = '';
 999+
 1000+ if ( $latestRev && $previousRev ) {
 1001+ $latest = $latestRev->getText();
 1002+ $previous = $previousRev->getText();
 1003+ if ( $previous !== $latest ) {
 1004+ $diff = new DifferenceEngine;
 1005+ if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) {
 1006+ $diff->setTextLanguage( $this->targetLanguage );
 1007+ }
 1008+ $diff->setText( $previous, $latest );
 1009+ $diff->setReducedLineNumbers();
 1010+ $diff->showDiffStyle();
 1011+ $diffText = $diff->getDiff( false, false );
 1012+ }
 1013+ }
 1014+
 1015+ if ( !$latestRev ) {
 1016+ return null;
 1017+ }
 1018+
 1019+ global $wgUser;
 1020+ $user = $latestRev->getUserText( Revision::FOR_THIS_USER, $wgUser );
 1021+ $comment = $latestRev->getComment();
 1022+
 1023+ if ( $diffText === '' ) {
 1024+ if ( strval( $comment ) !== '' ) {
 1025+ $text = wfMessage( 'translate-dynagroup-byc', $user, $comment )->escaped();
 1026+ } else {
 1027+ $text = wfMessage( 'translate-dynagroup-by', $user )->escaped();
 1028+ }
 1029+ } else {
 1030+ if ( strval( $comment ) !== '' ) {
 1031+ $text = wfMessage( 'translate-dynagroup-lastc', $user, $comment )->escaped();
 1032+ } else {
 1033+ $text = wfMessage( 'translate-dynagroup-last', $user )->escaped();
 1034+ }
 1035+ }
 1036+
 1037+ return TranslateUtils::fieldset( $text, $diffText, array( 'class' => 'mw-sp-translate-latestchange' ) );
 1038+ }
 1039+
9851040 /**
9861041 * @param $label string
9871042 * @return string
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -413,6 +413,11 @@
414414 'translate-dynagroup-recent-label' => 'Recent translations',
415415 'translate-dynagroup-recent-desc' => 'This message group shows all recent translations into this language.
416416 Most useful with Accept messages or Review all translations task.',
 417+
 418+ 'translate-dynagroup-by' => 'Translation made by {{GENDER:$1|$1}}',
 419+ 'translate-dynagroup-byc' => 'Translation made by {{GENDER:$1|$1}} ($2)',
 420+ 'translate-dynagroup-last' => 'Latest change by {{GENDER:$1|$1}}',
 421+ 'translate-dynagroup-lastc' => 'Latest change by {{GENDER:$1|$1}} ($2)',
417422 );
418423
419424 /** Message documentation (Message documentation)
Index: trunk/extensions/Translate/resources/ext.translate.quickedit.css
@@ -88,3 +88,7 @@
8989 .mw-sp-translate-edit-warnings { background-color: #FFDBDB; }
9090 .mw-translate-definition-preview { padding: 3px; }
9191 .mw-translate-edit-tmsugs { background-color: #C0F9B6; }
 92+
 93+.mw-sp-translate-latestchange {
 94+ padding-bottom: 0px;
 95+}

Status & tagging log