当前位置: 首页>>代码示例>>PHP>>正文


PHP DifferenceEngine::getDiff方法代码示例

本文整理汇总了PHP中DifferenceEngine::getDiff方法的典型用法代码示例。如果您正苦于以下问题:PHP DifferenceEngine::getDiff方法的具体用法?PHP DifferenceEngine::getDiff怎么用?PHP DifferenceEngine::getDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DifferenceEngine的用法示例。


在下文中一共展示了DifferenceEngine::getDiff方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: formatChange

 /**
  * @param MessageGroup $group
  * @param string $code
  * @param string $type
  * @param array $params
  * @param int $limit
  * @return string HTML
  */
 protected function formatChange(MessageGroup $group, $code, $type, $params, &$limit)
 {
     $key = $params['key'];
     $title = Title::makeTitleSafe($group->getNamespace(), "{$key}/{$code}");
     $id = self::changeId($group->getId(), $code, $type, $key);
     if ($title && $title->exists() && $type === 'addition') {
         // The message has for some reason dropped out from cache
         // or perhaps it is being reused. In any case treat it
         // as a change for display, so the admin can see if
         // action is needed and let the message be processed.
         // Otherwise it will end up in the postponed category
         // forever and will prevent rebuilding the cache, which
         // leads to many other annoying problems.
         $type = 'change';
     } elseif ($title && !$title->exists() && ($type === 'deletion' || $type === 'change')) {
         return '';
     }
     $text = '';
     if ($type === 'deletion') {
         $wiki = ContentHandler::getContentText(Revision::newFromTitle($title)->getContent());
         $oldContent = ContentHandler::makeContent($wiki, $title);
         $newContent = ContentHandler::makeContent('', $title);
         $this->diff->setContent($oldContent, $newContent);
         $text = $this->diff->getDiff(Linker::link($title), '');
     } elseif ($type === 'addition') {
         $oldContent = ContentHandler::makeContent('', $title);
         $newContent = ContentHandler::makeContent($params['content'], $title);
         $this->diff->setContent($oldContent, $newContent);
         $text = $this->diff->getDiff('', Linker::link($title));
     } elseif ($type === 'change') {
         $wiki = ContentHandler::getContentText(Revision::newFromTitle($title)->getContent());
         $handle = new MessageHandle($title);
         if ($handle->isFuzzy()) {
             $wiki = '!!FUZZY!!' . str_replace(TRANSLATE_FUZZY, '', $wiki);
         }
         $label = $this->msg('translate-manage-action-ignore')->text();
         $actions = Xml::checkLabel($label, "i/{$id}", "i/{$id}");
         $limit--;
         if ($group->getSourceLanguage() === $code) {
             $label = $this->msg('translate-manage-action-fuzzy')->text();
             $actions .= ' ' . Xml::checkLabel($label, "f/{$id}", "f/{$id}", true);
             $limit--;
         }
         $oldContent = ContentHandler::makeContent($wiki, $title);
         $newContent = ContentHandler::makeContent($params['content'], $title);
         $this->diff->setContent($oldContent, $newContent);
         $text .= $this->diff->getDiff(Linker::link($title), $actions);
     }
     $hidden = Html::hidden($id, 1);
     $limit--;
     $text .= $hidden;
     $classes = "mw-translate-smg-change smg-change-{$type}";
     if ($limit < 0) {
         // Don't add if one of the fields might get dropped of at submission
         return '';
     }
     return Html::rawElement('div', array('class' => $classes), $text);
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:66,代码来源:SpecialManageGroups.php

示例2: formatDiffRow

 public static function formatDiffRow($title, $oldid, $newid, $timestamp, $comment, $actiontext = '')
 {
     global $wgFeedDiffCutoff, $wgContLang, $wgUser;
     wfProfileIn(__FUNCTION__);
     $skin = $wgUser->getSkin();
     # log enties
     $completeText = '<p>' . implode(' ', array_filter(array($actiontext, $skin->formatComment($comment)))) . "</p>\n";
     //NOTE: Check permissions for anonymous users, not current user.
     //      No "privileged" version should end up in the cache.
     //      Most feed readers will not log in anway.
     $anon = new User();
     $accErrors = $title->getUserPermissionsErrors('read', $anon, true);
     if ($title->getNamespace() >= 0 && !$accErrors) {
         if ($oldid) {
             wfProfileIn(__FUNCTION__ . "-dodiff");
             #$diffText = $de->getDiff( wfMsg( 'revisionasof',
             #	$wgContLang->timeanddate( $timestamp ) ),
             #	wfMsg( 'currentrev' ) );
             // Don't bother generating the diff if we won't be able to show it
             if ($wgFeedDiffCutoff > 0) {
                 $de = new DifferenceEngine($title, $oldid, $newid);
                 $diffText = $de->getDiff(wfMsg('previousrevision'), wfMsg('revisionasof', $wgContLang->timeanddate($timestamp)));
             }
             if (strlen($diffText) > $wgFeedDiffCutoff || $wgFeedDiffCutoff <= 0) {
                 // Omit large diffs
                 $diffLink = $title->escapeFullUrl('diff=' . $newid . '&oldid=' . $oldid);
                 $diffText = '<a href="' . $diffLink . '">' . htmlspecialchars(wfMsgForContent('showdiff')) . '</a>';
             } elseif ($diffText === false) {
                 // Error in diff engine, probably a missing revision
                 $diffText = "<p>Can't load revision {$newid}</p>";
             } else {
                 // Diff output fine, clean up any illegal UTF-8
                 $diffText = UtfNormal::cleanUp($diffText);
                 $diffText = self::applyDiffStyle($diffText);
             }
             wfProfileOut(__FUNCTION__ . "-dodiff");
         } else {
             $rev = Revision::newFromId($newid);
             if (is_null($rev)) {
                 $newtext = '';
             } else {
                 $newtext = $rev->getText();
             }
             $diffText = '<p><b>' . wfMsg('newpage') . '</b></p>' . '<div>' . nl2br(htmlspecialchars($newtext)) . '</div>';
         }
         $completeText .= $diffText;
     }
     wfProfileOut(__FUNCTION__);
     return $completeText;
 }
开发者ID:ui-libraries,项目名称:TIRW,代码行数:50,代码来源:FeedUtils.php

示例3: getData

 public function getData()
 {
     $db = wfGetDB(DB_MASTER);
     $conds = array('rt_page' => $this->handle->getTitle()->getArticleID(), 'rt_type' => RevTag::getType('tp:transver'));
     $options = array('ORDER BY' => 'rt_revision DESC');
     $translationRevision = $db->selectField('revtag', 'rt_value', $conds, __METHOD__, $options);
     if ($translationRevision === false) {
         throw new TranslationHelperException("No definition revision recorded");
     }
     $definitionTitle = Title::makeTitleSafe($this->handle->getTitle()->getNamespace(), $this->handle->getKey() . '/' . $this->group->getSourceLanguage());
     if (!$definitionTitle || !$definitionTitle->exists()) {
         throw new TranslationHelperException("Definition page doesn't exist");
     }
     // Using newFromId instead of newFromTitle, because the page might have been renamed
     $oldrev = Revision::newFromId($translationRevision);
     if (!$oldrev) {
         throw new TranslationHelperException("Old definition version doesn't exist anymore");
     }
     $oldContent = $oldrev->getContent();
     $newContent = $this->getDefinitionContent();
     if (!$oldContent) {
         throw new TranslationHelperException("Old definition version doesn't exist anymore");
     }
     if (!$oldContent instanceof WikitextContent || !$newContent instanceof WikitextContent) {
         throw new TranslationHelperException('Can only work on Wikitext content');
     }
     if ($oldContent->equals($newContent)) {
         throw new TranslationHelperException('No changes');
     }
     $diff = new DifferenceEngine($this->context);
     if (method_exists('DifferenceEngine', 'setTextLanguage')) {
         $diff->setTextLanguage($this->group->getSourceLanguage());
     }
     $diff->setContent($oldContent, $newContent);
     $diff->setReducedLineNumbers();
     $diff->showDiffStyle();
     $html = $diff->getDiff($this->context->msg('tpt-diff-old')->escaped(), $this->context->msg('tpt-diff-new')->escaped());
     return array('value_old' => $oldContent->getNativeData(), 'value_new' => $newContent->getNativeData(), 'revisionid_old' => $oldrev->getId(), 'revisionid_new' => $definitionTitle->getLatestRevId(), 'language' => $this->group->getSourceLanguage(), 'html' => $html);
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:39,代码来源:UpdatedDefinitionAid.php

示例4: getDiff

 /**
  * Get a diff between the current contents of the edit box and the
  * version of the page we're editing from.
  *
  * If this is a section edit, we'll replace the section as for final
  * save and then make a comparison.
  *
  * @return string HTML
  */
 function getDiff()
 {
     $oldtext = $this->mArticle->fetchContent();
     $newtext = $this->mArticle->replaceSection($this->section, $this->textbox1, $this->summary, $this->edittime);
     $newtext = $this->mArticle->preSaveTransform($newtext);
     $oldtitle = wfMsgExt('currentrev', array('parseinline'));
     $newtitle = wfMsgExt('yourtext', array('parseinline'));
     if ($oldtext !== false || $newtext != '') {
         $de = new DifferenceEngine($this->mTitle);
         $de->setText($oldtext, $newtext);
         $difftext = $de->getDiff($oldtitle, $newtitle);
     } else {
         $difftext = '';
     }
     return '<div id="wikiDiff">' . $difftext . '</div>';
 }
开发者ID:puring0815,项目名称:OpenKore,代码行数:25,代码来源:EditPage.php

示例5: getLastDiff

 protected function getLastDiff()
 {
     // Shortcuts
     $title = $this->handle->getTitle();
     $latestRevId = $title->getLatestRevID();
     $previousRevId = $title->getPreviousRevisionID($latestRevId);
     $latestRev = Revision::newFromTitle($title, $latestRevId);
     $previousRev = Revision::newFromTitle($title, $previousRevId);
     $diffText = '';
     if ($latestRev && $previousRev) {
         $latest = $latestRev->getText();
         $previous = $previousRev->getText();
         if ($previous !== $latest) {
             $diff = new DifferenceEngine();
             if (method_exists('DifferenceEngine', 'setTextLanguage')) {
                 $diff->setTextLanguage($this->getTargetLanguage());
             }
             $diff->setText($previous, $latest);
             $diff->setReducedLineNumbers();
             $diff->showDiffStyle();
             $diffText = $diff->getDiff(false, false);
         }
     }
     if (!$latestRev) {
         return null;
     }
     global $wgUser;
     $user = $latestRev->getUserText(Revision::FOR_THIS_USER, $wgUser);
     $comment = $latestRev->getComment();
     if ($diffText === '') {
         if (strval($comment) !== '') {
             $text = wfMessage('translate-dynagroup-byc', $user, $comment)->escaped();
         } else {
             $text = wfMessage('translate-dynagroup-by', $user)->escaped();
         }
     } else {
         if (strval($comment) !== '') {
             $text = wfMessage('translate-dynagroup-lastc', $user, $comment)->escaped();
         } else {
             $text = wfMessage('translate-dynagroup-last', $user)->escaped();
         }
     }
     return TranslateUtils::fieldset($text, $diffText, array('class' => 'mw-sp-translate-latestchange'));
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:44,代码来源:TranslationHelpers.php

示例6: 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) {
//.........这里部分代码省略.........
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:101,代码来源:MessageWebImporter.php

示例7: getDiff

 /**
  * Get a diff between the current contents of the edit box and the
  * version of the page we're editing from.
  *
  * If this is a section edit, we'll replace the section as for final
  * save and then make a comparison.
  *
  * @return string HTML
  */
 function getDiff()
 {
     require_once 'DifferenceEngine.php';
     $oldtext = $this->mArticle->fetchContent();
     $newtext = $this->mArticle->getTextOfLastEditWithSectionReplacedOrAdded($this->section, $this->textbox1, $this->summary, $this->edittime);
     $oldtitle = wfMsg('currentrev');
     $newtitle = wfMsg('yourtext');
     if ($oldtext != wfMsg('noarticletext') || $newtext != '') {
         $difftext = DifferenceEngine::getDiff($oldtext, $newtext, $oldtitle, $newtitle);
     }
     return '<div id="wikiDiff">' . $difftext . '</div>';
 }
开发者ID:BackupTheBerlios,项目名称:enotifwiki,代码行数:21,代码来源:EditPage.php

示例8: perform

 function perform($bPerformEdits = true)
 {
     global $wgRequest, $wgOut, $wgUser, $wgTitle, $wgLang;
     $iMaxPerCriterion = $bPerformEdits ? MER_MAX_EXECUTE_PAGES : MER_MAX_PREVIEW_DIFFS;
     $aErrors = array();
     $aPages = $this->getPages($aErrors, $iMaxPerCriterion);
     if ($aPages === null) {
         $this->showForm(wfMsg('masseditregex-err-nopages'));
         return;
     }
     // Show the form again ready for further editing if we're just previewing
     if (!$bPerformEdits) {
         $this->showForm();
     }
     $diff = new DifferenceEngine();
     $diff->showDiffStyle();
     // send CSS link to the browser for diff colours
     $wgOut->addHTML('<ul>');
     if (count($aErrors)) {
         $wgOut->addHTML('<li>' . join('</li><li> ', $aErrors) . '</li>');
     }
     $htmlDiff = '';
     $editToken = $wgUser->editToken();
     $iArticleCount = 0;
     foreach ($aPages as $p) {
         $iArticleCount++;
         if (!isset($p['revisions'])) {
             $wgOut->addHTML('<li>' . wfMsg('masseditregex-page-not-exists', $p['title']) . '</li>');
             continue;
             // empty page
         }
         $curContent = $p['revisions'][0]['*'];
         $iCount = 0;
         $newContent = $curContent;
         foreach ($this->aMatch as $i => $strMatch) {
             $this->strNextReplace = $this->aReplace[$i];
             $result = @preg_replace_callback($strMatch, array($this, 'regexCallback'), $newContent, -1, $iCount);
             if ($result !== null) {
                 $newContent = $result;
             } else {
                 $strErrorMsg = '<li>' . wfMsg('masseditregex-badregex') . ' <b>' . htmlspecialchars($strMatch) . '</b></li>';
                 $wgOut->addHTML($strErrorMsg);
                 unset($this->aMatch[$i]);
             }
         }
         if ($bPerformEdits) {
             // Not in preview mode, make the edits
             $wgOut->addHTML('<li>' . wfMsg('masseditregex-num-changes', $p['title'], $iCount) . '</li>');
             $req = new DerivativeRequest($wgRequest, array('action' => 'edit', 'bot' => true, 'title' => $p['title'], 'summary' => $this->strSummary, 'text' => $newContent, 'basetimestamp' => $p['starttimestamp'], 'watchlist' => 'nochange', 'nocreate' => 1, 'token' => $editToken), true);
             $processor = new ApiMain($req, true);
             try {
                 $processor->execute();
             } catch (UsageException $e) {
                 $wgOut->addHTML('<li><ul><li>' . wfMsg('masseditregex-editfailed') . ' ' . $e . '</li></ul></li>');
             }
         } else {
             // In preview mode, display the first few diffs
             $diff->setText($curContent, $newContent);
             $htmlDiff .= $diff->getDiff('<b>' . $p['title'] . ' - ' . wfMsg('masseditregex-before') . '</b>', '<b>' . wfMsg('masseditregex-after') . '</b>');
             if ($iArticleCount >= MER_MAX_PREVIEW_DIFFS) {
                 $htmlDiff .= Xml::element('p', null, wfMsg('masseditregex-max-preview-diffs', $wgLang->formatNum(MER_MAX_PREVIEW_DIFFS)));
                 break;
             }
         }
     }
     $wgOut->addHTML('</ul>');
     if ($bPerformEdits) {
         $wgOut->addWikiMsg('masseditregex-num-articles-changed', $iArticleCount);
         $wgOut->addHTML($this->sk->makeKnownLinkObj(SpecialPage::getSafeTitleFor('Contributions', $wgUser->getName()), wfMsgHtml('masseditregex-view-full-summary')));
     } else {
         // Only previewing, show the diffs now (after any errors)
         $wgOut->addHTML($htmlDiff);
     }
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:74,代码来源:MassEditRegex.class.php

示例9: getPageDiff

 protected function getPageDiff()
 {
     $this->mustBeKnownMessage();
     $title = $this->handle->getTitle();
     $key = $this->handle->getKey();
     if (!$title->exists()) {
         return null;
     }
     $definitionTitle = Title::makeTitleSafe($title->getNamespace(), "{$key}/en");
     if (!$definitionTitle || !$definitionTitle->exists()) {
         return null;
     }
     $db = wfGetDB(DB_MASTER);
     $conds = array('rt_page' => $title->getArticleID(), 'rt_type' => RevTag::getType('tp:transver'));
     $options = array('ORDER BY' => 'rt_revision DESC');
     $latestRevision = $definitionTitle->getLatestRevID();
     $translationRevision = $db->selectField('revtag', 'rt_value', $conds, __METHOD__, $options);
     if ($translationRevision === false) {
         return null;
     }
     // Using newFromId instead of newFromTitle, because the page might have been renamed
     $oldrev = Revision::newFromId($translationRevision);
     if (!$oldrev) {
         // And someone might still have deleted it
         return null;
     }
     $oldtext = ContentHandler::getContentText($oldrev->getContent());
     $newContent = Revision::newFromTitle($definitionTitle, $latestRevision)->getContent();
     $newtext = ContentHandler::getContentText($newContent);
     if ($oldtext === $newtext) {
         return null;
     }
     $diff = new DifferenceEngine();
     if (method_exists('DifferenceEngine', 'setTextLanguage')) {
         $diff->setTextLanguage($this->group->getSourceLanguage());
     }
     $oldContent = ContentHandler::makeContent($oldtext, $diff->getTitle());
     $newContent = ContentHandler::makeContent($newtext, $diff->getTitle());
     $diff->setContent($oldContent, $newContent);
     $diff->setReducedLineNumbers();
     $diff->showDiffStyle();
     return $diff->getDiff(wfMessage('tpt-diff-old')->escaped(), wfMessage('tpt-diff-new')->escaped());
 }
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:43,代码来源:TranslationHelpers.php

示例10: 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'));
//.........这里部分代码省略.........
开发者ID:HuijiWiki,项目名称:mediawiki-extensions-Translate,代码行数:101,代码来源:SpecialPageTranslation.php

示例11: formatDiffRow

 /**
  * Really format a diff for the newsfeed
  *
  * @param $title Title object
  * @param $oldid Integer: old revision's id
  * @param $newid Integer: new revision's id
  * @param $timestamp Integer: new revision's timestamp
  * @param $comment String: new revision's comment
  * @param $actiontext String: text of the action; in case of log event
  * @return String
  */
 public static function formatDiffRow($title, $oldid, $newid, $timestamp, $comment, $actiontext = '')
 {
     global $wgFeedDiffCutoff, $wgLang;
     wfProfileIn(__METHOD__);
     # log enties
     $completeText = '<p>' . implode(' ', array_filter(array($actiontext, Linker::formatComment($comment)))) . "</p>\n";
     // NOTE: Check permissions for anonymous users, not current user.
     //       No "privileged" version should end up in the cache.
     //       Most feed readers will not log in anway.
     $anon = new User();
     $accErrors = $title->getUserPermissionsErrors('read', $anon, true);
     // Can't diff special pages, unreadable pages or pages with no new revision
     // to compare against: just return the text.
     if ($title->getNamespace() < 0 || $accErrors || !$newid) {
         wfProfileOut(__METHOD__);
         return $completeText;
     }
     if ($oldid) {
         wfProfileIn(__METHOD__ . "-dodiff");
         #$diffText = $de->getDiff( wfMessage( 'revisionasof',
         #	$wgLang->timeanddate( $timestamp ),
         #	$wgLang->date( $timestamp ),
         #	$wgLang->time( $timestamp ) )->text(),
         #	wfMessage( 'currentrev' )->text() );
         $diffText = '';
         // Don't bother generating the diff if we won't be able to show it
         if ($wgFeedDiffCutoff > 0) {
             $de = new DifferenceEngine($title, $oldid, $newid);
             $diffText = $de->getDiff(wfMessage('previousrevision')->text(), wfMessage('revisionasof', $wgLang->timeanddate($timestamp), $wgLang->date($timestamp), $wgLang->time($timestamp))->text());
         }
         if ($wgFeedDiffCutoff <= 0 || strlen($diffText) > $wgFeedDiffCutoff) {
             // Omit large diffs
             $diffText = self::getDiffLink($title, $newid, $oldid);
         } elseif ($diffText === false) {
             // Error in diff engine, probably a missing revision
             $diffText = "<p>Can't load revision {$newid}</p>";
         } else {
             // Diff output fine, clean up any illegal UTF-8
             $diffText = UtfNormal::cleanUp($diffText);
             $diffText = self::applyDiffStyle($diffText);
         }
         wfProfileOut(__METHOD__ . "-dodiff");
     } else {
         $rev = Revision::newFromId($newid);
         if ($wgFeedDiffCutoff <= 0 || is_null($rev)) {
             $newtext = '';
         } else {
             $newtext = $rev->getText();
         }
         if ($wgFeedDiffCutoff <= 0 || strlen($newtext) > $wgFeedDiffCutoff) {
             // Omit large new page diffs, bug 29110
             $diffText = self::getDiffLink($title, $newid);
         } else {
             $diffText = '<p><b>' . wfMessage('newpage')->text() . '</b></p>' . '<div>' . nl2br(htmlspecialchars($newtext)) . '</div>';
         }
     }
     $completeText .= $diffText;
     wfProfileOut(__METHOD__);
     return $completeText;
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:71,代码来源:FeedUtils.php

示例12: showDiff

 /**
  * Get a diff between the current contents of the edit box and the
  * version of the page we're editing from.
  *
  * If this is a section edit, we'll replace the section as for final
  * save and then make a comparison.
  */
 function showDiff()
 {
     global $wgUser, $wgContLang, $wgParser, $wgOut;
     $oldtitlemsg = 'currentrev';
     # if message does not exist, show diff against the preloaded default
     if ($this->mTitle->getNamespace() == NS_MEDIAWIKI && !$this->mTitle->exists()) {
         $oldtext = $this->mTitle->getDefaultMessageText();
         if ($oldtext !== false) {
             $oldtitlemsg = 'defaultmessagetext';
         }
     } else {
         $oldtext = $this->mArticle->getRawText();
     }
     $newtext = $this->mArticle->replaceSection($this->section, $this->textbox1, $this->summary, $this->edittime);
     wfRunHooks('EditPageGetDiffText', array($this, &$newtext));
     $popts = ParserOptions::newFromUserAndLang($wgUser, $wgContLang);
     $newtext = $wgParser->preSaveTransform($newtext, $this->mTitle, $wgUser, $popts);
     if ($oldtext !== false || $newtext != '') {
         $oldtitle = wfMessage($oldtitlemsg)->parse();
         $newtitle = wfMessage('yourtext')->parse();
         $de = new DifferenceEngine($this->mArticle->getContext());
         $de->setText($oldtext, $newtext);
         $difftext = $de->getDiff($oldtitle, $newtitle);
         $de->showDiffStyle();
     } else {
         $difftext = '';
     }
     $wgOut->addHTML('<div id="wikiDiff">' . $difftext . '</div>');
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:36,代码来源:EditPage.php

示例13: 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) {
//.........这里部分代码省略.........
开发者ID:schwarer2006,项目名称:wikia,代码行数:101,代码来源:SpecialManageGroups.php

示例14: showDiff

 function showDiff($otext, $ntext, $otitle, $ntitle)
 {
     global $wgOut;
     $wgOut->addHTML(DifferenceEngine::getDiff($otext, $ntext, $otitle, $ntitle));
 }
开发者ID:BackupTheBerlios,项目名称:blahtex,代码行数:5,代码来源:DifferenceEngine.php

示例15: 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" );
//.........这里部分代码省略.........
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:101,代码来源:MessageWebImporter.php


注:本文中的DifferenceEngine::getDiff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。