a bunch of wiki fixes
This commit is contained in:
parent
2a36504b4f
commit
d02c803d60
2 changed files with 48 additions and 48 deletions
|
@ -26,22 +26,20 @@ class WikiPage {
|
||||||
var $locked;
|
var $locked;
|
||||||
var $body;
|
var $body;
|
||||||
|
|
||||||
public function WikiPage($row=null) {
|
public function WikiPage($row) {
|
||||||
if(!is_null($row)) {
|
assert(!empty($row));
|
||||||
$this->id = $row['id'];
|
|
||||||
$this->owner_id = $row['owner_id'];
|
$this->id = $row['id'];
|
||||||
$this->owner_ip = $row['owner_ip'];
|
$this->owner_id = $row['owner_id'];
|
||||||
$this->date = $row['date'];
|
$this->owner_ip = $row['owner_ip'];
|
||||||
$this->title = $row['title'];
|
$this->date = $row['date'];
|
||||||
$this->revision = $row['revision'];
|
$this->title = $row['title'];
|
||||||
$this->locked = ($row['locked'] == 'Y');
|
$this->revision = $row['revision'];
|
||||||
$this->body = $row['body'];
|
$this->locked = ($row['locked'] == 'Y');
|
||||||
}
|
$this->body = $row['body'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_owner() {
|
public function get_owner() {
|
||||||
global $config;
|
|
||||||
global $database;
|
|
||||||
return User::by_id($this->owner_id);
|
return User::by_id($this->owner_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +73,10 @@ class Wiki extends SimpleExtension {
|
||||||
$lock = isset($_POST['lock']) && ($_POST['lock'] == "on");
|
$lock = isset($_POST['lock']) && ($_POST['lock'] == "on");
|
||||||
|
|
||||||
if($this->can_edit($user, $this->get_page($title))) {
|
if($this->can_edit($user, $this->get_page($title))) {
|
||||||
$wikipage = new WikiPage();
|
$wikipage = $this->get_page($title);
|
||||||
$wikipage->title = $title;
|
|
||||||
$wikipage->rev = $rev;
|
$wikipage->rev = $rev;
|
||||||
$wikipage->body = $body;
|
$wikipage->body = $body;
|
||||||
$wikipage->lock = $user->is_admin() ? $lock : false;
|
$wikipage->locked = $user->is_admin() ? $lock : false;
|
||||||
send_event(new WikiUpdateEvent($user, $wikipage));
|
send_event(new WikiUpdateEvent($user, $wikipage));
|
||||||
|
|
||||||
$u_title = url_escape($title);
|
$u_title = url_escape($title);
|
||||||
|
@ -115,13 +112,24 @@ class Wiki extends SimpleExtension {
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function can_edit($user, $page) {
|
/**
|
||||||
|
* See if the given user is allowed to edit the given page
|
||||||
|
*
|
||||||
|
* @retval boolean
|
||||||
|
*/
|
||||||
|
public static function can_edit(User $user, WikiPage $page) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if(!is_null($page) && $page->is_locked() && !$user->is_admin()) return false;
|
// admins can edit everything
|
||||||
|
if($user->is_admin()) return true;
|
||||||
|
|
||||||
|
// anon / user can't ever edit locked pages
|
||||||
|
if($page->is_locked()) return false;
|
||||||
|
|
||||||
|
// anon / user can edit if allowed by config
|
||||||
if($config->get_bool("wiki_edit_anon", false) && $user->is_anonymous()) return true;
|
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($config->get_bool("wiki_edit_user", false) && !$user->is_anonymous()) return true;
|
||||||
if($user->is_admin()) return true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +169,7 @@ class Wiki extends SimpleExtension {
|
||||||
ORDER BY revision DESC", array($title));
|
ORDER BY revision DESC", array($title));
|
||||||
|
|
||||||
// fall back to wiki:default
|
// fall back to wiki:default
|
||||||
if(is_null($row)) {
|
if(empty($row)) {
|
||||||
$row = $database->db->GetRow("
|
$row = $database->db->GetRow("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM wiki_pages
|
FROM wiki_pages
|
||||||
|
@ -169,17 +177,15 @@ class Wiki extends SimpleExtension {
|
||||||
ORDER BY revision DESC", "wiki:default");
|
ORDER BY revision DESC", "wiki:default");
|
||||||
|
|
||||||
// fall further back to manual
|
// fall further back to manual
|
||||||
if(is_null($row)) {
|
if(empty($row)) {
|
||||||
$row = array(
|
$row = array(
|
||||||
"id" => -1,
|
"id" => -1,
|
||||||
"owner_ip" => "0.0.0.0",
|
"owner_ip" => "0.0.0.0",
|
||||||
"date" => "",
|
"date" => "",
|
||||||
"revision" => 0,
|
"revision" => 0,
|
||||||
"locked" => false,
|
"locked" => false,
|
||||||
"body" => "
|
"body" => "This is a default page for when a page is empty, ".
|
||||||
This is a default page for when a page is empty,
|
"it can be edited by editing [[wiki:default]].",
|
||||||
it can be edited by editing [[wiki:default]].
|
|
||||||
",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +195,7 @@ class Wiki extends SimpleExtension {
|
||||||
$row["owner_id"] = $config->get_int("anon_id", 0);
|
$row["owner_id"] = $config->get_int("anon_id", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!is_null($row));
|
assert(!empty($row));
|
||||||
|
|
||||||
return new WikiPage($row);
|
return new WikiPage($row);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ class WikiTheme extends Themelet {
|
||||||
$tfe = new TextFormattingEvent($nav_page->body);
|
$tfe = new TextFormattingEvent($nav_page->body);
|
||||||
send_event($tfe);
|
send_event($tfe);
|
||||||
|
|
||||||
|
// only the admin can edit the sidebar
|
||||||
global $user;
|
global $user;
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar", "edit=on")."'>Edit</a>)";
|
$tfe->formatted .= "<p>(<a href='".make_link("wiki/wiki:sidebar", "edit=on")."'>Edit</a>)";
|
||||||
|
@ -36,16 +37,6 @@ class WikiTheme extends Themelet {
|
||||||
$page->add_block(new Block("Editor", $this->create_edit_html($wiki_page)));
|
$page->add_block(new Block("Editor", $this->create_edit_html($wiki_page)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function can_edit(User $user, WikiPage $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;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function create_edit_html(WikiPage $page) {
|
protected function create_edit_html(WikiPage $page) {
|
||||||
$h_title = html_escape($page->title);
|
$h_title = html_escape($page->title);
|
||||||
$u_title = url_escape($page->title);
|
$u_title = url_escape($page->title);
|
||||||
|
@ -76,20 +67,23 @@ class WikiTheme extends Themelet {
|
||||||
$tfe = new TextFormattingEvent($page->body);
|
$tfe = new TextFormattingEvent($page->body);
|
||||||
send_event($tfe);
|
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;
|
global $user;
|
||||||
if($this->can_edit($user, $page)) {
|
$edit = Wiki::can_edit($user, $page) ?
|
||||||
$html .= "[<a href='".make_link("wiki/{$page->title}", "edit=on")."'>edit</a>] ";
|
"[<a href='".make_link("wiki/{$page->title}", "edit=on")."'>edit</a>] " :
|
||||||
}
|
"";
|
||||||
|
|
||||||
$html .= "</p></div>";
|
return "
|
||||||
|
<div class='wiki-page'>
|
||||||
return $html;
|
$tfe->formatted
|
||||||
|
<hr>
|
||||||
|
<p class='wiki-footer'>
|
||||||
|
Revision {$page->revision}
|
||||||
|
by <a href='".make_link("user/{$owner->name}")."'>{$owner->name}</a>
|
||||||
|
at {$page->date}
|
||||||
|
$edit
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Reference in a new issue