Skip to content

Commit 9ac36d6

Browse files
committed
支持编辑
1 parent aadc92f commit 9ac36d6

File tree

6 files changed

+282
-55
lines changed

6 files changed

+282
-55
lines changed

server/apps/controllers/Wiki.php

Lines changed: 116 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ function upload()
292292
return App\Content::upload();
293293
}
294294

295+
protected function createPage($pid)
296+
{
297+
298+
}
299+
295300
function edit()
296301
{
297302
$this->session->start();
@@ -312,24 +317,58 @@ function edit()
312317
$_cont = model('WikiContent');
313318
$_tree = model('WikiTree');
314319

315-
$cont = $_cont->get($id);
316-
$node = $_tree->get($id);
317-
318-
if ($cont->close_edit == 1)
320+
if (!empty($_GET['create']))
321+
{
322+
$cont = $_cont->get();
323+
$node = $_tree->get();
324+
$create = true;
325+
}
326+
else
319327
{
320-
return "管理员已禁止编辑本页面。";
328+
$cont = $_cont->get($id);
329+
$node = $_tree->get($id);
330+
$create = false;
331+
332+
if ($cont->close_edit == 1)
333+
{
334+
return "管理员已禁止编辑本页面。";
335+
}
321336
}
322337

323338
if (!empty($_POST))
324339
{
340+
if (empty($_POST['title']))
341+
{
342+
$this->assign("info", ['message' => "标题不能为空!", 'code' => 4001]);
343+
goto display;
344+
}
345+
if (empty($_POST['content']))
346+
{
347+
$this->assign("info", ['message' => "内容不能为空!", 'code' => 4002]);
348+
goto display;
349+
}
325350
if (!empty($_POST['content']) and $_POST['content'][0] == '`')
326351
{
327-
$_POST['content'] = ' '.$_POST['content'];
352+
$_POST['content'] = ' ' . $_POST['content'];
353+
}
354+
//检查内容是否变更
355+
if ($_POST['content'] === $cont->content and trim($_POST['title']) == $cont->title)
356+
{
357+
$this->assign("info", ['message' => "标题和内容无任何修改", 'code' => 4003]);
358+
goto display;
328359
}
329360

330-
//更新内容和标题
331-
if (!($_POST['content'] === $cont->content and trim($_POST['title']) == $cont->title))
361+
//编辑
362+
if (!$create)
332363
{
364+
$cont->title = trim($_POST['title']);
365+
$cont->content = $_POST['content'];
366+
$cont->uptime = time();
367+
368+
//更新节点
369+
$node->update_uid = $uid;
370+
$node->text = $cont->title;
371+
333372
//写入历史记录
334373
$_historyTable = table('wiki_history');
335374
$_historyTable->put(array(
@@ -352,35 +391,84 @@ function edit()
352391
}
353392
//增加版本号
354393
$cont->version = intval($cont->version) + 1;
394+
395+
//更新缓存
396+
App\Content::clearCache($node->id);
397+
if (!$node->save())
398+
{
399+
error:
400+
$this->assign("info", ['message' => "提交失败,请稍后重试!", 'code' => 201]);
401+
goto display;
402+
}
403+
if (!$cont->save())
404+
{
405+
goto error;
406+
}
407+
$this->assign("info", ['message' => "编辑成功,感谢您的贡献!", 'code' => 0]);
355408
}
356409
else
357410
{
358-
goto display;
359-
}
411+
$page = $_tree->get($_GET['id'])->get();
360412

361-
$cont->title = trim($_POST['title']);
362-
$cont->content = $_POST['content'];
363-
$cont->uptime = time();
413+
$cont->title = trim($_POST['title']);
414+
$cont->content = $_POST['content'];
364415

365-
//更新节点
366-
$node->update_uid = $uid;
367-
$node->text = $cont->title;
416+
$node->project_id = $page['project_id'];
417+
$node->update_uid = $node->create_uid = $uid;
418+
$node->text = $cont->title;
368419

369-
//更新缓存
370-
App\Content::clearCache($node->id);
371-
if (!$node->save())
372-
{
373-
error:
374-
$this->assign("info", "提交失败,请稍后重试!");
375-
}
376-
if (!$cont->save())
377-
{
378-
goto error;
420+
//创建子页面
421+
if ($_GET['create'] == 'child')
422+
{
423+
$node->pid = $_GET['id'];
424+
}
425+
//创建同级页面
426+
else
427+
{
428+
$node->pid = $page['pid'];
429+
}
430+
$node->publish = 1;
431+
if (!$node->save())
432+
{
433+
goto error;
434+
}
435+
$cont->id = $node->_current_id;
436+
$cont->uptime = time();
437+
$cont->version = 1;
438+
//写入历史记录
439+
$_historyTable = table('wiki_history');
440+
$_historyTable->put(array(
441+
'wiki_id' => $node->id,
442+
'uid' => $uid,
443+
'content' => $cont->content,
444+
'title' => $cont->title,
445+
'version' => intval($cont->version),
446+
));
447+
//更新索引
448+
if ($this->project_id == 1)
449+
{
450+
$index = new App\Indexer('wiki');
451+
$index->add([
452+
'pid' => $node->id,
453+
'subject' => $cont->title,
454+
'message' => $cont->content,
455+
'chrono' => time()
456+
]);
457+
}
458+
if (!$cont->save())
459+
{
460+
goto error;
461+
}
462+
$this->assign("info", ['message' => "添加成功,感谢您的贡献!", 'code' => 0]);
379463
}
380-
$this->assign("info", "编辑成功,感谢您的贡献!");
381464
}
382465
display:
383-
$this->assign("node", $node->get());
466+
$_node = $node->get();
467+
if (empty($_node['id']))
468+
{
469+
$_node['id'] = $node->_current_id;
470+
}
471+
$this->assign("node", $_node);
384472
$this->assign("page", $cont->get());
385473
$this->display();
386474
}

server/apps/templates/wiki/edit.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@
2727
</head>
2828
<body>
2929
<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 } ?>
30+
<?php if (!empty($info))
31+
{ ?>
32+
<div id="alert-info"
33+
class="alert alert-<?= $info['code'] == 0 ? 'success' : 'danger' ?>"><?= $info['message'] ?> <a
34+
href="/wiki/page/<?= $_GET['id'] ?>.html">点击返回</a></div>
35+
<?php }
36+
else
37+
{ ?>
38+
<div class="bs-callout bs-callout-info" style="margin-top: 0" id="div_notice">
39+
<h4>感谢您向我们贡献文档!
40+
<button type="button" class="close" onclick="$('#div_notice').hide(200);"><span
41+
aria-hidden="true">×</span><span
42+
class="sr-only">Close</span></button>
43+
</h4>
44+
<p style="line-height: 2; margin-top: 15px;">请遵守
45+
<a href="/wiki/page/p-document_contribution.html" target="_blank">《Swoole社区文档编辑条例》</a>中约定的各项细则,编辑成功后系统会自动将您的名字加入贡献者名单。
46+
<br/>请勿恶意编辑内容,否则根据社区编辑规则您的账户会被加入黑名单。</p>
47+
</div>
48+
<?php } ?>
4449
<form method="post">
4550
<div class="form-group">
4651
<input type="input" name="title" style="width: 100%;" value="<?= $this->value($page, 'title') ?>"

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<div class="sidebar-nav">
5454
<ul class="nav">
5555
{{foreach item=v from=$tree.child}}
56-
<li class="active">
56+
<li class="active" {{if $v.id == $smarty.get.id}}id="wiki_node_active"{{/if}}>
5757
<h3><a href="/wiki/page/{{if $v.link}}p-{{$v.link}}{{else}}{{$v.id}}{{/if}}.html">{{$v.text}}</a></h3>
5858
</li>
5959
<li>
@@ -82,15 +82,42 @@ <h3><a href="/wiki/page/{{if $v.link}}p-{{$v.link}}{{else}}{{$v.id}}{{/if}}.html
8282
</div>
8383
</div>
8484
<div class="wiki_content blob instapaper_body">
85-
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
86-
{{if $wiki_page}}
87-
<h1 id="h_title">{{$wiki_page.title}}
85+
<div class="panel-heading" style="margin: 0;background-color: #f5f5f5; border-color: #ddd;">
86+
<div class="row text-right" style="padding-right: 10px;">
87+
88+
<a class="btn btn-info" href="/wiki/edit/?id={{$wiki_page.id}}&create=child">
89+
<span class="glyphicon glyphicon-file"></span>增加子页面</a>
90+
{{if $wiki_page.id != $project.home_id}}
91+
<a class="btn btn-info" href="/wiki/edit/?id={{$wiki_page.id}}&create=brother">
92+
<span class="glyphicon glyphicon-file"></span>增加同级页面</a>
93+
{{/if}}
94+
8895
{{if $wiki_page.close_edit == 0}}
89-
<small class="right" style="font-size: 14px; margin-top: 40px;">
90-
<a href="/wiki/edit/?id={{$wiki_page.id}}">[编辑本页]</a>
91-
</small>
96+
<a href="/wiki/edit/?id={{$wiki_page.id}}" class="btn btn-success"><span
97+
class="glyphicon glyphicon-edit"></span>
98+
编辑本页
99+
</a>
92100
{{/if}}
93-
</h1>
101+
102+
<div class="btn-group text-left">
103+
<button type="button" class="btn btn-default">更多...</button>
104+
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
105+
<span class="caret"></span>
106+
<span class="sr-only">Toggle Dropdown</span>
107+
</button>
108+
<ul class="dropdown-menu">
109+
<li><a href="#">Markdown源码</a></li>
110+
<li><a href="#">历史修改记录</a></li>
111+
<li><a href="#">贡献者名单</a></li>
112+
<!--<li role="separator" class="divider"></li>-->
113+
<!--<li><a href="#">Separated link</a></li>-->
114+
</ul>
115+
</div>
116+
</div>
117+
</div>
118+
<article class="markdown-body entry-content" itemprop="mainContentOfPage">
119+
{{if $wiki_page}}
120+
<h1 id="h_title">{{$wiki_page.title}}</h1>
94121
{{/if}}
95122
{{$content}}
96123
</article>
@@ -209,7 +236,7 @@ <h1 id="h_title">{{$wiki_page.title}}
209236
headingSelector: 'h2, h3'
210237
});
211238
tocbot.refresh();
212-
$('.js-toc').css("left", $('.entry-content').position().left + 850);
239+
$('.js-toc').css("left", $('.entry-content').position().left + 870);
213240
var timer = setInterval(function () {
214241
divAlign();
215242
window.clearInterval(timer);
@@ -243,6 +270,8 @@ <h1 id="h_title">{{$wiki_page.title}}
243270
</script>
244271
</div>
245272
</div>
273+
<script src="/static/js/jquery.min.js"></script>
274+
<script src="/static/bootstrap3/dist/js/bootstrap.min.js"></script>
246275
<div class="container footer" style="height: 80px; clear: both">
247276
<hr />
248277
<p>&copy; Swoole.com 2008 - {{'Y'|date}} 备案号:京ICP备14049466号-7 | <a href="https://wiki.swoole.com/wiki/page/p-copyright.html">版权声明</a> 官方QQ群:399424487 开发组邮件列表:

0 commit comments

Comments
 (0)