jenkins-bot has submitted this change and it was merged.

Change subject: Use Content objects for diffing in UpdatedDefinitionAid
......................................................................


Use Content objects for diffing in UpdatedDefinitionAid

Bug: 47628
Change-Id: I2b0a7648c136d58516013724ef3176b33ec30be3
---
M translationaids/TranslationAid.php
M translationaids/UpdatedDefinitionAid.php
2 files changed, 23 insertions(+), 6 deletions(-)

Approvals:
  Nikerabbit: Looks good to me, approved
  Daniel Kinzler: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/translationaids/TranslationAid.php 
b/translationaids/TranslationAid.php
index 149d25f..9c0f26a 100644
--- a/translationaids/TranslationAid.php
+++ b/translationaids/TranslationAid.php
@@ -83,6 +83,15 @@
        }
 
        /**
+        * @return Content
+        */
+       protected function getDefinitionContent() {
+               $text = $this->getDefinition();
+
+               return ContentHandler::makeContent( $text, 
$this->handle->getTitle() );
+       }
+
+       /**
         * Get the translations in all languages. Cached for performance.
         * Fuzzy translation are not included.
         *
diff --git a/translationaids/UpdatedDefinitionAid.php 
b/translationaids/UpdatedDefinitionAid.php
index e5cc987..7a8357c 100644
--- a/translationaids/UpdatedDefinitionAid.php
+++ b/translationaids/UpdatedDefinitionAid.php
@@ -46,18 +46,26 @@
                        throw new TranslationHelperException( "Old definition 
version doesn't exist anymore" );
                }
 
-               $oldtext = $oldrev->getText();
-               $newtext = $this->getDefinition();
+               $oldContent = $oldrev->getContent();
+               $newContent = $this->getDefinitionContent();
 
-               if ( $oldtext === $newtext ) {
-                       throw new TranslationHelperException( "No changes" );
+               if ( !$oldContent ) {
+                       throw new TranslationHelperException( "Old definition 
version doesn't exist anymore" );
                }
 
-               $diff = new DifferenceEngine;
+               if ( !$oldContent instanceof WikitextContent || !$newContent 
instanceof WikitextContent ) {
+                       throw new TranslationHelperException( 'Can only work on 
Wikitext content' );
+               }
+
+               if ( $oldContent->equals( $newContent ) ) {
+                       throw new TranslationHelperException( 'No changes' );
+               }
+
+               $diff = new DifferenceEngine( $this->context );
                if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) {
                        $diff->setTextLanguage( 
$this->group->getSourceLanguage() );
                }
-               $diff->setText( $oldtext, $newtext );
+               $diff->setContent( $oldContent, $newContent );
                $diff->setReducedLineNumbers();
                $diff->showDiffStyle();
 

-- 
To view, visit https://gerrit.wikimedia.org/r/138352
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2b0a7648c136d58516013724ef3176b33ec30be3
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to