Skip to content

Commit 14708f1

Browse files
committed
增加开放编辑的功能
1 parent 0bc3c42 commit 14708f1

File tree

10 files changed

+1866
-18
lines changed

10 files changed

+1866
-18
lines changed

server/apps/configs/upload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
$upload['base_dir'] = dirname(WEBPATH).'/web/static/uploads/';
3-
$upload['base_url'] = WEBROOT.'/static/uploads/';
2+
$upload['base_dir'] = dirname(WEBPATH) . '/web/static/uploads/';
3+
$upload['base_url'] = WEBROOT . '/static/uploads/';
44
return $upload;

server/apps/configs/user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$user['default_avatar'] = '/static/images/default.png';
33
$user['login_table'] = 'user_login';
4-
$user['login_url'] = '/page/login/';
4+
$user['login_url'] = WEBROOT.'/page/login/';
55
return $user;

server/apps/controllers/Wiki.php

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function __construct($swoole)
2727

2828
function index()
2929
{
30-
if(isset($_GET['prid']))
30+
if (isset($_GET['prid']))
3131
{
3232
$this->project_id = intval($_GET['prid']);
3333
}
@@ -219,10 +219,66 @@ private function getTreeData()
219219
$this->swoole->tpl->assign("tree", $tree);
220220
}
221221

222-
function tree()
222+
function edit()
223223
{
224-
$this->swoole->tpl->assign("tree", json_encode(App\Content::getTree($this->project_id)));
225-
$this->swoole->tpl->display("wiki/tree.html");
224+
$this->user->loginRequire();
225+
if (empty($_GET['id']))
226+
{
227+
return "error: requirer miki_page id";
228+
}
229+
230+
$id = (int)$_GET['id'];
231+
$_cont = model('WikiContent');
232+
$_tree = model('WikiTree');
233+
234+
$cont = $_cont->get($id);
235+
$node = $_tree->get($id);
236+
237+
if ($cont->close_edit == 1)
238+
{
239+
return "管理员已禁止编辑本页面。";
240+
}
241+
242+
if (!empty($_POST))
243+
{
244+
if (!empty($_POST['content']) and $_POST['content'][0] == '`')
245+
{
246+
$_POST['content'] = ' '.$_POST['content'];
247+
}
248+
249+
$uid = $_SESSION['user_id'];
250+
//更新内容和标题
251+
if (!($_POST['content'] === $cont->content and trim($_POST['title']) == $cont->title))
252+
{
253+
//写入历史记录
254+
$_historyTable = table('wiki_history');
255+
$_historyTable->put(array(
256+
'wiki_id' => $node->id,
257+
'uid' => $uid,
258+
'content' => $cont->content,
259+
'title' => $cont->title,
260+
'version' => intval($cont->version),
261+
));
262+
//增加版本号
263+
$cont->version = intval($cont->version) + 1;
264+
}
265+
266+
$cont->title = trim($_POST['title']);
267+
$cont->content = $_POST['content'];
268+
$cont->uptime = time();
269+
270+
//更新节点
271+
$node->update_uid = $uid;
272+
$node->text = $cont->title;
273+
$node->link = trim($_POST['link']);
274+
275+
$node->save();
276+
$cont->save();
277+
$this->assign("info", "编辑成功,感谢您的贡献!");
278+
}
279+
$this->assign("node", $node->get());
280+
$this->assign("page", $cont->get());
281+
$this->display();
226282
}
227283
}
228284

server/apps/controllers/Wiki_admin.php

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,61 @@ function diff()
155155
$this->display();
156156
}
157157

158+
function revert()
159+
{
160+
if (empty($_GET['id']))
161+
{
162+
throw new Swoole\Exception\InvalidParam("缺少ID");
163+
}
164+
if (!isset($_GET['version']))
165+
{
166+
throw new Swoole\Exception\InvalidParam("需要version参数");
167+
}
168+
$wiki_id = intval($_GET['id']);
169+
$_table = table('wiki_history');
170+
list($res) = $_table->gets(array(
171+
'version' => intval($_GET['version']),
172+
'wiki_id' => $wiki_id,
173+
));
174+
175+
$_cont = model('WikiContent');
176+
$_tree = model('WikiTree');
177+
$cont = $_cont->get($wiki_id);
178+
$node = $_tree->get($wiki_id);
179+
if (!$cont->exist())
180+
{
181+
throw new Swoole\Exception\NotFound("页面不存在");
182+
}
183+
184+
$newVersion = intval($cont->version) + 1;
185+
//写入历史记录
186+
$_historyTable = table('wiki_history');
187+
$_historyTable->put(array(
188+
'wiki_id' => $wiki_id,
189+
'uid' => $this->uid,
190+
'content' => $cont->content,
191+
'title' => $cont->title,
192+
'version' => $cont->version,
193+
));
194+
//增加版本号
195+
$cont->version = $newVersion;
196+
$cont->title = $res['title'];
197+
$cont->content = $res['content'];
198+
$cont->uptime = time();
199+
//更新节点
200+
$node->link = $res['title'];
201+
$node->update_uid = $this->uid;
202+
$node->save();
203+
$cont->save();
204+
$this->http->redirect('/wiki_admin/main/?id='.$wiki_id);
205+
}
206+
158207
function order()
159208
{
160-
if(empty($_GET['id']))
209+
if (empty($_GET['id']))
161210
{
162211
return "错误:父页面id为空";
163-
};
212+
}
164213

165214
$parent_id = intval($_GET['id']);
166215
$model = createModel('WikiTree');
@@ -418,6 +467,9 @@ function create()
418467
$in['project_id'] = $cnode['project_id'];
419468
}
420469

470+
$in['publish'] = intval($_POST['publish']);
471+
$in['order_by_time'] = intval($_POST['order_by_time']);
472+
421473
$in['create_uid'] = $this->uid;
422474
$node_id = $_tree->put($in);
423475
$_cont = createModel('WikiContent');
@@ -429,6 +481,8 @@ function create()
429481
}
430482
$in2['content'] = $_POST['content'];
431483
$in2['id'] = $node_id;
484+
$in2['close_comment'] = intval($_POST['close_comment']);
485+
$in2['close_edit'] = intval($_POST['close_edit']);
432486
$_cont->put($in2);
433487

434488
//写入历史记录
@@ -449,10 +503,15 @@ function create()
449503
'close_comment',
450504
array('0' => '开启', '1' => '关闭'), 0, false, null, 'radio-inline'
451505
);
506+
//关闭编辑
507+
$form['close_edit'] = Swoole\Form::radio('close_edit',
508+
array('0' => '允许', '1' => '禁止'), 0, false, null, 'radio-inline');
452509
$form['order_by_time'] = Swoole\Form::radio(
453510
'order_by_time',
454511
array('0'=>'手工排序', '1'=>'按添加时间自动排序'), 0, false, null, 'radio-inline'
455512
);
513+
$form['publish'] = Swoole\Form::radio('publish',
514+
array('0' => '关闭', '1' => '开启'), 1, false, null, 'radio-inline');
456515
$this->assign("page", array());
457516
$this->assign("form", $form);
458517
$this->display();
@@ -566,20 +625,21 @@ function modify()
566625

567626
$cont = $_cont->get($id);
568627
$node = $_tree->get($id);
628+
//关闭评论
569629
$form['comment'] = Swoole\Form::radio('close_comment',
570630
array('0' => '开启', '1' => '关闭'), $cont['close_comment'], false, null, 'radio-inline');
571-
631+
//关闭编辑
632+
$form['close_edit'] = Swoole\Form::radio('close_edit',
633+
array('0' => '允许', '1' => '禁止'), $cont['close_edit'], false, null, 'radio-inline');
572634
$form['order_by_time'] = Swoole\Form::radio('order_by_time',
573635
array('0' => '手工排序', '1' => '按添加时间自动排序'), $node['order_by_time'], false, null, 'radio-inline');
574-
575636
$form['publish'] = Swoole\Form::radio('publish',
576637
array('0' => '关闭', '1' => '开启'), $node['publish'], false, null, 'radio-inline');
577638

578639
$this->assign("form", $form);
579640

580641
if (!empty($_POST))
581642
{
582-
583643
if (!empty($_POST['content']) and $_POST['content'][0] == '`')
584644
{
585645
$_POST['content'] = ' '.$_POST['content'];
@@ -603,7 +663,8 @@ function modify()
603663

604664
$cont->title = trim($_POST['title']);
605665
$cont->content = $_POST['content'];
606-
$cont->close_comment = $_POST['close_comment'];
666+
$cont->close_comment = intval($_POST['close_comment']);
667+
$cont->close_edit = intval($_POST['close_edit']);
607668
$cont->uptime = time();
608669

609670
//更新节点

server/apps/templates/footer.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="clear"></div>
22
<div id='footer'>
3-
Swoole.com版权所有 备案号:京ICP备10021081号
4-
QQ群:8745758 <a href="/person/sendmail/?to=1">给管理员写信</a> <a href="/links.html">友情链接</a><br />
5-
源代码托管提供商Google Code <a href="http://code.google.com/p/swoole/" target="_blank">http://code.google.com/p/swoole/ </a>
3+
Swoole.com版权所有 京ICP备14049466号-7
4+
QQ群:193772828 <a href="/person/sendmail/?to=1">给管理员写信</a> <br />
5+
源代码托管在Github <a href="https://github.com/swoole/swoole-src" target="_blank">https://github.com/swoole/swoole-src </a>
66

77
<div style="display:none">
88
<script type="text/javascript">

server/apps/templates/wiki/edit.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 href="/static/editor.md/css/editormd.css" rel="stylesheet">
15+
<link rel="StyleSheet" href="/static/js/tree/dtree.css" type="text/css" />
16+
<link rel="StyleSheet" href="/static/css/doc.css" type="text/css" />
17+
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
18+
<!--[if lt IE 9]>
19+
<script src="/static/bootstrap3/dist/js/html5shiv.js"></script>
20+
<script src="/static/bootstrap3/dist/js/respond.min.js"></script>
21+
<![endif]-->
22+
<script src="/static/js/rainbow-custom.min.js"></script>
23+
<script src="/static/js/jquery.min.js"></script>
24+
<script src="/static/js/dtree.js"></script>
25+
<script src="/static/editor.md/editormd.min.js"></script>
26+
<title>编辑页面_Swoole文档中心</title>
27+
</head>
28+
<body>
29+
<div class="main" style="width: 96%; margin-top: 20px;">
30+
<?php if (!empty($info)){ ?>
31+
<div id="alert-info" class="alert alert-success"><?= $info ?> <a href="/wiki/page/<?=$page['id']?>.html">点击返回</a></div>
32+
<?php }else{ ?>
33+
<div class="bs-callout bs-callout-info" style="margin-top: 0" id="div_notice">
34+
<h4>感谢您向我们贡献文档!
35+
<button type="button" class="close" onclick="$('#div_notice').hide(200);"><span
36+
aria-hidden="true">×</span><span
37+
class="sr-only">Close</span></button>
38+
</h4>
39+
<p style="line-height: 2; margin-top: 15px;">请遵守
40+
<a href="/wiki/page/p-document_contribution.html" target="_blank">《Swoole社区文档编辑条例》</a>中约定的各项细则,编辑成功后系统会自动将您的名字加入贡献者名单。
41+
<br/>请勿恶意编辑内容,否则根据社区编辑规则您的账户会被加入黑名单。</p>
42+
</div>
43+
<?php } ?>
44+
<form method="post">
45+
<div class="form-group">
46+
<input type="input" name="title" style="width: 100%;" value="<?= $this->value($page, 'title') ?>"
47+
class="form-control" placeholder="请输入标题">
48+
</div>
49+
<div class="form-group" id="md_editor">
50+
<textarea id="content" name="content"
51+
style="width: 100%; height: 640px;"><?= $this->value($page, 'content') ?></textarea>
52+
</div>
53+
<hr>
54+
<button type="submit" class="button btn-primary">提交编辑</button>
55+
<button type="button" class="button" onclick="history.back()">取消并返回</button>
56+
</form>
57+
</div>
58+
<script>
59+
var WikiEditor;
60+
$(function () {
61+
WikiEditor = editormd("md_editor", {
62+
width: "100%",
63+
height: 640,
64+
syncScrolling: "single",
65+
path: "/static/editor.md/lib/",
66+
imageUpload : true,
67+
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp"],
68+
imageUploadURL : "/wiki_admin/upload/?id=<?=$this->value($page, 'id')?>"
69+
});
70+
});
71+
</script>
72+
</body>
73+
</html>

server/apps/templates/wiki/noframe/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ <h3><a href="/wiki/page/{{if $v.link}}p-{{$v.link}}{{else}}{{$v.id}}{{/if}}.html
8181
<div class="wiki_content blob instapaper_body">
8282
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
8383
{{if $wiki_page}}
84-
<h1>{{$wiki_page.title}}</h1>
84+
<h1 id="h_title">{{$wiki_page.title}}
85+
{{if $wiki_page.close_edit == 0}}
86+
<small class="right" style="font-size: 14px; margin-top: 40px;">
87+
<a href="/wiki/edit/?id={{$wiki_page.id}}">[编辑本页]</a>
88+
</small>
89+
{{/if}}
90+
</h1>
8591
{{/if}}
8692
{{$content}}
8793
</article>

server/apps/templates/wiki_admin/create.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class="form-control" placeholder="请输入页面文件名">
6363
<span>是否公开:</span>
6464
<?= $form['publish'] ?>
6565
</div>
66+
<div class="form-group">
67+
<span>允许编辑:</span>
68+
<?= $form['close_edit'] ?>
69+
</div>
6670
<div class="form-group">
6771
<span>时间排序:</span>
6872
<?= $form['order_by_time'] ?>

server/apps/templates/wiki_admin/history.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<title><?=$wiki_page['title']?>_Swoole文档中心</title>
2424
</head>
2525
<body>
26-
<div class="main_right">
26+
<div class="main_right" style="width: 96%;">
2727
<style type="text/css">
2828
td {
2929
vertical-align: middle !important;
@@ -58,6 +58,7 @@ class="badge right">当前版本: <?= $wiki_page['version'] ?></span></a>
5858
<td><a href="/page/user/uid-<?= $li['uid'] ?>"><?= $users[$li['uid']] ?></a></td>
5959
<td><?=$li['addtime']?></td>
6060
<td>
61+
<a href="/wiki_admin/revert/?id=<?=$_GET['id']?>&version=<?=$li['version']?>" class="btn btn-sm btn-warning">回滚到此版本</a>
6162
<a href="/wiki_admin/diff/?id=<?=$_GET['id']?>&version=<?=$li['version']?>&compare=current" class="btn btn-sm btn-info">与当前版本对比</a>
6263
<?php if ($li['version'] > 0) {?>
6364
<a href="/wiki_admin/diff/?id=<?=$_GET['id']?>&version=<?=$li['version']?>&compare=last" class="btn btn-sm btn-default">与上个版本对比</a>

0 commit comments

Comments
 (0)