From 98407a7ab8cdc6e868009187f47cc7768449a3c9 Mon Sep 17 00:00:00 2001 From: andi Date: Sun, 26 Jun 2005 12:09:13 +0200 Subject: [PATCH] directory cleanup This cleans up the directory structure as discussed on the mailning list. Users should delete their previous _cache directories to recover diskspace. darcs-hash:20050626100913-9977f-83c0fdc32047db2090fc52a843ffae50cbf12248.gz --- conf/dokuwiki.php | 5 +---- data/{media => }/.htaccess | 0 data/pages/.htaccess | 2 -- inc/auth.php | 4 ++-- inc/common.php | 8 +++++++- inc/init.php | 40 +++++++++++++++++++++++++------------- inc/lang/hu/semantic.cache | 15 -------------- inc/pageutils.php | 19 ++++++++++++++++++ inc/parserutils.php | 6 ++---- lib/exe/fetch.php | 9 +++------ 10 files changed, 60 insertions(+), 48 deletions(-) rename data/{media => }/.htaccess (100%) delete mode 100644 data/pages/.htaccess delete mode 100644 inc/lang/hu/semantic.cache diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php index f151a58e0..504c0ffdb 100644 --- a/conf/dokuwiki.php +++ b/conf/dokuwiki.php @@ -13,10 +13,7 @@ $conf['umask'] = 0111; //set the umask for new files $conf['dmask'] = 0000; //directory mask accordingly $conf['lang'] = 'en'; //your language $conf['basedir'] = ''; //absolute dir from serveroot - blank for autodetection -$conf['datadir'] = './data/pages'; //where to store the data -$conf['olddir'] = './data/attic'; //where to store old revisions -$conf['mediadir'] = './data/media'; //where to store media files -$conf['changelog'] = './data/changes.log'; //change log +$conf['savedir'] = './data'; //where to store all the files /* Display Options */ diff --git a/data/media/.htaccess b/data/.htaccess similarity index 100% rename from data/media/.htaccess rename to data/.htaccess diff --git a/data/pages/.htaccess b/data/pages/.htaccess deleted file mode 100644 index 9c96d3742..000000000 --- a/data/pages/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -order allow,deny -deny from all diff --git a/inc/auth.php b/inc/auth.php index fdf5d17f3..da3d770d1 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -148,7 +148,7 @@ function auth_browseruid(){ * Creates a random key to encrypt the password in cookies * * This function tries to read the password for encrypting - * cookies from $conf['datadir'].'/_cache/_htcookiesalt' + * cookies from $conf['metadir'].'/_htcookiesalt' * if no such file is found a random key is created and * and stored in this file. * @@ -158,7 +158,7 @@ function auth_browseruid(){ */ function auth_cookiesalt(){ global $conf; - $file = $conf['datadir'].'/_cache/_htcookiesalt'; + $file = $conf['metadir'].'/_htcookiesalt'; $salt = io_readFile($file); if(empty($salt)){ $salt = uniqid(rand(),true); diff --git a/inc/common.php b/inc/common.php index 353b306e6..53bb73a13 100644 --- a/inc/common.php +++ b/inc/common.php @@ -593,7 +593,7 @@ function saveWikiText($id,$text,$summary){ //purge cache on add by updating the purgefile if($conf['purgeonadd'] && (!$old || $del)){ - io_saveFile($conf['datadir'].'/_cache/purgefile',time()); + io_saveFile($conf['cachedir'].'/purgefile',time()); } } @@ -809,6 +809,12 @@ function check(){ msg('Mediadir is not writable',-1); } + if(is_writable($conf['cachedir'])){ + msg('Cachedir is writable',1); + }else{ + msg('Cachedir is not writable',-1); + } + if(is_writable(DOKU_INC.'conf/users.auth.php')){ msg('conf/users.auth.php is writable',1); }else{ diff --git a/inc/init.php b/inc/init.php index ba24d7ced..370e308b7 100644 --- a/inc/init.php +++ b/inc/init.php @@ -66,34 +66,46 @@ // remember original umask $conf['oldumask'] = umask(); - // make absolute mediaweb - if(!preg_match('#^(https?://|/)#i',$conf['mediaweb'])){ - $conf['mediaweb'] = getBaseURL().$conf['mediaweb']; - } - // make real paths and check them - $conf['datadir'] = init_path($conf['datadir']); - if(!$conf['datadir']) die('Wrong datadir! Check config!'); - $conf['olddir'] = init_path($conf['olddir']); - if(!$conf['olddir']) die('Wrong olddir! Check config!'); - $conf['mediadir'] = init_path($conf['mediadir']); - if(!$conf['mediadir']) die('Wrong mediadir! Check config!'); + init_paths(); // automatic upgrade to script versions of certain files scriptify(DOKU_INC.'conf/users.auth'); scriptify(DOKU_INC.'conf/acl.auth'); +/** + * Checks paths from config file + */ +function init_paths(){ + global $conf; + + $paths = array('datadir' => 'pages', + 'olddir' => 'attic', + 'mediadir' => 'media', + 'metadir' => 'meta', + 'cachedir' => 'cache', + 'lockdir' => 'locks', + 'changelog' => 'changes.log'); + + foreach($paths as $c => $p){ + + if(!$conf[$c]) $conf[$c] = $conf['savedir'].'/'.$p; + $conf[$c] = init_path($conf[$c]); + if(!$conf[$c]) die("$c does not exist or isn't writable. Check config!"); + } +} + /** * returns absolute path * - * This tries the given past first, then checks in DOKU_INC + * This tries the given path first, then checks in DOKU_INC */ function init_path($path){ $p = realpath($path); - if(is_dir($p)) return $p; + if(@file_exists($p)) return $p; $p = realpath(DOKU_INC.$path); - if(is_dir($p)) return $p; + if(@file_exists($p)) return $p; return ''; } diff --git a/inc/lang/hu/semantic.cache b/inc/lang/hu/semantic.cache deleted file mode 100644 index 057c8e1b9..000000000 --- a/inc/lang/hu/semantic.cache +++ /dev/null @@ -1,15 +0,0 @@ -;; Object hu/ -;; SEMANTICDB Tags save file -(semanticdb-project-database-file "hu/" - :tables (list - (semanticdb-table "lang.php" - :major-mode 'php-mode - :tags 'nil - :file "lang.php" - :pointmax 4377 - ) - ) - :file "semantic.cache" - :semantic-tag-version "2.0beta3" - :semanticdb-version "2.0beta3" - ) diff --git a/inc/pageutils.php b/inc/pageutils.php index 884df9e96..8477792e0 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -231,4 +231,23 @@ function resolve_pageid($ns,&$page,&$exists){ if(!empty($hash)) $page .= '#'.$hash; } +/** + * Returns the name of a cachefile from given data + * + * The needed directory is created by this function! + * + * @author Andreas Gohr + * + * @param string $data This data is used to create a unique md5 name + * @param string $ext This is appended to the filename if given + * @return string The filename of the cachefile + */ +function getCacheName($data,$ext=''){ + global $conf; + $md5 = md5($data); + $file = $conf['cachedir'].'/'.$md5{0}.'/'.$md5.$ext; + io_makeFileDir($file); + return $file; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/parserutils.php b/inc/parserutils.php index bd5317e1b..9046cfdbe 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -67,8 +67,7 @@ function p_locale_xhtml($id){ */ function p_cached_xhtml($file){ global $conf; - $cache = $conf['datadir'].'/_cache/xhtml/'; - $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']); + $cache = getCacheName($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.xhtml'); $purge = $conf['datadir'].'/_cache/purgefile'; // check if cache can be used @@ -112,8 +111,7 @@ function p_cached_xhtml($file){ */ function p_cached_instructions($file,$cacheonly=false){ global $conf; - $cache = $conf['datadir'].'/_cache/instructions/'; - $cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']); + $cache = getCacheName($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'],'.i'); // check if cache can be used $cachetime = @filemtime($cache); // 0 if not exists diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index fffbf4483..384ff2d32 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -101,13 +101,12 @@ function get_resized($file, $ext, $w, $h=0){ global $conf; - $md5 = md5($file); $info = getimagesize($file); if(!$h) $h = round(($w * $info[1]) / $info[0]); //cache - $local = $conf['mediadir'].'/_cache/'.$md5.'.'.$w.'x'.$h.'.'.$ext; + $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext); $mtime = @filemtime($local); // 0 if not exists if( $mtime > filemtime($file) || resize_image($ext,$file,$info[0],$info[1],$local,$w,$h) ){ @@ -144,9 +143,7 @@ function get_from_URL($url,$ext,$cache){ global $conf; $url = strtolower($url); - $md5 = md5($url); - - $local = $conf['mediadir']."/_cache/$md5.$ext"; + $local = getCacheName($url,".media.$ext"); $mtime = @filemtime($local); // 0 if not exists //decide if download needed: @@ -204,7 +201,7 @@ function resize_image($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ } // create cachedir - io_makeFileDir($to); + //io_makeFileDir($to); // not needed anymore, should exist //try resampling first if(function_exists("imagecopyresampled")){