27 $revTagStore = Services::getInstance()->getRevTagStore();
29 $translationRevision = $revTagStore->getTransver( $this->handle->getTitle() );
30 if ( $translationRevision ===
null ) {
34 $sourceLanguage = $this->group->getSourceLanguage();
35 $definitionTitle = Title::makeTitleSafe(
36 $this->handle->getTitle()->getNamespace(),
37 $this->handle->getKey() .
'/' . $sourceLanguage
40 if ( !$definitionTitle || !$definitionTitle->exists() ) {
45 $mwInstance = MediaWikiServices::getInstance();
46 $revisionLookup = $mwInstance->getRevisionLookup();
47 $oldRevRecord = $revisionLookup->getRevisionById( $translationRevision );
48 if ( !$oldRevRecord ) {
53 if ( $oldRevRecord->getPageId() !== $definitionTitle->getArticleID() ) {
54 throw new TranslationHelperException(
55 'Translation unit definition id does not match old revision definition id'
59 $oldContent = $oldRevRecord->getContent( SlotRecord::MAIN );
60 $newContent = $this->dataProvider->getDefinitionContent();
63 throw new TranslationHelperException(
'Old definition version does not exist anymore' );
66 if ( !$oldContent instanceof WikitextContent || !$newContent instanceof WikitextContent ) {
67 throw new TranslationHelperException(
'Can only work on Wikitext content' );
70 if ( $oldContent->equals( $newContent ) ) {
71 throw new TranslationHelperException(
'No changes' );
74 $diff =
new DifferenceEngine( $this->context );
75 $diff->setTextLanguage(
76 $mwInstance->getLanguageFactory()->getLanguage( $sourceLanguage )
78 $diff->setContent( $oldContent, $newContent );
79 $diff->setReducedLineNumbers();
80 $diff->showDiffStyle();
82 $html = $diff->getDiff(
83 $this->context->msg(
'tpt-diff-old' )->escaped(),
84 $this->context->msg(
'tpt-diff-new' )->escaped()
88 'value_old' => $oldContent->getText(),
89 'value_new' => $newContent->getText(),
90 'revisionid_old' => $oldRevRecord->getId(),
91 'revisionid_new' => $definitionTitle->getLatestRevID(),
92 'language' => $this->group->getSourceLanguage(),