per-page locking

git-svn-id: file:///home/shish/svn/shimmie2/trunk@134 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-05-23 23:37:29 +00:00
parent f91d777045
commit bb19755625

View file

@ -27,6 +27,7 @@ class WikiPage {
var $date; var $date;
var $title; var $title;
var $revision; var $revision;
var $locked;
var $body; var $body;
public function WikiPage($row=null) { public function WikiPage($row=null) {
@ -37,6 +38,7 @@ class WikiPage {
$this->date = $row['date']; $this->date = $row['date'];
$this->title = $row['title']; $this->title = $row['title'];
$this->revision = $row['revision']; $this->revision = $row['revision'];
$this->locked = ($row['locked'] == 'Y');
$this->body = $row['body']; $this->body = $row['body'];
} }
} }
@ -47,7 +49,7 @@ class WikiPage {
} }
public function is_locked() { public function is_locked() {
return false; return $this->locked;
} }
} }
// }}} // }}}
@ -55,10 +57,7 @@ class Wiki extends Extension {
// event handler {{{ // event handler {{{
public function receive_event($event) { public function receive_event($event) {
if(is_a($event, 'InitExtEvent')) { if(is_a($event, 'InitExtEvent')) {
global $config; $this->setup();
if($config->get_int("ext_wiki_version") < 1) {
$this->install();
}
} }
if(is_a($event, 'PageRequestEvent') && ($event->page == "wiki")) { if(is_a($event, 'PageRequestEvent') && ($event->page == "wiki")) {
@ -81,10 +80,16 @@ class Wiki extends Extension {
$title = $_POST['title']; $title = $_POST['title'];
$rev = $_POST['revision']; $rev = $_POST['revision'];
$body = $_POST['body']; $body = $_POST['body'];
$lock = $_POST['lock'];
global $user; global $user;
if($this->can_edit($user, $this->get_page($title))) { if($this->can_edit($user, $this->get_page($title))) {
$this->set_page($title, $rev, $body); if($user->is_admin()) {
$this->set_page($title, $rev, $body, $lock);
}
else {
$this->set_page($title, $rev, $body, false);
}
$u_title = url_escape($title); $u_title = url_escape($title);
@ -141,9 +146,11 @@ class Wiki extends Extension {
} }
// }}} // }}}
// installer {{{ // installer {{{
protected function install() { private function setup() {
global $database; global $database;
global $config; global $config;
if($config->get_int("ext_wiki_version") < 1) {
$database->Execute("CREATE TABLE wiki_pages ( $database->Execute("CREATE TABLE wiki_pages (
id int(11) NOT NULL auto_increment, id int(11) NOT NULL auto_increment,
owner_id int(11) NOT NULL, owner_id int(11) NOT NULL,
@ -156,6 +163,12 @@ class Wiki extends Extension {
)"); )");
$config->set_int("ext_wiki_version", 1); $config->set_int("ext_wiki_version", 1);
} }
if($config->get_int("ext_wiki_version") < 2) {
$database->Execute("ALTER TABLE wiki_pages ADD COLUMN
locked ENUM('Y', 'N') DEFAULT 'N' NOT NULL AFTER REVISION");
$config->set_int("ext_wiki_version", 2);
}
}
// }}} // }}}
// database {{{ // database {{{
private function get_page($title, $revision=-1) { private function get_page($title, $revision=-1) {
@ -167,13 +180,13 @@ class Wiki extends Extension {
ORDER BY revision DESC", array($title)); ORDER BY revision DESC", array($title));
return ($row ? new WikiPage($row) : null); return ($row ? new WikiPage($row) : null);
} }
private function set_page($title, $rev, $body) { private function set_page($title, $rev, $body, $locked) {
global $database; global $database;
global $user; global $user;
// FIXME: deal with collisions // FIXME: deal with collisions
$row = $database->Execute(" $row = $database->Execute("
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, body) INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
VALUES (?, ?, now(), ?, ?, ?)", array($user->id, $_SERVER['REMOTE_ADDR'], $title, $rev, $body)); VALUES (?, ?, now(), ?, ?, ?, ?)", array($user->id, $_SERVER['REMOTE_ADDR'], $title, $rev, $locked?'Y':'N', $body));
} }
// }}} // }}}
// html {{{ // html {{{
@ -182,11 +195,20 @@ class Wiki extends Extension {
$u_title = url_escape($page->title); $u_title = url_escape($page->title);
$i_revision = int_escape($page->revision) + 1; $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 " return "
<form action='".make_link("wiki/$u_title", "save=on")."' method='POST'> <form action='".make_link("wiki/$u_title", "save=on")."' method='POST'>
<input type='hidden' name='title' value='$h_title'> <input type='hidden' name='title' value='$h_title'>
<input type='hidden' name='revision' value='$i_revision'> <input type='hidden' name='revision' value='$i_revision'>
<textarea name='body' style='width: 100%' rows='20'>".html_escape($page->body)."</textarea> <textarea name='body' style='width: 100%' rows='20'>".html_escape($page->body)."</textarea>
$lock
<br><input type='submit' value='Save'> <br><input type='submit' value='Save'>
</form> </form>
"; ";