wiki themed
git-svn-id: file:///home/shish/svn/shimmie2/trunk@330 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
05ab9e5468
commit
852412ddf2
2 changed files with 102 additions and 71 deletions
|
@ -54,17 +54,16 @@ class WikiPage {
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
class Wiki extends Extension {
|
class Wiki extends Extension {
|
||||||
// event handler {{{
|
var $theme;
|
||||||
|
|
||||||
public function receive_event($event) {
|
public function receive_event($event) {
|
||||||
|
if(is_null($this->theme)) $this->theme = get_theme_object("wiki", "WikiTheme");
|
||||||
|
|
||||||
if(is_a($event, 'InitExtEvent')) {
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
$this->setup();
|
$this->setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "wiki")) {
|
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "wiki")) {
|
||||||
global $page;
|
|
||||||
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
|
|
||||||
if(is_null($event->get_arg(0)) || strlen(trim($event->get_arg(0))) == 0) {
|
if(is_null($event->get_arg(0)) || strlen(trim($event->get_arg(0))) == 0) {
|
||||||
$title = "Index";
|
$title = "Index";
|
||||||
}
|
}
|
||||||
|
@ -72,10 +71,8 @@ class Wiki extends Extension {
|
||||||
$title = $event->get_arg(0);
|
$title = $event->get_arg(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page->set_title(html_escape($title));
|
|
||||||
$page->set_heading(html_escape($title));
|
|
||||||
|
|
||||||
$content = $this->get_page($title);
|
$content = $this->get_page($title);
|
||||||
|
|
||||||
if(isset($_GET['save']) && $_GET['save'] == "on") {
|
if(isset($_GET['save']) && $_GET['save'] == "on") {
|
||||||
$title = $_POST['title'];
|
$title = $_POST['title'];
|
||||||
$rev = int_escape($_POST['revision']);
|
$rev = int_escape($_POST['revision']);
|
||||||
|
@ -93,16 +90,11 @@ class Wiki extends Extension {
|
||||||
|
|
||||||
$u_title = url_escape($title);
|
$u_title = url_escape($title);
|
||||||
|
|
||||||
global $page;
|
$event->page->set_mode("redirect");
|
||||||
$page->set_mode("redirect");
|
$event->page->set_redirect(make_link("wiki/$u_title"));
|
||||||
$page->set_redirect(make_link("wiki/$u_title"));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
global $page;
|
$this->theme->display_error($event->page, "Denied", "You do not have permission to edit this page");
|
||||||
$page->set_title("Denied");
|
|
||||||
$page->set_heading("Denied");
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
$page->add_block(new Block("Denied", "You do not have permission to edit this page"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(is_null($content)) {
|
else if(is_null($content)) {
|
||||||
|
@ -114,18 +106,17 @@ class Wiki extends Extension {
|
||||||
$blank->body = $default->body;
|
$blank->body = $default->body;
|
||||||
$blank->owner_id = $config->get_int('anon_id');
|
$blank->owner_id = $config->get_int('anon_id');
|
||||||
$blank->date = $default->date;
|
$blank->date = $default->date;
|
||||||
$content = $this->create_display_html($blank);
|
$this->theme->display_page($event->page, $blank, $this->get_page("wiki:sidebar"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$content = $this->create_edit_html($blank);
|
$this->theme->display_page_editor($event->page, $blank);
|
||||||
}
|
}
|
||||||
$page->add_block(new Block("Content", $content));
|
|
||||||
}
|
}
|
||||||
else if(isset($_GET['edit']) && $_GET['edit'] == "on") {
|
else if(isset($_GET['edit']) && $_GET['edit'] == "on") {
|
||||||
$page->add_block(new Block("Content", $this->create_edit_html($content)));
|
$this->theme->display_page_editor($event->page, $content);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$page->add_block(new Block("Content", $this->create_display_html($content)));
|
$this->theme->display_page($event->page, $content, $this->get_page("wiki:sidebar"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +131,7 @@ class Wiki extends Extension {
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
// misc {{{
|
|
||||||
private function can_edit($user, $page) {
|
private function can_edit($user, $page) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
@ -151,7 +141,7 @@ class Wiki extends Extension {
|
||||||
if($user->is_admin()) return true;
|
if($user->is_admin()) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
// installer {{{
|
// installer {{{
|
||||||
private function setup() {
|
private function setup() {
|
||||||
global $database;
|
global $database;
|
||||||
|
@ -196,53 +186,6 @@ class Wiki extends Extension {
|
||||||
VALUES (?, ?, now(), ?, ?, ?, ?)", array($user->id, $_SERVER['REMOTE_ADDR'], $title, $rev, $locked?'Y':'N', $body));
|
VALUES (?, ?, now(), ?, ?, ?, ?)", array($user->id, $_SERVER['REMOTE_ADDR'], $title, $rev, $locked?'Y':'N', $body));
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// html {{{
|
|
||||||
private function create_edit_html($page) {
|
|
||||||
$h_title = html_escape($page->title);
|
|
||||||
$u_title = url_escape($page->title);
|
|
||||||
$i_revision = int_escape($page->revision) + 1;
|
|
||||||
|
|
||||||
global $user;
|
|
||||||
if($user->is_admin()) {
|
|
||||||
$val = $page->is_locked() ? " checked" : "";
|
|
||||||
$lock = "<br>Lock page: <input type='checkbox' name='lock'$val>";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$lock = "";
|
|
||||||
}
|
|
||||||
return "
|
|
||||||
<form action='".make_link("wiki/$u_title", "save=on")."' method='POST'>
|
|
||||||
<input type='hidden' name='title' value='$h_title'>
|
|
||||||
<input type='hidden' name='revision' value='$i_revision'>
|
|
||||||
<textarea name='body' style='width: 100%' rows='20'>".html_escape($page->body)."</textarea>
|
|
||||||
$lock
|
|
||||||
<br><input type='submit' value='Save'>
|
|
||||||
</form>
|
|
||||||
";
|
|
||||||
}
|
|
||||||
|
|
||||||
private function create_display_html($page) {
|
|
||||||
$owner = $page->get_owner();
|
|
||||||
|
|
||||||
$tfe = new TextFormattingEvent($page->body);
|
|
||||||
send_event($tfe);
|
|
||||||
|
|
||||||
$html = "<div class='wiki-page'>";
|
|
||||||
$html .= $tfe->formatted;
|
|
||||||
$html .= "<hr>";
|
|
||||||
$html .= "<p class='wiki-footer'>Revision {$page->revision} by ".
|
|
||||||
"<a href='".make_link("user/{$owner->name}")."'>{$owner->name}</a> at {$page->date} ";
|
|
||||||
|
|
||||||
global $user;
|
|
||||||
if($this->can_edit($user, $page)) {
|
|
||||||
$html .= "[<a href='".make_link("wiki/{$page->title}", "edit=on")."'>edit</a>] ";
|
|
||||||
}
|
|
||||||
|
|
||||||
$html .= "</p></div>";
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
// }}}
|
|
||||||
}
|
}
|
||||||
add_event_listener(new Wiki());
|
add_event_listener(new Wiki());
|
||||||
?>
|
?>
|
||||||
|
|
88
contrib/wiki/theme.php
Normal file
88
contrib/wiki/theme.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class WikiTheme {
|
||||||
|
public function display_page($page, $wiki_page, $nav_page) {
|
||||||
|
if(is_null($nav_page)) {
|
||||||
|
$nav_page = new WikiPage();
|
||||||
|
$nav_page->body = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$tfe = new TextFormattingEvent($nav_page->body);
|
||||||
|
send_event($tfe);
|
||||||
|
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar", "edit=on")."'>Edit</a>)";
|
||||||
|
}
|
||||||
|
|
||||||
|
$page->set_title(html_escape($wiki_page->title));
|
||||||
|
$page->set_heading(html_escape($wiki_page->title));
|
||||||
|
$page->add_block(new NavBlock());
|
||||||
|
$page->add_block(new Block("Wiki Index", $tfe->formatted, "left", 20));
|
||||||
|
$page->add_block(new Block("Content", $this->create_display_html($wiki_page)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function display_page_editor($page, $wiki_page) {
|
||||||
|
$page->set_title(html_escape($wiki_page->title));
|
||||||
|
$page->set_heading(html_escape($wiki_page->title));
|
||||||
|
$page->add_block(new NavBlock());
|
||||||
|
$page->add_block(new Block("Editor", $this->create_edit_html($wiki_page)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function can_edit($user, $page) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if(!is_null($page) && $page->is_locked() && !$user->is_admin()) return false;
|
||||||
|
if($config->get_bool("wiki_edit_anon", false) && $user->is_anonymous()) return true;
|
||||||
|
if($config->get_bool("wiki_edit_user", false) && !$user->is_anonymous()) return true;
|
||||||
|
if($user->is_admin()) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create_edit_html($page) {
|
||||||
|
$h_title = html_escape($page->title);
|
||||||
|
$u_title = url_escape($page->title);
|
||||||
|
$i_revision = int_escape($page->revision) + 1;
|
||||||
|
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$val = $page->is_locked() ? " checked" : "";
|
||||||
|
$lock = "<br>Lock page: <input type='checkbox' name='lock'$val>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$lock = "";
|
||||||
|
}
|
||||||
|
return "
|
||||||
|
<form action='".make_link("wiki/$u_title", "save=on")."' method='POST'>
|
||||||
|
<input type='hidden' name='title' value='$h_title'>
|
||||||
|
<input type='hidden' name='revision' value='$i_revision'>
|
||||||
|
<textarea name='body' style='width: 100%' rows='20'>".html_escape($page->body)."</textarea>
|
||||||
|
$lock
|
||||||
|
<br><input type='submit' value='Save'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create_display_html($page) {
|
||||||
|
$owner = $page->get_owner();
|
||||||
|
|
||||||
|
$tfe = new TextFormattingEvent($page->body);
|
||||||
|
send_event($tfe);
|
||||||
|
|
||||||
|
$html = "<div class='wiki-page'>";
|
||||||
|
$html .= $tfe->formatted;
|
||||||
|
$html .= "<hr>";
|
||||||
|
$html .= "<p class='wiki-footer'>Revision {$page->revision} by ".
|
||||||
|
"<a href='".make_link("user/{$owner->name}")."'>{$owner->name}</a> at {$page->date} ";
|
||||||
|
|
||||||
|
global $user;
|
||||||
|
if($this->can_edit($user, $page)) {
|
||||||
|
$html .= "[<a href='".make_link("wiki/{$page->title}", "edit=on")."'>edit</a>] ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= "</p></div>";
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Reference in a new issue