protected function getTranslationPageDiff() { global $wgEnablePageTranslation; if ( !$wgEnablePageTranslation ) { return null; } $this->mustBeKnownMessage(); if ( !$this->group instanceof WikiPageMessageGroup ) { return null; } // Shortcuts $code = $this->handle->getCode(); $key = $this->handle->getKey(); // TODO: encapsulate somewhere $page = TranslatablePage::newFromTitle( $this->group->getTitle() ); $rev = $page->getTransRev( "$key/$code" ); $latest = $page->getMarkedTag(); if ( $rev === $latest ) { return null; } $oldpage = TranslatablePage::newFromRevision( $this->group->getTitle(), $rev ); $oldtext = $newtext = null; foreach ( $oldpage->getParse()->getSectionsForSave() as $section ) { if ( $this->group->getTitle()->getPrefixedDBKey() . '/' . $section->id === $key ) { $oldtext = $section->getTextForTrans(); } } foreach ( $page->getParse()->getSectionsForSave() as $section ) { if ( $this->group->getTitle()->getPrefixedDBKey() . '/' . $section->id === $key ) { $newtext = $section->getTextForTrans(); } } if ( $oldtext === $newtext ) { return null; } $diff = new DifferenceEngine; if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) { $diff->setTextLanguage( $this->group->getSourceLanguage() ); } $diff->setText( $oldtext, $newtext ); $diff->setReducedLineNumbers(); $diff->showDiffStyle(); return $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) ); }
public static function sourceExport(RequestContext $context, TranslateTask $task = null, MessageGroup $group, array $options) { if ($task || $options['taction'] !== 'export' || !$group instanceof WikiPageMessageGroup) { return true; } $page = TranslatablePage::newFromTitle($group->getTitle()); $collection = $group->initCollection($options['language']); $collection->loadTranslations(DB_MASTER); $text = $page->getParse()->getTranslationPageText($collection); $display = $page->getPageDisplayTitle($options['language']); if ($display) { $text = "{{DISPLAYTITLE:{$display}}}{$text}"; } $output = Html::element('textarea', array('rows' => 25), $text); $context->getOutput()->addHtml($output); return false; }