r61172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61171‎ | r61172 | r61173 >
Date:16:31, 17 January 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Collapse tm suggestions to use available space efficiently

Identical suggestions are collapsed into one line. Maximum of three
lines are now shown after collapsing. Backlinks are represented as
a bullet (•, hard-coded) after the accuracy display.

Fix also backlink generation to automatically add action=edit
and loadgroup with correct group id.
Modified paths:
  • /trunk/extensions/Translate/README (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -12,7 +12,7 @@
1313 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
1414 */
1515
16 -define( 'TRANSLATE_VERSION', '2010-01-04' );
 16+define( 'TRANSLATE_VERSION', '2010-01-16' );
1717
1818 $wgExtensionCredits['specialpage'][] = array(
1919 'path' => __FILE__,
Index: trunk/extensions/Translate/README
@@ -34,11 +34,15 @@
3535 }
3636 </code>
3737
 38+== Changes in ??? ==
 39+* 2010-01-16 Translation memory suggestions are aggregated intelligently to save space
 40+ There is link back to the original message in tm suggestions
 41+ tm-export superceded dump-tm
 42+
3843 == Changes in version 12 ==
3944 - Page translation
4045 - New fuzzy system, should be faster now
4146 - Edit are consistently filled when starting translation
42 -- ???
4347
4448 == Changes in version 11 ==
4549 * 2009-05-09
Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -133,13 +133,13 @@
134134 global $wgTranslateTM;
135135 if ( $wgTranslateTM === false ) return null;
136136 if ( !$this->targetLanguage ) return null;
 137+ if ( strval( $this->getDefinition() ) === '' ) return null;
137138
138139 // Needed data
139140 $code = $this->targetLanguage;
140141 $definition = $this->getDefinition();
 142+ $ns = $this->title->getNsText();
141143
142 - $boxes = array();
143 -
144144 // Fetch suggestions
145145 $server = $wgTranslateTM['server'];
146146 $port = $wgTranslateTM['port'];
@@ -148,24 +148,45 @@
149149 $url = "$server:$port/tmserver/en/$code/unit/$def";
150150 $suggestions = Http::get( $url, $timeout );
151151
 152+ $sugFields = array();
152153 // Parse suggestions, but limit to three (in case there would be more)
153154 if ( $suggestions !== false ) {
154155 $suggestions = json_decode( $suggestions, true );
155 - $suggestions = array_slice( $suggestions, 0, 3 );
156156 foreach ( $suggestions as $s ) {
157 - $label = wfMsgHtml( 'translate-edit-tmmatch' , sprintf( '%.2f', $s['quality'] ) );
 157+ // No use to suggest them what they are currently viewing
 158+ if ( $s['context'] === "$ns:{$this->page}" ) continue;
 159+
 160+ $accuracy = wfMsgHtml( 'translate-edit-tmmatch' , sprintf( '%.2f', $s['quality'] ) );
 161+ $legend = array( $accuracy => array() );
 162+
158163 $source_page = Title::newFromText( $s['context'] . "/$code" );
159164 if ( $source_page ) {
160 - $label = self::editLink( $source_page,
161 - htmlspecialchars( $label ), array( 'action' => 'edit' )
162 - );
 165+ $legend[$accuracy][] = self::editLink( $source_page, '•' );
163166 }
 167+
164168 $text = TranslateUtils::convertWhiteSpaceToHTML( $s['target'] );
165169 $params = array( 'class' => 'mw-sp-translate-edit-tmsug', 'title' => $s['source'] );
166 - $boxes[] = Html::rawElement( 'div', $params, self::legend( $label ) . $text . self::clear() );
 170+
 171+ if ( isset( $sugFields[$s['target']] ) ) {
 172+ $sugFields[$s['target']][2] = array_merge_recursive( $sugFields[$s['target']][2], $legend );
 173+ } else {
 174+ $sugFields[$s['target']] = array( $text, $params, $legend );
 175+ }
167176 }
 177+
 178+ $boxes = array();
 179+ foreach( $sugFields as $field ) {
 180+ list( $text, $params, $label ) = $field;
 181+ $legend = array();
 182+ foreach ( $label as $acc => $links ) { $legend[] = $acc . ' ' . implode( " ", $links ); }
 183+ $legend = implode( ' | ', $legend );
 184+ $boxes[] = Html::rawElement( 'div', $params, self::legend( $legend ) . $text . self::clear() );
 185+ }
168186 }
169187
 188+ // Limit to three max
 189+ $boxes = array_slice( $boxes, 0, 3 );
 190+
170191 // Enclose if there is more than one box
171192 if ( count( $boxes ) ) {
172193 $sep = Html::element( 'hr', array( 'class' => 'mw-translate-sep' ) );
@@ -259,9 +280,7 @@
260281
261282 $target = Title::makeTitleSafe( $ns, "$page/$fbcode" );
262283 if ( $target ) {
263 - $label = self::editLink( $target,
264 - htmlspecialchars( $label ), array( 'action' => 'edit' )
265 - );
 284+ $label = self::editLink( $target, htmlspecialchars( $label ) );
266285 }
267286
268287 $text = TranslateUtils::convertWhiteSpaceToHTML( $text );
@@ -290,7 +309,7 @@
291310 $ns = $this->title->getNamespace();
292311
293312 $title = Title::makeTitle( $ns, $page . '/' . $wgTranslateDocumentationLanguageCode );
294 - $edit = self::editLink( $title, wfMsgHtml( 'translate-edit-contribute' ), array( 'action' => 'edit' ) );
 313+ $edit = self::editLink( $title, wfMsgHtml( 'translate-edit-contribute' ) );
295314 $info = TranslateUtils::getMessageContent( $page, $wgTranslateDocumentationLanguageCode, $ns );
296315
297316 $class = 'mw-sp-translate-edit-info';
@@ -431,10 +450,15 @@
432451 return TranslateUtils::fieldset( $title, Html::element( 'span', null, $msg ), $attributes );
433452 }
434453
435 -
436454 public static function editLink( $target, $text, $params = array() ) {
437455 global $wgUser;
438456
 457+ list( $page, ) = self::figureMessage( $target );
 458+ $group = TranslateUtils::messageKeyToGroup( $target->getNamespace(), $page );
 459+ if ( $group ) $group = MessageGroups::getGroup( $group );
 460+ $params += array( 'action' => 'edit' );
 461+ if ( $group ) $params += array( 'loadgroup' => $group->getId() );
 462+
439463 $jsEdit = TranslationEditPage::jsEdit( $target );
440464
441465 return $wgUser->getSkin()->link( $target, $text, $jsEdit, $params );

Status & tagging log