From ec7eb75a6b05cf93a7691bed138c8ba95c37f1dd Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 29 Oct 2013 20:39:07 +0100 Subject: [PATCH] Fix the prevention of automatic edits for pages that are currently locked or edited This makes the lock check more strict by reporting pages as locked that are locked by the current user in order to prevent accidently moving or modifying pages that are currently edited. --- action.php | 13 +++++++++---- helper.php | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/action.php b/action.php index fdea668..dcb4200 100644 --- a/action.php +++ b/action.php @@ -51,10 +51,15 @@ function handle_read(Doku_Event $event, $param) { if (isset($stack[$id])) return; - // Don't change the page when the user is currently changing the page content or the page is locked by another user - // FIXME: this doesn't work, most probably because $ACT is an array or not yet set - if ((isset($ACT) && (in_array($ACT, array('save', 'preview', 'recover', 'revert')))) - || checklock($id) !== false) return; + // Don't change the page when the user is currently changing the page content or the page is locked + $forbidden_actions = array('save', 'preview', 'recover', 'revert'); + if ((isset($ACT) && ( + in_array($ACT, $forbidden_actions) || (is_array($ACT) && in_array(key($ACT), $forbidden_actions) + ))) + // checklock checks if the page lock hasn't expired and the page hasn't been locked by another user + // the file exists check checks if the page is reported unlocked if a lock exists which means that + // the page is locked by the current user + || checklock($id) !== false || @file_exists(wikiLockFN($id))) return; $helper = $this->loadHelper('pagemove', true); if(!is_null($helper)) { diff --git a/helper.php b/helper.php index 083fe98..5ddda97 100644 --- a/helper.php +++ b/helper.php @@ -344,7 +344,10 @@ public function move_page(&$opts, $checkonly = false) { } // Check file is not locked - if (checklock($ID) !== false) { + // checklock checks if the page lock hasn't expired and the page hasn't been locked by another user + // the file exists check checks if the page is reported unlocked if a lock exists which means that + // the page is locked by the current user + if (checklock($ID) !== false || @file_exists(wikiLockFN($ID))) { msg( sprintf($this->getLang('pm_filelocked'), hsc($ID)), -1); return false; }