summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Coburn <btcoburn@silicodon.net>2006-07-05 05:31:35 +0200
committerBen Coburn <btcoburn@silicodon.net>2006-07-05 05:31:35 +0200
commitc9b4bd1e30a047b11d0beaa4458204126e0c1b92 (patch)
treefcc68cf213146532363ca534c6e4a65e458a6b21
parent306ca8aa54954ea2623d9e4927a2c07b9efdfea3 (diff)
downloadrpg-c9b4bd1e30a047b11d0beaa4458204126e0c1b92.tar.gz
rpg-c9b4bd1e30a047b11d0beaa4458204126e0c1b92.tar.bz2
refactor wiki page edit locking
- Adds a new function in 'inc/pageutils.php', wikiLockFN($id) - All page edit locks should now be created with the file name generated by wikiLockFN($id). - wikiLockFN - Generates wiki page editing locks in the 'data/locks' directory where they belong. - This avoids polluting the 'data/pages' directory with lock files, which were causing namespaces to be created before they logically should exist. darcs-hash:20060705033135-05dcb-8eac316587cd54c6ebd861fe7b15975d90b0e4dc.gz
-rwxr-xr-xbin/dwpage.php4
-rw-r--r--inc/common.php6
-rw-r--r--inc/html.php2
-rw-r--r--inc/pageutils.php11
4 files changed, 17 insertions, 6 deletions
diff --git a/bin/dwpage.php b/bin/dwpage.php
index 9fd523c93..a30a28e04 100755
--- a/bin/dwpage.php
+++ b/bin/dwpage.php
@@ -158,7 +158,7 @@ function clearLock($WIKI_ID) {
unlock($WIKI_ID);
- if ( file_exists(wikiFN($WIKI_ID).'.lock') ) {
+ if ( file_exists(wikiLockFN($WIKI_ID)) ) {
fwrite( STDERR, "Unable to clear lock for $WIKI_ID\n" );
exit(1);
}
@@ -168,7 +168,7 @@ function clearLock($WIKI_ID) {
#------------------------------------------------------------------------------
function deleteLock($WIKI_ID) {
- $wikiLockFN = wikiFN($WIKI_ID).'.lock';
+ $wikiLockFN = wikiLockFN($WIKI_ID);
if ( file_exists($wikiLockFN) ) {
if ( !unlink($wikiLockFN) ) {
diff --git a/inc/common.php b/inc/common.php
index e47b4e7a3..b1246ba7f 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -523,7 +523,7 @@ function clientIP($single=false){
*/
function checklock($id){
global $conf;
- $lock = wikiFN($id).'.lock';
+ $lock = wikiLockFN($id);
//no lockfile
if(!@file_exists($lock)) return false;
@@ -549,7 +549,7 @@ function checklock($id){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function lock($id){
- $lock = wikiFN($id).'.lock';
+ $lock = wikiLockFN($id);
if($_SERVER['REMOTE_USER']){
io_saveFile($lock,$_SERVER['REMOTE_USER']);
}else{
@@ -564,7 +564,7 @@ function lock($id){
* @return bool true if a lock was removed
*/
function unlock($id){
- $lock = wikiFN($id).'.lock';
+ $lock = wikiLockFN($id);
if(@file_exists($lock)){
$ip = io_readFile($lock);
if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){
diff --git a/inc/html.php b/inc/html.php
index 2a02b8c34..7f5050b8d 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -422,7 +422,7 @@ function html_locked(){
global $lang;
global $INFO;
- $locktime = filemtime(wikiFN($ID).'.lock');
+ $locktime = filemtime(wikiLockFN($ID));
$expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
$min = round(($conf['locktime'] - (time() - $locktime) )/60);
diff --git a/inc/pageutils.php b/inc/pageutils.php
index f9d182aac..c10c1c4e8 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -152,6 +152,17 @@ function wikiFN($id,$rev=''){
}
/**
+ * Returns the full path to the file for locking the page while editing.
+ *
+ * @author Ben Coburn <btcoburn@silicodon.net>
+ */
+function wikiLockFN($id) {
+ global $conf;
+ return $conf['lockdir'].'/'.sha1(cleanID($id)).'.lock';
+}
+
+
+/**
* returns the full path to the meta file specified by ID and extension
*
* The filename is URL encoded to protect Unicode chars