summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-03-20 19:21:50 +0100
committerandi <andi@splitbrain.org>2005-03-20 19:21:50 +0100
commit53d6ccfe6aabe82c94115350d2f791f2e09d60d6 (patch)
treef058acedde548940333d6b84cc74f943c026ec9a
parent81aafed45def19b4c7ddd3065daa294c142365a5 (diff)
downloadrpg-53d6ccfe6aabe82c94115350d2f791f2e09d60d6.tar.gz
rpg-53d6ccfe6aabe82c94115350d2f791f2e09d60d6.tar.bz2
remove empty namespaces on page deletion
darcs-hash:20050320182150-9977f-34610c4d2cd518c1de891e098859e1aaa74355a8.gz
-rw-r--r--inc/common.php4
-rw-r--r--inc/io.php19
2 files changed, 22 insertions, 1 deletions
diff --git a/inc/common.php b/inc/common.php
index 482bb1e2d..47defb8af 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -487,7 +487,7 @@ function parsedWiki($id,$rev='',$excuse=true){
//ensure $id is in global $ID (needed for parsing)
global $ID;
$ID = $id;
-
+
if($rev){
if(@file_exists($file)){
$ret = parse(io_readFile($file));
@@ -689,6 +689,8 @@ function saveWikiText($id,$text,$summary){
$del = true;
//autoset summary on deletion
if(empty($summary)) $summary = $lang['deleted'];
+ //remove empty namespaces
+ io_sweepNS($id);
}else{
// save file (datadir is created in io_saveFile)
io_saveFile($file,$text);
diff --git a/inc/io.php b/inc/io.php
index d59efbc78..ceb747ed9 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -57,6 +57,25 @@ function io_cacheParse($file){
}
/**
+ * Removes empty directories
+ *
+ * @todo use safemode hack
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function io_sweepNS($id){
+ global $conf;
+
+ //scan all namespaces
+ while(($id = getNS($id)) !== false){
+ $dir = $conf['datadir'].'/'.str_replace(':','/',$id);
+ $dir = utf8_encodeFN($dir);
+
+ //try to delete dir else return
+ if(!@rmdir($dir)) return;
+ }
+}
+
+/**
* Returns content of $file as cleaned string.
*
* Uses gzip if extension is .gz