move wfRecursiveRemoveDir to global functions
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 77820ea..3151755 100644 (file)
@@ -2615,6 +2615,29 @@ function wfMkdirParents( $dir, $mode = null, $caller = null ) {
        return $ok;
 }
 
+/**
+ * Remove a directory and all its content.
+ * Does not hide error.
+ */
+function wfRecursiveRemoveDir( $dir ) {
+       wfDebug( __FUNCTION__ . "( $dir )\n" );
+       // taken from http://de3.php.net/manual/en/function.rmdir.php#98622
+       if ( is_dir( $dir ) ) {
+               $objects = scandir( $dir );
+               foreach ( $objects as $object ) {
+                       if ( $object != "." && $object != ".." ) {
+                               if ( filetype( $dir . '/' . $object ) == "dir" ) {
+                                       wfRecursiveRemoveDir( $dir . '/' . $object );
+                               } else {
+                                       unlink( $dir . '/' . $object );
+                               }
+                       }
+               }
+               reset( $objects );
+               rmdir( $dir );
+       }
+}
+
 /**
  * @param $nr Mixed: the number to format
  * @param $acc Integer: the number of digits after the decimal point, default 2