Merge pull request #814 from LaureeGrd/wiki-toggle-revisions

Option to disable wiki revisions
This commit is contained in:
Shish 2021-01-20 08:33:35 +00:00 committed by GitHub
commit 875c40ef00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,6 +99,7 @@ class WikiPage
abstract class WikiConfig abstract class WikiConfig
{ {
const TAG_SHORTWIKIS = "shortwikis_on_tags"; const TAG_SHORTWIKIS = "shortwikis_on_tags";
const ENABLE_REVISIONS = "wiki_revisions";
} }
class Wiki extends Extension class Wiki extends Extension
@ -110,12 +111,14 @@ class Wiki extends Extension
{ {
global $config; global $config;
$config->set_default_bool(WikiConfig::TAG_SHORTWIKIS, false); $config->set_default_bool(WikiConfig::TAG_SHORTWIKIS, false);
$config->set_default_bool(WikiConfig::ENABLE_REVISIONS, true);
} }
// Add a block to the Board Config / Setup // Add a block to the Board Config / Setup
public function onSetupBuilding(SetupBuildingEvent $event) public function onSetupBuilding(SetupBuildingEvent $event)
{ {
$sb = $event->panel->create_new_block("Wiki"); $sb = $event->panel->create_new_block("Wiki");
$sb->add_bool_option(WikiConfig::ENABLE_REVISIONS, "Enable wiki revisions: ");
$sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: "); $sb->add_bool_option(WikiConfig::TAG_SHORTWIKIS, "Show shortwiki entry when searching for a single tag: ");
} }
@ -227,9 +230,13 @@ class Wiki extends Extension
public function onWikiUpdate(WikiUpdateEvent $event) public function onWikiUpdate(WikiUpdateEvent $event)
{ {
global $database; global $database, $config;
$wpage = $event->wikipage; $wpage = $event->wikipage;
$exists = $database->exists("SELECT id FROM wiki_pages WHERE title = :title", ["title"=>$wpage->title]);
try { try {
if ($config->get_bool(WikiConfig::ENABLE_REVISIONS) || ! $exists) {
$database->execute( $database->execute(
" "
INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body) INSERT INTO wiki_pages(owner_id, owner_ip, date, title, revision, locked, body)
@ -237,6 +244,15 @@ class Wiki extends Extension
["owner_id"=>$event->user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'], ["owner_id"=>$event->user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'],
"title"=>$wpage->title, "revision"=>$wpage->revision, "locked"=>$wpage->locked, "body"=>$wpage->body] "title"=>$wpage->title, "revision"=>$wpage->revision, "locked"=>$wpage->locked, "body"=>$wpage->body]
); );
} else {
$database->execute(
"
UPDATE wiki_pages SET owner_id=:owner_id, owner_ip=:owner_ip, date=now(), locked=:locked, body=:body
WHERE title = :title ORDER BY revision DESC LIMIT 1",
["owner_id"=>$event->user->id, "owner_ip"=>$_SERVER['REMOTE_ADDR'],
"title"=>$wpage->title, "locked"=>$wpage->locked, "body"=>$wpage->body]
);
}
} catch (Exception $e) { } catch (Exception $e) {
throw new WikiUpdateException("Somebody else edited that page at the same time :-("); throw new WikiUpdateException("Somebody else edited that page at the same time :-(");
} }