本文整理汇总了PHP中TableDiffFormatter::format方法的典型用法代码示例。如果您正苦于以下问题:PHP TableDiffFormatter::format方法的具体用法?PHP TableDiffFormatter::format怎么用?PHP TableDiffFormatter::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableDiffFormatter
的用法示例。
在下文中一共展示了TableDiffFormatter::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showDiffs
function showDiffs($a, $b)
{
$ota = explode("\n", str_replace("\r\n", "\n", $a));
$nta = explode("\n", str_replace("\r\n", "\n", $b));
$diffs = new Diff($ota, $nta);
$formatter = new TableDiffFormatter();
$funky = $formatter->format($diffs);
preg_match_all('/<span class="diffchange">(.*?)<\\/span>/', $funky, $matches);
foreach ($matches[1] as $bit) {
$hex = bin2hex($bit);
echo "\t{$hex}\n";
}
}
示例2: Diff
function test_white_between_words()
{
// From FS#2161
global $lang;
$df = new Diff(explode("\n", "example"), explode("\n", "example example2"));
$idf = new InlineDiffFormatter();
$tdf = new TableDiffFormatter();
$this->assertEqual($idf->format($df), '<tr><td colspan="4" class="diff-blockheader">@@ ' . $lang['line'] . ' -1 +1 @@ <span class="diff-deletedline"><del>' . $lang['deleted'] . '</del></span> <span class="diff-addedline">' . $lang['created'] . '</span></td></tr>
<tr><td colspan="4">example <span class="diff-addedline">example2</span></td></tr>
');
$this->assertEqual($tdf->format($df), '<tr><td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
<td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td>
</tr>
<tr><td>-</td><td class="diff-deletedline">example</td><td>+</td><td class="diff-addedline">example <strong>example2</strong></td></tr>
');
}
示例3: show_texts_diff
function show_texts_diff($text1, $text2, $display_line_numbers = false)
{
if (is_null($text1)) {
$text1 = '';
}
if (is_null($text2)) {
$text2 = '';
}
if ($text1 == $text2 || !is_scalar($text1) || !is_scalar($text2)) {
// arguments are not scalars or are identical => do nothing
return '';
}
$lines1 = explode("\n", $text1);
$lines2 = explode("\n", $text2);
$diffs = new Diff($lines1, $lines2);
$formatter = new TableDiffFormatter($display_line_numbers);
return $formatter->format($diffs);
}
示例4: html_diff
/**
* show diff
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_diff($text = '', $intro = true)
{
require_once DOKU_INC . 'inc/DifferenceEngine.php';
global $ID;
global $REV;
global $lang;
global $conf;
// we're trying to be clever here, revisions to compare can be either
// given as rev and rev2 parameters, with rev2 being optional. Or in an
// array in rev2.
$rev1 = $REV;
if (is_array($_REQUEST['rev2'])) {
$rev1 = (int) $_REQUEST['rev2'][0];
$rev2 = (int) $_REQUEST['rev2'][1];
if (!$rev1) {
$rev1 = $rev2;
unset($rev2);
}
} else {
$rev2 = (int) $_REQUEST['rev2'];
}
if ($text) {
// compare text to the most current revision
$l_rev = '';
$l_text = rawWiki($ID, '');
$l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . $ID . ' ' . strftime($conf['dformat'], @filemtime(wikiFN($ID))) . '</a> ' . $lang['current'];
$r_rev = '';
$r_text = cleanText($text);
$r_head = $lang['yours'];
} else {
if ($rev1 && $rev2) {
// two specific revisions wanted
// make sure order is correct (older on the left)
if ($rev1 < $rev2) {
$l_rev = $rev1;
$r_rev = $rev2;
} else {
$l_rev = $rev2;
$r_rev = $rev1;
}
} elseif ($rev1) {
// single revision given, compare to current
$r_rev = '';
$l_rev = $rev1;
} else {
// no revision was given, compare previous to current
$r_rev = '';
$revs = getRevisions($ID, 0, 1);
$l_rev = $revs[0];
}
// when both revisions are empty then the page was created just now
if (!$l_rev && !$r_rev) {
$l_text = '';
} else {
$l_text = rawWiki($ID, $l_rev);
}
$r_text = rawWiki($ID, $r_rev);
if (!$l_rev) {
$l_head = '—';
} else {
$l_info = getRevisionInfo($ID, $l_rev, true);
if ($l_info['user']) {
$l_user = editorinfo($l_info['user']);
if (auth_ismanager()) {
$l_user .= ' (' . $l_info['ip'] . ')';
}
} else {
$l_user = $l_info['ip'];
}
$l_user = '<span class="user">' . $l_user . '</span>';
$l_sum = $l_info['sum'] ? '<span class="sum">' . hsc($l_info['sum']) . '</span>' : '';
if ($l_info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
$l_minor = 'class="minor"';
}
$l_head = '<a class="wikilink1" href="' . wl($ID, "rev={$l_rev}") . '">' . $ID . ' [' . strftime($conf['dformat'], $l_rev) . ']</a>' . '<br />' . $l_user . ' ' . $l_sum;
}
if ($r_rev) {
$r_info = getRevisionInfo($ID, $r_rev, true);
if ($r_info['user']) {
$r_user = editorinfo($r_info['user']);
if (auth_ismanager()) {
$r_user .= ' (' . $r_info['ip'] . ')';
}
} else {
$r_user = $r_info['ip'];
}
$r_user = '<span class="user">' . $r_user . '</span>';
$r_sum = $r_info['sum'] ? '<span class="sum">' . hsc($r_info['sum']) . '</span>' : '';
if ($r_info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) {
$r_minor = 'class="minor"';
}
$r_head = '<a class="wikilink1" href="' . wl($ID, "rev={$r_rev}") . '">' . $ID . ' [' . strftime($conf['dformat'], $r_rev) . ']</a>' . '<br />' . $r_user . ' ' . $r_sum;
} elseif ($_rev = @filemtime(wikiFN($ID))) {
$_info = getRevisionInfo($ID, $_rev, true);
if ($_info['user']) {
//.........这里部分代码省略.........
示例5: html_diff
/**
* show diff
*
* @author Andreas Gohr <andi@splitbrain.org>
* Modified by Brandon Zehm, pulled from dokuwiki.
* Requires DifferenceEngine.php from dokuwiki.
*
* Input: two strings
* Output: html
*/
function html_diff($old, $new, $oldname = '', $newname = '', $stdout = 1)
{
global $conf;
$html = '';
if (!($old and $new)) {
return 'ERROR => Insufficient parameters passed to html_diff()!';
}
// Load diff code
require_once $conf['inc_diff'];
$df = new Diff(explode("\n", htmlspecialchars($old)), explode("\n", htmlspecialchars($new)));
$tdf = new TableDiffFormatter();
$html .= <<<EOL
<table class="diff" width="100%">
<tr>
<td colspan="2" width="50%" class="diff-header">
{$oldname}
</td>
<td colspan="2" width="50%" class="diff-header">
{$newname}
</td>
</tr>
EOL;
$html .= $tdf->format($df) . "</table>";
if ($stdout) {
echo $html;
} else {
return $html;
}
}
示例6: array
/**
* Return an HTML table allowing to display differences between two texts, the same way MediaWiki does
*
* @param string $value1
* @param string $value2
* @param array $table_options attributes to add on the <table> tag
*/
function format_differences($value1, $value2, $table_options = array())
{
if (!is_array($value1)) {
$value1 = explode("\r\n", $value1);
}
if (!is_array($value2)) {
$value2 = explode("\r\n", $value2);
}
require_once App::pluginPath('alaxos') . '/lib/DifferenceEngine.php';
$formatter = new TableDiffFormatter();
$formatter->line_name = __d('alaxos', 'line', true);
$table_rows = $formatter->format(new Diff($value1, $value2));
if (!empty($table_rows)) {
return $this->Html->tag('table', $table_rows, $table_options);
} else {
return null;
}
}
示例7: textDiff
/**
* Generates diff, to be wrapped internally in a logging/instrumentation
*
* @param string $otext Old text, must be already segmented
* @param string $ntext New text, must be already segmented
* @return bool|string
*/
protected function textDiff($otext, $ntext)
{
global $wgExternalDiffEngine, $wgContLang;
$otext = str_replace("\r\n", "\n", $otext);
$ntext = str_replace("\r\n", "\n", $ntext);
if ($wgExternalDiffEngine == 'wikidiff' || $wgExternalDiffEngine == 'wikidiff3') {
wfDeprecated("\$wgExternalDiffEngine = '{$wgExternalDiffEngine}'", '1.27');
$wgExternalDiffEngine = false;
}
if ($wgExternalDiffEngine == 'wikidiff2') {
if (function_exists('wikidiff2_do_diff')) {
# Better external diff engine, the 2 may some day be dropped
# This one does the escaping and segmenting itself
$text = wikidiff2_do_diff($otext, $ntext, 2);
$text .= $this->debug('wikidiff2');
return $text;
}
} elseif ($wgExternalDiffEngine !== false) {
# Diff via the shell
$tmpDir = wfTempDir();
$tempName1 = tempnam($tmpDir, 'diff_');
$tempName2 = tempnam($tmpDir, 'diff_');
$tempFile1 = fopen($tempName1, "w");
if (!$tempFile1) {
return false;
}
$tempFile2 = fopen($tempName2, "w");
if (!$tempFile2) {
return false;
}
fwrite($tempFile1, $otext);
fwrite($tempFile2, $ntext);
fclose($tempFile1);
fclose($tempFile2);
$cmd = wfEscapeShellArg($wgExternalDiffEngine, $tempName1, $tempName2);
$difftext = wfShellExec($cmd);
$difftext .= $this->debug("external {$wgExternalDiffEngine}");
unlink($tempName1);
unlink($tempName2);
return $difftext;
}
# Native PHP diff
$ota = explode("\n", $wgContLang->segmentForDiff($otext));
$nta = explode("\n", $wgContLang->segmentForDiff($ntext));
$diffs = new Diff($ota, $nta);
$formatter = new TableDiffFormatter();
$difftext = $wgContLang->unsegmentForDiff($formatter->format($diffs));
return $difftext;
}
示例8: compareTask
/**
* Compare two versions of a wiki page
*
* @return void
*/
public function compareTask()
{
include_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'differenceengine.php';
$this->view->page = $this->page;
$this->view->config = $this->config;
$this->view->base_path = $this->_base_path;
$this->view->sub = $this->_sub;
// Incoming
$oldid = Request::getInt('oldid', 0);
$diff = Request::getInt('diff', 0);
// Do some error checking
if (!$diff) {
$this->setError(Lang::txt('COM_WIKI_ERROR_MISSING_VERSION'));
$this->displayTask();
return;
}
if ($diff == $oldid) {
$this->setError(Lang::txt('COM_WIKI_ERROR_SAME_VERSIONS'));
$this->displayTask();
return;
}
// If no initial page is given, compare to the current revision
$this->view->revision = $this->page->revision('current');
$this->view->or = $this->page->revision($oldid);
$this->view->dr = $this->page->revision($diff);
// Diff the two versions
$ota = explode("\n", $this->view->or->get('pagetext'));
$nta = explode("\n", $this->view->dr->get('pagetext'));
//$diffs = new Diff($ota, $nta);
$formatter = new \TableDiffFormatter();
$this->view->content = $formatter->format(new \Diff($ota, $nta));
// Prep the pagename for display
// e.g. "MainPage" becomes "Main Page"
$this->view->title = $this->page->get('title');
// Set the page's <title> tag
Document::setTitle(Lang::txt(strtoupper($this->_option)) . ': ' . $this->view->title . ': ' . Lang::txt(strtoupper($this->_option . '_' . $this->_task)));
// Set the pathway
if (Pathway::count() <= 0) {
Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option);
}
Pathway::append($this->view->title, $this->page->link());
Pathway::append(Lang::txt(strtoupper($this->_option . '_' . $this->_task)), $this->page->link() . '&' . ($this->_sub ? 'action' : 'task') . '=' . $this->_task);
$this->view->sub = $this->_sub;
$this->view->message = $this->_message;
$this->view->name = Lang::txt(strtoupper($this->_option));
foreach ($this->getErrors() as $error) {
$this->view->setError($error);
}
$this->view->display();
}
示例9: html_diff
/**
* show diff
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $text - compare with this text with most current version
* @param bool $intr - display the intro text
*/
function html_diff($text = '', $intro = true, $type = null)
{
global $ID;
global $REV;
global $lang;
global $conf;
if (!$type) {
$type = $_REQUEST['difftype'];
}
if ($type != 'inline') {
$type = 'sidebyside';
}
// we're trying to be clever here, revisions to compare can be either
// given as rev and rev2 parameters, with rev2 being optional. Or in an
// array in rev2.
$rev1 = $REV;
if (is_array($_REQUEST['rev2'])) {
$rev1 = (int) $_REQUEST['rev2'][0];
$rev2 = (int) $_REQUEST['rev2'][1];
if (!$rev1) {
$rev1 = $rev2;
unset($rev2);
}
} else {
$rev2 = (int) $_REQUEST['rev2'];
}
$r_minor = '';
$l_minor = '';
if ($text) {
// compare text to the most current revision
$l_rev = '';
$l_text = rawWiki($ID, '');
$l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . $lang['current'];
$r_rev = '';
$r_text = cleanText($text);
$r_head = $lang['yours'];
} else {
if ($rev1 && $rev2) {
// two specific revisions wanted
// make sure order is correct (older on the left)
if ($rev1 < $rev2) {
$l_rev = $rev1;
$r_rev = $rev2;
} else {
$l_rev = $rev2;
$r_rev = $rev1;
}
} elseif ($rev1) {
// single revision given, compare to current
$r_rev = '';
$l_rev = $rev1;
} else {
// no revision was given, compare previous to current
$r_rev = '';
$revs = getRevisions($ID, 0, 1);
$l_rev = $revs[0];
$REV = $l_rev;
// store revision back in $REV
}
// when both revisions are empty then the page was created just now
if (!$l_rev && !$r_rev) {
$l_text = '';
} else {
$l_text = rawWiki($ID, $l_rev);
}
$r_text = rawWiki($ID, $r_rev);
list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev);
}
$df = new Diff(explode("\n", htmlspecialchars($l_text)), explode("\n", htmlspecialchars($r_text)));
if ($type == 'inline') {
$tdf = new InlineDiffFormatter();
} else {
$tdf = new TableDiffFormatter();
}
if ($intro) {
print p_locale_xhtml('diff');
}
if (!$text) {
ptln('<div class="diffoptions">');
$form = new Doku_Form(array('action' => wl()));
$form->addHidden('id', $ID);
$form->addHidden('rev2[0]', $l_rev);
$form->addHidden('rev2[1]', $r_rev);
$form->addHidden('do', 'diff');
$form->addElement(form_makeListboxField('difftype', array('sidebyside' => $lang['diff_side'], 'inline' => $lang['diff_inline']), $type, $lang['diff_type'], '', '', array('class' => 'quickselect')));
$form->addElement(form_makeButton('submit', 'diff', 'Go'));
$form->printForm();
$diffurl = wl($ID, array('do' => 'diff', 'rev2[0]' => $l_rev, 'rev2[1]' => $r_rev, 'difftype' => $type));
ptln('<p><a class="wikilink1" href="' . $diffurl . '">' . $lang['difflink'] . '</a></p>');
ptln('</div>');
}
?>
<table class="diff diff_<?php
//.........这里部分代码省略.........
示例10: generateDiffBody
/**
* Generate a diff, no caching
* $otext and $ntext must be already segmented
*/
function generateDiffBody($otext, $ntext)
{
global $wgExternalDiffEngine, $wgContLang;
$fname = 'DifferenceEngine::generateDiffBody';
$otext = str_replace("\r\n", "\n", $otext);
$ntext = str_replace("\r\n", "\n", $ntext);
if ($wgExternalDiffEngine == 'wikidiff') {
# For historical reasons, external diff engine expects
# input text to be HTML-escaped already
$otext = htmlspecialchars($wgContLang->segmentForDiff($otext));
$ntext = htmlspecialchars($wgContLang->segmentForDiff($ntext));
if (!function_exists('wikidiff_do_diff')) {
dl('php_wikidiff.so');
}
return $wgContLang->unsegementForDiff(wikidiff_do_diff($otext, $ntext, 2));
}
if ($wgExternalDiffEngine == 'wikidiff2') {
# Better external diff engine, the 2 may some day be dropped
# This one does the escaping and segmenting itself
if (!function_exists('wikidiff2_do_diff')) {
//wfProfileIn( "$fname-dl" );
@dl('php_wikidiff2.so');
//wfProfileOut( "$fname-dl" );
}
if (function_exists('wikidiff2_do_diff')) {
//wfProfileIn( 'wikidiff2_do_diff' );
$text = wikidiff2_do_diff($otext, $ntext, 2);
//wfProfileOut( 'wikidiff2_do_diff' );
return $text;
}
}
if ($wgExternalDiffEngine !== false) {
# Diff via the shell
global $wgTmpDirectory;
$tempName1 = tempnam($wgTmpDirectory, 'diff_');
$tempName2 = tempnam($wgTmpDirectory, 'diff_');
$tempFile1 = fopen($tempName1, "w");
if (!$tempFile1) {
//wfProfileOut( $fname );
return false;
}
$tempFile2 = fopen($tempName2, "w");
if (!$tempFile2) {
//wfProfileOut( $fname );
return false;
}
fwrite($tempFile1, $otext);
fwrite($tempFile2, $ntext);
fclose($tempFile1);
fclose($tempFile2);
$cmd = wfEscapeShellArg($wgExternalDiffEngine, $tempName1, $tempName2);
//wfProfileIn( "$fname-shellexec" );
$difftext = wfShellExec($cmd);
//wfProfileOut( "$fname-shellexec" );
unlink($tempName1);
unlink($tempName2);
return $difftext;
}
# Native PHP diff
$ota = explode("\n", $wgContLang->segmentForDiff($otext));
$nta = explode("\n", $wgContLang->segmentForDiff($ntext));
$diffs = new Diff($ota, $nta);
$formatter = new TableDiffFormatter();
return $wgContLang->unsegmentForDiff($formatter->format($diffs));
}
示例11: rss_buildItems
/**
* Add recent changed pages to a feed object
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param object $rss - the FeedCreator Object
* @param array $data - the items to add
* @param array $opt - the feed options
*/
function rss_buildItems(&$rss, &$data, $opt)
{
global $conf;
global $lang;
global $auth;
$eventData = array('rss' => &$rss, 'data' => &$data, 'opt' => &$opt);
$event = new Doku_Event('FEED_DATA_PROCESS', $eventData);
if ($event->advise_before(false)) {
foreach ($data as $ditem) {
if (!is_array($ditem)) {
// not an array? then only a list of IDs was given
$ditem = array('id' => $ditem);
}
$item = new FeedItem();
$id = $ditem['id'];
$meta = p_get_metadata($id);
// add date
if ($ditem['date']) {
$date = $ditem['date'];
} elseif ($meta['date']['modified']) {
$date = $meta['date']['modified'];
} else {
$date = @filemtime(wikiFN($id));
}
if ($date) {
$item->date = date('r', $date);
}
// add title
if ($conf['useheading'] && $meta['title']) {
$item->title = $meta['title'];
} else {
$item->title = $ditem['id'];
}
if ($conf['rss_show_summary'] && !empty($ditem['sum'])) {
$item->title .= ' - ' . strip_tags($ditem['sum']);
}
// add item link
switch ($opt['link_to']) {
case 'page':
$item->link = wl($id, 'rev=' . $date, true, '&');
break;
case 'rev':
$item->link = wl($id, 'do=revisions&rev=' . $date, true, '&');
break;
case 'current':
$item->link = wl($id, '', true, '&');
break;
case 'diff':
default:
$item->link = wl($id, 'rev=' . $date . '&do=diff', true, '&');
}
// add item content
switch ($opt['item_content']) {
case 'diff':
case 'htmldiff':
require_once DOKU_INC . 'inc/DifferenceEngine.php';
$revs = getRevisions($id, 0, 1);
$rev = $revs[0];
if ($rev) {
$df = new Diff(explode("\n", htmlspecialchars(rawWiki($id, $rev))), explode("\n", htmlspecialchars(rawWiki($id, ''))));
} else {
$df = new Diff(array(''), explode("\n", htmlspecialchars(rawWiki($id, ''))));
}
if ($opt['item_content'] == 'htmldiff') {
$tdf = new TableDiffFormatter();
$content = '<table>';
$content .= '<tr><th colspan="2" width="50%">' . $rev . '</th>';
$content .= '<th colspan="2" width="50%">' . $lang['current'] . '</th></tr>';
$content .= $tdf->format($df);
$content .= '</table>';
} else {
$udf = new UnifiedDiffFormatter();
$content = "<pre>\n" . $udf->format($df) . "\n</pre>";
}
break;
case 'html':
$content = p_wiki_xhtml($id, $date, false);
// no TOC in feeds
$content = preg_replace('/(<!-- TOC START -->).*(<!-- TOC END -->)/s', '', $content);
// make URLs work when canonical is not set, regexp instead of rerendering!
if (!$conf['canonical']) {
$base = preg_quote(DOKU_REL, '/');
$content = preg_replace('/(<a href|<img src)="(' . $base . ')/s', '$1="' . DOKU_URL, $content);
}
break;
case 'abstract':
default:
$content = $meta['description']['abstract'];
}
$item->description = $content;
//FIXME a plugin hook here could be senseful
// add user
//.........这里部分代码省略.........
示例12: html_diff
/**
* Show diff
* between current page version and provided $text
* or between the revisions provided via GET or POST
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $text when non-empty: compare with this text with most current version
* @param bool $intro display the intro text
* @param string $type type of the diff (inline or sidebyside)
*/
function html_diff($text = '', $intro = true, $type = null)
{
global $ID;
global $REV;
global $lang;
global $INPUT;
global $INFO;
$pagelog = new PageChangeLog($ID);
/*
* Determine diff type
*/
if (!$type) {
$type = $INPUT->str('difftype');
if (empty($type)) {
$type = get_doku_pref('difftype', $type);
if (empty($type) && $INFO['ismobile']) {
$type = 'inline';
}
}
}
if ($type != 'inline') {
$type = 'sidebyside';
}
/*
* Determine requested revision(s)
*/
// we're trying to be clever here, revisions to compare can be either
// given as rev and rev2 parameters, with rev2 being optional. Or in an
// array in rev2.
$rev1 = $REV;
$rev2 = $INPUT->ref('rev2');
if (is_array($rev2)) {
$rev1 = (int) $rev2[0];
$rev2 = (int) $rev2[1];
if (!$rev1) {
$rev1 = $rev2;
unset($rev2);
}
} else {
$rev2 = $INPUT->int('rev2');
}
/*
* Determine left and right revision, its texts and the header
*/
$r_minor = '';
$l_minor = '';
if ($text) {
// compare text to the most current revision
$l_rev = '';
$l_text = rawWiki($ID, '');
$l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . $lang['current'];
$r_rev = '';
$r_text = cleanText($text);
$r_head = $lang['yours'];
} else {
if ($rev1 && isset($rev2) && $rev2) {
// two specific revisions wanted
// make sure order is correct (older on the left)
if ($rev1 < $rev2) {
$l_rev = $rev1;
$r_rev = $rev2;
} else {
$l_rev = $rev2;
$r_rev = $rev1;
}
} elseif ($rev1) {
// single revision given, compare to current
$r_rev = '';
$l_rev = $rev1;
} else {
// no revision was given, compare previous to current
$r_rev = '';
$revs = $pagelog->getRevisions(0, 1);
$l_rev = $revs[0];
$REV = $l_rev;
// store revision back in $REV
}
// when both revisions are empty then the page was created just now
if (!$l_rev && !$r_rev) {
$l_text = '';
} else {
$l_text = rawWiki($ID, $l_rev);
}
$r_text = rawWiki($ID, $r_rev);
list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
}
/*
* Build navigation
*/
$l_nav = '';
//.........这里部分代码省略.........
示例13: array
function compare_diff($old, $cur, $titles = array())
{
$this->add_tag_head('compare_diff.css');
include_once $this->root->mytrustdirpath . '/include/DifferenceEngine.php';
$this->compare_diff_pre($old);
$this->compare_diff_pre($cur);
$df = new Diff($old, $cur);
$tdf = new TableDiffFormatter();
$html = $tdf->format($df);
if ($titles) {
$title = <<<EOD
<tr>
<th colspan="2">{$titles[0]}</th>
<th colspan="2">{$titles[1]}</th>
</tr>
EOD;
} else {
$title = '';
}
return <<<EOD
<table class="diff">
{$title}
{$html}
</table>
EOD;
}
示例14: param
$Session->assert_received_crumb('item');
// Check permission:
$current_User->check_perm('item_post!CURSTATUS', 'edit', true, $edited_Item);
param('r1', 'integer', 0);
$r2 = (int) param('r2', 'string', 0);
$Revision_1 = $edited_Item->get_revision($r1);
$Revision_2 = $edited_Item->get_revision($r2);
load_class('_core/model/_diff.class.php', 'Diff');
// Compare the titles of two revisions
$revisions_difference_title = new Diff(explode("\n", $Revision_1->iver_title), explode("\n", $Revision_2->iver_title));
$format = new TitleDiffFormatter();
$revisions_difference_title = $format->format($revisions_difference_title);
// Compare the contents of two revisions
$revisions_difference_content = new Diff(explode("\n", $Revision_1->iver_content), explode("\n", $Revision_2->iver_content));
$format = new TableDiffFormatter();
$revisions_difference_content = $format->format($revisions_difference_content);
break;
case 'history_restore':
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb('item');
// Check permission:
$current_User->check_perm('item_post!CURSTATUS', 'edit', true, $edited_Item);
param('r', 'integer', 0);
if ($r > 0) {
// Update item only from revisions ($r == 0 for current version)
$Revision = $edited_Item->get_revision($r);
$edited_Item->set('status', $Revision->iver_status);
$edited_Item->set('title', $Revision->iver_title);
$edited_Item->set('content', $Revision->iver_content);
if ($edited_Item->dbupdate()) {
// Item updated
示例15: textDiff
/**
* Generates diff, to be wrapped internally in a logging/instrumentation
*
* @param string $otext Old text, must be already segmented
* @param string $ntext New text, must be already segmented
* @return bool|string
*/
protected function textDiff($otext, $ntext)
{
global $wgExternalDiffEngine, $wgContLang;
$otext = str_replace("\r\n", "\n", $otext);
$ntext = str_replace("\r\n", "\n", $ntext);
if ($wgExternalDiffEngine == 'wikidiff' || $wgExternalDiffEngine == 'wikidiff3') {
wfDeprecated("\$wgExternalDiffEngine = '{$wgExternalDiffEngine}'", '1.27');
$wgExternalDiffEngine = false;
} elseif ($wgExternalDiffEngine == 'wikidiff2') {
// Same as above, but with no deprecation warnings
$wgExternalDiffEngine = false;
} elseif (!is_string($wgExternalDiffEngine) && $wgExternalDiffEngine !== false) {
// And prevent people from shooting themselves in the foot...
wfWarn('$wgExternalDiffEngine is set to a non-string value, forcing it to false');
$wgExternalDiffEngine = false;
}
if (function_exists('wikidiff2_do_diff') && $wgExternalDiffEngine === false) {
# Better external diff engine, the 2 may some day be dropped
# This one does the escaping and segmenting itself
$text = wikidiff2_do_diff($otext, $ntext, 2);
$text .= $this->debug('wikidiff2');
return $text;
} elseif ($wgExternalDiffEngine !== false && is_executable($wgExternalDiffEngine)) {
# Diff via the shell
$tmpDir = wfTempDir();
$tempName1 = tempnam($tmpDir, 'diff_');
$tempName2 = tempnam($tmpDir, 'diff_');
$tempFile1 = fopen($tempName1, "w");
if (!$tempFile1) {
return false;
}
$tempFile2 = fopen($tempName2, "w");
if (!$tempFile2) {
return false;
}
fwrite($tempFile1, $otext);
fwrite($tempFile2, $ntext);
fclose($tempFile1);
fclose($tempFile2);
$cmd = wfEscapeShellArg($wgExternalDiffEngine, $tempName1, $tempName2);
$difftext = wfShellExec($cmd);
$difftext .= $this->debug("external {$wgExternalDiffEngine}");
unlink($tempName1);
unlink($tempName2);
return $difftext;
}
# Native PHP diff
$ota = explode("\n", $wgContLang->segmentForDiff($otext));
$nta = explode("\n", $wgContLang->segmentForDiff($ntext));
$diffs = new Diff($ota, $nta);
$formatter = new TableDiffFormatter();
$difftext = $wgContLang->unsegmentForDiff($formatter->format($diffs));
return $difftext;
}