28 $revTagStore = Services::getInstance()->getRevTagStore();
30 $translationRevision = $revTagStore->getTransver( $this->handle->getTitle() );
31 if ( $translationRevision ===
null ) {
35 $sourceLanguage = $this->group->getSourceLanguage();
36 $definitionTitle = Title::makeTitleSafe(
37 $this->handle->getTitle()->getNamespace(),
38 $this->handle->getKey() .
'/' . $sourceLanguage
41 if ( !$definitionTitle || !$definitionTitle->exists() ) {
46 $mwInstance = MediaWikiServices::getInstance();
47 $revisionLookup = $mwInstance->getRevisionLookup();
48 $oldRevRecord = $revisionLookup->getRevisionById( $translationRevision );
49 if ( !$oldRevRecord ) {
54 if ( $oldRevRecord->getPageId() !== $definitionTitle->getArticleID() ) {
55 throw new TranslationHelperException(
56 'Translation unit definition id does not match old revision definition id'
60 $oldContent = $oldRevRecord->getContent( SlotRecord::MAIN );
61 $newContent = $this->dataProvider->getDefinitionContent();
64 throw new TranslationHelperException(
'Old definition version does not exist anymore' );
67 if ( !$oldContent instanceof WikitextContent || !$newContent instanceof WikitextContent ) {
68 throw new TranslationHelperException(
'Can only work on Wikitext content' );
71 if ( $oldContent->equals( $newContent ) ) {
72 throw new TranslationHelperException(
'No changes' );
75 $newRevRecord =
new MutableRevisionRecord( $definitionTitle );
76 $newRevRecord->setContent( SlotRecord::MAIN, $newContent );
78 $diff =
new DifferenceEngine( $this->context );
79 $diff->setTextLanguage( $mwInstance->getLanguageFactory()->getLanguage( $sourceLanguage ) );
80 $diff->setRevisions( $oldRevRecord, $newRevRecord );
81 $diff->setReducedLineNumbers();
82 $diff->showDiffStyle();
84 $html = $diff->getDiff(
85 $this->context->msg(
'tpt-diff-old' )->escaped(),
86 $this->context->msg(
'tpt-diff-new' )->escaped()
90 'value_old' => $oldContent->getText(),
91 'value_new' => $newContent->getText(),
92 'revisionid_old' => $oldRevRecord->getId(),
93 'revisionid_new' => $definitionTitle->getLatestRevID(),
94 'language' => $this->group->getSourceLanguage(),