Skip to content

Commit f5c244e

Browse files
committed
readded the diff viewer
1 parent 0c4fb50 commit f5c244e

File tree

5 files changed

+78
-26
lines changed

5 files changed

+78
-26
lines changed

Profile.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ public function getTimes() {
8484
return array($ltime, $rtime);
8585
}
8686

87+
/**
88+
* Return the Diff for a given page ID
89+
*
90+
* @param string $id
91+
* @return \Diff
92+
*/
93+
public function diffPage($id) {
94+
$this->client->query('wiki.getPage', $id);
95+
$remote = $this->client->getResponse();
96+
$local = rawWiki($id);
97+
98+
$df = new \Diff(
99+
explode("\n", htmlspecialchars($local)),
100+
explode("\n", htmlspecialchars($remote))
101+
);
102+
return $df;
103+
}
104+
87105
/**
88106
* Get a list of changed files
89107
*

diff.php

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
<?php
2-
/**
3-
* CAPTCHA antispam plugin - Image generator
4-
*
5-
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6-
* @author Andreas Gohr <gohr@cosmocode.de>
7-
*/
82

9-
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
10-
require_once(DOKU_INC.'inc/init.php');
11-
require_once(DOKU_INC.'inc/auth.php');
12-
session_write_close();
13-
require_once(DOKU_INC.'inc/template.php');
14-
require_once(DOKU_INC.'inc/DifferenceEngine.php');
15-
require_once(dirname(__FILE__).'/admin.php');
3+
use dokuwiki\plugin\sync\ProfileManager;
164

5+
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../../../') . '/');
6+
require_once(DOKU_INC . 'inc/init.php');
7+
session_write_close();
178
if(!auth_isadmin()) die('not you my friend!');
189

19-
$id = cleanID($_REQUEST['id']);
20-
$plugin = new admin_plugin_sync();
10+
global $INPUT;
11+
global $conf;
12+
global $lang;
13+
14+
$id = $INPUT->filter('cleanid')->str('id');
15+
$profno = $INPUT->int('no');
16+
$prmanager = new ProfileManager();
17+
$profile = $prmanager->getProfile($profno);
18+
$plugin = plugin_load('admin', 'sync');
19+
2120
header('Content-Type: text/html; charset=utf-8');
2221
?>
2322
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
24-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
25-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $conf['lang']?>"
26-
lang="<?php echo $conf['lang']?>" dir="<?php echo $lang['direction']?>">
23+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
24+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $conf['lang'] ?>"
25+
lang="<?php echo $conf['lang'] ?>" dir="<?php echo $lang['direction'] ?>">
2726
<head>
28-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
29-
<title><?php echo $plugin->getLang('diff')?></title>
30-
<?php tpl_metaheaders()?>
27+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
28+
<title><?php echo $plugin->getLang('diff') ?></title>
29+
<?php tpl_metaheaders() ?>
3130
</head>
3231
<body>
33-
<div class="dokuwiki">
34-
<?php $plugin->_diff($id);?>
35-
</div>
32+
<div class="dokuwiki">
33+
<?php
34+
$df = $profile->diffPage($id);
35+
$tdf = new TableDiffFormatter();
36+
echo '<table class="diff" id="plugin__sync_diff">';
37+
echo '<tr>';
38+
echo '<th colspan="2">' . $plugin->getLang('local') . '</th>';
39+
echo '<th colspan="2">' . $plugin->getLang('remote') . '</th>';
40+
echo '</tr>';
41+
echo $tdf->format($df);
42+
echo '</table>';
43+
?>
44+
</div>
3645
</body>
3746

lang/en/lang.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
$lang['js']['loading'] = 'Retrieving File List…';
6969
$lang['js']['summary'] = 'Summary';
7070

71-
7271
$lang['timeout'] = 'Timeout';
7372

7473

style.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
width: 9em;
5959
}
6060

61+
th.diff,
62+
td.diff {
63+
width: 4em;
64+
}
65+
6166
// general setup for custom radio buttons
6267
label input {
6368
visibility: hidden;

sync.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jQuery(function () {
3232
$output.append($table);
3333

3434
var $lbl = jQuery('<label>');
35-
$lbl.text(LANG.plugins.sync.summary +': ');
35+
$lbl.text(LANG.plugins.sync.summary + ': ');
3636
var $sum = jQuery('<input>');
3737
$sum.attr('type', 'text');
3838
$sum.addClass('edit');
@@ -47,6 +47,9 @@ jQuery(function () {
4747
$progress.hide();
4848
}
4949

50+
/**
51+
* Get the table headers
52+
*/
5053
function headers() {
5154
var $tr = jQuery('<tr>');
5255

@@ -93,9 +96,27 @@ jQuery(function () {
9396

9497
$tr.find('.dir').append(dir(item));
9598

99+
if (type === '1') {
100+
var url = DOKU_BASE + 'lib/plugins/sync/diff.php?no=' + SYNC_DATA.profile + '&id=' + encodeURIComponent(id);
101+
var a = jQuery('<a>');
102+
a.attr('href', url);
103+
a.attr('target', '_blank');
104+
a.text(LANG.plugins.sync.diff);
105+
a.click(diffclick);
106+
$tr.find('.diff').append(a);
107+
}
108+
96109
return $tr;
97110
}
98111

112+
113+
function diffclick(e) {
114+
e.preventDefault();
115+
e.stopPropagation();
116+
window.open(this.href, 'diff', 'height=600,width=800');
117+
118+
}
119+
99120
/**
100121
* Get the direction buttons for the given Item
101122
*

0 commit comments

Comments
 (0)