r56494 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56493‎ | r56494 | r56495 >
Date:08:32, 17 September 2009
Author:purodha
Status:deferred (Comments)
Tags:
Comment:
Fix r56463.
Modified paths:
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -288,13 +288,14 @@
289289 $en = $group->getMessage( $key, 'en' );
290290 $xx = $group->getMessage( $key, $code );
291291
292 -
293292 // Set-up the content area contents properly and not randomly as in
294293 // MediaWiki core. $translation is also used for checks later on. Also
295294 // add the fuzzy string if necessary.
296295 $translation = TranslateUtils::getMessageContent( $key, $code, $nsMain );
 296+ $isfuzzy = false;
297297 if ( $translation !== null ) {
298 - if ( !self::hasFuzzyString( $translation) && self::isFuzzy( $object->mTitle ) ) {
 298+ $isfuzzy = self::isFuzzy( $object->mTitle );
 299+ if ( !self::hasFuzzyString( $translation) && $isfuzzy ) {
299300 $translation = TRANSLATE_FUZZY . $translation;
300301 }
301302 } else {
@@ -402,8 +403,11 @@
403404 }
404405 }
405406
 407+ // Diff of current version of original, and its version before last edit of translation, if any
406408 global $wgEnablePageTranslation;
407 - if ( $wgEnablePageTranslation && $group instanceof WikiPageMessageGroup ) {
 409+ $showdiff1 = ( $wgEnablePageTranslation && $group instanceof WikiPageMessageGroup );
 410+ $showdiff2 = ( $isfuzzy );
 411+ if ( $showdiff1 ) {
408412 // TODO: encapsulate somewhere
409413 $page = TranslatablePage::newFromTitle( $group->title );
410414 $rev = $page->getTransRev( "$key/$code" );
@@ -417,23 +421,76 @@
418422 $oldtext = $section->getTextForTrans();
419423 }
420424 }
421 -
422425 foreach ( $page->getParse()->getSectionsForSave() as $section ) {
423426 if ( $group->title->getPrefixedDBKey() .'/'. $section->id === $key ) {
424427 $newtext = $section->getTextForTrans();
425428 }
426429 }
 430+ }
 431+ else
 432+ {
 433+ }
 434+ } elseif ( $showdiff2 ) {
 435+ $newtext = $en; // FIXME: this should be sufficient, but this seems to come from the MessagesEnphp file instead of most recent the data base record, which is wrong.
 436+ $en_title = Title::makeTitle( $nsMain, $key . '/en' ); // workaround
 437+ $revision = Revision::newFromTitle($en_title); // workaround
 438+ $newtext = $revision->getText(); // workaround
 439+ $oldtext = FALSE;
 440+ // find timestamp of last revision of the current page before it was fuzzied.
 441+ $rev = $object->getBaseRevision()->getId();
 442+ if ( $rev )
 443+ {
 444+ $fname = __METHOD__ . ' (TranslateEditAddons)';
 445+ $dbr = wfGetDB( DB_SLAVE );
 446+ $pid = $dbr->selectField( 'revision', 'rev_page', array( 'rev_id' => $rev ), $fname );
 447+ if ( $pid )
 448+ {
 449+ $not_fuzzy = TranslateEditAddons::findLastRevisionByTag( $rev, 'fuzzy', FALSE );
 450+ if ( $not_fuzzy )
 451+ {
 452+ $rev_en = $dbr->selectRow(
 453+ array ( 'revision', 'page'),
 454+ 'rev_id',
 455+ array(
 456+ 'page_namespace' => $nsMain,
 457+ 'page_title' => $key . '/en',
 458+ 'rev_page = page_id',
 459+ 'rev_timestamp < '.$not_fuzzy->rev_timestamp
 460+ ),
 461+ $fname,
 462+ array(
 463+ 'ORDER BY' => 'rev_timestamp DESC',
 464+ 'LIMIT' => 1
 465+ )
 466+ );
 467+ if ( $rev_en )
 468+ {
 469+ $rev_en = $rev_en->rev_id;
 470+ }
 471+ if ( $rev_en )
 472+ {
 473+ $revision = Revision::newFromId($rev_en);
 474+ $oldtext = $revision->getText();
427475
428 - if ( $oldtext !== $newtext ) {
429 - wfLoadExtensionMessages( 'PageTranslation' );
430 - $diff = new DifferenceEngine;
431 - $diff->setText( $oldtext, $newtext );
432 - $diff->setReducedLineNumbers();
433 - $boxes[] = $diff->getDiff( wfMsgHtml('tpt-diff-old'), wfMsgHtml('tpt-diff-new') );
434 - $diff->showDiffStyle();
 476+ // FIXME: Own header messages for this case
 477+ // FIXME: Links to the revision pages
 478+ // FIXME: Previous and next links
 479+ // FIXME: Allow switching to HTMLdiff
 480+ }
 481+ }
435482 }
436483 }
437484 }
 485+ if ( ( $showdiff1 || $showdiff2 ) && ( $oldtext !== $newtext ) && ( $oldtext !== FALSE ) ) {
 486+ wfLoadExtensionMessages( 'PageTranslation' );
 487+ $diff = new DifferenceEngine;
 488+ if ( $showdiff1 )
 489+ $diff->setReducedLineNumbers();
 490+ $diff->setText( $oldtext, $newtext );
 491+ $diff->showDiffStyle();
 492+ $boxes[] = $diff->getDiff( wfMsgHtml('tpt-diff-old'), wfMsgHtml('tpt-diff-new') );
 493+ // FIXME: If there are versions in between say so.
 494+ }
438495
439496 // Definition
440497 if ( $en !== null ) {
@@ -489,6 +546,45 @@
490547 return $res === $id;
491548 }
492549
 550+ /**
 551+ * Get last revision of a page (not) having a specific revision tag
 552+ * @param $pageId page Id
 553+ * @param $set TRUE: find youngest revison having the tag
 554+ * FALSE: find youngest revison *not* having the tag
 555+ * @param $rtt_name revision tag name to look for
 556+ * @return FALSE: no such revision found
 557+ * otherwise,
 558+ * if $not is TRUE: object ( rev_id, rev_timestamp, NULL, NULL )
 559+ * if $not is FALSE: object ( rev_id, rev_timestamp, rt_value, rt_revision )
 560+ * TODO: move to a more appropriate place, maybe in core.
 561+ * @author Purodha
 562+ */
 563+ public static function findLastRevisionByTag( $pageId, $rtt_name='fuzzy', $set=false ) {
 564+ $fname = __METHOD__ . ' (TranslateEditAddons)';
 565+ $dbr = wfGetDB( DB_SLAVE );
 566+ $id = $dbr->selectField( 'revtag_type', 'rtt_id', array( 'rtt_name' => $rtt_name ), $fname );
 567+ $tables = array( 'revision' , 'revtag' );
 568+ $fields = array( 'rev_id', 'rev_timestamp', 'rt_value', 'rt_revision' );
 569+ $conds = array(
 570+ 'rev_page' => $pageId,
 571+ );
 572+ if ( $set )
 573+ {
 574+ $conds[ 'rt_page' ] = $pageId;
 575+ $conds[ 'rt_type' ] = $id;
 576+ }
 577+ else
 578+ {
 579+ $conds[] = 'rt_page IS NULL';
 580+ $conds[] = 'rt_type IS NULL';
 581+ }
 582+ $join_conds [ 'revtag' ] = array('LEFT JOIN', 'rev_id = rt_revision');
 583+ $options['ORDER BY'] = 'rev_timestamp DESC';
 584+ $options['LIMIT'] = 1;
 585+ $res = $dbr->selectRow( $tables, $fields, $conds, $fname, $options, $join_conds );
 586+ return $res;
 587+ }
 588+
493589 public static function isMessageNamespace( Title $title ) {
494590 global $wgTranslateMessageNamespaces;;
495591 $namespace = $title->getNamespace();

Follow-up revisions

RevisionCommit summaryAuthorDate
r56598Revert r56494 (second try of r56465). Causes fatals. PHP Fatal error: Call t...siebrand14:03, 18 September 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56463Fix link to author views.demon23:59, 16 September 2009

Comments

#Comment by 😂 (talk | contribs)   17:21, 17 September 2009

Probably referring to r56465, but definitely not r56463

#Comment by Purodha (talk | contribs)   21:27, 17 September 2009

True, refers to r56465.

Status & tagging log