Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -288,13 +288,14 @@ |
289 | 289 | $en = $group->getMessage( $key, 'en' ); |
290 | 290 | $xx = $group->getMessage( $key, $code ); |
291 | 291 | |
292 | | - |
293 | 292 | // Set-up the content area contents properly and not randomly as in |
294 | 293 | // MediaWiki core. $translation is also used for checks later on. Also |
295 | 294 | // add the fuzzy string if necessary. |
296 | 295 | $translation = TranslateUtils::getMessageContent( $key, $code, $nsMain ); |
| 296 | + $isfuzzy = false; |
297 | 297 | if ( $translation !== null ) { |
298 | | - if ( !self::hasFuzzyString( $translation) && self::isFuzzy( $object->mTitle ) ) { |
| 298 | + $isfuzzy = self::isFuzzy( $object->mTitle ); |
| 299 | + if ( !self::hasFuzzyString( $translation) && $isfuzzy ) { |
299 | 300 | $translation = TRANSLATE_FUZZY . $translation; |
300 | 301 | } |
301 | 302 | } else { |
— | — | @@ -402,8 +403,11 @@ |
403 | 404 | } |
404 | 405 | } |
405 | 406 | |
| 407 | + // Diff of current version of original, and its version before last edit of translation, if any |
406 | 408 | global $wgEnablePageTranslation; |
407 | | - if ( $wgEnablePageTranslation && $group instanceof WikiPageMessageGroup ) { |
| 409 | + $showdiff1 = ( $wgEnablePageTranslation && $group instanceof WikiPageMessageGroup ); |
| 410 | + $showdiff2 = ( $isfuzzy ); |
| 411 | + if ( $showdiff1 ) { |
408 | 412 | // TODO: encapsulate somewhere |
409 | 413 | $page = TranslatablePage::newFromTitle( $group->title ); |
410 | 414 | $rev = $page->getTransRev( "$key/$code" ); |
— | — | @@ -417,23 +421,76 @@ |
418 | 422 | $oldtext = $section->getTextForTrans(); |
419 | 423 | } |
420 | 424 | } |
421 | | - |
422 | 425 | foreach ( $page->getParse()->getSectionsForSave() as $section ) { |
423 | 426 | if ( $group->title->getPrefixedDBKey() .'/'. $section->id === $key ) { |
424 | 427 | $newtext = $section->getTextForTrans(); |
425 | 428 | } |
426 | 429 | } |
| 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__ . ' (' . get_class( $this ) . ')'; |
| 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(); |
427 | 475 | |
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 | + } |
435 | 482 | } |
436 | 483 | } |
437 | 484 | } |
| 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 | + } |
438 | 495 | |
439 | 496 | // Definition |
440 | 497 | if ( $en !== null ) { |
— | — | @@ -489,6 +546,45 @@ |
490 | 547 | return $res === $id; |
491 | 548 | } |
492 | 549 | |
| 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__ . ' (' . get_class( $this ) . ')'; |
| 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 | + |
493 | 589 | public static function isMessageNamespace( Title $title ) { |
494 | 590 | global $wgTranslateMessageNamespaces;; |
495 | 591 | $namespace = $title->getNamespace(); |