本文整理汇总了PHP中TranslateUtils::convertWhiteSpaceToHTML方法的典型用法代码示例。如果您正苦于以下问题:PHP TranslateUtils::convertWhiteSpaceToHTML方法的具体用法?PHP TranslateUtils::convertWhiteSpaceToHTML怎么用?PHP TranslateUtils::convertWhiteSpaceToHTML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TranslateUtils
的用法示例。
在下文中一共展示了TranslateUtils::convertWhiteSpaceToHTML方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: suggestionField
/**
* @param $text string
* @return string
*/
public function suggestionField($text)
{
static $counter = 0;
$code = $this->getTargetLanguage();
$counter++;
$dialogID = $this->dialogID();
$id = Sanitizer::escapeId("tmsug-{$dialogID}-{$counter}");
$contents = Html::rawElement('div', array('lang' => $code, 'dir' => Language::factory($code)->getDir()), TranslateUtils::convertWhiteSpaceToHTML($text));
$contents .= $this->wrapInsert($id, $text);
return $this->adder($id, $code) . "\n" . $contents;
}
示例2: execute
public function execute( $messages ) {
global $wgOut, $wgLang;
$this->out = $wgOut;
// Set up diff engine
$diff = new DifferenceEngine;
$diff->showDiffStyle();
$diff->setReducedLineNumbers();
// Check whether we do processing
$process = $this->allowProcess();
// Initialise collection
$group = $this->getGroup();
$code = $this->getCode();
$collection = $group->initCollection( $code );
$collection->loadTranslations();
$this->out->addHTML( $this->doHeader() );
// Determine changes
$alldone = $process;
$changed = array();
foreach ( $messages as $key => $value ) {
$fuzzy = $old = false;
if ( isset( $collection[$key] ) ) {
$old = $collection[$key]->translation();
}
// No changes at all, ignore
if ( strval( $old ) === strval( $value ) ) {
continue;
}
if ( $old === false ) {
$name = wfMsgHtml( 'translate-manage-import-new',
'<code style="font-weight:normal;">' . htmlspecialchars( $key ) . '</code>'
);
$text = TranslateUtils::convertWhiteSpaceToHTML( $value );
$changed[] = self::makeSectionElement( $name, 'new', $text );
} else {
$diff->setText( $old, $value );
$text = $diff->getDiff( '', '' );
$type = 'changed';
global $wgRequest;
$action = $wgRequest->getVal( self::escapeNameForPHP( "action-$type-$key" ) );
if ( $process ) {
if ( !count( $changed ) ) {
$changed[] = '<ul>';
}
if ( $action === null ) {
$message = wfMsgExt( 'translate-manage-inconsistent', 'parseinline', wfEscapeWikiText( "action-$type-$key" ) );
$changed[] = "<li>$message</li></ul>";
$process = false;
} else {
// Check processing time
if ( !isset( $this->time ) ) {
$this->time = wfTimestamp();
}
$message = self::doAction(
$action,
$group,
$key,
$code,
$value
);
$key = array_shift( $message );
$params = $message;
$message = wfMsgExt( $key, 'parseinline', $params );
$changed[] = "<li>$message</li>";
if ( $this->checkProcessTime() ) {
$process = false;
$duration = $wgLang->formatNum( $this->processingTime );
$message = wfMsgExt( 'translate-manage-toolong', 'parseinline', $duration );
$changed[] = "<li>$message</li></ul>";
}
continue;
}
}
$alldone = false;
$actions = $this->getActions();
$defaction = $this->getDefaultAction( $fuzzy, $action );
$act = array();
foreach ( $actions as $action ) {
$label = wfMsg( "translate-manage-action-$action" );
$name = self::escapeNameForPHP( "action-$type-$key" );
$id = Sanitizer::escapeId( "action-$key-$action" );
//.........这里部分代码省略.........
示例3: contents
public function contents() {
$optional = wfMsgHtml( 'translate-optional' );
$this->doLinkBatch();
$sourceLang = Language::factory( $this->group->getSourceLanguage() );
$targetLang = Language::factory( $this->collection->getLanguage() );
$titleMap = $this->collection->keys();
$output = '';
$this->collection->initMessages(); // Just to be sure
foreach ( $this->collection as $key => $m ) {
$tools = array();
$title = $titleMap[$key];
$original = $m->definition();
if ( $m->translation() !== null ) {
$message = $m->translation();
$rclasses = self::getLanguageAttributes( $targetLang );
$rclasses['class'] = 'translated';
} else {
$message = $original;
$rclasses = self::getLanguageAttributes( $sourceLang );
$rclasses['class'] = 'untranslated';
}
global $wgLang;
$niceTitle = htmlspecialchars( $wgLang->truncate( $title->getPrefixedText(), -35 ) );
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker() : new Linker();
$tools['edit'] = $linker->link(
$title,
$niceTitle,
TranslationEditPage::jsEdit( $title, $this->group->getId() ),
array( 'action' => 'edit' ) + $this->editLinkParams,
'known'
);
$anchor = 'msg_' . $key;
$anchor = Xml::element( 'a', array( 'id' => $anchor, 'href' => "#$anchor" ), "↓" );
$extra = '';
if ( $m->hasTag( 'optional' ) ) {
$extra = '<br />' . $optional;
}
$leftColumn = $this->getReviewButton( $m ) . $anchor . $tools['edit'] . $extra . $this->getReviewStatus( $m );
if ( $this->reviewMode && $original !== $message ) {
$output .= Xml::tags( 'tr', array( 'class' => 'orig' ),
Xml::tags( 'td', array( 'rowspan' => '2' ), $leftColumn ) .
Xml::tags( 'td', self::getLanguageAttributes( $sourceLang ),
TranslateUtils::convertWhiteSpaceToHTML( $original ) )
);
$output .= Xml::tags( 'tr', array( 'class' => 'new' ),
Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) )
);
} else {
$output .= Xml::tags( 'tr', array( 'class' => 'def' ),
Xml::tags( 'td', null, $leftColumn ) .
Xml::tags( 'td', $rclasses, TranslateUtils::convertWhiteSpaceToHTML( $message ) )
);
}
$output .= "\n";
}
return $output;
}
示例4: contents
public function contents()
{
$optional = $this->context->msg('translate-optional')->escaped();
$this->doLinkBatch();
$sourceLang = Language::factory($this->group->getSourceLanguage());
$targetLang = Language::factory($this->collection->getLanguage());
$titleMap = $this->collection->keys();
$output = '';
$this->collection->initMessages();
// Just to be sure
/**
* @var TMessage $m
*/
foreach ($this->collection as $key => $m) {
$tools = array();
/**
* @var Title $title
*/
$title = $titleMap[$key];
$original = $m->definition();
$translation = $m->translation();
$hasTranslation = $translation !== null;
if ($hasTranslation) {
$message = $translation;
$extraAttribs = self::getLanguageAttributes($targetLang);
} else {
$message = $original;
$extraAttribs = self::getLanguageAttributes($sourceLang);
}
Hooks::run('TranslateFormatMessageBeforeTable', array(&$message, $m, $this->group, $targetLang, &$extraAttribs));
// Using Html::element( a ) because Linker::link is memory hog.
// It takes about 20 KiB per call, and that times 5000 is quite
// a lot of memory.
$niceTitle = htmlspecialchars($this->context->getLanguage()->truncate($title->getPrefixedText(), -35));
$linkAttribs = array('href' => $title->getLocalUrl(array('action' => 'edit')));
$linkAttribs += TranslationEditPage::jsEdit($title, $this->group->getId());
$tools['edit'] = Html::element('a', $linkAttribs, $niceTitle);
$anchor = 'msg_' . $key;
$anchor = Xml::element('a', array('id' => $anchor, 'href' => "#{$anchor}"), "↓");
$extra = '';
if ($m->hasTag('optional')) {
$extra = '<br />' . $optional;
}
$tqeData = $extraAttribs + array('data-title' => $title->getPrefixedText(), 'data-group' => $this->group->getId(), 'id' => 'tqe-anchor-' . substr(sha1($title->getPrefixedText()), 0, 12), 'class' => 'tqe-inlineeditable ' . ($hasTranslation ? 'translated' : 'untranslated'));
$button = $this->getReviewButton($m);
$status = $this->getReviewStatus($m);
$leftColumn = $button . $anchor . $tools['edit'] . $extra . $status;
if ($this->reviewMode) {
$output .= Xml::tags('tr', array('class' => 'orig'), Xml::tags('td', array('rowspan' => '2'), $leftColumn) . Xml::tags('td', self::getLanguageAttributes($sourceLang), TranslateUtils::convertWhiteSpaceToHTML($original)));
$output .= Xml::tags('tr', null, Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
} else {
$output .= Xml::tags('tr', array('class' => 'def'), Xml::tags('td', null, $leftColumn) . Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
}
$output .= "\n";
}
return $output;
}
示例5: getOtherLanguagesBox
public function getOtherLanguagesBox()
{
$code = $this->handle->getCode();
$page = $this->handle->getKey();
$ns = $this->handle->getTitle()->getNamespace();
$boxes = array();
foreach (self::getFallbacks($code) as $fbcode) {
$text = TranslateUtils::getMessageContent($page, $fbcode, $ns);
if ($text === null) {
continue;
}
$context = RequestContext::getMain();
$label = TranslateUtils::getLanguageName($fbcode, $context->getLanguage()->getCode()) . $context->msg('word-separator')->text() . $context->msg('parentheses', wfBCP47($fbcode))->text();
$target = Title::makeTitleSafe($ns, "{$page}/{$fbcode}");
if ($target) {
$label = self::ajaxEditLink($target, htmlspecialchars($label));
}
$dialogID = $this->dialogID();
$id = Sanitizer::escapeId("other-{$fbcode}-{$dialogID}");
$params = array('class' => 'mw-translate-edit-item');
$display = TranslateUtils::convertWhiteSpaceToHTML($text);
$display = Html::rawElement('div', array('lang' => $fbcode, 'dir' => Language::factory($fbcode)->getDir()), $display);
$contents = self::legend($label) . "\n" . $this->adder($id, $fbcode) . $display . self::clear();
$boxes[] = Html::rawElement('div', $params, $contents) . $this->wrapInsert($id, $text);
}
if (count($boxes)) {
$sep = Html::element('hr', array('class' => 'mw-translate-sep'));
return TranslateUtils::fieldset(wfMessage('translate-edit-in-other-languages', $page)->escaped(), implode("{$sep}\n", $boxes), array('class' => 'mw-sp-translate-edit-inother'));
}
return null;
}
示例6: showTranslations
/**
* Builds a table with all translations of $title.
*
* @param $title Title (default: null)
* @return void
*/
function showTranslations(Title $title)
{
global $wgOut, $wgUser, $wgLang;
$sk = $wgUser->getSkin();
$namespace = $title->getNamespace();
$message = $title->getDBkey();
$inMessageGroup = TranslateUtils::messageKeyToGroup($title->getNamespace(), $title->getText());
if (!$inMessageGroup) {
$wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText());
return;
}
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('page', array('page_namespace', 'page_title'), array('page_namespace' => $namespace, 'page_title ' . $dbr->buildLike("{$message}/", $dbr->anyString())), __METHOD__, array('ORDER BY' => 'page_title', 'USE INDEX' => 'name_title'));
if (!$res->numRows()) {
$wgOut->addWikiMsg('translate-translations-no-message', $title->getPrefixedText());
return;
} else {
$wgOut->addWikiMsg('translate-translations-count', $wgLang->formatNum($res->numRows()));
}
// Normal output.
$titles = array();
foreach ($res as $s) {
$titles[] = $s->page_title;
}
$pageInfo = TranslateUtils::getContents($titles, $namespace);
$tableheader = Xml::openElement('table', array('class' => 'mw-sp-translate-table sortable'));
$tableheader .= Xml::openElement('tr');
$tableheader .= Xml::element('th', null, wfMsg('allmessagesname'));
$tableheader .= Xml::element('th', null, wfMsg('allmessagescurrent'));
$tableheader .= Xml::closeElement('tr');
// Adapted version of TranslateUtils:makeListing() by Nikerabbit.
$out = $tableheader;
$canTranslate = $wgUser->isAllowed('translate');
$ajaxPageList = array();
$historyText = " <sup>" . wfMsgHtml('translate-translations-history-short') . "</sup> ";
foreach ($res as $s) {
$key = $s->page_title;
$tTitle = Title::makeTitle($s->page_namespace, $key);
$ajaxPageList[] = $tTitle->getPrefixedDBkey();
$code = $this->getCode($s->page_title);
$text = TranslateUtils::getLanguageName($code, false, $wgLang->getCode()) . " ({$code})";
$text = htmlspecialchars($text);
if ($canTranslate) {
$tools['edit'] = TranslationHelpers::ajaxEditLink($tTitle, $text);
} else {
$tools['edit'] = $sk->link($tTitle, $text);
}
$tools['history'] = $sk->link($tTitle, $historyText, array('action', 'title' => wfMsg('history-title', $tTitle->getPrefixedDBkey())), array('action' => 'history'));
if (TranslateEditAddons::isFuzzy($tTitle)) {
$class = 'orig';
} else {
$class = 'def';
}
$leftColumn = $tools['history'] . $tools['edit'];
$out .= Xml::tags('tr', array('class' => $class), Xml::tags('td', null, $leftColumn) . Xml::tags('td', array('lang' => $code, 'dir' => Language::factory($code)->getDir()), TranslateUtils::convertWhiteSpaceToHTML($pageInfo[$key][0])));
}
$out .= Xml::closeElement('table');
$wgOut->addHTML($out);
$vars = array('trlKeys' => $ajaxPageList);
$wgOut->addScript(Skin::makeVariablesScript($vars));
}
示例7: showPage
/**
* 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'));
//.........这里部分代码省略.........
示例8: execute
public function execute($par)
{
global $wgLanguageCode;
$this->setHeaders();
$this->checkPermissions();
$server = TTMServer::primary();
if (!$server instanceof SearchableTTMServer) {
throw new ErrorPageError('tux-sst-nosolr-title', 'tux-sst-nosolr-body');
}
$out = $this->getOutput();
$out->addModuleStyles('jquery.uls.grid');
$out->addModuleStyles('ext.translate.special.searchtranslations.styles');
$out->addModuleStyles('ext.translate.special.translate.styles');
$out->addModules('ext.translate.special.searchtranslations');
$out->addModules('ext.translate.special.searchtranslations.operatorsuggest');
TranslateUtils::addSpecialHelpLink($out, 'Help:Extension:Translate#searching');
$this->opts = $opts = new FormOptions();
$opts->add('query', '');
$opts->add('sourcelanguage', $wgLanguageCode);
$opts->add('language', '');
$opts->add('group', '');
$opts->add('grouppath', '');
$opts->add('filter', '');
$opts->add('match', '');
$opts->add('case', '');
$opts->add('limit', $this->limit);
$opts->add('offset', 0);
$opts->fetchValuesFromRequest($this->getRequest());
$queryString = $opts->getValue('query');
if ($queryString === '') {
$this->showEmptySearch();
return;
}
$params = $opts->getAllValues();
$filter = $opts->getValue('filter');
try {
$translationSearch = new CrossLanguageTranslationSearchQuery($params, $server);
if (in_array($filter, $translationSearch->getAvailableFilters())) {
if ($opts->getValue('language') === '') {
$params['language'] = $this->getLanguage()->getCode();
$opts->setValue('language', $params['language']);
}
$documents = $translationSearch->getDocuments();
$total = $translationSearch->getTotalHits();
$resultset = $translationSearch->getResultSet();
} else {
$resultset = $server->search($queryString, $params, $this->hl);
$documents = $server->getDocuments($resultset);
$total = $server->getTotalHits($resultset);
}
} catch (TTMServerException $e) {
error_log('Translation search server unavailable:' . $e->getMessage());
throw new ErrorPageError('tux-sst-solr-offline-title', 'tux-sst-solr-offline-body');
}
// Part 1: facets
$facets = $server->getFacets($resultset);
$facetHtml = '';
if (count($facets['language']) > 0) {
if ($filter !== '') {
$facets['language'] = array_merge($facets['language'], array($opts->getValue('language') => $total));
}
$facetHtml = Html::element('div', array('class' => 'row facet languages', 'data-facets' => FormatJson::encode($this->getLanguages($facets['language'])), 'data-language' => $opts->getValue('language')), $this->msg('tux-sst-facet-language'));
}
if (count($facets['group']) > 0) {
$facetHtml .= Html::element('div', array('class' => 'row facet groups', 'data-facets' => FormatJson::encode($this->getGroups($facets['group'])), 'data-group' => $opts->getValue('group')), $this->msg('tux-sst-facet-group'));
}
// Part 2: results
$resultsHtml = '';
$title = Title::newFromText($queryString);
if ($title && !in_array($filter, $translationSearch->getAvailableFilters())) {
$handle = new MessageHandle($title);
$code = $handle->getCode();
$language = $opts->getValue('language');
if ($handle->isValid() && $code !== '' && $code !== $language) {
$groupId = $handle->getGroup()->getId();
$helpers = new TranslationHelpers($title, $groupId);
$document['wiki'] = wfWikiId();
$document['localid'] = $handle->getTitleForBase()->getPrefixedText();
$document['content'] = $helpers->getTranslation();
$document['language'] = $handle->getCode();
array_unshift($documents, $document);
$total++;
}
}
foreach ($documents as $document) {
$text = $document['content'];
$text = TranslateUtils::convertWhiteSpaceToHTML($text);
list($pre, $post) = $this->hl;
$text = str_replace($pre, '<strong class="tux-search-highlight">', $text);
$text = str_replace($post, '</strong>', $text);
$title = Title::newFromText($document['localid'] . '/' . $document['language']);
if (!$title) {
// Should not ever happen but who knows...
continue;
}
$resultAttribs = array('class' => 'row tux-message', 'data-title' => $title->getPrefixedText(), 'data-language' => $document['language']);
$handle = new MessageHandle($title);
if ($handle->isValid()) {
$groupId = $handle->getGroup()->getId();
$helpers = new TranslationHelpers($title, $groupId);
//.........这里部分代码省略.........
示例9: importForm
/**
* @todo Very long code block; split up.
*
* @param $group MessageGroup
* @param $code
*/
public function importForm($group, $code)
{
$this->setSubtitle($group, $code);
$formParams = array('method' => 'post', 'action' => $this->getTitle()->getFullURL(array('group' => $group->getId())), 'class' => 'mw-translate-manage');
global $wgRequest, $wgLang;
if ($wgRequest->wasPosted() && $wgRequest->getBool('process', false) && $this->user->isAllowed('translate-manage') && $this->user->matchEditToken($wgRequest->getVal('token'))) {
$process = true;
} else {
$process = false;
}
$this->out->addHTML(Xml::openElement('form', $formParams) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Html::hidden('token', $this->user->editToken()) . Html::hidden('group', $group->getId()) . Html::hidden('process', 1));
// BEGIN
$cache = new MessageGroupCache($group, $code);
if (!$cache->exists() && $code === 'en') {
$cache->create();
}
$collection = $group->initCollection($code);
$collection->loadTranslations();
$diff = new DifferenceEngine();
$diff->showDiffStyle();
$diff->setReducedLineNumbers();
$ignoredMessages = $collection->getTags('ignored');
if (!is_array($ignoredMessages)) {
$ignoredMessages = array();
}
$messages = $group->load($code);
$changed = array();
foreach ($messages as $key => $value) {
// ignored? ignore!
if (in_array($key, $ignoredMessages)) {
continue;
}
$fuzzy = $old = false;
if (isset($collection[$key])) {
$old = $collection[$key]->translation();
}
// No changes at all, ignore.
if (str_replace(TRANSLATE_FUZZY, '', $old) === $value) {
continue;
}
if ($old === false) {
$name = wfMsgHtml('translate-manage-import-new', '<code style="font-weight:normal;">' . htmlspecialchars($key) . '</code>');
$text = TranslateUtils::convertWhiteSpaceToHTML($value);
$changed[] = MessageWebImporter::makeSectionElement($name, 'new', $text);
} else {
if (TranslateEditAddons::hasFuzzyString($old)) {
// NO-OP
} else {
$transTitle = MessageWebImporter::makeTranslationTitle($group, $key, $code);
if (TranslateEditAddons::isFuzzy($transTitle)) {
$old = TRANSLATE_FUZZY . $old;
}
}
$diff->setText($old, $value);
$text = $diff->getDiff('', '');
$type = 'changed';
if ($process) {
if (!count($changed)) {
$changed[] = '<ul>';
}
$action = $wgRequest->getVal(MessageWebImporter::escapeNameForPHP("action-{$type}-{$key}"));
if ($action === null) {
$message = wfMsgExt('translate-manage-inconsistent', 'parseinline', wfEscapeWikiText("action-{$type}-{$key}"));
$changed[] = "<li>{$message}</li></ul>";
$process = false;
} else {
// Initialise processing time counter.
if (!isset($this->time)) {
$this->time = wfTimestamp();
}
$fuzzybot = FuzzyBot::getUser();
$message = MessageWebImporter::doAction($action, $group, $key, $code, $value, '', $fuzzybot, EDIT_FORCE_BOT);
$key = array_shift($message);
$params = $message;
$message = wfMsgExt($key, 'parseinline', $params);
$changed[] = "<li>{$message}</li>";
if ($this->checkProcessTime()) {
$process = false;
$duration = $wgLang->formatNum($this->processingTime);
$message = wfMsgExt('translate-manage-toolong', 'parseinline', $duration);
$changed[] = "<li>{$message}</li></ul>";
}
continue;
}
}
if ($code !== 'en') {
$actions = array('import', 'conflict', 'ignore');
} else {
$actions = array('import', 'fuzzy', 'ignore');
}
$act = array();
if ($this->user->isAllowed('translate-manage')) {
$defaction = $fuzzy ? 'conflict' : 'import';
foreach ($actions as $action) {
//.........这里部分代码省略.........
示例10: execute
public function execute($messages)
{
$context = RequestContext::getMain();
$this->out = $context->getOutput();
// Set up diff engine
$diff = new DifferenceEngine();
$diff->showDiffStyle();
$diff->setReducedLineNumbers();
// Check whether we do processing
$process = $this->allowProcess();
// Initialise collection
$group = $this->getGroup();
$code = $this->getCode();
$collection = $group->initCollection($code);
$collection->loadTranslations();
$this->out->addHTML($this->doHeader());
// Determine changes
$alldone = $process;
$changed = array();
foreach ($messages as $key => $value) {
$fuzzy = $old = false;
if (isset($collection[$key])) {
$old = $collection[$key]->translation();
}
// No changes at all, ignore
if (strval($old) === strval($value)) {
continue;
}
if ($old === false) {
$para = '<code class="mw-tmi-new">' . htmlspecialchars($key) . '</code>';
$name = $context->msg('translate-manage-import-new')->rawParams($para)->escaped();
$text = TranslateUtils::convertWhiteSpaceToHTML($value);
$changed[] = self::makeSectionElement($name, 'new', $text);
} else {
$oldContent = ContentHandler::makeContent($old, $diff->getTitle());
$newContent = ContentHandler::makeContent($value, $diff->getTitle());
$diff->setContent($oldContent, $newContent);
$text = $diff->getDiff('', '');
$type = 'changed';
$action = $context->getRequest()->getVal(self::escapeNameForPHP("action-{$type}-{$key}"));
if ($process) {
if (!count($changed)) {
$changed[] = '<ul>';
}
if ($action === null) {
$message = $context->msg('translate-manage-inconsistent', wfEscapeWikiText("action-{$type}-{$key}"))->parse();
$changed[] = "<li>{$message}</li></ul>";
$process = false;
} else {
// Check processing time
if (!isset($this->time)) {
$this->time = wfTimestamp();
}
$message = self::doAction($action, $group, $key, $code, $value);
$key = array_shift($message);
$params = $message;
$message = $context->msg($key, $params)->parse();
$changed[] = "<li>{$message}</li>";
if ($this->checkProcessTime()) {
$process = false;
$message = $context->msg('translate-manage-toolong')->numParams($this->processingTime)->parse();
$changed[] = "<li>{$message}</li></ul>";
}
continue;
}
}
$alldone = false;
$actions = $this->getActions();
$defaction = $this->getDefaultAction($fuzzy, $action);
$act = array();
// Give grep a chance to find the usages:
// translate-manage-action-import, translate-manage-action-conflict,
// translate-manage-action-ignore, translate-manage-action-fuzzy
foreach ($actions as $action) {
$label = $context->msg("translate-manage-action-{$action}")->text();
$name = self::escapeNameForPHP("action-{$type}-{$key}");
$id = Sanitizer::escapeId("action-{$key}-{$action}");
$act[] = Xml::radioLabel($label, $name, $action, $id, $action === $defaction);
}
$param = '<code class="mw-tmi-diff">' . htmlspecialchars($key) . '</code>';
$name = $context->msg('translate-manage-import-diff', $param, implode(' ', $act))->text();
$changed[] = self::makeSectionElement($name, $type, $text);
}
}
if (!$process) {
$collection->filter('hastranslation', false);
$keys = $collection->getMessageKeys();
$diff = array_diff($keys, array_keys($messages));
foreach ($diff as $s) {
$para = '<code class="mw-tmi-deleted">' . htmlspecialchars($s) . '</code>';
$name = $context->msg('translate-manage-import-deleted')->rawParams($para)->escaped();
$text = TranslateUtils::convertWhiteSpaceToHTML($collection[$s]->translation());
$changed[] = self::makeSectionElement($name, 'deleted', $text);
}
}
if ($process || !count($changed) && $code !== 'en') {
if (!count($changed)) {
$this->out->addWikiMsg('translate-manage-nochanges-other');
}
if (!count($changed) || strpos($changed[count($changed) - 1], '<li>') !== 0) {
//.........这里部分代码省略.........
示例11: showPage
/**
* 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' )
);
//.........这里部分代码省略.........