Skip to content

Commit a5e6fad

Browse files
committed
增加历史版本对比的功能
1 parent e0d27c4 commit a5e6fad

File tree

8 files changed

+913
-4
lines changed

8 files changed

+913
-4
lines changed

server/apps/controllers/Wiki_admin.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,55 @@ function main()
9797
$this->display();
9898
}
9999

100+
function history()
101+
{
102+
if (empty($_GET['id']))
103+
{
104+
throw new Swoole\Exception\InvalidParam("缺少ID");
105+
}
106+
$this->getMainData();
107+
$_table = table('wiki_history');
108+
$list = $_table->gets(array('select' => 'id, version, title, uid, addtime',
109+
'wiki_id' => intval($_GET['id'])));
110+
$this->assign('list', $list);
111+
$this->display();
112+
}
113+
114+
function diff()
115+
{
116+
if (empty($_GET['id']))
117+
{
118+
throw new Swoole\Exception\InvalidParam("缺少ID");
119+
}
120+
if (!isset($_GET['version']))
121+
{
122+
throw new Swoole\Exception\InvalidParam("需要version参数");
123+
}
124+
$this->getMainData();
125+
$_table = table('wiki_history');
126+
list($res) = $_table->gets(array(
127+
'version' => intval($_GET['version']),
128+
'wiki_id' => $_GET['id']
129+
));
130+
$this->assign('a', $res['content']);
131+
if (isset($_GET['compare']) and $_GET['compare'] == 'last')
132+
{
133+
$version_b = intval($_GET['version']) - 1;
134+
list($res) = $_table->gets(array(
135+
'version' => $version_b,
136+
'wiki_id' => $_GET['id']
137+
));
138+
$this->assign('b', $res['content']);
139+
$this->assign('version_b', $version_b);
140+
}
141+
else
142+
{
143+
$this->assign('b', $this->tpl_var['wiki_page']['content']);
144+
$this->assign('version_b', $this->tpl_var['wiki_page']['version']);
145+
}
146+
$this->display();
147+
}
148+
100149
function order()
101150
{
102151
if(empty($_GET['id']))
@@ -346,7 +395,7 @@ function create()
346395
$node_id = $_tree->put($in);
347396
$_cont = createModel('WikiContent');
348397

349-
$in2['title'] = $in['title'];
398+
$in2['title'] = $in['text'];
350399
if (strlen($_POST['content']) > 0 and $_POST['content']{0} == '`')
351400
{
352401
$_POST['content'] = ' ' . $_POST['content'];
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5+
<link rel='stylesheet' href='/static/css/markdown.css' type='text/css' />
6+
<!-- Bootstrap core CSS -->
7+
<link href="/static/bootstrap3/dist/css/bootstrap.css" rel="stylesheet">
8+
<!-- Bootstrap theme -->
9+
<link href="/static/bootstrap3/dist/css/bootstrap-theme.min.css" rel="stylesheet">
10+
11+
<!-- Custom styles for this template -->
12+
<link href="/static/css/theme.css" rel="stylesheet">
13+
<link href="/static/css/code.css" rel="stylesheet">
14+
<link rel="StyleSheet" href="/static/js/tree/dtree.css" type="text/css" />
15+
<link rel="StyleSheet" href="/static/jsdifflib/diffview.css" type="text/css" />
16+
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
17+
<!--[if lt IE 9]>
18+
<script src="/static/bootstrap3/dist/js/html5shiv.js"></script>
19+
<script src="/static/bootstrap3/dist/js/respond.min.js"></script>
20+
<![endif]-->
21+
<script src="/static/js/rainbow-custom.min.js"></script>
22+
<script src="/static/js/jquery.js"></script>
23+
<script src="/static/js/dtree.js"></script>
24+
<script src="/static/jsdifflib/difflib.js"></script>
25+
<script src="/static/jsdifflib/diffview.js"></script>
26+
<title>比较_Swoole文档中心</title>
27+
</head>
28+
<body>
29+
<div class="main_right">
30+
<style type="text/css">
31+
td {
32+
vertical-align: middle !important;
33+
}
34+
</style>
35+
<div id="text_a" style="display: none"><?= $a ?></div>
36+
<div id="text_b" style="display: none"><?= $b ?></div>
37+
<div id="readme" class="blob instapaper_body">
38+
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
39+
<?php if ($wiki_page) { ?>
40+
<h1><?=$wiki_page['title']?>
41+
<a href="/wiki_admin/main/?id=<?= $wiki_page['id'] ?>"> <span
42+
class="badge right">当前版本: <?= $wiki_page['version'] ?></span></a>
43+
</h1>
44+
<?php }?>
45+
<script type="application/javascript">
46+
$(document).ready(function(){
47+
var base = difflib.stringAsLines($("#text_a").html());
48+
var newtxt = difflib.stringAsLines($("#text_b").html());
49+
var sm = new difflib.SequenceMatcher(base, newtxt);
50+
var opcodes = sm.get_opcodes();
51+
var html = diffview.buildView({
52+
baseTextLines: base,
53+
newTextLines: newtxt,
54+
opcodes: opcodes,
55+
// set the display titles for each resource
56+
baseTextName: "version-<?=$_GET['version']?>",
57+
newTextName: "version-<?=$version_b?>",
58+
contextSize: null,
59+
viewType: 0
60+
});
61+
$("#diffoutput").html(html);
62+
});
63+
</script>
64+
</article>
65+
<div id="diffoutput"></div>
66+
</div>
67+
</div>
68+
</body>
69+
</html>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5+
<link rel='stylesheet' href='/static/css/markdown.css' type='text/css' />
6+
<!-- Bootstrap core CSS -->
7+
<link href="/static/bootstrap3/dist/css/bootstrap.css" rel="stylesheet">
8+
<!-- Bootstrap theme -->
9+
<link href="/static/bootstrap3/dist/css/bootstrap-theme.min.css" rel="stylesheet">
10+
11+
<!-- Custom styles for this template -->
12+
<link href="/static/css/theme.css" rel="stylesheet">
13+
<link href="/static/css/code.css" rel="stylesheet">
14+
<link rel="StyleSheet" href="/static/js/tree/dtree.css" type="text/css" />
15+
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
16+
<!--[if lt IE 9]>
17+
<script src="/static/bootstrap3/dist/js/html5shiv.js"></script>
18+
<script src="/static/bootstrap3/dist/js/respond.min.js"></script>
19+
<![endif]-->
20+
<script src="/static/js/rainbow-custom.min.js"></script>
21+
<script src="/static/js/jquery.js"></script>
22+
<script src="/static/js/dtree.js"></script>
23+
<title><?=$wiki_page['title']?>_Swoole文档中心</title>
24+
</head>
25+
<body>
26+
<div class="main_right">
27+
<style type="text/css">
28+
td {
29+
vertical-align: middle !important;
30+
}
31+
</style>
32+
<div id="readme" class="blob instapaper_body">
33+
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
34+
<?php if ($wiki_page) { ?>
35+
<h1><?=$wiki_page['title']?>
36+
<a href="/wiki_admin/main/?id=<?= $wiki_page['id'] ?>"> <span
37+
class="badge right">当前版本: <?= $wiki_page['version'] ?></span></a>
38+
</h1>
39+
<?php }?>
40+
</article>
41+
<table class="table table-bordered table-striped" style="margin-top: 20px;">
42+
<thead>
43+
<tr>
44+
<th style="width: 70px;">版本号</th>
45+
<th>标题</th>
46+
<th>修改人</th>
47+
<th>修改时间</th>
48+
<th>操作</th>
49+
</tr>
50+
</thead>
51+
<tbody>
52+
<?php foreach($list as $li): ?>
53+
<tr>
54+
<td>
55+
<span class="badge right">版本: <?=$li['version']?></span>
56+
</td>
57+
<td><?=$li['title']?></td>
58+
<td><?=$li['uid']?></td>
59+
<td><?=$li['addtime']?></td>
60+
<td>
61+
<a href="/wiki_admin/diff/?id=<?=$_GET['id']?>&version=<?=$li['version']?>&compare=current" class="btn btn-sm btn-info">与当前版本对比</a>
62+
<?php if ($li['version'] > 0) {?>
63+
<a href="/wiki_admin/diff/?id=<?=$_GET['id']?>&version=<?=$li['version']?>&compare=last" class="btn btn-sm btn-default">与上个版本对比</a>
64+
<?php } ?>
65+
</tr>
66+
<?php endforeach; ?>
67+
</tbody>
68+
</table>
69+
</div>
70+
<hr />
71+
<!-- Duoshuo Comment BEGIN -->
72+
<div class="ds-thread" data-thread-key="wiki-<?=$wiki_page['id']?>" data-title="<?=$wiki_page['title']?>"
73+
data-url="http://wiki.swoole.com/wiki/page/<?=$wiki_page['id']?>.html"></div>
74+
<script type="text/javascript">
75+
$(document).ready(function() {
76+
$('a').each(function(e){
77+
//外链
78+
if(this.href.substring(7, location.host.length +7) != location.host) {
79+
this.target = "_blank";
80+
}
81+
});
82+
});
83+
</script>
84+
<!-- Duoshuo Comment END -->
85+
</div>
86+
<div style="display: none">
87+
<script type="text/javascript">
88+
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
89+
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F4967f2faa888a2e52742bebe7fcb5f7d' type='text/javascript'%3E%3C/script%3E"));
90+
</script>
91+
</div>
92+
</body>
93+
</html>

server/apps/templates/wiki_admin/main.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
<div id="readme" class="blob instapaper_body">
2828
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
2929
<?php if ($wiki_page) { ?>
30-
<h1><?=$wiki_page['title']?></h1>
30+
<h1><?=$wiki_page['title']?>
31+
<a href="/wiki_admin/history/?id=<?=$wiki_page['id']?>"><span class="badge right">当前版本: <?=$wiki_page['version']?></span></a>
32+
</h1>
3133
<?php }?>
3234
<?php include __DIR__."/admin_menu.php"; ?>
3335
<?=$content?>

server/apps/templates/wiki_admin/tree.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
var open;
3838
var node_id;
3939
for (var i = 0; i < wiki_tree_data.length; i++) {
40-
if(wiki_tree_data[i]['link'].substring(0, 7)=='http://'
41-
|| wiki_tree_data[i]['link'].substring(0, 8)=='https://') {
40+
if(wiki_tree_data[i]['link'].length > 0 && (wiki_tree_data[i]['link'].substring(0, 7)=='http://'
41+
|| wiki_tree_data[i]['link'].substring(0, 8)=='https://')) {
4242
link = wiki_tree_data[i]['link']
4343
} else {
4444
link = '/wiki_admin/main/'+wiki_tree_data[i]['id'];

0 commit comments

Comments
 (0)