/** * Displays the sections and changes for the user to review * @param TranslatablePage $page * @param array $sections */ public function showPage(TranslatablePage $page, array $sections) { global $wgContLang; $out = $this->getOutput(); $out->setSubtitle(Linker::link($page->getTitle())); $out->addModules('ext.translate.special.pagetranslation'); $out->addWikiMsg('tpt-showpage-intro'); $formParams = array('method' => 'post', 'action' => $this->getPageTitle()->getFullURL(), 'class' => 'mw-tpt-sp-markform'); $out->addHTML(Xml::openElement('form', $formParams) . Html::hidden('title', $this->getPageTitle()->getPrefixedText()) . Html::hidden('revision', $page->getRevision()) . Html::hidden('target', $page->getTitle()->getPrefixedtext()) . Html::hidden('token', $this->getUser()->getEditToken())); $out->wrapWikiMsg('==$1==', 'tpt-sections-oldnew'); $diffOld = $this->msg('tpt-diff-old')->escaped(); $diffNew = $this->msg('tpt-diff-new')->escaped(); $hasChanges = false; // Check whether page title was previously marked for translation. // If the page is marked for translation the first time, default to checked. $defaultChecked = $page->hasPageDisplayTitle(); /** * @var TPSection $s */ foreach ($sections as $s) { if ($s->name === 'Page display title') { // Set section type as new if title previously unchecked $s->type = $defaultChecked ? $s->type : 'new'; // Checkbox for page title optional translation $this->getOutput()->addHTML(Xml::checkLabel($this->msg('tpt-translate-title')->text(), 'translatetitle', 'mw-translate-title', $defaultChecked)); } if ($s->type === 'new') { $hasChanges = true; $name = $this->msg('tpt-section-new', $s->name)->escaped(); } else { $name = $this->msg('tpt-section', $s->name)->escaped(); } if ($s->type === 'changed') { $hasChanges = true; $diff = new DifferenceEngine(); if (method_exists('DifferenceEngine', 'setTextLanguage')) { $diff->setTextLanguage($wgContLang); } $diff->setReducedLineNumbers(); $oldContent = ContentHandler::makeContent($s->getOldText(), $diff->getTitle()); $newContent = ContentHandler::makeContent($s->getText(), $diff->getTitle()); $diff->setContent($oldContent, $newContent); $text = $diff->getDiff($diffOld, $diffNew); $diffOld = $diffNew = null; $diff->showDiffStyle(); $id = "tpt-sect-{$s->id}-action-nofuzzy"; $checkLabel = Xml::checkLabel($this->msg('tpt-action-nofuzzy')->text(), $id, $id, false); $text = $checkLabel . $text; } else { $text = TranslateUtils::convertWhiteSpaceToHTML($s->getText()); } # For changed text, the language is set by $diff->setTextLanguage() $lang = $s->type === 'changed' ? null : $wgContLang; $out->addHTML(MessageWebImporter::makeSectionElement($name, $s->type, $text, $lang)); } $deletedSections = $page->getParse()->getDeletedSections(); if (count($deletedSections)) { $hasChanges = true; $out->wrapWikiMsg('==$1==', 'tpt-sections-deleted'); /** * @var TPSection $s */ foreach ($deletedSections as $s) { $name = $this->msg('tpt-section-deleted', $s->id)->escaped(); $text = TranslateUtils::convertWhiteSpaceToHTML($s->getText()); $out->addHTML(MessageWebImporter::makeSectionElement($name, $s->type, $text, $wgContLang)); } } // Display template changes if applicable if ($page->getMarkedTag() !== false) { $hasChanges = true; $newTemplate = $page->getParse()->getTemplatePretty(); $oldPage = TranslatablePage::newFromRevision($page->getTitle(), $page->getMarkedTag()); $oldTemplate = $oldPage->getParse()->getTemplatePretty(); if ($oldTemplate !== $newTemplate) { $out->wrapWikiMsg('==$1==', 'tpt-sections-template'); $diff = new DifferenceEngine(); if (method_exists('DifferenceEngine', 'setTextLanguage')) { $diff->setTextLanguage($wgContLang); } $oldContent = ContentHandler::makeContent($oldTemplate, $diff->getTitle()); $newContent = ContentHandler::makeContent($newTemplate, $diff->getTitle()); $diff->setContent($oldContent, $newContent); $text = $diff->getDiff($this->msg('tpt-diff-old')->escaped(), $this->msg('tpt-diff-new')->escaped()); $diff->showDiffStyle(); $diff->setReducedLineNumbers(); $contentParams = array('class' => 'mw-tpt-sp-content'); $out->addHTML(Xml::tags('div', $contentParams, $text)); } } if (!$hasChanges) { $out->wrapWikiMsg('<div class="successbox">$1</div>', 'tpt-mark-nochanges'); } $this->priorityLanguagesForm($page); $out->addHTML(Xml::submitButton($this->msg('tpt-submit')->text()) . Xml::closeElement('form')); }
/** * Displays the sections and changes for the user to review * @param $page TranslatablePage * @param $sections array */ public function showPage( TranslatablePage $page, Array $sections ) { global $wgOut, $wgContLang; $wgOut->setSubtitle( $this->user->getSkin()->link( $page->getTitle() ) ); $wgOut->addModules( 'ext.translate.special.pagetranslation' ); $wgOut->addWikiMsg( 'tpt-showpage-intro' ); $formParams = array( 'method' => 'post', 'action' => $this->getTitle()->getFullURL(), 'class' => 'mw-tpt-sp-markform', ); $wgOut->addHTML( Xml::openElement( 'form', $formParams ) . Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . Html::hidden( 'revision', $page->getRevision() ) . Html::hidden( 'target', $page->getTitle()->getPrefixedtext() ) . Html::hidden( 'token', $this->user->editToken() ) ); $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-oldnew' ); $diffOld = wfMsgHtml( 'tpt-diff-old' ); $diffNew = wfMsgHtml( 'tpt-diff-new' ); foreach ( $sections as $s ) { if ( $s->type === 'new' ) { $input = Xml::input( 'tpt-sect-' . $s->id, 15, $s->name ); $name = wfMsgHtml( 'tpt-section-new', $input ); } else { $name = wfMsgHtml( 'tpt-section', htmlspecialchars( $s->name ) ); } if ( $s->type === 'changed' ) { $diff = new DifferenceEngine; if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) { $diff->setTextLanguage( $wgContLang ); } $diff->setReducedLineNumbers(); $diff->setText( $s->getOldText(), $s->getText() ); $text = $diff->getDiff( $diffOld, $diffNew ); $diffOld = $diffNew = null; $diff->showDiffStyle(); $id = "tpt-sect-{$s->id}-action-nofuzzy"; $text = Xml::checkLabel( wfMsg( 'tpt-action-nofuzzy' ), $id, $id, false ) . $text; } else { $text = TranslateUtils::convertWhiteSpaceToHTML( $s->getText() ); } # For changed text, the language is set by $diff->setTextLanguage() $lang = $s->type === 'changed' ? null : $wgContLang; $wgOut->addHTML( MessageWebImporter::makeSectionElement( $name, $s->type, $text, $lang ) ); } $deletedSections = $page->getParse()->getDeletedSections(); if ( count( $deletedSections ) ) { $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-deleted' ); foreach ( $deletedSections as $s ) { $name = wfMsgHtml( 'tpt-section-deleted', htmlspecialchars( $s->id ) ); $text = TranslateUtils::convertWhiteSpaceToHTML( $s->getText() ); $wgOut->addHTML( MessageWebImporter::makeSectionElement( $name, $s->type, $text, $wgContLang ) ); } } // Display template changes if applicable if ( $page->getMarkedTag() !== false ) { $newTemplate = $page->getParse()->getTemplatePretty(); $oldPage = TranslatablePage::newFromRevision( $page->getTitle(), $page->getMarkedTag() ); $oldTemplate = $oldPage->getParse()->getTemplatePretty(); if ( $oldTemplate !== $newTemplate ) { $wgOut->wrapWikiMsg( '==$1==', 'tpt-sections-template' ); $diff = new DifferenceEngine; if ( method_exists( 'DifferenceEngine', 'setTextLanguage' ) ) { $diff->setTextLanguage( $wgContLang ); } $diff->setText( $oldTemplate, $newTemplate ); $text = $diff->getDiff( wfMsgHtml( 'tpt-diff-old' ), wfMsgHtml( 'tpt-diff-new' ) ); $diff->showDiffStyle(); $diff->setReducedLineNumbers(); $contentParams = array( 'class' => 'mw-tpt-sp-content' ); $wgOut->addHTML( Xml::tags( 'div', $contentParams, $text ) ); } } $wgOut->addHTML( Xml::submitButton( wfMsg( 'tpt-submit' ) ) . Xml::closeElement( 'form' ) ); }