diff --git a/doku.php b/doku.php
index 0b5af8493562432bec37ac97d0f15c6e75f199f7..2ee9badc0c8081cf7a7147076efbff852ebb1e3f 100644
--- a/doku.php
+++ b/doku.php
@@ -8,74 +8,74 @@
 
 //  xdebug_start_profiling();
 
-  if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
-  require_once(DOKU_INC.'inc/init.php');
-  require_once(DOKU_INC.'inc/common.php');
-  require_once(DOKU_INC.'inc/events.php');
-  require_once(DOKU_INC.'inc/pageutils.php');
-  require_once(DOKU_INC.'inc/html.php');
-  require_once(DOKU_INC.'inc/auth.php');
-  require_once(DOKU_INC.'inc/actions.php');
-
-  //import variables
-  $QUERY = trim($_REQUEST['id']);
-  $ID    = getID();
-  $NS    = getNS($ID);
-  $REV   = $_REQUEST['rev'];
-  $ACT   = $_REQUEST['do'];
-  $IDX   = $_REQUEST['idx'];
-  $DATE  = $_REQUEST['date'];
-  $RANGE = $_REQUEST['lines'];
-  $HIGH  = $_REQUEST['s'];
-  if(empty($HIGH)) $HIGH = getGoogleQuery();
-
-  $TEXT  = cleanText($_POST['wikitext']);
-  $PRE   = cleanText($_POST['prefix']);
-  $SUF   = cleanText($_POST['suffix']);
-  $SUM   = $_REQUEST['summary'];
-
-  //sanitize revision
-  $REV = preg_replace('/[^0-9]/','',$REV);
-
-  //we accept the do param as HTTP header, too:
-  if(!empty($_SERVER['HTTP_X_DOKUWIKI_DO'])){
+if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
+require_once(DOKU_INC.'inc/init.php');
+require_once(DOKU_INC.'inc/common.php');
+require_once(DOKU_INC.'inc/events.php');
+require_once(DOKU_INC.'inc/pageutils.php');
+require_once(DOKU_INC.'inc/html.php');
+require_once(DOKU_INC.'inc/auth.php');
+require_once(DOKU_INC.'inc/actions.php');
+
+//import variables
+$QUERY = trim($_REQUEST['id']);
+$ID    = getID();
+$NS    = getNS($ID);
+$REV   = $_REQUEST['rev'];
+$ACT   = $_REQUEST['do'];
+$IDX   = $_REQUEST['idx'];
+$DATE  = $_REQUEST['date'];
+$RANGE = $_REQUEST['lines'];
+$HIGH  = $_REQUEST['s'];
+if(empty($HIGH)) $HIGH = getGoogleQuery();
+
+$TEXT  = cleanText($_POST['wikitext']);
+$PRE   = cleanText($_POST['prefix']);
+$SUF   = cleanText($_POST['suffix']);
+$SUM   = $_REQUEST['summary'];
+
+//sanitize revision
+$REV = preg_replace('/[^0-9]/','',$REV);
+
+//we accept the do param as HTTP header, too:
+if(!empty($_SERVER['HTTP_X_DOKUWIKI_DO'])){
     $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
-  }
+}
 
-  if(!empty($IDX)) $ACT='index';
-  //set default #FIXME not needed here? done in actions?
-  if(empty($ACT)) $ACT = 'show';
+if(!empty($IDX)) $ACT='index';
+//set default #FIXME not needed here? done in actions?
+if(empty($ACT)) $ACT = 'show';
 
-  //make infos about the selected page available
-  $INFO = pageinfo();
+//make infos about the selected page available
+$INFO = pageinfo();
 
-  // handle debugging
-  if($conf['allowdebug'] && $ACT == 'debug'){
+// handle debugging
+if($conf['allowdebug'] && $ACT == 'debug'){
     html_debug();
     exit;
-  }
+}
 
-  //send 404 for missing pages if configured or ID has special meaning to bots
-  if(!$INFO['exists'] &&
-     ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/',$ID)) &&
-     ($ACT == 'show' || substr($ACT,0,7) == 'export_') ){
+//send 404 for missing pages if configured or ID has special meaning to bots
+if(!$INFO['exists'] &&
+  ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/',$ID)) &&
+  ($ACT == 'show' || substr($ACT,0,7) == 'export_') ){
     header('HTTP/1.0 404 Not Found');
-  }
+}
 
-  //prepare breadcrumbs (initialize a static var)
-  if ($conf['breadcrumbs']) breadcrumbs();
+//prepare breadcrumbs (initialize a static var)
+if ($conf['breadcrumbs']) breadcrumbs();
 
-  // check upstream
-  checkUpdateMessages();
+// check upstream
+checkUpdateMessages();
 
-  trigger_event('DOKUWIKI_STARTED',$tmp=array());
+trigger_event('DOKUWIKI_STARTED',$tmp=array());
 
-  //close session
-  session_write_close();
+//close session
+session_write_close();
 
-  //do the work
-  act_dispatch($ACT);
+//do the work
+act_dispatch($ACT);
 
-  trigger_event('DOKUWIKI_DONE', $tmp=array());
+trigger_event('DOKUWIKI_DONE', $tmp=array());
 
 //  xdebug_dump_function_profile(1);
diff --git a/feed.php b/feed.php
index 9dc96d05240927d8559dff8f62c85a3c15d5a075..cc4b084422a22bfeb3c0781e54e33dc1f88649ff 100644
--- a/feed.php
+++ b/feed.php
@@ -6,74 +6,74 @@
  * @author     Andreas Gohr <andi@splitbrain.org>
  */
 
-  if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
-  require_once(DOKU_INC.'inc/init.php');
-  require_once(DOKU_INC.'inc/common.php');
-  require_once(DOKU_INC.'inc/events.php');
-  require_once(DOKU_INC.'inc/parserutils.php');
-  require_once(DOKU_INC.'inc/feedcreator.class.php');
-  require_once(DOKU_INC.'inc/auth.php');
-  require_once(DOKU_INC.'inc/pageutils.php');
-  require_once(DOKU_INC.'inc/httputils.php');
-
-  //close session
-  session_write_close();
-
-  // get params
-  $opt = rss_parseOptions();
-
-  // the feed is dynamic - we need a cache for each combo
-  // (but most people just use the default feed so it's still effective)
-  $cache = getCacheName(join('',array_values($opt)).$_SERVER['REMOTE_USER'],'.feed');
-  $cmod = @filemtime($cache); // 0 if not exists
-  if ($cmod && (@filemtime(DOKU_CONF.'local.php')>$cmod || @filemtime(DOKU_CONF.'dokuwiki.php')>$cmod)) {
+if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
+require_once(DOKU_INC.'inc/init.php');
+require_once(DOKU_INC.'inc/common.php');
+require_once(DOKU_INC.'inc/events.php');
+require_once(DOKU_INC.'inc/parserutils.php');
+require_once(DOKU_INC.'inc/feedcreator.class.php');
+require_once(DOKU_INC.'inc/auth.php');
+require_once(DOKU_INC.'inc/pageutils.php');
+require_once(DOKU_INC.'inc/httputils.php');
+
+//close session
+session_write_close();
+
+// get params
+$opt = rss_parseOptions();
+
+// the feed is dynamic - we need a cache for each combo
+// (but most people just use the default feed so it's still effective)
+$cache = getCacheName(join('',array_values($opt)).$_SERVER['REMOTE_USER'],'.feed');
+$cmod = @filemtime($cache); // 0 if not exists
+if ($cmod && (@filemtime(DOKU_CONF.'local.php')>$cmod || @filemtime(DOKU_CONF.'dokuwiki.php')>$cmod)) {
     // ignore cache if feed prefs may have changed
     $cmod = 0;
-  }
-
-  // check cacheage and deliver if nothing has changed since last
-  // time or the update interval has not passed, also handles conditional requests
-  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
-  header('Pragma: public');
-  header('Content-Type: application/xml; charset=utf-8');
-  header('X-Robots-Tag: noindex');
-  if($cmod && (($cmod+$conf['rss_update']>time()) || ($cmod>@filemtime($conf['changelog'])))){
+}
+
+// check cacheage and deliver if nothing has changed since last
+// time or the update interval has not passed, also handles conditional requests
+header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+header('Pragma: public');
+header('Content-Type: application/xml; charset=utf-8');
+header('X-Robots-Tag: noindex');
+if($cmod && (($cmod+$conf['rss_update']>time()) || ($cmod>@filemtime($conf['changelog'])))){
     http_conditionalRequest($cmod);
     if($conf['allowdebug']) header("X-CacheUsed: $cache");
     print io_readFile($cache);
     exit;
-  } else {
+} else {
     http_conditionalRequest(time());
-  }
-
-  // create new feed
-  $rss = new DokuWikiFeedCreator();
-  $rss->title = $conf['title'].(($opt['namespace']) ? ' '.$opt['namespace'] : '');
-  $rss->link  = DOKU_URL;
-  $rss->syndicationURL = DOKU_URL.'feed.php';
-  $rss->cssStyleSheet  = DOKU_URL.'lib/exe/css.php?s=feed';
-
-  $image = new FeedImage();
-  $image->title = $conf['title'];
-  $image->url = DOKU_URL."lib/images/favicon.ico";
-  $image->link = DOKU_URL;
-  $rss->image = $image;
-
-  if($opt['feed_mode'] == 'list'){
+ }
+
+// create new feed
+$rss = new DokuWikiFeedCreator();
+$rss->title = $conf['title'].(($opt['namespace']) ? ' '.$opt['namespace'] : '');
+$rss->link  = DOKU_URL;
+$rss->syndicationURL = DOKU_URL.'feed.php';
+$rss->cssStyleSheet  = DOKU_URL.'lib/exe/css.php?s=feed';
+
+$image = new FeedImage();
+$image->title = $conf['title'];
+$image->url = DOKU_URL."lib/images/favicon.ico";
+$image->link = DOKU_URL;
+$rss->image = $image;
+
+if($opt['feed_mode'] == 'list'){
     rssListNamespace($rss,$opt);
-  }elseif($opt['feed_mode'] == 'search'){
+}elseif($opt['feed_mode'] == 'search'){
     rssSearch($rss,$opt);
-  }else{
+}else{
     rssRecentChanges($rss,$opt);
-  }
+}
 
-  $feed = $rss->createFeed($opt['feed_type'],'utf-8');
+$feed = $rss->createFeed($opt['feed_type'],'utf-8');
 
-  // save cachefile
-  io_saveFile($cache,$feed);
+// save cachefile
+io_saveFile($cache,$feed);
 
-  // finally deliver
-  print $feed;
+// finally deliver
+print $feed;
 
 // ---------------------------------------------------------------- //
 
@@ -101,25 +101,25 @@ function rss_parseOptions(){
     $opt['guardmail']  = ($conf['mailguard'] != '' && $conf['mailguard'] != 'none');
 
     switch ($opt['feed_type']){
-      case 'rss':
-         $opt['feed_type'] = 'RSS0.91';
-         $opt['mime_type'] = 'text/xml';
-         break;
-      case 'rss2':
-         $opt['feed_type'] = 'RSS2.0';
-         $opt['mime_type'] = 'text/xml';
-         break;
-      case 'atom':
-         $opt['feed_type'] = 'ATOM0.3';
-         $opt['mime_type'] = 'application/xml';
-         break;
-      case 'atom1':
-         $opt['feed_type'] = 'ATOM1.0';
-         $opt['mime_type'] = 'application/atom+xml';
-         break;
-      default:
-         $opt['feed_type'] = 'RSS1.0';
-         $opt['mime_type'] = 'application/xml';
+        case 'rss':
+            $opt['feed_type'] = 'RSS0.91';
+            $opt['mime_type'] = 'text/xml';
+            break;
+        case 'rss2':
+            $opt['feed_type'] = 'RSS2.0';
+            $opt['mime_type'] = 'text/xml';
+            break;
+        case 'atom':
+            $opt['feed_type'] = 'ATOM0.3';
+            $opt['mime_type'] = 'application/xml';
+            break;
+        case 'atom1':
+            $opt['feed_type'] = 'ATOM1.0';
+            $opt['mime_type'] = 'application/atom+xml';
+            break;
+        default:
+            $opt['feed_type'] = 'RSS1.0';
+            $opt['mime_type'] = 'application/xml';
     }
     return $opt;
 }
@@ -229,7 +229,6 @@ function rss_buildItems(&$rss,&$data,$opt){
         }
         $item->description = $content; //FIXME a plugin hook here could be senseful
 
-
         // add user
         # FIXME should the user be pulled from metadata as well?
         $user = null;
@@ -256,8 +255,8 @@ function rss_buildItems(&$rss,&$data,$opt){
         if($meta['subject']){
             $item->category = $meta['subject'];
         }else{
-           $cat = getNS($id);
-           if($cat) $item->category = $cat;
+            $cat = getNS($id);
+            if($cat) $item->category = $cat;
         }
 
         // finally add the item to the feed object, after handing it to registered plugins
@@ -267,7 +266,7 @@ function rss_buildItems(&$rss,&$data,$opt){
                         'rss'   => &$rss);
         $evt = new Doku_Event('FEED_ITEM_ADD', $evdata);
         if ($evt->advise_before()){
-          $rss->addItem($item);
+            $rss->addItem($item);
         }
         $evt->advise_after(); // for completeness
     }
diff --git a/inc/auth.php b/inc/auth.php
index 684885890d50d7891150ade0b8e3f13b8a68f1a7..e0b23c0e62a3a7ce2c318bda299062551e66b627 100644
--- a/inc/auth.php
+++ b/inc/auth.php
@@ -9,22 +9,22 @@
  * @author     Andreas Gohr <andi@splitbrain.org>
  */
 
-  if(!defined('DOKU_INC')) die('meh.');
-  require_once(DOKU_INC.'inc/common.php');
-  require_once(DOKU_INC.'inc/io.php');
-
-  // some ACL level defines
-  define('AUTH_NONE',0);
-  define('AUTH_READ',1);
-  define('AUTH_EDIT',2);
-  define('AUTH_CREATE',4);
-  define('AUTH_UPLOAD',8);
-  define('AUTH_DELETE',16);
-  define('AUTH_ADMIN',255);
-
-  global $conf;
-
-  if($conf['useacl']){
+if(!defined('DOKU_INC')) die('meh.');
+require_once(DOKU_INC.'inc/common.php');
+require_once(DOKU_INC.'inc/io.php');
+
+// some ACL level defines
+define('AUTH_NONE',0);
+define('AUTH_READ',1);
+define('AUTH_EDIT',2);
+define('AUTH_CREATE',4);
+define('AUTH_UPLOAD',8);
+define('AUTH_DELETE',16);
+define('AUTH_ADMIN',255);
+
+global $conf;
+
+if($conf['useacl']){
     require_once(DOKU_INC.'inc/blowfish.php');
     require_once(DOKU_INC.'inc/mail.php');
 
@@ -32,87 +32,87 @@
 
     // load the the backend auth functions and instantiate the auth object
     if (@file_exists(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php')) {
-      require_once(DOKU_INC.'inc/auth/basic.class.php');
-      require_once(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php');
-
-      $auth_class = "auth_".$conf['authtype'];
-      if (class_exists($auth_class)) {
-        $auth = new $auth_class();
-        if ($auth->success == false) {
-          // degrade to unauthenticated user
-          unset($auth);
-          auth_logoff();
-          msg($lang['authtempfail'], -1);
+        require_once(DOKU_INC.'inc/auth/basic.class.php');
+        require_once(DOKU_INC.'inc/auth/'.$conf['authtype'].'.class.php');
+
+        $auth_class = "auth_".$conf['authtype'];
+        if (class_exists($auth_class)) {
+            $auth = new $auth_class();
+            if ($auth->success == false) {
+                // degrade to unauthenticated user
+                unset($auth);
+                auth_logoff();
+                msg($lang['authtempfail'], -1);
+            }
+        } else {
+            nice_die($lang['authmodfailed']);
         }
-      } else {
-        nice_die($lang['authmodfailed']);
-      }
     } else {
-      nice_die($lang['authmodfailed']);
+        nice_die($lang['authmodfailed']);
     }
-  }
+}
 
-  // do the login either by cookie or provided credentials
-  if($conf['useacl']){
+// do the login either by cookie or provided credentials
+if($conf['useacl']){
     if($auth){
-      if (!isset($_REQUEST['u'])) $_REQUEST['u'] = '';
-      if (!isset($_REQUEST['p'])) $_REQUEST['p'] = '';
-      if (!isset($_REQUEST['r'])) $_REQUEST['r'] = '';
-      $_REQUEST['http_credentials'] = false;
-      if (!$conf['rememberme']) $_REQUEST['r'] = false;
-
-      // streamline HTTP auth credentials (IIS/rewrite -> mod_php)
-      if(isset($_SERVER['HTTP_AUTHORIZATION'])){
-        list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) =
-          explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
-      }
-
-      // if no credentials were given try to use HTTP auth (for SSO)
-      if(empty($_REQUEST['u']) && empty($_COOKIE[DOKU_COOKIE]) && !empty($_SERVER['PHP_AUTH_USER'])){
-        $_REQUEST['u'] = $_SERVER['PHP_AUTH_USER'];
-        $_REQUEST['p'] = $_SERVER['PHP_AUTH_PW'];
-        $_REQUEST['http_credentials'] = true;
-      }
-
-      if($_REQUEST['authtok']){
-        // when an authentication token is given, trust the session
-        auth_validateToken($_REQUEST['authtok']);
-      }elseif(!is_null($auth) && $auth->canDo('external')){
-        // external trust mechanism in place
-        $auth->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']);
-      }else{
-        $evdata = array(
-            'action'   => $ACT,
-            'user'     => $_REQUEST['u'],
-            'password' => $_REQUEST['p'],
-            'sticky'   => $_REQUEST['r'],
-            'silent'   => $_REQUEST['http_credentials'],
-        );
-        $evt = new Doku_Event('AUTH_LOGIN_CHECK',$evdata);
-        if($evt->advise_before()){
-            auth_login($evdata['user'],
-                       $evdata['password'],
-                       $evdata['sticky'],
-                       $evdata['silent']);
+        if (!isset($_REQUEST['u'])) $_REQUEST['u'] = '';
+        if (!isset($_REQUEST['p'])) $_REQUEST['p'] = '';
+        if (!isset($_REQUEST['r'])) $_REQUEST['r'] = '';
+        $_REQUEST['http_credentials'] = false;
+        if (!$conf['rememberme']) $_REQUEST['r'] = false;
+
+        // streamline HTTP auth credentials (IIS/rewrite -> mod_php)
+        if(isset($_SERVER['HTTP_AUTHORIZATION'])){
+            list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']) =
+                explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
+        }
+
+        // if no credentials were given try to use HTTP auth (for SSO)
+        if(empty($_REQUEST['u']) && empty($_COOKIE[DOKU_COOKIE]) && !empty($_SERVER['PHP_AUTH_USER'])){
+            $_REQUEST['u'] = $_SERVER['PHP_AUTH_USER'];
+            $_REQUEST['p'] = $_SERVER['PHP_AUTH_PW'];
+            $_REQUEST['http_credentials'] = true;
+        }
+
+        if($_REQUEST['authtok']){
+            // when an authentication token is given, trust the session
+            auth_validateToken($_REQUEST['authtok']);
+        }elseif(!is_null($auth) && $auth->canDo('external')){
+            // external trust mechanism in place
+            $auth->trustExternal($_REQUEST['u'],$_REQUEST['p'],$_REQUEST['r']);
+        }else{
+            $evdata = array(
+                    'action'   => $ACT,
+                    'user'     => $_REQUEST['u'],
+                    'password' => $_REQUEST['p'],
+                    'sticky'   => $_REQUEST['r'],
+                    'silent'   => $_REQUEST['http_credentials'],
+                    );
+            $evt = new Doku_Event('AUTH_LOGIN_CHECK',$evdata);
+            if($evt->advise_before()){
+                auth_login($evdata['user'],
+                        $evdata['password'],
+                        $evdata['sticky'],
+                        $evdata['silent']);
+            }
+            $evt->advise_after();
+            unset($evt);
+            unset($evdata);
         }
-        $evt->advise_after();
-        unset($evt);
-        unset($evdata);
-      }
     }
 
     //load ACL into a global array
     global $AUTH_ACL;
     if(is_readable(DOKU_CONF.'acl.auth.php')){
-      $AUTH_ACL = file(DOKU_CONF.'acl.auth.php');
-      if(isset($_SERVER['REMOTE_USER'])){
-        $AUTH_ACL = str_replace('%USER%',$_SERVER['REMOTE_USER'],$AUTH_ACL);
-        $AUTH_ACL = str_replace('@USER@',$_SERVER['REMOTE_USER'],$AUTH_ACL); //legacy
-      }
+        $AUTH_ACL = file(DOKU_CONF.'acl.auth.php');
+        if(isset($_SERVER['REMOTE_USER'])){
+            $AUTH_ACL = str_replace('%USER%',$_SERVER['REMOTE_USER'],$AUTH_ACL);
+            $AUTH_ACL = str_replace('@USER@',$_SERVER['REMOTE_USER'],$AUTH_ACL); //legacy
+        }
     }else{
-      $AUTH_ACL = array();
+        $AUTH_ACL = array();
     }
-  }
+}
 
 /**
  * This tries to login the user based on the sent auth credentials
@@ -142,53 +142,53 @@
  * @param   bool    $sticky  Cookie should not expire
  * @param   bool    $silent  Don't show error on bad auth
  * @return  bool             true on successful auth
-*/
+ */
 function auth_login($user,$pass,$sticky=false,$silent=false){
-  global $USERINFO;
-  global $conf;
-  global $lang;
-  global $auth;
-  $sticky ? $sticky = true : $sticky = false; //sanity check
-
-  if(!empty($user)){
-    //usual login
-    if ($auth->checkPass($user,$pass)){
-      // make logininfo globally available
-      $_SERVER['REMOTE_USER'] = $user;
-      auth_setCookie($user,PMA_blowfish_encrypt($pass,auth_cookiesalt()),$sticky);
-      return true;
+    global $USERINFO;
+    global $conf;
+    global $lang;
+    global $auth;
+    $sticky ? $sticky = true : $sticky = false; //sanity check
+
+    if(!empty($user)){
+        //usual login
+        if ($auth->checkPass($user,$pass)){
+            // make logininfo globally available
+            $_SERVER['REMOTE_USER'] = $user;
+            auth_setCookie($user,PMA_blowfish_encrypt($pass,auth_cookiesalt()),$sticky);
+            return true;
+        }else{
+            //invalid credentials - log off
+            if(!$silent) msg($lang['badlogin'],-1);
+            auth_logoff();
+            return false;
+        }
     }else{
-      //invalid credentials - log off
-      if(!$silent) msg($lang['badlogin'],-1);
-      auth_logoff();
-      return false;
-    }
-  }else{
-    // read cookie information
-    list($user,$sticky,$pass) = auth_getCookie();
-    // get session info
-    $session = $_SESSION[DOKU_COOKIE]['auth'];
-    if($user && $pass){
-      // we got a cookie - see if we can trust it
-      if(isset($session) &&
-        $auth->useSessionCache($user) &&
-        ($session['time'] >= time()-$conf['auth_security_timeout']) &&
-        ($session['user'] == $user) &&
-        ($session['pass'] == $pass) &&  //still crypted
-        ($session['buid'] == auth_browseruid()) ){
-        // he has session, cookie and browser right - let him in
-        $_SERVER['REMOTE_USER'] = $user;
-        $USERINFO = $session['info']; //FIXME move all references to session
-        return true;
-      }
-      // no we don't trust it yet - recheck pass but silent
-      $pass = PMA_blowfish_decrypt($pass,auth_cookiesalt());
-      return auth_login($user,$pass,$sticky,true);
+        // read cookie information
+        list($user,$sticky,$pass) = auth_getCookie();
+        // get session info
+        $session = $_SESSION[DOKU_COOKIE]['auth'];
+        if($user && $pass){
+            // we got a cookie - see if we can trust it
+            if(isset($session) &&
+                    $auth->useSessionCache($user) &&
+                    ($session['time'] >= time()-$conf['auth_security_timeout']) &&
+                    ($session['user'] == $user) &&
+                    ($session['pass'] == $pass) &&  //still crypted
+                    ($session['buid'] == auth_browseruid()) ){
+                // he has session, cookie and browser right - let him in
+                $_SERVER['REMOTE_USER'] = $user;
+                $USERINFO = $session['info']; //FIXME move all references to session
+                return true;
+            }
+            // no we don't trust it yet - recheck pass but silent
+            $pass = PMA_blowfish_decrypt($pass,auth_cookiesalt());
+            return auth_login($user,$pass,$sticky,true);
+        }
     }
-  }
-  //just to be sure
-  auth_logoff(true);
-  return false;
+    //just to be sure
+    auth_logoff(true);
+    return false;
 }
 
 /**
@@ -244,14 +244,14 @@ function auth_createToken(){
  * @return  string  a MD5 sum of various browser headers
  */
 function auth_browseruid(){
-  $ip   = clientIP(true);
-  $uid  = '';
-  $uid .= $_SERVER['HTTP_USER_AGENT'];
-  $uid .= $_SERVER['HTTP_ACCEPT_ENCODING'];
-  $uid .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
-  $uid .= $_SERVER['HTTP_ACCEPT_CHARSET'];
-  $uid .= substr($ip,0,strpos($ip,'.'));
-  return md5($uid);
+    $ip   = clientIP(true);
+    $uid  = '';
+    $uid .= $_SERVER['HTTP_USER_AGENT'];
+    $uid .= $_SERVER['HTTP_ACCEPT_ENCODING'];
+    $uid .= $_SERVER['HTTP_ACCEPT_LANGUAGE'];
+    $uid .= $_SERVER['HTTP_ACCEPT_CHARSET'];
+    $uid .= substr($ip,0,strpos($ip,'.'));
+    return md5($uid);
 }
 
 /**
@@ -267,14 +267,14 @@ function auth_browseruid(){
  * @return  string
  */
 function auth_cookiesalt(){
-  global $conf;
-  $file = $conf['metadir'].'/_htcookiesalt';
-  $salt = io_readFile($file);
-  if(empty($salt)){
-    $salt = uniqid(rand(),true);
-    io_saveFile($file,$salt);
-  }
-  return $salt;
+    global $conf;
+    $file = $conf['metadir'].'/_htcookiesalt';
+    $salt = io_readFile($file);
+    if(empty($salt)){
+        $salt = uniqid(rand(),true);
+        io_saveFile($file,$salt);
+    }
+    return $salt;
 }
 
 /**
@@ -287,35 +287,35 @@ function auth_cookiesalt(){
  * @param bool $keepbc - when true, the breadcrumb data is not cleared
  */
 function auth_logoff($keepbc=false){
-  global $conf;
-  global $USERINFO;
-  global $INFO, $ID;
-  global $auth;
-
-  // make sure the session is writable (it usually is)
-  @session_start();
-
-  if(isset($_SESSION[DOKU_COOKIE]['auth']['user']))
-    unset($_SESSION[DOKU_COOKIE]['auth']['user']);
-  if(isset($_SESSION[DOKU_COOKIE]['auth']['pass']))
-    unset($_SESSION[DOKU_COOKIE]['auth']['pass']);
-  if(isset($_SESSION[DOKU_COOKIE]['auth']['info']))
-    unset($_SESSION[DOKU_COOKIE]['auth']['info']);
-  if(!$keepbc && isset($_SESSION[DOKU_COOKIE]['bc']))
-    unset($_SESSION[DOKU_COOKIE]['bc']);
-  if(isset($_SERVER['REMOTE_USER']))
-    unset($_SERVER['REMOTE_USER']);
-  $USERINFO=null; //FIXME
-
-  if (version_compare(PHP_VERSION, '5.2.0', '>')) {
-    setcookie(DOKU_COOKIE,'',time()-600000,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
-  }else{
-    setcookie(DOKU_COOKIE,'',time()-600000,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
-  }
-
-  if($auth && $auth->canDo('logoff')){
-    $auth->logOff();
-  }
+    global $conf;
+    global $USERINFO;
+    global $INFO, $ID;
+    global $auth;
+
+    // make sure the session is writable (it usually is)
+    @session_start();
+
+    if(isset($_SESSION[DOKU_COOKIE]['auth']['user']))
+        unset($_SESSION[DOKU_COOKIE]['auth']['user']);
+    if(isset($_SESSION[DOKU_COOKIE]['auth']['pass']))
+        unset($_SESSION[DOKU_COOKIE]['auth']['pass']);
+    if(isset($_SESSION[DOKU_COOKIE]['auth']['info']))
+        unset($_SESSION[DOKU_COOKIE]['auth']['info']);
+    if(!$keepbc && isset($_SESSION[DOKU_COOKIE]['bc']))
+        unset($_SESSION[DOKU_COOKIE]['bc']);
+    if(isset($_SERVER['REMOTE_USER']))
+        unset($_SERVER['REMOTE_USER']);
+    $USERINFO=null; //FIXME
+
+    if (version_compare(PHP_VERSION, '5.2.0', '>')) {
+        setcookie(DOKU_COOKIE,'',time()-600000,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
+    }else{
+        setcookie(DOKU_COOKIE,'',time()-600000,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
+    }
+
+    if($auth && $auth->canDo('logoff')){
+        $auth->logOff();
+    }
 }
 
 /**
@@ -333,52 +333,52 @@ function auth_logoff($keepbc=false){
  * @param  bool   adminonly - when true checks if user is admin
  */
 function auth_ismanager($user=null,$groups=null,$adminonly=false){
-  global $conf;
-  global $USERINFO;
-
-  if(!$conf['useacl']) return false;
-  if(is_null($user))   $user   = $_SERVER['REMOTE_USER'];
-  if(is_null($groups)) $groups = (array) $USERINFO['grps'];
-  $user   = auth_nameencode($user);
-
-  // check username against superuser and manager
-  $superusers = explode(',', $conf['superuser']);
-  $superusers = array_unique($superusers);
-  $superusers = array_map('trim', $superusers);
-  // prepare an array containing only true values for array_map call
-  $alltrue = array_fill(0, count($superusers), true);
-  $superusers = array_map('auth_nameencode', $superusers, $alltrue);
-  if(in_array($user, $superusers)) return true;
-
-  if(!$adminonly){
-    $managers = explode(',', $conf['manager']);
-    $managers = array_unique($managers);
-    $managers = array_map('trim', $managers);
-    // prepare an array containing only true values for array_map call
-    $alltrue = array_fill(0, count($managers), true);
-    $managers = array_map('auth_nameencode', $managers, $alltrue);
-    if(in_array($user, $managers)) return true;
-  }
+    global $conf;
+    global $USERINFO;
 
-  // check user's groups against superuser and manager
-  if (!empty($groups)) {
+    if(!$conf['useacl']) return false;
+    if(is_null($user))   $user   = $_SERVER['REMOTE_USER'];
+    if(is_null($groups)) $groups = (array) $USERINFO['grps'];
+    $user   = auth_nameencode($user);
 
-    //prepend groups with @ and nameencode
-    $cnt = count($groups);
-    for($i=0; $i<$cnt; $i++){
-      $groups[$i] = '@'.auth_nameencode($groups[$i]);
-    }
+    // check username against superuser and manager
+    $superusers = explode(',', $conf['superuser']);
+    $superusers = array_unique($superusers);
+    $superusers = array_map('trim', $superusers);
+    // prepare an array containing only true values for array_map call
+    $alltrue = array_fill(0, count($superusers), true);
+    $superusers = array_map('auth_nameencode', $superusers, $alltrue);
+    if(in_array($user, $superusers)) return true;
 
-    // check groups against superuser and manager
-    foreach($superusers as $supu)
-      if(in_array($supu, $groups)) return true;
     if(!$adminonly){
-      foreach($managers as $mana)
-        if(in_array($mana, $groups)) return true;
+        $managers = explode(',', $conf['manager']);
+        $managers = array_unique($managers);
+        $managers = array_map('trim', $managers);
+        // prepare an array containing only true values for array_map call
+        $alltrue = array_fill(0, count($managers), true);
+        $managers = array_map('auth_nameencode', $managers, $alltrue);
+        if(in_array($user, $managers)) return true;
     }
-  }
 
-  return false;
+    // check user's groups against superuser and manager
+    if (!empty($groups)) {
+
+        //prepend groups with @ and nameencode
+        $cnt = count($groups);
+        for($i=0; $i<$cnt; $i++){
+            $groups[$i] = '@'.auth_nameencode($groups[$i]);
+        }
+
+        // check groups against superuser and manager
+        foreach($superusers as $supu)
+            if(in_array($supu, $groups)) return true;
+        if(!$adminonly){
+            foreach($managers as $mana)
+                if(in_array($mana, $groups)) return true;
+        }
+    }
+
+    return false;
 }
 
 /**
@@ -392,7 +392,7 @@ function auth_ismanager($user=null,$groups=null,$adminonly=false){
  * @see auth_ismanager
  */
 function auth_isadmin($user=null,$groups=null){
-  return auth_ismanager($user,$groups,true);
+    return auth_ismanager($user,$groups,true);
 }
 
 /**
@@ -406,11 +406,11 @@ function auth_isadmin($user=null,$groups=null){
  * @return int          permission level
  */
 function auth_quickaclcheck($id){
-  global $conf;
-  global $USERINFO;
-  # if no ACL is used always return upload rights
-  if(!$conf['useacl']) return AUTH_UPLOAD;
-  return auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']);
+    global $conf;
+    global $USERINFO;
+    # if no ACL is used always return upload rights
+    if(!$conf['useacl']) return AUTH_UPLOAD;
+    return auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']);
 }
 
 /**
@@ -425,96 +425,96 @@ function auth_quickaclcheck($id){
  * @return int             permission level
  */
 function auth_aclcheck($id,$user,$groups){
-  global $conf;
-  global $AUTH_ACL;
-
-  // if no ACL is used always return upload rights
-  if(!$conf['useacl']) return AUTH_UPLOAD;
-
-  //make sure groups is an array
-  if(!is_array($groups)) $groups = array();
-
-  //if user is superuser or in superusergroup return 255 (acl_admin)
-  if(auth_isadmin($user,$groups)) { return AUTH_ADMIN; }
-
-  $user = auth_nameencode($user);
-
-  //prepend groups with @ and nameencode
-  $cnt = count($groups);
-  for($i=0; $i<$cnt; $i++){
-    $groups[$i] = '@'.auth_nameencode($groups[$i]);
-  }
-
-  $ns    = getNS($id);
-  $perm  = -1;
-
-  if($user || count($groups)){
-    //add ALL group
-    $groups[] = '@ALL';
-    //add User
-    if($user) $groups[] = $user;
-    //build regexp
-    $regexp   = join('|',$groups);
-  }else{
-    $regexp = '@ALL';
-  }
-
-  //check exact match first
-  $matches = preg_grep('/^'.preg_quote($id,'/').'\s+('.$regexp.')\s+/',$AUTH_ACL);
-  if(count($matches)){
-    foreach($matches as $match){
-      $match = preg_replace('/#.*$/','',$match); //ignore comments
-      $acl   = preg_split('/\s+/',$match);
-      if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
-      if($acl[2] > $perm){
-        $perm = $acl[2];
-      }
-    }
-    if($perm > -1){
-      //we had a match - return it
-      return $perm;
+    global $conf;
+    global $AUTH_ACL;
+
+    // if no ACL is used always return upload rights
+    if(!$conf['useacl']) return AUTH_UPLOAD;
+
+    //make sure groups is an array
+    if(!is_array($groups)) $groups = array();
+
+    //if user is superuser or in superusergroup return 255 (acl_admin)
+    if(auth_isadmin($user,$groups)) { return AUTH_ADMIN; }
+
+    $user = auth_nameencode($user);
+
+    //prepend groups with @ and nameencode
+    $cnt = count($groups);
+    for($i=0; $i<$cnt; $i++){
+        $groups[$i] = '@'.auth_nameencode($groups[$i]);
     }
-  }
 
-  //still here? do the namespace checks
-  if($ns){
-    $path = $ns.':\*';
-  }else{
-    $path = '\*'; //root document
-  }
+    $ns    = getNS($id);
+    $perm  = -1;
 
-  do{
-    $matches = preg_grep('/^'.$path.'\s+('.$regexp.')\s+/',$AUTH_ACL);
+    if($user || count($groups)){
+        //add ALL group
+        $groups[] = '@ALL';
+        //add User
+        if($user) $groups[] = $user;
+        //build regexp
+        $regexp   = join('|',$groups);
+    }else{
+        $regexp = '@ALL';
+    }
+
+    //check exact match first
+    $matches = preg_grep('/^'.preg_quote($id,'/').'\s+('.$regexp.')\s+/',$AUTH_ACL);
     if(count($matches)){
-      foreach($matches as $match){
-        $match = preg_replace('/#.*$/','',$match); //ignore comments
-        $acl   = preg_split('/\s+/',$match);
-        if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
-        if($acl[2] > $perm){
-          $perm = $acl[2];
+        foreach($matches as $match){
+            $match = preg_replace('/#.*$/','',$match); //ignore comments
+            $acl   = preg_split('/\s+/',$match);
+            if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
+            if($acl[2] > $perm){
+                $perm = $acl[2];
+            }
+        }
+        if($perm > -1){
+            //we had a match - return it
+            return $perm;
         }
-      }
-      //we had a match - return it
-      return $perm;
     }
 
-    //get next higher namespace
-    $ns   = getNS($ns);
-
-    if($path != '\*'){
-      $path = $ns.':\*';
-      if($path == ':\*') $path = '\*';
+    //still here? do the namespace checks
+    if($ns){
+        $path = $ns.':\*';
     }else{
-      //we did this already
-      //looks like there is something wrong with the ACL
-      //break here
-      msg('No ACL setup yet! Denying access to everyone.');
-      return AUTH_NONE;
+        $path = '\*'; //root document
     }
-  }while(1); //this should never loop endless
 
-  //still here? return no permissions
-  return AUTH_NONE;
+    do{
+        $matches = preg_grep('/^'.$path.'\s+('.$regexp.')\s+/',$AUTH_ACL);
+        if(count($matches)){
+            foreach($matches as $match){
+                $match = preg_replace('/#.*$/','',$match); //ignore comments
+                $acl   = preg_split('/\s+/',$match);
+                if($acl[2] > AUTH_DELETE) $acl[2] = AUTH_DELETE; //no admins in the ACL!
+                if($acl[2] > $perm){
+                    $perm = $acl[2];
+                }
+            }
+            //we had a match - return it
+            return $perm;
+        }
+
+        //get next higher namespace
+        $ns   = getNS($ns);
+
+        if($path != '\*'){
+            $path = $ns.':\*';
+            if($path == ':\*') $path = '\*';
+        }else{
+            //we did this already
+            //looks like there is something wrong with the ACL
+            //break here
+            msg('No ACL setup yet! Denying access to everyone.');
+            return AUTH_NONE;
+        }
+    }while(1); //this should never loop endless
+
+    //still here? return no permissions
+    return AUTH_NONE;
 }
 
 /**
@@ -531,21 +531,21 @@ function auth_aclcheck($id,$user,$groups){
  * @see rawurldecode()
  */
 function auth_nameencode($name,$skip_group=false){
-  global $cache_authname;
-  $cache =& $cache_authname;
-  $name  = (string) $name;
-
-  if (!isset($cache[$name][$skip_group])) {
-    if($skip_group && $name{0} =='@'){
-      $cache[$name][$skip_group] = '@'.preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e',
-                                                    "'%'.dechex(ord(substr('\\1',-1)))",substr($name,1));
-    }else{
-      $cache[$name][$skip_group] = preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e',
-                                                "'%'.dechex(ord(substr('\\1',-1)))",$name);
+    global $cache_authname;
+    $cache =& $cache_authname;
+    $name  = (string) $name;
+
+    if (!isset($cache[$name][$skip_group])) {
+        if($skip_group && $name{0} =='@'){
+            $cache[$name][$skip_group] = '@'.preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e',
+                    "'%'.dechex(ord(substr('\\1',-1)))",substr($name,1));
+        }else{
+            $cache[$name][$skip_group] = preg_replace('/([\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f])/e',
+                    "'%'.dechex(ord(substr('\\1',-1)))",$name);
+        }
     }
-  }
 
-  return $cache[$name][$skip_group];
+    return $cache[$name][$skip_group];
 }
 
 /**
@@ -557,21 +557,21 @@ function auth_nameencode($name,$skip_group=false){
  * @return string  pronouncable password
  */
 function auth_pwgen(){
-  $pw = '';
-  $c  = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
-  $v  = 'aeiou';              //vowels
-  $a  = $c.$v;                //both
-
-  //use two syllables...
-  for($i=0;$i < 2; $i++){
-    $pw .= $c[rand(0, strlen($c)-1)];
-    $pw .= $v[rand(0, strlen($v)-1)];
-    $pw .= $a[rand(0, strlen($a)-1)];
-  }
-  //... and add a nice number
-  $pw .= rand(10,99);
-
-  return $pw;
+    $pw = '';
+    $c  = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
+    $v  = 'aeiou';              //vowels
+    $a  = $c.$v;                //both
+
+    //use two syllables...
+    for($i=0;$i < 2; $i++){
+        $pw .= $c[rand(0, strlen($c)-1)];
+        $pw .= $v[rand(0, strlen($v)-1)];
+        $pw .= $a[rand(0, strlen($a)-1)];
+    }
+    //... and add a nice number
+    $pw .= rand(10,99);
+
+    return $pw;
 }
 
 /**
@@ -582,26 +582,26 @@ function auth_pwgen(){
  * @return bool  true on success
  */
 function auth_sendPassword($user,$password){
-  global $conf;
-  global $lang;
-  global $auth;
-
-  $hdrs  = '';
-  $userinfo = $auth->getUserData($user);
-
-  if(!$userinfo['mail']) return false;
-
-  $text = rawLocale('password');
-  $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
-  $text = str_replace('@FULLNAME@',$userinfo['name'],$text);
-  $text = str_replace('@LOGIN@',$user,$text);
-  $text = str_replace('@PASSWORD@',$password,$text);
-  $text = str_replace('@TITLE@',$conf['title'],$text);
-
-  return mail_send($userinfo['name'].' <'.$userinfo['mail'].'>',
-                   $lang['regpwmail'],
-                   $text,
-                   $conf['mailfrom']);
+    global $conf;
+    global $lang;
+    global $auth;
+
+    $hdrs  = '';
+    $userinfo = $auth->getUserData($user);
+
+    if(!$userinfo['mail']) return false;
+
+    $text = rawLocale('password');
+    $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text);
+    $text = str_replace('@FULLNAME@',$userinfo['name'],$text);
+    $text = str_replace('@LOGIN@',$user,$text);
+    $text = str_replace('@PASSWORD@',$password,$text);
+    $text = str_replace('@TITLE@',$conf['title'],$text);
+
+    return mail_send($userinfo['name'].' <'.$userinfo['mail'].'>',
+            $lang['regpwmail'],
+            $text,
+            $conf['mailfrom']);
 }
 
 /**
@@ -614,74 +614,74 @@ function auth_sendPassword($user,$password){
  * @return bool  true on success, false on any error
  */
 function register(){
-  global $lang;
-  global $conf;
-  global $auth;
-
-  if(!$_POST['save']) return false;
-  if(!$auth->canDo('addUser')) return false;
-
-  //clean username
-  $_POST['login'] = preg_replace('/.*:/','',$_POST['login']);
-  $_POST['login'] = cleanID($_POST['login']);
-  //clean fullname and email
-  $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['fullname']));
-  $_POST['email']    = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['email']));
-
-  if( empty($_POST['login']) ||
-      empty($_POST['fullname']) ||
-      empty($_POST['email']) ){
-    msg($lang['regmissing'],-1);
-    return false;
-  }
+    global $lang;
+    global $conf;
+    global $auth;
+
+    if(!$_POST['save']) return false;
+    if(!$auth->canDo('addUser')) return false;
+
+    //clean username
+    $_POST['login'] = preg_replace('/.*:/','',$_POST['login']);
+    $_POST['login'] = cleanID($_POST['login']);
+    //clean fullname and email
+    $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['fullname']));
+    $_POST['email']    = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['email']));
+
+    if( empty($_POST['login']) ||
+        empty($_POST['fullname']) ||
+        empty($_POST['email']) ){
+        msg($lang['regmissing'],-1);
+        return false;
+    }
 
-  if ($conf['autopasswd']) {
-    $pass = auth_pwgen();                // automatically generate password
-  } elseif (empty($_POST['pass']) ||
+    if ($conf['autopasswd']) {
+        $pass = auth_pwgen();                // automatically generate password
+    } elseif (empty($_POST['pass']) ||
             empty($_POST['passchk'])) {
-    msg($lang['regmissing'], -1);        // complain about missing passwords
-    return false;
-  } elseif ($_POST['pass'] != $_POST['passchk']) {
-    msg($lang['regbadpass'], -1);      // complain about misspelled passwords
-    return false;
-  } else {
-    $pass = $_POST['pass'];              // accept checked and valid password
-  }
+        msg($lang['regmissing'], -1);        // complain about missing passwords
+        return false;
+    } elseif ($_POST['pass'] != $_POST['passchk']) {
+        msg($lang['regbadpass'], -1);      // complain about misspelled passwords
+        return false;
+    } else {
+        $pass = $_POST['pass'];              // accept checked and valid password
+    }
 
-  //check mail
-  if(!mail_isvalid($_POST['email'])){
-    msg($lang['regbadmail'],-1);
-    return false;
-  }
+    //check mail
+    if(!mail_isvalid($_POST['email'])){
+        msg($lang['regbadmail'],-1);
+        return false;
+    }
 
-  //okay try to create the user
-  if(!$auth->triggerUserMod('create', array($_POST['login'],$pass,$_POST['fullname'],$_POST['email']))){
-    msg($lang['reguexists'],-1);
-    return false;
-  }
-
-  // create substitutions for use in notification email
-  $substitutions = array(
-    'NEWUSER' => $_POST['login'],
-    'NEWNAME' => $_POST['fullname'],
-    'NEWEMAIL' => $_POST['email'],
-  );
-
-  if (!$conf['autopasswd']) {
-    msg($lang['regsuccess2'],1);
-    notify('', 'register', '', $_POST['login'], false, $substitutions);
-    return true;
-  }
+    //okay try to create the user
+    if(!$auth->triggerUserMod('create', array($_POST['login'],$pass,$_POST['fullname'],$_POST['email']))){
+        msg($lang['reguexists'],-1);
+        return false;
+    }
 
-  // autogenerated password? then send him the password
-  if (auth_sendPassword($_POST['login'],$pass)){
-    msg($lang['regsuccess'],1);
-    notify('', 'register', '', $_POST['login'], false, $substitutions);
-    return true;
-  }else{
-    msg($lang['regmailfail'],-1);
-    return false;
-  }
+    // create substitutions for use in notification email
+    $substitutions = array(
+            'NEWUSER' => $_POST['login'],
+            'NEWNAME' => $_POST['fullname'],
+            'NEWEMAIL' => $_POST['email'],
+            );
+
+    if (!$conf['autopasswd']) {
+        msg($lang['regsuccess2'],1);
+        notify('', 'register', '', $_POST['login'], false, $substitutions);
+        return true;
+    }
+
+    // autogenerated password? then send him the password
+    if (auth_sendPassword($_POST['login'],$pass)){
+        msg($lang['regsuccess'],1);
+        notify('', 'register', '', $_POST['login'], false, $substitutions);
+        return true;
+    }else{
+        msg($lang['regmailfail'],-1);
+        return false;
+    }
 }
 
 /**
@@ -690,65 +690,64 @@ function register(){
  * @author    Christopher Smith <chris@jalakai.co.uk>
  */
 function updateprofile() {
-  global $conf;
-  global $INFO;
-  global $lang;
-  global $auth;
-
-  if(empty($_POST['save'])) return false;
-  if(!checkSecurityToken()) return false;
+    global $conf;
+    global $INFO;
+    global $lang;
+    global $auth;
 
-  // should not be able to get here without Profile being possible...
-  if(!$auth->canDo('Profile')) {
-    msg($lang['profna'],-1);
-    return false;
-  }
+    if(empty($_POST['save'])) return false;
+    if(!checkSecurityToken()) return false;
 
-  if ($_POST['newpass'] != $_POST['passchk']) {
-    msg($lang['regbadpass'], -1);      // complain about misspelled passwords
-    return false;
-  }
+    // should not be able to get here without Profile being possible...
+    if(!$auth->canDo('Profile')) {
+        msg($lang['profna'],-1);
+        return false;
+    }
 
-  //clean fullname and email
-  $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['fullname']));
-  $_POST['email']    = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['email']));
+    if ($_POST['newpass'] != $_POST['passchk']) {
+        msg($lang['regbadpass'], -1);      // complain about misspelled passwords
+        return false;
+    }
 
-  if (empty($_POST['fullname']) || empty($_POST['email'])) {
-    msg($lang['profnoempty'],-1);
-    return false;
-  }
+    //clean fullname and email
+    $_POST['fullname'] = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['fullname']));
+    $_POST['email']    = trim(preg_replace('/[\x00-\x1f:<>&%,;]+/','',$_POST['email']));
 
-  if (!mail_isvalid($_POST['email'])){
-    msg($lang['regbadmail'],-1);
-    return false;
-  }
+    if (empty($_POST['fullname']) || empty($_POST['email'])) {
+        msg($lang['profnoempty'],-1);
+        return false;
+    }
 
-  if ($_POST['fullname'] != $INFO['userinfo']['name'] && $auth->canDo('modName')) $changes['name'] = $_POST['fullname'];
-  if ($_POST['email'] != $INFO['userinfo']['mail'] && $auth->canDo('modMail')) $changes['mail'] = $_POST['email'];
-  if (!empty($_POST['newpass']) && $auth->canDo('modPass')) $changes['pass'] = $_POST['newpass'];
+    if (!mail_isvalid($_POST['email'])){
+        msg($lang['regbadmail'],-1);
+        return false;
+    }
 
+    if ($_POST['fullname'] != $INFO['userinfo']['name'] && $auth->canDo('modName')) $changes['name'] = $_POST['fullname'];
+    if ($_POST['email'] != $INFO['userinfo']['mail'] && $auth->canDo('modMail')) $changes['mail'] = $_POST['email'];
+    if (!empty($_POST['newpass']) && $auth->canDo('modPass')) $changes['pass'] = $_POST['newpass'];
 
-  if (!count($changes)) {
-    msg($lang['profnochange'], -1);
-    return false;
-  }
+    if (!count($changes)) {
+        msg($lang['profnochange'], -1);
+        return false;
+    }
 
-  if ($conf['profileconfirm']) {
-    if (!$auth->checkPass($_SERVER['REMOTE_USER'], $_POST['oldpass'])) {
-      msg($lang['badlogin'],-1);
-      return false;
+    if ($conf['profileconfirm']) {
+        if (!$auth->checkPass($_SERVER['REMOTE_USER'], $_POST['oldpass'])) {
+            msg($lang['badlogin'],-1);
+            return false;
+        }
     }
-  }
 
-  if ($result = $auth->triggerUserMod('modify', array($_SERVER['REMOTE_USER'], $changes))) {
-    // update cookie and session with the changed data
-    $cookie = base64_decode($_COOKIE[DOKU_COOKIE]);
-    list($user,$sticky,$pass) = explode('|',$cookie,3);
-    if ($changes['pass']) $pass = PMA_blowfish_encrypt($changes['pass'],auth_cookiesalt());
+    if ($result = $auth->triggerUserMod('modify', array($_SERVER['REMOTE_USER'], $changes))) {
+        // update cookie and session with the changed data
+        $cookie = base64_decode($_COOKIE[DOKU_COOKIE]);
+        list($user,$sticky,$pass) = explode('|',$cookie,3);
+        if ($changes['pass']) $pass = PMA_blowfish_encrypt($changes['pass'],auth_cookiesalt());
 
-    auth_setCookie($_SERVER['REMOTE_USER'],$pass,(bool)$sticky);
-    return true;
-  }
+        auth_setCookie($_SERVER['REMOTE_USER'],$pass,(bool)$sticky);
+        return true;
+    }
 }
 
 /**
@@ -764,7 +763,7 @@ function updateprofile() {
  * @author Andreas Gohr <andi@splitbrain.org>
  *
  * @return bool true on success, false on any error
-*/
+ */
 function act_resendpwd(){
     global $lang;
     global $conf;
@@ -896,8 +895,12 @@ function auth_cryptPassword($clear,$method='',$salt=null){
             $len = strlen($clear);
             $text = $clear.'$'.$magic.'$'.$salt;
             $bin = pack("H32", md5($clear.$salt.$clear));
-            for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
-            for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $clear{0}; }
+            for($i = $len; $i > 0; $i -= 16) {
+                $text .= substr($bin, 0, min(16, $i));
+            }
+            for($i = $len; $i > 0; $i >>= 1) {
+                $text .= ($i & 1) ? chr(0) : $clear{0};
+            }
             $bin = pack("H32", md5($text));
             for($i = 0; $i < 1000; $i++) {
                 $new = ($i & 1) ? $clear : $bin;
diff --git a/inc/html.php b/inc/html.php
index 0ea72c06c0b8eb21ec438cb8d1ed5307563ec2fd..1fb5b020211cbb20822e82942846428b00dfcd43 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -16,13 +16,13 @@ require_once(DOKU_INC.'inc/form.php');
  *
  * @author Andreas Gohr <andi@splitbrain.org>
  */
-function html_wikilink($id,$name=NULL,$search=''){
-  static $xhtml_renderer = NULL;
-  if(is_null($xhtml_renderer)){
-    $xhtml_renderer = p_get_renderer('xhtml');
-  }
+function html_wikilink($id,$name=null,$search=''){
+    static $xhtml_renderer = null;
+    if(is_null($xhtml_renderer)){
+        $xhtml_renderer = p_get_renderer('xhtml');
+    }
 
-  return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
+    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
 }
 
 /**
@@ -31,11 +31,11 @@ function html_wikilink($id,$name=NULL,$search=''){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_attbuild($attributes){
-  $ret = '';
-  foreach ( $attributes as $key => $value ) {
-    $ret .= $key.'="'.formtext($value).'" ';
-  }
-  return trim($ret);
+    $ret = '';
+    foreach ( $attributes as $key => $value ) {
+        $ret .= $key.'="'.formtext($value).'" ';
+    }
+    return trim($ret);
 }
 
 /**
@@ -44,40 +44,40 @@ function html_attbuild($attributes){
  * @author   Andreas Gohr <andi@splitbrain.org>
  */
 function html_login(){
-  global $lang;
-  global $conf;
-  global $ID;
-  global $auth;
-
-  print p_locale_xhtml('login');
-  print '<div class="centeralign">'.NL;
-  $form = new Doku_Form('dw__login');
-  $form->startFieldset($lang['btn_login']);
-  $form->addHidden('id', $ID);
-  $form->addHidden('do', 'login');
-  $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
-  $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
-  if($conf['rememberme']) {
-      $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
-  }
-  $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
-  $form->endFieldset();
-  html_form('login', $form);
-
-  if($auth && $auth->canDo('addUser') && actionOK('register')){
-    print '<p>';
-    print $lang['reghere'];
-    print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
-    print '</p>';
-  }
-
-  if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
-    print '<p>';
-    print $lang['pwdforget'];
-    print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
-    print '</p>';
-  }
-  print '</div>'.NL;
+    global $lang;
+    global $conf;
+    global $ID;
+    global $auth;
+
+    print p_locale_xhtml('login');
+    print '<div class="centeralign">'.NL;
+    $form = new Doku_Form('dw__login');
+    $form->startFieldset($lang['btn_login']);
+    $form->addHidden('id', $ID);
+    $form->addHidden('do', 'login');
+    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
+    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
+    if($conf['rememberme']) {
+        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
+    }
+    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
+    $form->endFieldset();
+    html_form('login', $form);
+
+    if($auth && $auth->canDo('addUser') && actionOK('register')){
+        print '<p>';
+        print $lang['reghere'];
+        print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
+        print '</p>';
+    }
+
+    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
+        print '<p>';
+        print $lang['pwdforget'];
+        print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
+        print '</p>';
+    }
+    print '</div>'.NL;
 }
 
 /**
@@ -87,21 +87,21 @@ function html_login(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_secedit_button($matches){
-  global $ID;
-  global $INFO;
-
-  $section = $matches[2];
-  $name = $matches[1];
-
-  $secedit  = '';
-  $secedit .= '<div class="secedit">';
-  $secedit .= html_btn('secedit',$ID,'',
-                        array('do'      => 'edit',
-                              'lines'   => "$section",
-                              'rev' => $INFO['lastmod']),
-                              'post', $name);
-  $secedit .= '</div>';
-  return $secedit;
+    global $ID;
+    global $INFO;
+
+    $section = $matches[2];
+    $name = $matches[1];
+
+    $secedit  = '';
+    $secedit .= '<div class="secedit">';
+    $secedit .= html_btn('secedit',$ID,'',
+            array('do'      => 'edit',
+                'lines'   => "$section",
+                'rev' => $INFO['lastmod']),
+            'post', $name);
+    $secedit .= '</div>';
+    return $secedit;
 }
 
 /**
@@ -110,16 +110,16 @@ function html_secedit_button($matches){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_secedit($text,$show=true){
-  global $INFO;
+    global $INFO;
 
-  if($INFO['writable'] && $show && !$INFO['rev']){
-    $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
-                         'html_secedit_button', $text);
-  }else{
-    $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
-  }
+    if($INFO['writable'] && $show && !$INFO['rev']){
+        $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
+                'html_secedit_button', $text);
+    }else{
+        $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
+    }
 
-  return $text;
+    return $text;
 }
 
 /**
@@ -128,12 +128,12 @@ function html_secedit($text,$show=true){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_topbtn(){
-  global $lang;
+    global $lang;
 
-  $ret  = '';
-  $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
+    $ret  = '';
+    $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
 
-  return $ret;
+    return $ret;
 }
 
 /**
@@ -143,53 +143,53 @@ function html_topbtn(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
-  global $conf;
-  global $lang;
-
-  $label = $lang['btn_'.$name];
-
-  $ret = '';
-  $tip = '';
-
-  //filter id (without urlencoding)
-  $id = idfilter($id,false);
-
-  //make nice URLs even for buttons
-  if($conf['userewrite'] == 2){
-    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
-  }elseif($conf['userewrite']){
-    $script = DOKU_BASE.$id;
-  }else{
-    $script = DOKU_BASE.DOKU_SCRIPT;
-    $params['id'] = $id;
-  }
-
-  $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
-
-  if(is_array($params)){
-    reset($params);
-    while (list($key, $val) = each($params)) {
-      $ret .= '<input type="hidden" name="'.$key.'" ';
-      $ret .= 'value="'.htmlspecialchars($val).'" />';
+    global $conf;
+    global $lang;
+
+    $label = $lang['btn_'.$name];
+
+    $ret = '';
+    $tip = '';
+
+    //filter id (without urlencoding)
+    $id = idfilter($id,false);
+
+    //make nice URLs even for buttons
+    if($conf['userewrite'] == 2){
+        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
+    }elseif($conf['userewrite']){
+        $script = DOKU_BASE.$id;
+    }else{
+        $script = DOKU_BASE.DOKU_SCRIPT;
+        $params['id'] = $id;
+    }
+
+    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
+
+    if(is_array($params)){
+        reset($params);
+        while (list($key, $val) = each($params)) {
+            $ret .= '<input type="hidden" name="'.$key.'" ';
+            $ret .= 'value="'.htmlspecialchars($val).'" />';
+        }
+    }
+
+    if ($tooltip!='') {
+        $tip = htmlspecialchars($tooltip);
+    }else{
+        $tip = htmlspecialchars($label);
     }
-  }
-
-  if ($tooltip!='') {
-      $tip = htmlspecialchars($tooltip);
-  }else{
-      $tip = htmlspecialchars($label);
-  }
-
-  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
-  if($akey){
-    $tip .= ' ['.strtoupper($akey).']';
-    $ret .= 'accesskey="'.$akey.'" ';
-  }
-  $ret .= 'title="'.$tip.'" ';
-  $ret .= '/>';
-  $ret .= '</div></form>';
-
-  return $ret;
+
+    $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
+    if($akey){
+        $tip .= ' ['.strtoupper($akey).']';
+        $ret .= 'accesskey="'.$akey.'" ';
+    }
+    $ret .= 'title="'.$tip.'" ';
+    $ret .= '/>';
+    $ret .= '</div></form>';
+
+    return $ret;
 }
 
 /**
@@ -198,36 +198,36 @@ function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_show($txt=''){
-  global $ID;
-  global $REV;
-  global $HIGH;
-  global $INFO;
-  //disable section editing for old revisions or in preview
-  if($txt || $REV){
-    $secedit = false;
-  }else{
-    $secedit = true;
-  }
-
-  if ($txt){
-    //PreviewHeader
-    echo '<br id="scroll__here" />';
-    echo p_locale_xhtml('preview');
-    echo '<div class="preview">';
-    $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
-    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
-    echo $html;
-    echo '<div class="clearer"></div>';
-    echo '</div>';
+    global $ID;
+    global $REV;
+    global $HIGH;
+    global $INFO;
+    //disable section editing for old revisions or in preview
+    if($txt || $REV){
+        $secedit = false;
+    }else{
+        $secedit = true;
+    }
+
+    if ($txt){
+        //PreviewHeader
+        echo '<br id="scroll__here" />';
+        echo p_locale_xhtml('preview');
+        echo '<div class="preview">';
+        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
+        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
+        echo $html;
+        echo '<div class="clearer"></div>';
+        echo '</div>';
 
-  }else{
-    if ($REV) print p_locale_xhtml('showrev');
-    $html = p_wiki_xhtml($ID,$REV,true);
-    $html = html_secedit($html,$secedit);
-    if($INFO['prependTOC']) $html = tpl_toc(true).$html;
-    $html = html_hilight($html,$HIGH);
-    echo $html;
-  }
+    }else{
+        if ($REV) print p_locale_xhtml('showrev');
+        $html = p_wiki_xhtml($ID,$REV,true);
+        $html = html_secedit($html,$secedit);
+        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
+        $html = html_hilight($html,$HIGH);
+        echo $html;
+    }
 }
 
 /**
@@ -236,25 +236,25 @@ function html_show($txt=''){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_draft(){
-  global $INFO;
-  global $ID;
-  global $lang;
-  global $conf;
-  $draft = unserialize(io_readFile($INFO['draft'],false));
-  $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
-
-  print p_locale_xhtml('draft');
-  $form = new Doku_Form('dw__editform');
-  $form->addHidden('id', $ID);
-  $form->addHidden('date', $draft['date']);
-  $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
-  $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
-  $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
-  $form->addElement(form_makeCloseTag('div'));
-  $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
-  $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
-  $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
-  html_form('draft', $form);
+    global $INFO;
+    global $ID;
+    global $lang;
+    global $conf;
+    $draft = unserialize(io_readFile($INFO['draft'],false));
+    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
+
+    print p_locale_xhtml('draft');
+    $form = new Doku_Form('dw__editform');
+    $form->addHidden('id', $ID);
+    $form->addHidden('date', $draft['date']);
+    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
+    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
+    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
+    $form->addElement(form_makeCloseTag('div'));
+    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
+    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
+    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
+    html_form('draft', $form);
 }
 
 /**
@@ -264,12 +264,12 @@ function html_draft(){
  * @author Harry Fuecks <hfuecks@gmail.com>
  */
 function html_hilight($html,$phrases){
-  $phrases = array_filter((array) $phrases);
-  $regex = join('|',array_map('preg_quote_cb',$phrases));
+    $phrases = array_filter((array) $phrases);
+    $regex = join('|',array_map('preg_quote_cb',$phrases));
 
-  if ($regex === '') return $html;
-  $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
-  return $html;
+    if ($regex === '') return $html;
+    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
+    return $html;
 }
 
 /**
@@ -278,11 +278,11 @@ function html_hilight($html,$phrases){
  * @author Harry Fuecks <hfuecks@gmail.com>
  */
 function html_hilight_callback($m) {
-  $hlight = unslash($m[0]);
-  if ( !isset($m[2])) {
-    $hlight = '<span class="search_hit">'.$hlight.'</span>';
-  }
-  return $hlight;
+    $hlight = unslash($m[0]);
+    if ( !isset($m[2])) {
+        $hlight = '<span class="search_hit">'.$hlight.'</span>';
+    }
+    return $hlight;
 }
 
 /**
@@ -291,83 +291,83 @@ function html_hilight_callback($m) {
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_search(){
-  require_once(DOKU_INC.'inc/search.php');
-  require_once(DOKU_INC.'inc/fulltext.php');
-  global $conf;
-  global $QUERY;
-  global $ID;
-  global $lang;
-
-  print p_locale_xhtml('searchpage');
-  flush();
-
-  //check if search is restricted to namespace
-  if(preg_match('/@([^@]*)/',$QUERY,$match)) {
-      $id = cleanID($match[1]);
-  } else {
-      $id = cleanID($QUERY);
-  }
-
-  //show progressbar
-  print '<div class="centeralign" id="dw__loading">'.NL;
-  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
-  print 'showLoadBar();'.NL;
-  print '//--><!]]></script>'.NL;
-  print '<br /></div>'.NL;
-  flush();
-
-  //do quick pagesearch
-  $data = array();
-
-  if($id) $data = ft_pageLookup($id);
-  if(count($data)){
-    print '<div class="search_quickresult">';
-    print '<h3>'.$lang['quickhits'].':</h3>';
-    print '<ul class="search_quickhits">';
-    foreach($data as $id){
-      print '<li> ';
-      $ns = getNS($id);
-      if($ns){
-        $name = shorten(noNS($id), ' ('.$ns.')',30);
-      }else{
-        $name = $id;
-      }
-      print html_wikilink(':'.$id,$name);
-      print '</li> ';
+    require_once(DOKU_INC.'inc/search.php');
+    require_once(DOKU_INC.'inc/fulltext.php');
+    global $conf;
+    global $QUERY;
+    global $ID;
+    global $lang;
+
+    print p_locale_xhtml('searchpage');
+    flush();
+
+    //check if search is restricted to namespace
+    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
+        $id = cleanID($match[1]);
+    } else {
+        $id = cleanID($QUERY);
     }
-    print '</ul> ';
-    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
-    print '<div class="clearer">&nbsp;</div>';
-    print '</div>';
-  }
-  flush();
-
-  //do fulltext search
-  $data = ft_pageSearch($QUERY,$regex);
-  if(count($data)){
-    $num = 1;
-    foreach($data as $id => $cnt){
-      print '<div class="search_result">';
-      print html_wikilink(':'.$id,useHeading('navigation')?NULL:$id,$regex);
-      if($cnt !== 0){
-        print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
-        if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
-          print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
+
+    //show progressbar
+    print '<div class="centeralign" id="dw__loading">'.NL;
+    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
+    print 'showLoadBar();'.NL;
+    print '//--><!]]></script>'.NL;
+    print '<br /></div>'.NL;
+    flush();
+
+    //do quick pagesearch
+    $data = array();
+
+    if($id) $data = ft_pageLookup($id);
+    if(count($data)){
+        print '<div class="search_quickresult">';
+        print '<h3>'.$lang['quickhits'].':</h3>';
+        print '<ul class="search_quickhits">';
+        foreach($data as $id){
+            print '<li> ';
+            $ns = getNS($id);
+            if($ns){
+                $name = shorten(noNS($id), ' ('.$ns.')',30);
+            }else{
+                $name = $id;
+            }
+            print html_wikilink(':'.$id,$name);
+            print '</li> ';
         }
-        $num++;
-      }
-      print '</div>';
-      flush();
+        print '</ul> ';
+        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
+        print '<div class="clearer">&nbsp;</div>';
+        print '</div>';
     }
-  }else{
-    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
-  }
-
-  //hide progressbar
-  print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
-  print 'hideLoadBar("dw__loading");'.NL;
-  print '//--><!]]></script>'.NL;
-  flush();
+    flush();
+
+    //do fulltext search
+    $data = ft_pageSearch($QUERY,$regex);
+    if(count($data)){
+        $num = 1;
+        foreach($data as $id => $cnt){
+            print '<div class="search_result">';
+            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
+            if($cnt !== 0){
+                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
+                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
+                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
+                }
+                $num++;
+            }
+            print '</div>';
+            flush();
+        }
+    }else{
+        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
+    }
+
+    //hide progressbar
+    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
+    print 'hideLoadBar("dw__loading");'.NL;
+    print '//--><!]]></script>'.NL;
+    flush();
 }
 
 /**
@@ -376,20 +376,20 @@ function html_search(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_locked(){
-  global $ID;
-  global $conf;
-  global $lang;
-  global $INFO;
-
-  $locktime = filemtime(wikiLockFN($ID));
-  $expire = dformat($locktime + $conf['locktime']);
-  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
-
-  print p_locale_xhtml('locked');
-  print '<ul>';
-  print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
-  print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
-  print '</ul>';
+    global $ID;
+    global $conf;
+    global $lang;
+    global $INFO;
+
+    $locktime = filemtime(wikiLockFN($ID));
+    $expire = dformat($locktime + $conf['locktime']);
+    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
+
+    print p_locale_xhtml('locked');
+    print '<ul>';
+    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
+    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
+    print '</ul>';
 }
 
 /**
@@ -399,159 +399,159 @@ function html_locked(){
  * @author Ben Coburn <btcoburn@silicodon.net>
  */
 function html_revisions($first=0){
-  global $ID;
-  global $INFO;
-  global $conf;
-  global $lang;
-  /* we need to get one additionally log entry to be able to
-   * decide if this is the last page or is there another one.
-   * see html_recent()
-   */
-  $revisions = getRevisions($ID, $first, $conf['recent']+1);
-  if(count($revisions)==0 && $first!=0){
-    $first=0;
-    $revisions = getRevisions($ID, $first, $conf['recent']+1);;
-  }
-  $hasNext = false;
-  if (count($revisions)>$conf['recent']) {
-    $hasNext = true;
-    array_pop($revisions); // remove extra log entry
-  }
-
-  $date = dformat($INFO['lastmod']);
-
-  print p_locale_xhtml('revisions');
-
-  $form = new Doku_Form('page__revisions', wl($ID));
-  $form->addElement(form_makeOpenTag('ul'));
-  if($INFO['exists'] && $first==0){
-    if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
-      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
-    else
-      $form->addElement(form_makeOpenTag('li'));
-    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
-    $form->addElement(form_makeTag('input', array(
-      'type' => 'checkbox',
-      'name' => 'rev2[]',
-      'value' => 'current')));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
-    $form->addElement($date);
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement(form_makeTag('img', array(
-      'src' =>  DOKU_BASE.'lib/images/blank.gif',
-      'width' => '15',
-      'height' => '11',
-      'alt'    => '')));
-
-    $form->addElement(form_makeOpenTag('a', array(
-      'class' => 'wikilink1',
-      'href'  => wl($ID))));
-    $form->addElement($ID);
-    $form->addElement(form_makeCloseTag('a'));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
-    $form->addElement(' &ndash; ');
-    $form->addElement(htmlspecialchars($INFO['sum']));
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
-    $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement('('.$lang['current'].')');
-    $form->addElement(form_makeCloseTag('div'));
-    $form->addElement(form_makeCloseTag('li'));
-  }
-
-  foreach($revisions as $rev){
-    $date   = dformat($rev);
-    $info   = getRevisionInfo($ID,$rev,true);
-    $exists = page_exists($ID,$rev);
-
-    if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
-      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
-    else
-      $form->addElement(form_makeOpenTag('li'));
-    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
-    if($exists){
-      $form->addElement(form_makeTag('input', array(
-        'type' => 'checkbox',
-        'name' => 'rev2[]',
-        'value' => $rev)));
-    }else{
-      $form->addElement(form_makeTag('img', array(
-        'src' => DOKU_BASE.'lib/images/blank.gif',
-        'width' => 14,
-        'height' => 11,
-        'alt' => '')));
+    global $ID;
+    global $INFO;
+    global $conf;
+    global $lang;
+    /* we need to get one additionally log entry to be able to
+     * decide if this is the last page or is there another one.
+     * see html_recent()
+     */
+    $revisions = getRevisions($ID, $first, $conf['recent']+1);
+    if(count($revisions)==0 && $first!=0){
+        $first=0;
+        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
     }
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
-    $form->addElement($date);
-    $form->addElement(form_makeCloseTag('span'));
-
-    if($exists){
-      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
-      $form->addElement(form_makeTag('img', array(
-        'src'    => DOKU_BASE.'lib/images/diff.png',
-        'width'  => 15,
-        'height' => 11,
-        'title'  => $lang['diff'],
-        'alt'    => $lang['diff'])));
-      $form->addElement(form_makeCloseTag('a'));
-
-      $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
-      $form->addElement($ID);
-      $form->addElement(form_makeCloseTag('a'));
-    }else{
-      $form->addElement(form_makeTag('img', array(
-        'src' => DOKU_BASE.'lib/images/blank.gif',
-        'width' => '15',
-        'height' => '11',
-        'alt'   => '')));
-      $form->addElement($ID);
+    $hasNext = false;
+    if (count($revisions)>$conf['recent']) {
+        $hasNext = true;
+        array_pop($revisions); // remove extra log entry
     }
 
-    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
-    $form->addElement(' &ndash; ');
-    $form->addElement(htmlspecialchars($info['sum']));
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
-    if($info['user']){
-      $form->addElement(editorinfo($info['user']));
-      if(auth_ismanager()){
-        $form->addElement(' ('.$info['ip'].')');
-      }
-    }else{
-      $form->addElement($info['ip']);
+    $date = dformat($INFO['lastmod']);
+
+    print p_locale_xhtml('revisions');
+
+    $form = new Doku_Form('page__revisions', wl($ID));
+    $form->addElement(form_makeOpenTag('ul'));
+    if($INFO['exists'] && $first==0){
+        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
+            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
+        else
+            $form->addElement(form_makeOpenTag('li'));
+        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
+        $form->addElement(form_makeTag('input', array(
+                        'type' => 'checkbox',
+                        'name' => 'rev2[]',
+                        'value' => 'current')));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
+        $form->addElement($date);
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeTag('img', array(
+                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
+                        'width' => '15',
+                        'height' => '11',
+                        'alt'    => '')));
+
+        $form->addElement(form_makeOpenTag('a', array(
+                        'class' => 'wikilink1',
+                        'href'  => wl($ID))));
+        $form->addElement($ID);
+        $form->addElement(form_makeCloseTag('a'));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
+        $form->addElement(' &ndash; ');
+        $form->addElement(htmlspecialchars($INFO['sum']));
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
+        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement('('.$lang['current'].')');
+        $form->addElement(form_makeCloseTag('div'));
+        $form->addElement(form_makeCloseTag('li'));
     }
-    $form->addElement(form_makeCloseTag('span'));
 
-    $form->addElement(form_makeCloseTag('div'));
-    $form->addElement(form_makeCloseTag('li'));
-  }
-  $form->addElement(form_makeCloseTag('ul'));
-  $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
-  html_form('revisions', $form);
-
-  print '<div class="pagenav">';
-  $last = $first + $conf['recent'];
-  if ($first > 0) {
-    $first -= $conf['recent'];
-    if ($first < 0) $first = 0;
-    print '<div class="pagenav-prev">';
-    print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
-    print '</div>';
-  }
-  if ($hasNext) {
-    print '<div class="pagenav-next">';
-    print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
+    foreach($revisions as $rev){
+        $date   = dformat($rev);
+        $info   = getRevisionInfo($ID,$rev,true);
+        $exists = page_exists($ID,$rev);
+
+        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
+            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
+        else
+            $form->addElement(form_makeOpenTag('li'));
+        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
+        if($exists){
+            $form->addElement(form_makeTag('input', array(
+                            'type' => 'checkbox',
+                            'name' => 'rev2[]',
+                            'value' => $rev)));
+        }else{
+            $form->addElement(form_makeTag('img', array(
+                            'src' => DOKU_BASE.'lib/images/blank.gif',
+                            'width' => 14,
+                            'height' => 11,
+                            'alt' => '')));
+        }
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
+        $form->addElement($date);
+        $form->addElement(form_makeCloseTag('span'));
+
+        if($exists){
+            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
+            $form->addElement(form_makeTag('img', array(
+                            'src'    => DOKU_BASE.'lib/images/diff.png',
+                            'width'  => 15,
+                            'height' => 11,
+                            'title'  => $lang['diff'],
+                            'alt'    => $lang['diff'])));
+            $form->addElement(form_makeCloseTag('a'));
+
+            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
+            $form->addElement($ID);
+            $form->addElement(form_makeCloseTag('a'));
+        }else{
+            $form->addElement(form_makeTag('img', array(
+                            'src' => DOKU_BASE.'lib/images/blank.gif',
+                            'width' => '15',
+                            'height' => '11',
+                            'alt'   => '')));
+            $form->addElement($ID);
+        }
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
+        $form->addElement(' &ndash; ');
+        $form->addElement(htmlspecialchars($info['sum']));
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
+        if($info['user']){
+            $form->addElement(editorinfo($info['user']));
+            if(auth_ismanager()){
+                $form->addElement(' ('.$info['ip'].')');
+            }
+        }else{
+            $form->addElement($info['ip']);
+        }
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeCloseTag('div'));
+        $form->addElement(form_makeCloseTag('li'));
+    }
+    $form->addElement(form_makeCloseTag('ul'));
+    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
+    html_form('revisions', $form);
+
+    print '<div class="pagenav">';
+    $last = $first + $conf['recent'];
+    if ($first > 0) {
+        $first -= $conf['recent'];
+        if ($first < 0) $first = 0;
+        print '<div class="pagenav-prev">';
+        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
+        print '</div>';
+    }
+    if ($hasNext) {
+        print '<div class="pagenav-next">';
+        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
+        print '</div>';
+    }
     print '</div>';
-  }
-  print '</div>';
 
 }
 
@@ -563,120 +563,120 @@ function html_revisions($first=0){
  * @author Ben Coburn <btcoburn@silicodon.net>
  */
 function html_recent($first=0){
-  global $conf;
-  global $lang;
-  global $ID;
-  /* we need to get one additionally log entry to be able to
-   * decide if this is the last page or is there another one.
-   * This is the cheapest solution to get this information.
-   */
-  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
-  if(count($recents) == 0 && $first != 0){
-    $first=0;
+    global $conf;
+    global $lang;
+    global $ID;
+    /* we need to get one additionally log entry to be able to
+     * decide if this is the last page or is there another one.
+     * This is the cheapest solution to get this information.
+     */
     $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
-  }
-  $hasNext = false;
-  if (count($recents)>$conf['recent']) {
-    $hasNext = true;
-    array_pop($recents); // remove extra log entry
-  }
-
-  print p_locale_xhtml('recent');
-
-  if (getNS($ID) != '')
-    print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
-
-  $form = new Doku_Form('dw__recent', script(), 'get');
-  $form->addHidden('sectok', null);
-  $form->addHidden('do', 'recent');
-  $form->addHidden('id', $ID);
-  $form->addElement(form_makeOpenTag('ul'));
-
-  foreach($recents as $recent){
-    $date = dformat($recent['date']);
-    if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
-      $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
-    else
-      $form->addElement(form_makeOpenTag('li'));
-
-    $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
-    $form->addElement($date);
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
-    $form->addElement(form_makeTag('img', array(
-      'src'   => DOKU_BASE.'lib/images/diff.png',
-      'width' => 15,
-      'height'=> 11,
-      'title' => $lang['diff'],
-      'alt'   => $lang['diff']
-    )));
-    $form->addElement(form_makeCloseTag('a'));
-
-    $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
-    $form->addElement(form_makeTag('img', array(
-      'src'   => DOKU_BASE.'lib/images/history.png',
-      'width' => 12,
-      'height'=> 14,
-      'title' => $lang['btn_revs'],
-      'alt'   => $lang['btn_revs']
-    )));
-    $form->addElement(form_makeCloseTag('a'));
-
-    $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?NULL:$recent['id']));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
-    $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
-    $form->addElement(form_makeCloseTag('span'));
-
-    $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
-    if($recent['user']){
-      $form->addElement(editorinfo($recent['user']));
-      if(auth_ismanager()){
-        $form->addElement(' ('.$recent['ip'].')');
-      }
-    }else{
-      $form->addElement($recent['ip']);
+    if(count($recents) == 0 && $first != 0){
+        $first=0;
+        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
+    }
+    $hasNext = false;
+    if (count($recents)>$conf['recent']) {
+        $hasNext = true;
+        array_pop($recents); // remove extra log entry
     }
-    $form->addElement(form_makeCloseTag('span'));
 
+    print p_locale_xhtml('recent');
+
+    if (getNS($ID) != '')
+        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
+
+    $form = new Doku_Form('dw__recent', script(), 'get');
+    $form->addHidden('sectok', null);
+    $form->addHidden('do', 'recent');
+    $form->addHidden('id', $ID);
+    $form->addElement(form_makeOpenTag('ul'));
+
+    foreach($recents as $recent){
+        $date = dformat($recent['date']);
+        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
+            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
+        else
+            $form->addElement(form_makeOpenTag('li'));
+
+        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
+        $form->addElement($date);
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
+        $form->addElement(form_makeTag('img', array(
+                        'src'   => DOKU_BASE.'lib/images/diff.png',
+                        'width' => 15,
+                        'height'=> 11,
+                        'title' => $lang['diff'],
+                        'alt'   => $lang['diff']
+                        )));
+        $form->addElement(form_makeCloseTag('a'));
+
+        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
+        $form->addElement(form_makeTag('img', array(
+                        'src'   => DOKU_BASE.'lib/images/history.png',
+                        'width' => 12,
+                        'height'=> 14,
+                        'title' => $lang['btn_revs'],
+                        'alt'   => $lang['btn_revs']
+                        )));
+        $form->addElement(form_makeCloseTag('a'));
+
+        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
+        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
+        if($recent['user']){
+            $form->addElement(editorinfo($recent['user']));
+            if(auth_ismanager()){
+                $form->addElement(' ('.$recent['ip'].')');
+            }
+        }else{
+            $form->addElement($recent['ip']);
+        }
+        $form->addElement(form_makeCloseTag('span'));
+
+        $form->addElement(form_makeCloseTag('div'));
+        $form->addElement(form_makeCloseTag('li'));
+    }
+    $form->addElement(form_makeCloseTag('ul'));
+
+    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
+    $last = $first + $conf['recent'];
+    if ($first > 0) {
+        $first -= $conf['recent'];
+        if ($first < 0) $first = 0;
+        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
+        $form->addElement(form_makeTag('input', array(
+                    'type'  => 'submit',
+                    'name'  => 'first['.$first.']',
+                    'value' => $lang['btn_newer'],
+                    'accesskey' => 'n',
+                    'title' => $lang['btn_newer'].' [N]',
+                    'class' => 'button'
+                    )));
+        $form->addElement(form_makeCloseTag('div'));
+    }
+    if ($hasNext) {
+        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
+        $form->addElement(form_makeTag('input', array(
+                        'type'  => 'submit',
+                        'name'  => 'first['.$last.']',
+                        'value' => $lang['btn_older'],
+                        'accesskey' => 'p',
+                        'title' => $lang['btn_older'].' [P]',
+                        'class' => 'button'
+                        )));
+        $form->addElement(form_makeCloseTag('div'));
+    }
     $form->addElement(form_makeCloseTag('div'));
-    $form->addElement(form_makeCloseTag('li'));
-  }
-  $form->addElement(form_makeCloseTag('ul'));
-
-  $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
-  $last = $first + $conf['recent'];
-  if ($first > 0) {
-    $first -= $conf['recent'];
-    if ($first < 0) $first = 0;
-    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
-    $form->addElement(form_makeTag('input', array(
-      'type'  => 'submit',
-      'name'  => 'first['.$first.']',
-      'value' => $lang['btn_newer'],
-      'accesskey' => 'n',
-      'title' => $lang['btn_newer'].' [N]',
-      'class' => 'button'
-    )));
-    $form->addElement(form_makeCloseTag('div'));
-  }
-  if ($hasNext) {
-    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
-    $form->addElement(form_makeTag('input', array(
-      'type'  => 'submit',
-      'name'  => 'first['.$last.']',
-      'value' => $lang['btn_older'],
-      'accesskey' => 'p',
-      'title' => $lang['btn_older'].' [P]',
-      'class' => 'button'
-    )));
-    $form->addElement(form_makeCloseTag('div'));
-  }
-  $form->addElement(form_makeCloseTag('div'));
-  html_form('recent', $form);
+    html_form('recent', $form);
 }
 
 /**
@@ -685,26 +685,26 @@ function html_recent($first=0){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_index($ns){
-  require_once(DOKU_INC.'inc/search.php');
-  global $conf;
-  global $ID;
-  $dir = $conf['datadir'];
-  $ns  = cleanID($ns);
-  #fixme use appropriate function
-  if(empty($ns)){
-    $ns = dirname(str_replace(':','/',$ID));
-    if($ns == '.') $ns ='';
-  }
-  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
-
-  echo p_locale_xhtml('index');
-  echo '<div id="index__tree">';
-
-  $data = array();
-  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
-  echo html_buildlist($data,'idx','html_list_index','html_li_index');
-
-  echo '</div>';
+    require_once(DOKU_INC.'inc/search.php');
+    global $conf;
+    global $ID;
+    $dir = $conf['datadir'];
+    $ns  = cleanID($ns);
+    #fixme use appropriate function
+    if(empty($ns)){
+        $ns = dirname(str_replace(':','/',$ID));
+        if($ns == '.') $ns ='';
+    }
+    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
+
+    echo p_locale_xhtml('index');
+    echo '<div id="index__tree">';
+
+    $data = array();
+    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
+    echo html_buildlist($data,'idx','html_list_index','html_li_index');
+
+    echo '</div>';
 }
 
 /**
@@ -715,18 +715,18 @@ function html_index($ns){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_list_index($item){
-  global $ID;
-  $ret = '';
-  $base = ':'.$item['id'];
-  $base = substr($base,strrpos($base,':')+1);
-  if($item['type']=='d'){
-    $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
-    $ret .= $base;
-    $ret .= '</strong></a>';
-  }else{
-    $ret .= html_wikilink(':'.$item['id']);
-  }
-  return $ret;
+    global $ID;
+    $ret = '';
+    $base = ':'.$item['id'];
+    $base = substr($base,strrpos($base,':')+1);
+    if($item['type']=='d'){
+        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
+        $ret .= $base;
+        $ret .= '</strong></a>';
+    }else{
+        $ret .= html_wikilink(':'.$item['id']);
+    }
+    return $ret;
 }
 
 /**
@@ -739,13 +739,13 @@ function html_list_index($item){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_li_index($item){
-  if($item['type'] == "f"){
-    return '<li class="level'.$item['level'].'">';
-  }elseif($item['open']){
-    return '<li class="open">';
-  }else{
-    return '<li class="closed">';
-  }
+    if($item['type'] == "f"){
+        return '<li class="level'.$item['level'].'">';
+    }elseif($item['open']){
+        return '<li class="open">';
+    }else{
+        return '<li class="closed">';
+    }
 }
 
 /**
@@ -754,7 +754,7 @@ function html_li_index($item){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_li_default($item){
-  return '<li class="level'.$item['level'].'">';
+    return '<li class="level'.$item['level'].'">';
 }
 
 /**
@@ -773,47 +773,47 @@ function html_li_default($item){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
-  $level = 0;
-  $opens = 0;
-  $ret   = '';
-
-  foreach ($data as $item){
-
-    if( $item['level'] > $level ){
-      //open new list
-      for($i=0; $i<($item['level'] - $level); $i++){
-        if ($i) $ret .= "<li class=\"clear\">\n";
-        $ret .= "\n<ul class=\"$class\">\n";
-      }
-    }elseif( $item['level'] < $level ){
-      //close last item
-      $ret .= "</li>\n";
-      for ($i=0; $i<($level - $item['level']); $i++){
-        //close higher lists
-        $ret .= "</ul>\n</li>\n";
-      }
-    }else{
-      //close last item
-      $ret .= "</li>\n";
-    }
+    $level = 0;
+    $opens = 0;
+    $ret   = '';
+
+    foreach ($data as $item){
+
+        if( $item['level'] > $level ){
+            //open new list
+            for($i=0; $i<($item['level'] - $level); $i++){
+                if ($i) $ret .= "<li class=\"clear\">\n";
+                $ret .= "\n<ul class=\"$class\">\n";
+            }
+        }elseif( $item['level'] < $level ){
+            //close last item
+            $ret .= "</li>\n";
+            for ($i=0; $i<($level - $item['level']); $i++){
+                //close higher lists
+                $ret .= "</ul>\n</li>\n";
+            }
+        }else{
+            //close last item
+            $ret .= "</li>\n";
+        }
 
-    //remember current level
-    $level = $item['level'];
+        //remember current level
+        $level = $item['level'];
 
-    //print item
-    $ret .= call_user_func($lifunc,$item);
-    $ret .= '<div class="li">';
+        //print item
+        $ret .= call_user_func($lifunc,$item);
+        $ret .= '<div class="li">';
 
-    $ret .= call_user_func($func,$item);
-    $ret .= '</div>';
-  }
+        $ret .= call_user_func($func,$item);
+        $ret .= '</div>';
+    }
 
-  //close remaining items and lists
-  for ($i=0; $i < $level; $i++){
-    $ret .= "</li></ul>\n";
-  }
+    //close remaining items and lists
+    for ($i=0; $i < $level; $i++){
+        $ret .= "</li></ul>\n";
+    }
 
-  return $ret;
+    return $ret;
 }
 
 /**
@@ -823,26 +823,26 @@ function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
  * @author Michael Klier <chi@chimeric.de>
  */
 function html_backlinks(){
-  require_once(DOKU_INC.'inc/fulltext.php');
-  global $ID;
-  global $conf;
-  global $lang;
-
-  print p_locale_xhtml('backlinks');
-
-  $data = ft_backlinks($ID);
-
-  if(!empty($data)) {
-      print '<ul class="idx">';
-      foreach($data as $blink){
-        print '<li><div class="li">';
-        print html_wikilink(':'.$blink,useHeading('navigation')?NULL:$blink);
-        print '</div></li>';
-      }
-      print '</ul>';
-  } else {
-      print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
-  }
+    require_once(DOKU_INC.'inc/fulltext.php');
+    global $ID;
+    global $conf;
+    global $lang;
+
+    print p_locale_xhtml('backlinks');
+
+    $data = ft_backlinks($ID);
+
+    if(!empty($data)) {
+        print '<ul class="idx">';
+        foreach($data as $blink){
+            print '<li><div class="li">';
+            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
+            print '</div></li>';
+        }
+        print '</ul>';
+    } else {
+        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
+    }
 }
 
 /**
@@ -851,132 +851,140 @@ function html_backlinks(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_diff($text='',$intro=true){
-  require_once(DOKU_INC.'inc/DifferenceEngine.php');
-  global $ID;
-  global $REV;
-  global $lang;
-  global $conf;
-
-  // we're trying to be clever here, revisions to compare can be either
-  // given as rev and rev2 parameters, with rev2 being optional. Or in an
-  // array in rev2.
-  $rev1 = $REV;
-
-  if(is_array($_REQUEST['rev2'])){
-    $rev1 = (int) $_REQUEST['rev2'][0];
-    $rev2 = (int) $_REQUEST['rev2'][1];
-
-    if(!$rev1){
-        $rev1 = $rev2;
-        unset($rev2);
-    }
-  }else{
-    $rev2 = (int) $_REQUEST['rev2'];
-  }
-
-  if($text){                      // compare text to the most current revision
-    $l_rev   = '';
-    $l_text  = rawWiki($ID,'');
-    $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
-               $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
-               $lang['current'];
-
-    $r_rev   = '';
-    $r_text  = cleanText($text);
-    $r_head  = $lang['yours'];
-  }else{
-    if($rev1 && $rev2){            // two specific revisions wanted
-      // make sure order is correct (older on the left)
-      if($rev1 < $rev2){
-        $l_rev = $rev1;
-        $r_rev = $rev2;
-      }else{
-        $l_rev = $rev2;
-        $r_rev = $rev1;
-      }
-    }elseif($rev1){                // single revision given, compare to current
-      $r_rev = '';
-      $l_rev = $rev1;
-    }else{                        // no revision was given, compare previous to current
-      $r_rev = '';
-      $revs = getRevisions($ID, 0, 1);
-      $l_rev = $revs[0];
-      $REV = $l_rev; // store revision back in $REV
-    }
+    require_once(DOKU_INC.'inc/DifferenceEngine.php');
+    global $ID;
+    global $REV;
+    global $lang;
+    global $conf;
 
-    // when both revisions are empty then the page was created just now
-    if(!$l_rev && !$r_rev){
-      $l_text = '';
-    }else{
-      $l_text = rawWiki($ID,$l_rev);
-    }
-    $r_text = rawWiki($ID,$r_rev);
+    // we're trying to be clever here, revisions to compare can be either
+    // given as rev and rev2 parameters, with rev2 being optional. Or in an
+    // array in rev2.
+    $rev1 = $REV;
 
+    if(is_array($_REQUEST['rev2'])){
+        $rev1 = (int) $_REQUEST['rev2'][0];
+        $rev2 = (int) $_REQUEST['rev2'][1];
 
-    if(!$l_rev){
-      $l_head = '&mdash;';
+        if(!$rev1){
+            $rev1 = $rev2;
+            unset($rev2);
+        }
     }else{
-      $l_info   = getRevisionInfo($ID,$l_rev,true);
-      if($l_info['user']){ $l_user = editorinfo($l_info['user']);
-        if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
-      } else { $l_user = $l_info['ip']; }
-      $l_user  = '<span class="user">'.$l_user.'</span>';
-      $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
-      if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
-
-      $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
-                $ID.' ['.dformat($l_rev).']</a>'.
-                '<br />'.$l_user.' '.$l_sum;
+        $rev2 = (int) $_REQUEST['rev2'];
     }
 
-    if($r_rev){
-      $r_info   = getRevisionInfo($ID,$r_rev,true);
-      if($r_info['user']){ $r_user = editorinfo($r_info['user']);
-        if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
-      } else { $r_user = $r_info['ip']; }
-      $r_user = '<span class="user">'.$r_user.'</span>';
-      $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
-      if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
-
-      $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
-                $ID.' ['.dformat($r_rev).']</a>'.
-                '<br />'.$r_user.' '.$r_sum;
-    }elseif($_rev = @filemtime(wikiFN($ID))){
-      $_info   = getRevisionInfo($ID,$_rev,true);
-      if($_info['user']){ $_user = editorinfo($_info['user']);
-        if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
-      } else { $_user = $_info['ip']; }
-      $_user = '<span class="user">'.$_user.'</span>';
-      $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
-      if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
-
-      $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
-               $ID.' ['.dformat($_rev).']</a> '.
-               '('.$lang['current'].')'.
-                '<br />'.$_user.' '.$_sum;
+    if($text){                      // compare text to the most current revision
+        $l_rev   = '';
+        $l_text  = rawWiki($ID,'');
+        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
+            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
+            $lang['current'];
+
+        $r_rev   = '';
+        $r_text  = cleanText($text);
+        $r_head  = $lang['yours'];
     }else{
-      $r_head = '&mdash; ('.$lang['current'].')';
+        if($rev1 && $rev2){            // two specific revisions wanted
+            // make sure order is correct (older on the left)
+            if($rev1 < $rev2){
+                $l_rev = $rev1;
+                $r_rev = $rev2;
+            }else{
+                $l_rev = $rev2;
+                $r_rev = $rev1;
+            }
+        }elseif($rev1){                // single revision given, compare to current
+            $r_rev = '';
+            $l_rev = $rev1;
+        }else{                        // no revision was given, compare previous to current
+            $r_rev = '';
+            $revs = getRevisions($ID, 0, 1);
+            $l_rev = $revs[0];
+            $REV = $l_rev; // store revision back in $REV
+        }
+
+        // when both revisions are empty then the page was created just now
+        if(!$l_rev && !$r_rev){
+            $l_text = '';
+        }else{
+            $l_text = rawWiki($ID,$l_rev);
+        }
+        $r_text = rawWiki($ID,$r_rev);
+
+        if(!$l_rev){
+            $l_head = '&mdash;';
+        }else{
+            $l_info   = getRevisionInfo($ID,$l_rev,true);
+            if($l_info['user']){
+                $l_user = editorinfo($l_info['user']);
+                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
+            } else {
+                $l_user = $l_info['ip'];
+            }
+            $l_user  = '<span class="user">'.$l_user.'</span>';
+            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
+            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
+
+            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
+            $ID.' ['.dformat($l_rev).']</a>'.
+            '<br />'.$l_user.' '.$l_sum;
+        }
+
+        if($r_rev){
+            $r_info   = getRevisionInfo($ID,$r_rev,true);
+            if($r_info['user']){
+                $r_user = editorinfo($r_info['user']);
+                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
+            } else {
+                $r_user = $r_info['ip'];
+            }
+            $r_user = '<span class="user">'.$r_user.'</span>';
+            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
+            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
+
+            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
+            $ID.' ['.dformat($r_rev).']</a>'.
+            '<br />'.$r_user.' '.$r_sum;
+        }elseif($_rev = @filemtime(wikiFN($ID))){
+            $_info   = getRevisionInfo($ID,$_rev,true);
+            if($_info['user']){
+                $_user = editorinfo($_info['user']);
+                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
+            } else {
+                $_user = $_info['ip'];
+            }
+            $_user = '<span class="user">'.$_user.'</span>';
+            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
+            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
+
+            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
+            $ID.' ['.dformat($_rev).']</a> '.
+            '('.$lang['current'].')'.
+            '<br />'.$_user.' '.$_sum;
+        }else{
+            $r_head = '&mdash; ('.$lang['current'].')';
+        }
     }
-  }
 
-  $df = new Diff(explode("\n",htmlspecialchars($l_text)),
-                 explode("\n",htmlspecialchars($r_text)));
+    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
+        explode("\n",htmlspecialchars($r_text)));
 
-  $tdf = new TableDiffFormatter();
-  if($intro) print p_locale_xhtml('diff');
-  ?>
+    $tdf = new TableDiffFormatter();
+    if($intro) print p_locale_xhtml('diff');
+    ?>
     <table class="diff">
-      <tr>
-        <th colspan="2" <?php echo $l_minor?>>
-          <?php echo $l_head?>
-        </th>
-        <th colspan="2" <?php echo $r_minor?>>
-          <?php echo $r_head?>
-        </th>
-      </tr>
-      <?php echo $tdf->format($df)?>
+    <tr>
+    <th colspan="2" <?php echo $l_minor?>>
+    <?php echo $l_head?>
+    </th>
+    <th colspan="2" <?php echo $r_minor?>>
+    <?php echo $r_head?>
+    </th>
+    </tr>
+    <?php echo $tdf->format($df)?>
     </table>
-  <?php
+    <?php
 }
 
 /**
@@ -985,18 +993,18 @@ function html_diff($text='',$intro=true){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_conflict($text,$summary){
-  global $ID;
-  global $lang;
-
-  print p_locale_xhtml('conflict');
-  $form = new Doku_Form('dw__editform');
-  $form->addHidden('id', $ID);
-  $form->addHidden('wikitext', $text);
-  $form->addHidden('summary', $summary);
-  $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
-  $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
-  html_form('conflict', $form);
-  print '<br /><br /><br /><br />'.NL;
+    global $ID;
+    global $lang;
+
+    print p_locale_xhtml('conflict');
+    $form = new Doku_Form('dw__editform');
+    $form->addHidden('id', $ID);
+    $form->addHidden('wikitext', $text);
+    $form->addHidden('summary', $summary);
+    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
+    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
+    html_form('conflict', $form);
+    print '<br /><br /><br /><br />'.NL;
 }
 
 /**
@@ -1025,28 +1033,28 @@ function html_msgarea(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_register(){
-  global $lang;
-  global $conf;
-  global $ID;
-
-  print p_locale_xhtml('register');
-  print '<div class="centeralign">'.NL;
-  $form = new Doku_Form('dw__register', wl($ID));
-  $form->startFieldset($lang['register']);
-  $form->addHidden('do', 'register');
-  $form->addHidden('save', '1');
-  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
-  if (!$conf['autopasswd']) {
-    $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
-    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
-  }
-  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
-  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
-  $form->addElement(form_makeButton('submit', '', $lang['register']));
-  $form->endFieldset();
-  html_form('register', $form);
-
-  print '</div>'.NL;
+    global $lang;
+    global $conf;
+    global $ID;
+
+    print p_locale_xhtml('register');
+    print '<div class="centeralign">'.NL;
+    $form = new Doku_Form('dw__register', wl($ID));
+    $form->startFieldset($lang['register']);
+    $form->addHidden('do', 'register');
+    $form->addHidden('save', '1');
+    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
+    if (!$conf['autopasswd']) {
+        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
+        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
+    }
+    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
+    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
+    $form->addElement(form_makeButton('submit', '', $lang['register']));
+    $form->endFieldset();
+    html_form('register', $form);
+
+    print '</div>'.NL;
 }
 
 /**
@@ -1056,42 +1064,42 @@ function html_register(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_updateprofile(){
-  global $lang;
-  global $conf;
-  global $ID;
-  global $INFO;
-  global $auth;
-
-  print p_locale_xhtml('updateprofile');
-
-  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
-  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
-  print '<div class="centeralign">'.NL;
-  $form = new Doku_Form('dw__register', wl($ID));
-  $form->startFieldset($lang['profile']);
-  $form->addHidden('do', 'profile');
-  $form->addHidden('save', '1');
-  $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
-  $attr = array('size'=>'50');
-  if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
-  $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
-  $attr = array('size'=>'50');
-  if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
-  $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
-  $form->addElement(form_makeTag('br'));
-  if ($auth->canDo('modPass')) {
-    $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
-    $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
-  }
-  if ($conf['profileconfirm']) {
+    global $lang;
+    global $conf;
+    global $ID;
+    global $INFO;
+    global $auth;
+
+    print p_locale_xhtml('updateprofile');
+
+    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
+    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
+    print '<div class="centeralign">'.NL;
+    $form = new Doku_Form('dw__register', wl($ID));
+    $form->startFieldset($lang['profile']);
+    $form->addHidden('do', 'profile');
+    $form->addHidden('save', '1');
+    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
+    $attr = array('size'=>'50');
+    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
+    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
+    $attr = array('size'=>'50');
+    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
+    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
     $form->addElement(form_makeTag('br'));
-    $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
-  }
-  $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
-  $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
-  $form->endFieldset();
-  html_form('updateprofile', $form);
-  print '</div>'.NL;
+    if ($auth->canDo('modPass')) {
+        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
+        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
+    }
+    if ($conf['profileconfirm']) {
+        $form->addElement(form_makeTag('br'));
+        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
+    }
+    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
+    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
+    $form->endFieldset();
+    html_form('updateprofile', $form);
+    print '</div>'.NL;
 }
 
 /**
@@ -1103,128 +1111,124 @@ function html_updateprofile(){
  * @author   Andreas Gohr <andi@splitbrain.org>
  */
 function html_edit($text=null,$include='edit'){ //FIXME: include needed?
-  global $ID;
-  global $REV;
-  global $DATE;
-  global $RANGE;
-  global $PRE;
-  global $SUF;
-  global $INFO;
-  global $SUM;
-  global $lang;
-  global $conf;
-  global $license;
-
-  //set summary default
-  if(!$SUM){
-    if($REV){
-      $SUM = $lang['restored'];
-    }elseif(!$INFO['exists']){
-      $SUM = $lang['created'];
+    global $ID;
+    global $REV;
+    global $DATE;
+    global $RANGE;
+    global $PRE;
+    global $SUF;
+    global $INFO;
+    global $SUM;
+    global $lang;
+    global $conf;
+    global $license;
+
+    //set summary default
+    if(!$SUM){
+        if($REV){
+            $SUM = $lang['restored'];
+        }elseif(!$INFO['exists']){
+            $SUM = $lang['created'];
+        }
     }
-  }
-
-  //no text? Load it!
-  if(!isset($text)){
-    $pr = false; //no preview mode
-    if($INFO['exists']){
-      if($RANGE){
-        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
-      }else{
-        $text = rawWiki($ID,$REV);
-      }
-      $check = md5($text);
-      $mod = false;
+
+    //no text? Load it!
+    if(!isset($text)){
+        $pr = false; //no preview mode
+        if($INFO['exists']){
+            if($RANGE){
+                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
+            }else{
+                $text = rawWiki($ID,$REV);
+            }
+            $check = md5($text);
+            $mod = false;
+        }else{
+            //try to load a pagetemplate
+            $data = array($ID);
+            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
+            $check = md5('');
+            $mod = $text!=='';
+        }
     }else{
-      //try to load a pagetemplate
-      $data = array($ID);
-      $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
-      $check = md5('');
-      $mod = $text!=='';
-    }
-  }else{
-    $pr = true; //preview mode
-    if (isset($_REQUEST['changecheck'])) {
-      $check = $_REQUEST['changecheck'];
-      $mod = md5($text)!==$check;
-    } else {
-      // Why? Assume default text is unmodified.
-      $check = md5($text);
-      $mod = false;
+        $pr = true; //preview mode
+        if (isset($_REQUEST['changecheck'])) {
+            $check = $_REQUEST['changecheck'];
+            $mod = md5($text)!==$check;
+        } else {
+            // Why? Assume default text is unmodified.
+            $check = md5($text);
+            $mod = false;
+        }
     }
-  }
-
-  $wr = $INFO['writable'] && !$INFO['locked'];
-  if($wr){
-    if ($REV) print p_locale_xhtml('editrev');
-    print p_locale_xhtml($include);
-  }else{
-    // check pseudo action 'source'
-    if(!actionOK('source')){
-      msg('Command disabled: source',-1);
-      return;
+
+    $wr = $INFO['writable'] && !$INFO['locked'];
+    if($wr){
+        if ($REV) print p_locale_xhtml('editrev');
+        print p_locale_xhtml($include);
+    }else{
+        // check pseudo action 'source'
+        if(!actionOK('source')){
+            msg('Command disabled: source',-1);
+            return;
+        }
+        print p_locale_xhtml('read');
     }
-    print p_locale_xhtml('read');
-  }
-  if(!$DATE) $DATE = $INFO['lastmod'];
-
-
-?>
-  <div style="width:99%;">
-
-   <div class="toolbar">
-      <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
-      <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
-      target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
-
-      <?php if($wr){?>
-      <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
-        <?php /* sets changed to true when previewed */?>
-        textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
-      //--><!]]></script>
-      <span id="spell__action"></span>
-      <div id="spell__suggest"></div>
-      <?php } ?>
-   </div>
-   <div id="spell__result"></div>
-<?php
-  $form = new Doku_Form('dw__editform');
-  $form->addHidden('id', $ID);
-  $form->addHidden('rev', $REV);
-  $form->addHidden('date', $DATE);
-  $form->addHidden('prefix', $PRE);
-  $form->addHidden('suffix', $SUF);
-  $form->addHidden('changecheck', $check);
-  $attr = array('tabindex'=>'1');
-  if (!$wr) $attr['readonly'] = 'readonly';
-  $form->addElement(form_makeWikiText($text, $attr));
-  $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
-  $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
-  $form->addElement(form_makeCloseTag('div'));
-  if ($wr) {
-    $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
-    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
-    $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
-    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
-    $form->addElement(form_makeCloseTag('div'));
-    $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
-    $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
-    $elem = html_minoredit();
-    if ($elem) $form->addElement($elem);
-    $form->addElement(form_makeCloseTag('div'));
-  }
-  $form->addElement(form_makeCloseTag('div'));
-  if($conf['license']){
-    $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
-    $out  = $lang['licenseok'];
-    $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
-    if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
-    $out .= '> '.$license[$conf['license']]['name'].'</a>';
-    $form->addElement($out);
-    $form->addElement(form_makeCloseTag('div'));
-  }
-  html_form('edit', $form);
-  print '</div>'.NL;
+    if(!$DATE) $DATE = $INFO['lastmod'];
+    ?>
+        <div style="width:99%;">
+
+        <div class="toolbar">
+        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
+        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
+            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
+
+            <?php if($wr){?>
+                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
+                    <?php /* sets changed to true when previewed */?>
+                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
+                //--><!]]></script>
+                <span id="spell__action"></span>
+            <?php } ?>
+        </div>
+        <?php
+        $form = new Doku_Form('dw__editform');
+        $form->addHidden('id', $ID);
+        $form->addHidden('rev', $REV);
+        $form->addHidden('date', $DATE);
+        $form->addHidden('prefix', $PRE);
+        $form->addHidden('suffix', $SUF);
+        $form->addHidden('changecheck', $check);
+        $attr = array('tabindex'=>'1');
+        if (!$wr) $attr['readonly'] = 'readonly';
+        $form->addElement(form_makeWikiText($text, $attr));
+        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
+        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
+        $form->addElement(form_makeCloseTag('div'));
+        if ($wr) {
+            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
+            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
+            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
+            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
+            $form->addElement(form_makeCloseTag('div'));
+            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
+            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
+            $elem = html_minoredit();
+            if ($elem) $form->addElement($elem);
+            $form->addElement(form_makeCloseTag('div'));
+        }
+        $form->addElement(form_makeCloseTag('div'));
+        if($conf['license']){
+            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
+            $out  = $lang['licenseok'];
+            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
+            if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
+            $out .= '> '.$license[$conf['license']]['name'].'</a>';
+            $form->addElement($out);
+            $form->addElement(form_makeCloseTag('div'));
+        }
+        html_form('edit', $form);
+        print '</div>'.NL;
 }
 
 /**
@@ -1233,17 +1237,17 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
  * @author Andrea Gohr <andi@splitbrain.org>
  */
 function html_minoredit(){
-  global $conf;
-  global $lang;
-  // minor edits are for logged in users only
-  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
-    return false;
-  }
-
-  $p = array();
-  $p['tabindex'] = 3;
-  if(!empty($_REQUEST['minor'])) $p['checked']='checked';
-  return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
+    global $conf;
+    global $lang;
+    // minor edits are for logged in users only
+    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
+        return false;
+    }
+
+    $p = array();
+    $p['tabindex'] = 3;
+    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
+    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
 }
 
 /**
@@ -1252,81 +1256,81 @@ function html_minoredit(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function html_debug(){
-  global $conf;
-  global $lang;
-  global $auth;
-  global $INFO;
-
-  //remove sensitive data
-  $cnf = $conf;
-  debug_guard($cnf);
-  $nfo = $INFO;
-  debug_guard($nfo);
-  $ses = $_SESSION;
-  debug_guard($ses);
-
-  print '<html><body>';
-
-  print '<p>When reporting bugs please send all the following ';
-  print 'output as a mail to andi@splitbrain.org ';
-  print 'The best way to do this is to save this page in your browser</p>';
-
-  print '<b>$INFO:</b><pre>';
-  print_r($nfo);
-  print '</pre>';
-
-  print '<b>$_SERVER:</b><pre>';
-  print_r($_SERVER);
-  print '</pre>';
-
-  print '<b>$conf:</b><pre>';
-  print_r($cnf);
-  print '</pre>';
-
-  print '<b>DOKU_BASE:</b><pre>';
-  print DOKU_BASE;
-  print '</pre>';
-
-  print '<b>abs DOKU_BASE:</b><pre>';
-  print DOKU_URL;
-  print '</pre>';
-
-  print '<b>rel DOKU_BASE:</b><pre>';
-  print dirname($_SERVER['PHP_SELF']).'/';
-  print '</pre>';
-
-  print '<b>PHP Version:</b><pre>';
-  print phpversion();
-  print '</pre>';
-
-  print '<b>locale:</b><pre>';
-  print setlocale(LC_ALL,0);
-  print '</pre>';
-
-  print '<b>encoding:</b><pre>';
-  print $lang['encoding'];
-  print '</pre>';
-
-  if($auth){
-    print '<b>Auth backend capabilities:</b><pre>';
-    print_r($auth->cando);
+    global $conf;
+    global $lang;
+    global $auth;
+    global $INFO;
+
+    //remove sensitive data
+    $cnf = $conf;
+    debug_guard($cnf);
+    $nfo = $INFO;
+    debug_guard($nfo);
+    $ses = $_SESSION;
+    debug_guard($ses);
+
+    print '<html><body>';
+
+    print '<p>When reporting bugs please send all the following ';
+    print 'output as a mail to andi@splitbrain.org ';
+    print 'The best way to do this is to save this page in your browser</p>';
+
+    print '<b>$INFO:</b><pre>';
+    print_r($nfo);
+    print '</pre>';
+
+    print '<b>$_SERVER:</b><pre>';
+    print_r($_SERVER);
+    print '</pre>';
+
+    print '<b>$conf:</b><pre>';
+    print_r($cnf);
+    print '</pre>';
+
+    print '<b>DOKU_BASE:</b><pre>';
+    print DOKU_BASE;
+    print '</pre>';
+
+    print '<b>abs DOKU_BASE:</b><pre>';
+    print DOKU_URL;
+    print '</pre>';
+
+    print '<b>rel DOKU_BASE:</b><pre>';
+    print dirname($_SERVER['PHP_SELF']).'/';
     print '</pre>';
-  }
 
-  print '<b>$_SESSION:</b><pre>';
-  print_r($ses);
-  print '</pre>';
+    print '<b>PHP Version:</b><pre>';
+    print phpversion();
+    print '</pre>';
+
+    print '<b>locale:</b><pre>';
+    print setlocale(LC_ALL,0);
+    print '</pre>';
+
+    print '<b>encoding:</b><pre>';
+    print $lang['encoding'];
+    print '</pre>';
+
+    if($auth){
+        print '<b>Auth backend capabilities:</b><pre>';
+        print_r($auth->cando);
+        print '</pre>';
+    }
+
+    print '<b>$_SESSION:</b><pre>';
+    print_r($ses);
+    print '</pre>';
 
-  print '<b>Environment:</b><pre>';
-  print_r($_ENV);
-  print '</pre>';
+    print '<b>Environment:</b><pre>';
+    print_r($_ENV);
+    print '</pre>';
 
-  print '<b>PHP settings:</b><pre>';
-  $inis = ini_get_all();
-  print_r($inis);
-  print '</pre>';
+    print '<b>PHP settings:</b><pre>';
+    $inis = ini_get_all();
+    print_r($inis);
+    print '</pre>';
 
-  print '</body></html>';
+    print '</body></html>';
 }
 
 /**
@@ -1346,15 +1350,15 @@ function html_admin(){
     $pluginlist = plugin_list('admin');
     $menu = array();
     foreach ($pluginlist as $p) {
-        if($obj =& plugin_load('admin',$p) === NULL) continue;
+        if($obj =& plugin_load('admin',$p) === null) continue;
 
         // check permissions
         if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
 
         $menu[$p] = array('plugin' => $p,
-                          'prompt' => $obj->getMenuText($conf['lang']),
-                          'sort' => $obj->getMenuSort()
-                         );
+                'prompt' => $obj->getMenuText($conf['lang']),
+                'sort' => $obj->getMenuSort()
+                );
     }
 
     print p_locale_xhtml('admin');
@@ -1412,7 +1416,6 @@ function html_admin(){
 
     ptln('</ul>');
 
-
     // print the rest as sorted list
     if(count($menu)){
         usort($menu, 'p_sort_modes');
@@ -1434,24 +1437,24 @@ function html_admin(){
  * @author Benoit Chesneau <benoit@bchesneau.info>
  */
 function html_resendpwd() {
-  global $lang;
-  global $conf;
-  global $ID;
-
-  print p_locale_xhtml('resendpwd');
-  print '<div class="centeralign">'.NL;
-  $form = new Doku_Form('dw__resendpwd', wl($ID));
-  $form->startFieldset($lang['resendpwd']);
-  $form->addHidden('do', 'resendpwd');
-  $form->addHidden('save', '1');
-  $form->addElement(form_makeTag('br'));
-  $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
-  $form->addElement(form_makeTag('br'));
-  $form->addElement(form_makeTag('br'));
-  $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
-  $form->endFieldset();
-  html_form('resendpwd', $form);
-  print '</div>'.NL;
+    global $lang;
+    global $conf;
+    global $ID;
+
+    print p_locale_xhtml('resendpwd');
+    print '<div class="centeralign">'.NL;
+    $form = new Doku_Form('dw__resendpwd', wl($ID));
+    $form->startFieldset($lang['resendpwd']);
+    $form->addHidden('do', 'resendpwd');
+    $form->addHidden('save', '1');
+    $form->addElement(form_makeTag('br'));
+    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
+    $form->addElement(form_makeTag('br'));
+    $form->addElement(form_makeTag('br'));
+    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
+    $form->endFieldset();
+    html_form('resendpwd', $form);
+    print '</div>'.NL;
 }
 
 /**
@@ -1471,7 +1474,8 @@ function html_TOC($toc){
     $out .= html_buildlist($toc,'toc','html_list_toc');
     $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
     $out .= '<!-- TOC END -->'.DOKU_LF;
-    return $out;                                                                                                }
+    return $out;
+}
 
 /**
  * Callback for html_buildlist
@@ -1484,7 +1488,7 @@ function html_list_toc($item){
     }
 
     return '<span class="li"><a href="'.$link.'" class="toc">'.
-           hsc($item['title']).'</a></span>';
+        hsc($item['title']).'</a></span>';
 }
 
 /**
@@ -1500,9 +1504,9 @@ function html_list_toc($item){
 function html_mktocitem($link, $text, $level, $hash='#'){
     global $conf;
     return  array( 'link'  => $hash.$link,
-                   'title' => $text,
-                   'type'  => 'ul',
-                   'level' => $level);
+            'title' => $text,
+            'type'  => 'ul',
+            'level' => $level);
 }
 
 /**
@@ -1512,9 +1516,9 @@ function html_mktocitem($link, $text, $level, $hash='#'){
  * @author Tom N Harris <tnharris@whoopdedo.org>
  */
 function html_form($name, &$form) {
-  // Safety check in case the caller forgets.
-  $form->endFieldset();
-  trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
+    // Safety check in case the caller forgets.
+    $form->endFieldset();
+    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
 }
 
 /**
@@ -1522,7 +1526,7 @@ function html_form($name, &$form) {
  * Just calls printForm() on the data object.
  */
 function html_form_output($data) {
-  $data->printForm();
+    $data->printForm();
 }
 
 /**
@@ -1602,4 +1606,3 @@ function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts
     return $out;
 }
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/httputils.php b/inc/httputils.php
index c55e9ab0db0bb475bce0a361a6ba20ea8b928c64..ed5d6dfd56d36307509222a86c63e91476117f61 100644
--- a/inc/httputils.php
+++ b/inc/httputils.php
@@ -19,45 +19,45 @@ define('HTTP_CHUNK_SIZE',16*1024);
  * @returns  void or exits with previously header() commands executed
  */
 function http_conditionalRequest($timestamp){
-  // A PHP implementation of conditional get, see
-  //   http://fishbowl.pastiche.org/archives/001132.html
-  $last_modified = substr(gmdate('r', $timestamp), 0, -5).'GMT';
-  $etag = '"'.md5($last_modified).'"';
-  // Send the headers
-  header("Last-Modified: $last_modified");
-  header("ETag: $etag");
-  // See if the client has provided the required headers
-  if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
-    $if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']);
-  }else{
-    $if_modified_since = false;
-  }
-
-  if (isset($_SERVER['HTTP_IF_NONE_MATCH'])){
-    $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
-  }else{
-    $if_none_match = false;
-  }
-
-  if (!$if_modified_since && !$if_none_match){
-    return;
-  }
-
-  // At least one of the headers is there - check them
-  if ($if_none_match && $if_none_match != $etag) {
-    return; // etag is there but doesn't match
-  }
-
-  if ($if_modified_since && $if_modified_since != $last_modified) {
-    return; // if-modified-since is there but doesn't match
-  }
-
-  // Nothing has changed since their last request - serve a 304 and exit
-  header('HTTP/1.0 304 Not Modified');
-
-  // don't produce output, even if compression is on
-  ob_end_clean();
-  exit;
+    // A PHP implementation of conditional get, see
+    //   http://fishbowl.pastiche.org/archives/001132.html
+    $last_modified = substr(gmdate('r', $timestamp), 0, -5).'GMT';
+    $etag = '"'.md5($last_modified).'"';
+    // Send the headers
+    header("Last-Modified: $last_modified");
+    header("ETag: $etag");
+    // See if the client has provided the required headers
+    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
+        $if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']);
+    }else{
+        $if_modified_since = false;
+    }
+
+    if (isset($_SERVER['HTTP_IF_NONE_MATCH'])){
+        $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
+    }else{
+        $if_none_match = false;
+    }
+
+    if (!$if_modified_since && !$if_none_match){
+        return;
+    }
+
+    // At least one of the headers is there - check them
+    if ($if_none_match && $if_none_match != $etag) {
+        return; // etag is there but doesn't match
+    }
+
+    if ($if_modified_since && $if_modified_since != $last_modified) {
+        return; // if-modified-since is there but doesn't match
+    }
+
+    // Nothing has changed since their last request - serve a 304 and exit
+    header('HTTP/1.0 304 Not Modified');
+
+    // don't produce output, even if compression is on
+    ob_end_clean();
+    exit;
 }
 
 /**
@@ -67,24 +67,24 @@ function http_conditionalRequest($timestamp){
  * @returns  void or exits with previously header() commands executed
  */
 function http_sendfile($file) {
-  global $conf;
-
-  //use x-sendfile header to pass the delivery to compatible webservers
-  if($conf['xsendfile'] == 1){
-    header("X-LIGHTTPD-send-file: $file");
-    ob_end_clean();
-    exit;
-  }elseif($conf['xsendfile'] == 2){
-    header("X-Sendfile: $file");
-    ob_end_clean();
-    exit;
-  }elseif($conf['xsendfile'] == 3){
-    header("X-Accel-Redirect: $file");
-    ob_end_clean();
-    exit;
-  }
+    global $conf;
+
+    //use x-sendfile header to pass the delivery to compatible webservers
+    if($conf['xsendfile'] == 1){
+        header("X-LIGHTTPD-send-file: $file");
+        ob_end_clean();
+        exit;
+    }elseif($conf['xsendfile'] == 2){
+        header("X-Sendfile: $file");
+        ob_end_clean();
+        exit;
+    }elseif($conf['xsendfile'] == 3){
+        header("X-Accel-Redirect: $file");
+        ob_end_clean();
+        exit;
+    }
 
-  return false;
+    return false;
 }
 
 /**
@@ -166,11 +166,11 @@ function http_rangeRequest($fh,$size,$mime){
         fseek($fh,$start); //seek to start of range
         $chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
         while (!feof($fh) && $chunk > 0) {
-          @set_time_limit(30); // large files can take a lot of time
-          print fread($fh, $chunk);
-          flush();
-          $len -= $chunk;
-          $chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
+            @set_time_limit(30); // large files can take a lot of time
+            print fread($fh, $chunk);
+            flush();
+            $len -= $chunk;
+            $chunk = ($len > HTTP_CHUNK_SIZE) ? HTTP_CHUNK_SIZE : $len;
         }
     }
     if($parts > 1){
diff --git a/inc/indexer.php b/inc/indexer.php
index 4b59684cd3be977b183039008e88040e4b7fcdf2..1f2ff89e3bab35183c0db87905bc8308e82efa9c 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -227,18 +227,18 @@ function idx_getPageWords($page){
     // ensure the deaccented or romanised page names of internal links are added to the token array
     // (this is necessary for the backlink function -- there maybe a better way!)
     if ($conf['deaccent']) {
-      $links = p_get_metadata($page,'relation references');
+        $links = p_get_metadata($page,'relation references');
 
-      if (!empty($links)) {
-        $tmp = join(' ',array_keys($links));                // make a single string
-        $tmp = strtr($tmp, ':', ' ');                       // replace namespace separator with a space
-        $link_tokens = array_unique(explode(' ', $tmp));    // break into tokens
+        if (!empty($links)) {
+            $tmp = join(' ',array_keys($links));                // make a single string
+            $tmp = strtr($tmp, ':', ' ');                       // replace namespace separator with a space
+            $link_tokens = array_unique(explode(' ', $tmp));    // break into tokens
 
-        foreach ($link_tokens as $link_token) {
-          if (isset($tokens[$link_token])) continue;
-          $tokens[$link_token] = 1;
+            foreach ($link_tokens as $link_token) {
+                if (isset($tokens[$link_token])) continue;
+                $tokens[$link_token] = 1;
+            }
         }
-      }
     }
 
     $words = array();
@@ -537,7 +537,7 @@ function idx_getIndexWordsSorted($words,&$result){
             }
         }
     }
-  return $wids;
+    return $wids;
 }
 
 /**
@@ -664,7 +664,9 @@ function idx_upgradePageWords(){
     if (empty($page_idx)) return;
     $pagewords = array();
     $len = count($page_idx);
-    for ($n=0;$n<$len;$n++) $pagewords[] = array();
+    for ($n=0;$n<$len;$n++){
+        $pagewords[] = array();
+    }
     unset($page_idx);
 
     $n=0;
diff --git a/inc/infoutils.php b/inc/infoutils.php
index c2db31f7d7fe78048ac643f9e1b5b0b45136912c..a334e09429390f91f09ce612f51f24ce997ba501 100644
--- a/inc/infoutils.php
+++ b/inc/infoutils.php
@@ -49,25 +49,25 @@ function checkUpdateMessages(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function getVersion(){
-  //import version string
-  if(@file_exists(DOKU_INC.'VERSION')){
-    //official release
-    return 'Release '.trim(io_readfile(DOKU_INC.'VERSION'));
-  }elseif(is_dir(DOKU_INC.'_darcs')){
-    //darcs checkout - read last 2000 bytes of inventory
-    $sz   = filesize(DOKU_INC.'_darcs/inventory');
-    $seek = max(0,$sz-2000);
-    $fh   = fopen(DOKU_INC.'_darcs/inventory','rb');
-    fseek($fh,$seek);
-    $chunk = fread($fh,2000);
-    fclose($fh);
-    $inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
-    $cur = array_pop($inv);
-    preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
-    return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
-  }else{
-    return 'snapshot?';
-  }
+    //import version string
+    if(@file_exists(DOKU_INC.'VERSION')){
+        //official release
+        return 'Release '.trim(io_readfile(DOKU_INC.'VERSION'));
+    }elseif(is_dir(DOKU_INC.'_darcs')){
+        //darcs checkout - read last 2000 bytes of inventory
+        $sz   = filesize(DOKU_INC.'_darcs/inventory');
+        $seek = max(0,$sz-2000);
+        $fh   = fopen(DOKU_INC.'_darcs/inventory','rb');
+        fseek($fh,$seek);
+        $chunk = fread($fh,2000);
+        fclose($fh);
+        $inv = preg_grep('#\*\*\d{14}[\]$]#',explode("\n",$chunk));
+        $cur = array_pop($inv);
+        preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches);
+        return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3];
+    }else{
+        return 'snapshot?';
+    }
 }
 
 /**
@@ -76,148 +76,147 @@ function getVersion(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function check(){
-  global $conf;
-  global $INFO;
-
-  msg('DokuWiki version: '.getVersion(),1);
-
-  if(version_compare(phpversion(),'5.0.0','<')){
-    msg('Your PHP version is too old ('.phpversion().' vs. 5.0.0+ recommended)',-1);
-  }else{
-    msg('PHP version '.phpversion(),1);
-  }
-
-  $mem = (int) php_to_byte(ini_get('memory_limit'));
-  if($mem){
-    if($mem < 16777216){
-        msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
-    }elseif($mem < 20971520){
-        msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1);
-    }elseif($mem < 33554432){
-        msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0);
+    global $conf;
+    global $INFO;
+
+    msg('DokuWiki version: '.getVersion(),1);
+
+    if(version_compare(phpversion(),'5.0.0','<')){
+        msg('Your PHP version is too old ('.phpversion().' vs. 5.0.0+ recommended)',-1);
+    }else{
+        msg('PHP version '.phpversion(),1);
+    }
+
+    $mem = (int) php_to_byte(ini_get('memory_limit'));
+    if($mem){
+        if($mem < 16777216){
+            msg('PHP is limited to less than 16MB RAM ('.$mem.' bytes). Increase memory_limit in php.ini',-1);
+        }elseif($mem < 20971520){
+            msg('PHP is limited to less than 20MB RAM ('.$mem.' bytes), you might encounter problems with bigger pages. Increase memory_limit in php.ini',-1);
+        }elseif($mem < 33554432){
+            msg('PHP is limited to less than 32MB RAM ('.$mem.' bytes), but that should be enough in most cases. If not, increase memory_limit in php.ini',0);
+        }else{
+            msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
+        }
+    }
+
+    if(is_writable($conf['changelog'])){
+        msg('Changelog is writable',1);
+    }else{
+        if (@file_exists($conf['changelog'])) {
+            msg('Changelog is not writable',-1);
+        }
+    }
+
+    if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
+        msg('Old changelog exists', 0);
+    }
+
+    if (@file_exists($conf['changelog'].'_failed')) {
+        msg('Importing old changelog failed', -1);
+    } else if (@file_exists($conf['changelog'].'_importing')) {
+        msg('Importing old changelog now.', 0);
+    } else if (@file_exists($conf['changelog'].'_import_ok')) {
+        msg('Old changelog imported', 1);
+        if (!plugin_isdisabled('importoldchangelog')) {
+            msg('Importoldchangelog plugin not disabled after import', -1);
+        }
+    }
+
+    if(is_writable($conf['datadir'])){
+        msg('Datadir is writable',1);
+    }else{
+        msg('Datadir is not writable',-1);
+    }
+
+    if(is_writable($conf['olddir'])){
+        msg('Attic is writable',1);
+    }else{
+        msg('Attic is not writable',-1);
+    }
+
+    if(is_writable($conf['mediadir'])){
+        msg('Mediadir is writable',1);
+    }else{
+        msg('Mediadir is not writable',-1);
+    }
+
+    if(is_writable($conf['cachedir'])){
+        msg('Cachedir is writable',1);
     }else{
-        msg('More than 32MB RAM ('.$mem.' bytes) available.',1);
+        msg('Cachedir is not writable',-1);
     }
-  }
 
+    if(is_writable($conf['lockdir'])){
+        msg('Lockdir is writable',1);
+    }else{
+        msg('Lockdir is not writable',-1);
+    }
 
-  if(is_writable($conf['changelog'])){
-    msg('Changelog is writable',1);
-  }else{
-    if (@file_exists($conf['changelog'])) {
-      msg('Changelog is not writable',-1);
+    if($conf['authtype'] == 'plain'){
+        if(is_writable(DOKU_CONF.'users.auth.php')){
+            msg('conf/users.auth.php is writable',1);
+        }else{
+            msg('conf/users.auth.php is not writable',0);
+        }
     }
-  }
-
-  if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
-    msg('Old changelog exists', 0);
-  }
-
-  if (@file_exists($conf['changelog'].'_failed')) {
-    msg('Importing old changelog failed', -1);
-  } else if (@file_exists($conf['changelog'].'_importing')) {
-    msg('Importing old changelog now.', 0);
-  } else if (@file_exists($conf['changelog'].'_import_ok')) {
-    msg('Old changelog imported', 1);
-    if (!plugin_isdisabled('importoldchangelog')) {
-      msg('Importoldchangelog plugin not disabled after import', -1);
+
+    if(function_exists('mb_strpos')){
+        if(defined('UTF8_NOMBSTRING')){
+            msg('mb_string extension is available but will not be used',0);
+        }else{
+            msg('mb_string extension is available and will be used',1);
+            if(ini_get('mbstring.func_overload') != 0){
+                msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1);
+            }
+        }
+    }else{
+        msg('mb_string extension not available - PHP only replacements will be used',0);
     }
-  }
-
-  if(is_writable($conf['datadir'])){
-    msg('Datadir is writable',1);
-  }else{
-    msg('Datadir is not writable',-1);
-  }
-
-  if(is_writable($conf['olddir'])){
-    msg('Attic is writable',1);
-  }else{
-    msg('Attic is not writable',-1);
-  }
-
-  if(is_writable($conf['mediadir'])){
-    msg('Mediadir is writable',1);
-  }else{
-    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($conf['lockdir'])){
-    msg('Lockdir is writable',1);
-  }else{
-    msg('Lockdir is not writable',-1);
-  }
-
-  if($conf['authtype'] == 'plain'){
-    if(is_writable(DOKU_CONF.'users.auth.php')){
-      msg('conf/users.auth.php is writable',1);
+
+    if($conf['allowdebug']){
+        msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
     }else{
-      msg('conf/users.auth.php is not writable',0);
+        msg('Debugging support is disabled',1);
     }
-  }
 
-  if(function_exists('mb_strpos')){
-    if(defined('UTF8_NOMBSTRING')){
-      msg('mb_string extension is available but will not be used',0);
+    if($INFO['userinfo']['name']){
+        msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0);
+        msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0);
     }else{
-      msg('mb_string extension is available and will be used',1);
-      if(ini_get('mbstring.func_overload') != 0){
-        msg('mb_string function overloading is enabled, this will cause problems and should be disabled',-1);
-      }
+        msg('You are currently not logged in',0);
+    }
+
+    msg('Your current permission for this page is '.$INFO['perm'],0);
+
+    if(is_writable($INFO['filepath'])){
+        msg('The current page is writable by the webserver',0);
+    }else{
+        msg('The current page is not writable by the webserver',0);
+    }
+
+    if($INFO['writable']){
+        msg('The current page is writable by you',0);
+    }else{
+        msg('The current page is not writable by you',0);
+    }
+
+    require_once(DOKU_INC.'inc/HTTPClient.php');
+    $check = wl('','',true).'data/_dummy';
+    $http = new DokuHTTPClient();
+    $http->timeout = 6;
+    $res = $http->get($check);
+    if(strpos($res,'data directory') !== false){
+        msg('It seems like the data directory is accessible from the web.
+                Make sure this directory is properly protected
+                (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
+    }elseif($http->status == 404 || $http->status == 403){
+        msg('The data directory seems to be properly protected',1);
+    }else{
+        msg('Failed to check if the data directory is accessible from the web.
+                Make sure this directory is properly protected
+                (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
     }
-  }else{
-    msg('mb_string extension not available - PHP only replacements will be used',0);
-  }
-
-  if($conf['allowdebug']){
-    msg('Debugging support is enabled. If you don\'t need it you should set $conf[\'allowdebug\'] = 0',-1);
-  }else{
-    msg('Debugging support is disabled',1);
-  }
-
-  if($INFO['userinfo']['name']){
-    msg('You are currently logged in as '.$_SERVER['REMOTE_USER'].' ('.$INFO['userinfo']['name'].')',0);
-    msg('You are part of the groups '.join($INFO['userinfo']['grps'],', '),0);
-  }else{
-    msg('You are currently not logged in',0);
-  }
-
-  msg('Your current permission for this page is '.$INFO['perm'],0);
-
-  if(is_writable($INFO['filepath'])){
-    msg('The current page is writable by the webserver',0);
-  }else{
-    msg('The current page is not writable by the webserver',0);
-  }
-
-  if($INFO['writable']){
-    msg('The current page is writable by you',0);
-  }else{
-    msg('The current page is not writable by you',0);
-  }
-
-  require_once(DOKU_INC.'inc/HTTPClient.php');
-  $check = wl('','',true).'data/_dummy';
-  $http = new DokuHTTPClient();
-  $http->timeout = 6;
-  $res = $http->get($check);
-  if(strpos($res,'data directory') !== false){
-    msg('It seems like the data directory is accessible from the web.
-         Make sure this directory is properly protected
-         (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
-  }elseif($http->status == 404 || $http->status == 403){
-    msg('The data directory seems to be properly protected',1);
-  }else{
-    msg('Failed to check if the data directory is accessible from the web.
-         Make sure this directory is properly protected
-         (See <a href="http://www.dokuwiki.org/security">security</a>)',-1);
-  }
 }
 
 /**
@@ -238,26 +237,26 @@ function check(){
  * @see    html_msgarea
  */
 function msg($message,$lvl=0,$line='',$file=''){
-  global $MSG;
-  $errors[-1] = 'error';
-  $errors[0]  = 'info';
-  $errors[1]  = 'success';
-  $errors[2]  = 'notify';
-
-  if($line || $file) $message.=' ['.basename($file).':'.$line.']';
-
-  if(!headers_sent()){
-    if(!isset($MSG)) $MSG = array();
-    $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
-  }else{
-    $MSG = array();
-    $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
-    if(function_exists('html_msgarea')){
-      html_msgarea();
+    global $MSG;
+    $errors[-1] = 'error';
+    $errors[0]  = 'info';
+    $errors[1]  = 'success';
+    $errors[2]  = 'notify';
+
+    if($line || $file) $message.=' ['.basename($file).':'.$line.']';
+
+    if(!headers_sent()){
+        if(!isset($MSG)) $MSG = array();
+        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
     }else{
-      print "ERROR($lvl) $message";
+        $MSG = array();
+        $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message);
+        if(function_exists('html_msgarea')){
+            html_msgarea();
+        }else{
+            print "ERROR($lvl) $message";
+        }
     }
-  }
 }
 
 /**
@@ -268,9 +267,9 @@ function msg($message,$lvl=0,$line='',$file=''){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function dbg($msg,$hidden=false){
-  (!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
-  print_r($msg);
-  (!$hidden) ? print '</pre>' : print "\n-->";
+    (!$hidden) ? print '<pre class="dbg">' : print "<!--\n";
+    print_r($msg);
+    (!$hidden) ? print '</pre>' : print "\n-->";
 }
 
 /**
@@ -279,19 +278,19 @@ function dbg($msg,$hidden=false){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function dbglog($msg,$header=''){
-  global $conf;
-  if(is_object($msg) || is_array($msg)){
-    $msg = print_r($msg,true);
-  }
-
-  if($header) $msg = "$header\n$msg";
-
-  $file = $conf['cachedir'].'/debug.log';
-  $fh = fopen($file,'a');
-  if($fh){
-    fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
-    fclose($fh);
-  }
+    global $conf;
+    if(is_object($msg) || is_array($msg)){
+        $msg = print_r($msg,true);
+    }
+
+    if($header) $msg = "$header\n$msg";
+
+    $file = $conf['cachedir'].'/debug.log';
+    $fh = fopen($file,'a');
+    if($fh){
+        fwrite($fh,date('H:i:s ').$_SERVER['REMOTE_ADDR'].': '.$msg."\n");
+        fclose($fh);
+    }
 }
 
 /**
@@ -300,44 +299,44 @@ function dbglog($msg,$header=''){
  * @author Gary Owen <gary_owen@bigfoot.com>
  */
 function dbg_backtrace(){
-  // Get backtrace
-  $backtrace = debug_backtrace();
-
-  // Unset call to debug_print_backtrace
-  array_shift($backtrace);
-
-  // Iterate backtrace
-  $calls = array();
-  $depth = count($backtrace) - 1;
-  foreach ($backtrace as $i => $call) {
-    $location = $call['file'] . ':' . $call['line'];
-    $function = (isset($call['class'])) ?
-    $call['class'] . $call['type'] . $call['function'] : $call['function'];
-
-    $params = array();
-    if (isset($call['args'])){
-        foreach($call['args'] as $arg){
-            if(is_object($arg)){
-                $params[] = '[Object '.get_class($arg).']';
-            }elseif(is_array($arg)){
-                $params[] = '[Array]';
-            }elseif(is_null($arg)){
-                $param[] = '[NULL]';
-            }else{
-                $params[] = (string) '"'.$arg.'"';
+    // Get backtrace
+    $backtrace = debug_backtrace();
+
+    // Unset call to debug_print_backtrace
+    array_shift($backtrace);
+
+    // Iterate backtrace
+    $calls = array();
+    $depth = count($backtrace) - 1;
+    foreach ($backtrace as $i => $call) {
+        $location = $call['file'] . ':' . $call['line'];
+        $function = (isset($call['class'])) ?
+            $call['class'] . $call['type'] . $call['function'] : $call['function'];
+
+        $params = array();
+        if (isset($call['args'])){
+            foreach($call['args'] as $arg){
+                if(is_object($arg)){
+                    $params[] = '[Object '.get_class($arg).']';
+                }elseif(is_array($arg)){
+                    $params[] = '[Array]';
+                }elseif(is_null($arg)){
+                    $param[] = '[NULL]';
+                }else{
+                    $params[] = (string) '"'.$arg.'"';
+                }
             }
         }
-    }
-    $params = implode(', ',$params);
+        $params = implode(', ',$params);
 
-    $calls[$depth - $i] = sprintf('%s(%s) called at %s',
-                          $function,
-                          str_replace("\n", '\n', $params),
-                          $location);
-  }
-  ksort($calls);
+        $calls[$depth - $i] = sprintf('%s(%s) called at %s',
+                $function,
+                str_replace("\n", '\n', $params),
+                $location);
+    }
+    ksort($calls);
 
-  return implode("\n", $calls);
+    return implode("\n", $calls);
 }
 
 /**
diff --git a/inc/init.php b/inc/init.php
index 0c474e33dffd0967484e0269a998313099ed83e4..58fa3e25b7f156fd841a38aac849dc059deeee23 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -3,292 +3,297 @@
  * Initialize some defaults needed for DokuWiki
  */
 
-  // start timing Dokuwiki execution
-  function delta_time($start=0) {
+// start timing Dokuwiki execution
+function delta_time($start=0) {
     list($usec, $sec) = explode(" ", microtime());
     return ((float)$usec+(float)$sec)-((float)$start);
-  }
-  define('DOKU_START_TIME', delta_time());
+}
+define('DOKU_START_TIME', delta_time());
 
-  global $config_cascade;
-  $config_cascade = '';
+global $config_cascade;
+$config_cascade = '';
 
-  // if available load a preload config file
-  $preload = fullpath(dirname(__FILE__)).'/preload.php';
-  if (@file_exists($preload)) include($preload);
+// if available load a preload config file
+$preload = fullpath(dirname(__FILE__)).'/preload.php';
+if (@file_exists($preload)) include($preload);
 
-  // define the include path
-  if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
+// define the include path
+if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
 
-  // define config path (packagers may want to change this to /etc/dokuwiki/)
-  if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
+// define config path (packagers may want to change this to /etc/dokuwiki/)
+if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
 
-  // check for error reporting override or set error reporting to sane values
-  if (!defined('DOKU_E_LEVEL') && @file_exists(DOKU_CONF.'report_e_all')) {
+// check for error reporting override or set error reporting to sane values
+if (!defined('DOKU_E_LEVEL') && @file_exists(DOKU_CONF.'report_e_all')) {
     define('DOKU_E_LEVEL', E_ALL);
-  }
-  if (!defined('DOKU_E_LEVEL')) {
+}
+if (!defined('DOKU_E_LEVEL')) {
     if(defined('E_DEPRECATED')){ // since php 5.3
-      error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
+        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
     }else{
-      error_reporting(E_ALL ^ E_NOTICE);
+        error_reporting(E_ALL ^ E_NOTICE);
     }
-  } else {
+} else {
     error_reporting(DOKU_E_LEVEL);
-  }
-
-  // init memory caches
-  global $cache_revinfo;  $cache_revinfo = array();
-  global $cache_wikifn;   $cache_wikifn = array();
-  global $cache_cleanid;  $cache_cleanid = array();
-  global $cache_authname; $cache_authname = array();
-  global $cache_metadata; $cache_metadata = array();
+}
 
-  //set the configuration cascade - but only if its not already been set in preload.php
-  if (empty($config_cascade)) {
+// init memory caches
+global $cache_revinfo;
+       $cache_revinfo = array();
+global $cache_wikifn;
+       $cache_wikifn = array();
+global $cache_cleanid;
+       $cache_cleanid = array();
+global $cache_authname;
+       $cache_authname = array();
+global $cache_metadata;
+       $cache_metadata = array();
+
+//set the configuration cascade - but only if its not already been set in preload.php
+if (empty($config_cascade)) {
     $config_cascade = array(
-      'main' => array(
-        'default'   => array(DOKU_CONF.'dokuwiki.php'),
-        'local'     => array(DOKU_CONF.'local.php'),
-        'protected' => array(DOKU_CONF.'local.protected.php'),
-      ),
-      'acronyms'  => array(
-        'default'   => array(DOKU_CONF.'acronyms.conf'),
-        'local'     => array(DOKU_CONF.'acronyms.local.conf'),
-      ),
-      'entities'  => array(
-        'default'   => array(DOKU_CONF.'entities.conf'),
-        'local'     => array(DOKU_CONF.'entities.local.conf'),
-      ),
-      'interwiki' => array(
-        'default'   => array(DOKU_CONF.'interwiki.conf'),
-        'local'     => array(DOKU_CONF.'interwiki.local.conf'),
-      ),
-      'license' => array(
-        'default'   => array(DOKU_CONF.'license.php'),
-        'local'     => array(DOKU_CONF.'license.local.php'),
-      ),
-      'mediameta' => array(
-        'default'   => array(DOKU_CONF.'mediameta.php'),
-        'local'     => array(DOKU_CONF.'mediameta.local.php'),
-      ),
-      'mime'      => array(
-        'default'   => array(DOKU_CONF.'mime.conf'),
-        'local'     => array(DOKU_CONF.'mime.local.conf'),
-      ),
-      'scheme'    => array(
-        'default'   => array(DOKU_CONF.'scheme.conf'),
-        'local'     => array(DOKU_CONF.'scheme.local.conf'),
-      ),
-      'smileys'   => array(
-        'default'   => array(DOKU_CONF.'smileys.conf'),
-        'local'     => array(DOKU_CONF.'smileys.local.conf'),
-      ),
-      'wordblock' => array(
-        'default'   => array(DOKU_CONF.'wordblock.conf'),
-        'local'     => array(DOKU_CONF.'wordblock.local.conf'),
-      ),
-    );
-  }
-
-  //prepare config array()
-  global $conf;
-  $conf = array();
-
-  // load the global config file(s)
-  foreach (array('default','local','protected') as $config_group) {
+            'main' => array(
+                'default'   => array(DOKU_CONF.'dokuwiki.php'),
+                'local'     => array(DOKU_CONF.'local.php'),
+                'protected' => array(DOKU_CONF.'local.protected.php'),
+                ),
+            'acronyms'  => array(
+                'default'   => array(DOKU_CONF.'acronyms.conf'),
+                'local'     => array(DOKU_CONF.'acronyms.local.conf'),
+                ),
+            'entities'  => array(
+                'default'   => array(DOKU_CONF.'entities.conf'),
+                'local'     => array(DOKU_CONF.'entities.local.conf'),
+                ),
+            'interwiki' => array(
+                'default'   => array(DOKU_CONF.'interwiki.conf'),
+                'local'     => array(DOKU_CONF.'interwiki.local.conf'),
+                ),
+            'license' => array(
+                'default'   => array(DOKU_CONF.'license.php'),
+                'local'     => array(DOKU_CONF.'license.local.php'),
+                ),
+            'mediameta' => array(
+                    'default'   => array(DOKU_CONF.'mediameta.php'),
+                    'local'     => array(DOKU_CONF.'mediameta.local.php'),
+                    ),
+            'mime'      => array(
+                    'default'   => array(DOKU_CONF.'mime.conf'),
+                    'local'     => array(DOKU_CONF.'mime.local.conf'),
+                    ),
+            'scheme'    => array(
+                    'default'   => array(DOKU_CONF.'scheme.conf'),
+                    'local'     => array(DOKU_CONF.'scheme.local.conf'),
+                    ),
+            'smileys'   => array(
+                    'default'   => array(DOKU_CONF.'smileys.conf'),
+                    'local'     => array(DOKU_CONF.'smileys.local.conf'),
+                    ),
+            'wordblock' => array(
+                    'default'   => array(DOKU_CONF.'wordblock.conf'),
+                    'local'     => array(DOKU_CONF.'wordblock.local.conf'),
+                    ),
+            );
+}
+
+//prepare config array()
+global $conf;
+$conf = array();
+
+// load the global config file(s)
+foreach (array('default','local','protected') as $config_group) {
     if (empty($config_cascade['main'][$config_group])) continue;
     foreach ($config_cascade['main'][$config_group] as $config_file) {
-      if (@file_exists($config_file)) {
-        include($config_file);
-      }
+        if (@file_exists($config_file)) {
+            include($config_file);
+        }
     }
-  }
+}
 
-  //prepare language array
-  global $lang;
-  $lang = array();
+//prepare language array
+global $lang;
+$lang = array();
 
-  //load the language files
-  require_once(DOKU_INC.'inc/lang/en/lang.php');
-  if ( $conf['lang'] && $conf['lang'] != 'en' ) {
+//load the language files
+require_once(DOKU_INC.'inc/lang/en/lang.php');
+if ( $conf['lang'] && $conf['lang'] != 'en' ) {
     require_once(DOKU_INC.'inc/lang/'.$conf['lang'].'/lang.php');
-  }
+}
 
-  //prepare license array()
-  global $license;
-  $license = array();
+//prepare license array()
+global $license;
+$license = array();
 
-  // load the license file(s)
-  foreach (array('default','local') as $config_group) {
+// load the license file(s)
+foreach (array('default','local') as $config_group) {
     if (empty($config_cascade['license'][$config_group])) continue;
     foreach ($config_cascade['license'][$config_group] as $config_file) {
-      if(@file_exists($config_file)){
-        include($config_file);
-      }
+        if(@file_exists($config_file)){
+            include($config_file);
+        }
     }
-  }
+}
 
-  // define baseURL
-  if(!defined('DOKU_REL')) define('DOKU_REL',getBaseURL(false));
-  if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true));
-  if(!defined('DOKU_BASE')){
+// define baseURL
+if(!defined('DOKU_REL')) define('DOKU_REL',getBaseURL(false));
+if(!defined('DOKU_URL')) define('DOKU_URL',getBaseURL(true));
+if(!defined('DOKU_BASE')){
     if($conf['canonical']){
-      define('DOKU_BASE',DOKU_URL);
+        define('DOKU_BASE',DOKU_URL);
     }else{
-      define('DOKU_BASE',DOKU_REL);
+        define('DOKU_BASE',DOKU_REL);
     }
-  }
+}
 
-  // define whitespace
-  if(!defined('DOKU_LF')) define ('DOKU_LF',"\n");
-  if(!defined('DOKU_TAB')) define ('DOKU_TAB',"\t");
+// define whitespace
+if(!defined('DOKU_LF')) define ('DOKU_LF',"\n");
+if(!defined('DOKU_TAB')) define ('DOKU_TAB',"\t");
 
-  // define cookie and session id, append server port when securecookie is configured FS#1664
-  if (!defined('DOKU_COOKIE')) define('DOKU_COOKIE', 'DW'.md5(DOKU_REL.(($conf['securecookie'])?$_SERVER['SERVER_PORT']:'')));
+// define cookie and session id, append server port when securecookie is configured FS#1664
+if (!defined('DOKU_COOKIE')) define('DOKU_COOKIE', 'DW'.md5(DOKU_REL.(($conf['securecookie'])?$_SERVER['SERVER_PORT']:'')));
 
-  // define Plugin dir
-  if(!defined('DOKU_PLUGIN'))  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+// define Plugin dir
+if(!defined('DOKU_PLUGIN'))  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
-  // define main script
-  if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');
+// define main script
+if(!defined('DOKU_SCRIPT')) define('DOKU_SCRIPT','doku.php');
 
-  // define Template baseURL
-  if(!defined('DOKU_TPL')) define('DOKU_TPL',
-                                  DOKU_BASE.'lib/tpl/'.$conf['template'].'/');
+// define Template baseURL
+if(!defined('DOKU_TPL')) define('DOKU_TPL',
+        DOKU_BASE.'lib/tpl/'.$conf['template'].'/');
 
-  // define real Template directory
-  if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
-                                  DOKU_INC.'lib/tpl/'.$conf['template'].'/');
+// define real Template directory
+if(!defined('DOKU_TPLINC')) define('DOKU_TPLINC',
+        DOKU_INC.'lib/tpl/'.$conf['template'].'/');
 
-  // make session rewrites XHTML compliant
-  @ini_set('arg_separator.output', '&amp;');
+// make session rewrites XHTML compliant
+@ini_set('arg_separator.output', '&amp;');
 
-  // make sure global zlib does not interfere FS#1132
-  @ini_set('zlib.output_compression', 'off');
+// make sure global zlib does not interfere FS#1132
+@ini_set('zlib.output_compression', 'off');
 
-  // increase PCRE backtrack limit
-  @ini_set('pcre.backtrack_limit', '20971520');
+// increase PCRE backtrack limit
+@ini_set('pcre.backtrack_limit', '20971520');
 
-  // enable gzip compression if supported
-  $conf['gzip_output'] &= (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
-  if ($conf['gzip_output'] &&
-      !defined('DOKU_DISABLE_GZIP_OUTPUT') &&
-      function_exists('ob_gzhandler')) {
+// enable gzip compression if supported
+$conf['gzip_output'] &= (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
+if ($conf['gzip_output'] &&
+        !defined('DOKU_DISABLE_GZIP_OUTPUT') &&
+        function_exists('ob_gzhandler')) {
     ob_start('ob_gzhandler');
-  }
+}
 
-  // init session
-  if (!headers_sent() && !defined('NOSESSION')){
+// init session
+if (!headers_sent() && !defined('NOSESSION')){
     session_name("DokuWiki");
     if (version_compare(PHP_VERSION, '5.2.0', '>')) {
-      session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
+        session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()),true);
     }else{
-      session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
+        session_set_cookie_params(0,DOKU_REL,'',($conf['securecookie'] && is_ssl()));
     }
     session_start();
 
     // load left over messages
     if(isset($_SESSION[DOKU_COOKIE]['msg'])){
-      $MSG = $_SESSION[DOKU_COOKIE]['msg'];
-      unset($_SESSION[DOKU_COOKIE]['msg']);
+        $MSG = $_SESSION[DOKU_COOKIE]['msg'];
+        unset($_SESSION[DOKU_COOKIE]['msg']);
     }
-  }
+}
 
-  // kill magic quotes
-  if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
+// kill magic quotes
+if (get_magic_quotes_gpc() && !defined('MAGIC_QUOTES_STRIPPED')) {
     if (!empty($_GET))    remove_magic_quotes($_GET);
     if (!empty($_POST))   remove_magic_quotes($_POST);
     if (!empty($_COOKIE)) remove_magic_quotes($_COOKIE);
     if (!empty($_REQUEST)) remove_magic_quotes($_REQUEST);
     @ini_set('magic_quotes_gpc', 0);
     define('MAGIC_QUOTES_STRIPPED',1);
-  }
-  @set_magic_quotes_runtime(0);
-  @ini_set('magic_quotes_sybase',0);
+}
+@set_magic_quotes_runtime(0);
+@ini_set('magic_quotes_sybase',0);
 
-  // don't let cookies ever interfere with request vars
-  $_REQUEST = array_merge($_GET,$_POST);
+// don't let cookies ever interfere with request vars
+$_REQUEST = array_merge($_GET,$_POST);
 
-  // we don't want a purge URL to be digged
-  if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
+// we don't want a purge URL to be digged
+if($_REQUEST['purge'] && $_SERVER['HTTP_REFERER']) unset($_REQUEST['purge']);
 
-  // disable gzip if not available
-  if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
+// disable gzip if not available
+if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
     $conf['compression'] = 'gz';
-  }
-  if($conf['compression'] == 'gz' && !function_exists('gzopen')){
+}
+if($conf['compression'] == 'gz' && !function_exists('gzopen')){
     $conf['compression'] = 0;
-  }
+}
 
-  // fix dateformat for upgraders
-  if(strpos($conf['dformat'],'%') === false){
+// fix dateformat for upgraders
+if(strpos($conf['dformat'],'%') === false){
     $conf['dformat'] = '%Y/%m/%d %H:%M';
-  }
+}
 
-  // precalculate file creation modes
-  init_creationmodes();
+// precalculate file creation modes
+init_creationmodes();
 
-  // make real paths and check them
-  init_paths();
-  init_files();
+// make real paths and check them
+init_paths();
+init_files();
 
-  // automatic upgrade to script versions of certain files
-  scriptify(DOKU_CONF.'users.auth');
-  scriptify(DOKU_CONF.'acl.auth');
+// automatic upgrade to script versions of certain files
+scriptify(DOKU_CONF.'users.auth');
+scriptify(DOKU_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',
-                 'indexdir'  => 'index',
-                 'lockdir'   => 'locks',
-                 'tmpdir'    => 'tmp');
-
-  foreach($paths as $c => $p){
-    if(empty($conf[$c]))  $conf[$c] = $conf['savedir'].'/'.$p;
-    $conf[$c]             = init_path($conf[$c]);
-    if(empty($conf[$c]))  nice_die("The $c ('$p') does not exist, isn't accessible or writable.
-                               You should check your config and permission settings.
-                               Or maybe you want to <a href=\"install.php\">run the
-                               installer</a>?");
-  }
-
-  // path to old changelog only needed for upgrading
-  $conf['changelog_old'] = init_path((isset($conf['changelog']))?($conf['changelog']):($conf['savedir'].'/changes.log'));
-  if ($conf['changelog_old']=='') { unset($conf['changelog_old']); }
-  // hardcoded changelog because it is now a cache that lives in meta
-  $conf['changelog'] = $conf['metadir'].'/_dokuwiki.changes';
-  $conf['media_changelog'] = $conf['metadir'].'/_media.changes';
+    global $conf;
+
+    $paths = array('datadir'   => 'pages',
+            'olddir'    => 'attic',
+            'mediadir'  => 'media',
+            'metadir'   => 'meta',
+            'cachedir'  => 'cache',
+            'indexdir'  => 'index',
+            'lockdir'   => 'locks',
+            'tmpdir'    => 'tmp');
+
+    foreach($paths as $c => $p){
+        if(empty($conf[$c]))  $conf[$c] = $conf['savedir'].'/'.$p;
+        $conf[$c]             = init_path($conf[$c]);
+        if(empty($conf[$c]))  nice_die("The $c ('$p') does not exist, isn't accessible or writable.
+                You should check your config and permission settings.
+                Or maybe you want to <a href=\"install.php\">run the
+                installer</a>?");
+    }
+
+    // path to old changelog only needed for upgrading
+    $conf['changelog_old'] = init_path((isset($conf['changelog']))?($conf['changelog']):($conf['savedir'].'/changes.log'));
+    if ($conf['changelog_old']=='') { unset($conf['changelog_old']); }
+    // hardcoded changelog because it is now a cache that lives in meta
+    $conf['changelog'] = $conf['metadir'].'/_dokuwiki.changes';
+    $conf['media_changelog'] = $conf['metadir'].'/_media.changes';
 }
 
 /**
  * Checks the existance of certain files and creates them if missing.
  */
 function init_files(){
-  global $conf;
-
-  $files = array( $conf['indexdir'].'/page.idx');
-
-  foreach($files as $file){
-    if(!@file_exists($file)){
-      $fh = @fopen($file,'a');
-      if($fh){
-        fclose($fh);
-        if($conf['fperm']) chmod($file, $conf['fperm']);
-      }else{
-        nice_die("$file is not writable. Check your permissions settings!");
-      }
+    global $conf;
+
+    $files = array( $conf['indexdir'].'/page.idx');
+
+    foreach($files as $file){
+        if(!@file_exists($file)){
+            $fh = @fopen($file,'a');
+            if($fh){
+                fclose($fh);
+                if($conf['fperm']) chmod($file, $conf['fperm']);
+            }else{
+                nice_die("$file is not writable. Check your permissions settings!");
+            }
+        }
     }
-  }
 }
 
 /**
@@ -300,26 +305,26 @@ function init_files(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function init_path($path){
-  // check existance
-  $p = fullpath($path);
-  if(!@file_exists($p)){
-    $p = fullpath(DOKU_INC.$path);
+    // check existance
+    $p = fullpath($path);
     if(!@file_exists($p)){
-      return '';
+        $p = fullpath(DOKU_INC.$path);
+        if(!@file_exists($p)){
+            return '';
+        }
     }
-  }
 
-  // check writability
-  if(!@is_writable($p)){
-    return '';
-  }
+    // check writability
+    if(!@is_writable($p)){
+        return '';
+    }
 
-  // check accessability (execute bit) for directories
-  if(@is_dir($p) && !@file_exists("$p/.")){
-    return '';
-  }
+    // check accessability (execute bit) for directories
+    if(@is_dir($p) && !@file_exists("$p/.")){
+        return '';
+    }
 
-  return $p;
+    return $p;
 }
 
 /**
@@ -329,28 +334,28 @@ function init_path($path){
  * setting the values only if needed.
  */
 function init_creationmodes(){
-  global $conf;
-
-  // Legacy support for old umask/dmask scheme
-  unset($conf['dmask']);
-  unset($conf['fmask']);
-  unset($conf['umask']);
-  unset($conf['fperm']);
-  unset($conf['dperm']);
-
-  // get system umask, fallback to 0 if none available
-  $umask = @umask();
-  if(!$umask) $umask = 0000;
-
-  // check what is set automatically by the system on file creation
-  // and set the fperm param if it's not what we want
-  $auto_fmode = 0666 & ~$umask;
-  if($auto_fmode != $conf['fmode']) $conf['fperm'] = $conf['fmode'];
-
-  // check what is set automatically by the system on file creation
-  // and set the dperm param if it's not what we want
-  $auto_dmode = $conf['dmode'] & ~$umask;
-  if($auto_dmode != $conf['dmode']) $conf['dperm'] = $conf['dmode'];
+    global $conf;
+
+    // Legacy support for old umask/dmask scheme
+    unset($conf['dmask']);
+    unset($conf['fmask']);
+    unset($conf['umask']);
+    unset($conf['fperm']);
+    unset($conf['dperm']);
+
+    // get system umask, fallback to 0 if none available
+    $umask = @umask();
+    if(!$umask) $umask = 0000;
+
+    // check what is set automatically by the system on file creation
+    // and set the fperm param if it's not what we want
+    $auto_fmode = 0666 & ~$umask;
+    if($auto_fmode != $conf['fmode']) $conf['fperm'] = $conf['fmode'];
+
+    // check what is set automatically by the system on file creation
+    // and set the dperm param if it's not what we want
+    $auto_dmode = $conf['dmode'] & ~$umask;
+    if($auto_dmode != $conf['dmode']) $conf['dperm'] = $conf['dmode'];
 }
 
 /**
@@ -359,22 +364,22 @@ function init_creationmodes(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function remove_magic_quotes(&$array) {
-  foreach (array_keys($array) as $key) {
-      // handle magic quotes in keynames (breaks order)
-      $sk = stripslashes($key);
-      if($sk != $key){
-          $array[$sk] = $array[$key];
-          unset($array[$key]);
-          $key = $sk;
-      }
-
-      // do recursion if needed
-      if (is_array($array[$key])) {
-          remove_magic_quotes($array[$key]);
-      }else {
-          $array[$key] = stripslashes($array[$key]);
-      }
-  }
+    foreach (array_keys($array) as $key) {
+        // handle magic quotes in keynames (breaks order)
+        $sk = stripslashes($key);
+        if($sk != $key){
+            $array[$sk] = $array[$key];
+            unset($array[$key]);
+            $key = $sk;
+        }
+
+        // do recursion if needed
+        if (is_array($array[$key])) {
+            remove_magic_quotes($array[$key]);
+        }else {
+            $array[$key] = stripslashes($array[$key]);
+        }
+    }
 }
 
 /**
@@ -384,59 +389,59 @@ function remove_magic_quotes(&$array) {
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function getBaseURL($abs=null){
-  global $conf;
-  //if canonical url enabled always return absolute
-  if(is_null($abs)) $abs = $conf['canonical'];
-
-  if($conf['basedir']){
-    $dir = $conf['basedir'];
-  }elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){
-    $dir = dirname($_SERVER['SCRIPT_NAME']);
-  }elseif(substr($_SERVER['PHP_SELF'],-4) == '.php'){
-    $dir = dirname($_SERVER['PHP_SELF']);
-  }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
-    $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
-                         $_SERVER['SCRIPT_FILENAME']);
-    $dir = dirname('/'.$dir);
-  }else{
-    $dir = '.'; //probably wrong
-  }
-
-  $dir = str_replace('\\','/',$dir);             // bugfix for weird WIN behaviour
-  $dir = preg_replace('#//+#','/',"/$dir/");     // ensure leading and trailing slashes
-
-  //handle script in lib/exe dir
-  $dir = preg_replace('!lib/exe/$!','',$dir);
-
-  //handle script in lib/plugins dir
-  $dir = preg_replace('!lib/plugins/.*$!','',$dir);
-
-  //finish here for relative URLs
-  if(!$abs) return $dir;
-
-  //use config option if available, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
-  if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
-
-  //split hostheader into host and port
-  list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
-  if(!$port)  $port = $_SERVER['SERVER_PORT'];
-  if(!$port)  $port = 80;
-
-  if(!is_ssl()){
-    $proto = 'http://';
-    if ($port == '80') {
-      $port='';
+    global $conf;
+    //if canonical url enabled always return absolute
+    if(is_null($abs)) $abs = $conf['canonical'];
+
+    if($conf['basedir']){
+        $dir = $conf['basedir'];
+    }elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){
+        $dir = dirname($_SERVER['SCRIPT_NAME']);
+    }elseif(substr($_SERVER['PHP_SELF'],-4) == '.php'){
+        $dir = dirname($_SERVER['PHP_SELF']);
+    }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
+        $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
+                $_SERVER['SCRIPT_FILENAME']);
+        $dir = dirname('/'.$dir);
+    }else{
+        $dir = '.'; //probably wrong
     }
-  }else{
-    $proto = 'https://';
-    if ($port == '443') {
-      $port='';
+
+    $dir = str_replace('\\','/',$dir);             // bugfix for weird WIN behaviour
+    $dir = preg_replace('#//+#','/',"/$dir/");     // ensure leading and trailing slashes
+
+        //handle script in lib/exe dir
+        $dir = preg_replace('!lib/exe/$!','',$dir);
+
+    //handle script in lib/plugins dir
+    $dir = preg_replace('!lib/plugins/.*$!','',$dir);
+
+    //finish here for relative URLs
+    if(!$abs) return $dir;
+
+    //use config option if available, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
+    if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
+
+    //split hostheader into host and port
+    list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
+    if(!$port)  $port = $_SERVER['SERVER_PORT'];
+    if(!$port)  $port = 80;
+
+    if(!is_ssl()){
+        $proto = 'http://';
+        if ($port == '80') {
+            $port='';
+        }
+    }else{
+        $proto = 'https://';
+        if ($port == '443') {
+            $port='';
+        }
     }
-  }
 
-  if($port) $port = ':'.$port;
+    if($port) $port = ':'.$port;
 
-  return $proto.$host.$port.$dir;
+    return $proto.$host.$port.$dir;
 }
 
 /**
@@ -465,52 +470,52 @@ function is_ssl(){
  * @author Jan Decaluwe <jan@jandecaluwe.com>
  */
 function scriptify($file) {
-  // checks
-  if (!is_readable($file)) {
-    return;
-  }
-  $fn = $file.'.php';
-  if (@file_exists($fn)) {
-    return;
-  }
-  $fh = fopen($fn, 'w');
-  if (!$fh) {
-    nice_die($fn.' is not writable. Check your permission settings!');
-  }
-  // write php exit hack first
-  fwrite($fh, "# $fn\n");
-  fwrite($fh, '# <?php exit()?>'."\n");
-  fwrite($fh, "# Don't modify the lines above\n");
-  fwrite($fh, "#\n");
-  // copy existing lines
-  $lines = file($file);
-  foreach ($lines as $line){
-    fwrite($fh, $line);
-  }
-  fclose($fh);
-  //try to rename the old file
-  io_rename($file,"$file.old");
+    // checks
+    if (!is_readable($file)) {
+        return;
+    }
+    $fn = $file.'.php';
+    if (@file_exists($fn)) {
+        return;
+    }
+    $fh = fopen($fn, 'w');
+    if (!$fh) {
+        nice_die($fn.' is not writable. Check your permission settings!');
+    }
+    // write php exit hack first
+    fwrite($fh, "# $fn\n");
+    fwrite($fh, '# <?php exit()?>'."\n");
+    fwrite($fh, "# Don't modify the lines above\n");
+    fwrite($fh, "#\n");
+    // copy existing lines
+    $lines = file($file);
+    foreach ($lines as $line){
+        fwrite($fh, $line);
+    }
+    fclose($fh);
+    //try to rename the old file
+    io_rename($file,"$file.old");
 }
 
 /**
  * print a nice message even if no styles are loaded yet.
  */
 function nice_die($msg){
-  echo<<<EOT
-  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
-   "http://www.w3.org/TR/html4/loose.dtd">
-  <html>
-    <head><title>DokuWiki Setup Error</title></head>
-    <body style="font-family: Arial, sans-serif">
-      <div style="width:60%; margin: auto; background-color: #fcc;
-                  border: 1px solid #faa; padding: 0.5em 1em;">
-      <h1 style="font-size: 120%">DokuWiki Setup Error</h1>
-      <p>$msg</p>
-      </div>
-    </body>
-  </html>
+    echo<<<EOT
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+    "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head><title>DokuWiki Setup Error</title></head>
+<body style="font-family: Arial, sans-serif">
+    <div style="width:60%; margin: auto; background-color: #fcc;
+                border: 1px solid #faa; padding: 0.5em 1em;">
+        <h1 style="font-size: 120%">DokuWiki Setup Error</h1>
+        <p>$msg</p>
+    </div>
+</body>
+</html>
 EOT;
-  exit;
+    exit;
 }
 
 
@@ -560,9 +565,9 @@ function fullpath($path,$exists=false){
     $newpath=array();
     foreach($path as $p) {
         if ($p === '' || $p === '.') continue;
-           if ($p==='..') {
-              array_pop($newpath);
-              continue;
+        if ($p==='..') {
+            array_pop($newpath);
+            continue;
         }
         array_push($newpath, $p);
     }
@@ -577,4 +582,3 @@ function fullpath($path,$exists=false){
 
 
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/io.php b/inc/io.php
index 2eb94db0c716b61ae8504ba0d0526865db5ff8e6..32a6f7b8e0a07f32f0c1c7bd8db4dde18d97c774 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -28,26 +28,26 @@ require_once(DOKU_INC.'inc/utf8.php');
  * @author Ben Coburn <btcoburn@silicodon.net>
  */
 function io_sweepNS($id,$basedir='datadir'){
-  global $conf;
-  $types = array ('datadir'=>'pages', 'mediadir'=>'media');
-  $ns_type = (isset($types[$basedir])?$types[$basedir]:false);
-
-  $delone = false;
-
-  //scan all namespaces
-  while(($id = getNS($id)) !== false){
-    $dir = $conf[$basedir].'/'.utf8_encodeFN(str_replace(':','/',$id));
-
-    //try to delete dir else return
-    if(@rmdir($dir)) {
-      if ($ns_type!==false) {
-        $data = array($id, $ns_type);
-        $delone = true; // we deleted at least one dir
-        trigger_event('IO_NAMESPACE_DELETED', $data);
-      }
-    } else { return $delone; }
-  }
-  return $delone;
+    global $conf;
+    $types = array ('datadir'=>'pages', 'mediadir'=>'media');
+    $ns_type = (isset($types[$basedir])?$types[$basedir]:false);
+
+    $delone = false;
+
+    //scan all namespaces
+    while(($id = getNS($id)) !== false){
+        $dir = $conf[$basedir].'/'.utf8_encodeFN(str_replace(':','/',$id));
+
+        //try to delete dir else return
+        if(@rmdir($dir)) {
+            if ($ns_type!==false) {
+                $data = array($id, $ns_type);
+                $delone = true; // we deleted at least one dir
+                trigger_event('IO_NAMESPACE_DELETED', $data);
+            }
+        } else { return $delone; }
+    }
+    return $delone;
 }
 
 /**
@@ -94,35 +94,35 @@ function _io_readWikiPage_action($data) {
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function io_readFile($file,$clean=true){
-  $ret = '';
-  if(@file_exists($file)){
-    if(substr($file,-3) == '.gz'){
-      $ret = join('',gzfile($file));
-    }else if(substr($file,-4) == '.bz2'){
-      $ret = bzfile($file);
+    $ret = '';
+    if(@file_exists($file)){
+        if(substr($file,-3) == '.gz'){
+            $ret = join('',gzfile($file));
+        }else if(substr($file,-4) == '.bz2'){
+            $ret = bzfile($file);
+        }else{
+            $ret = file_get_contents($file);
+        }
+    }
+    if($clean){
+        return cleanText($ret);
     }else{
-      $ret = file_get_contents($file);
+        return $ret;
     }
-  }
-  if($clean){
-    return cleanText($ret);
-  }else{
-    return $ret;
-  }
 }
 /**
-* Returns the content of a .bz2 compressed file as string
-* @author marcel senf <marcel@rucksackreinigung.de>
-*/
+ * Returns the content of a .bz2 compressed file as string
+ * @author marcel senf <marcel@rucksackreinigung.de>
+ */
 
 function bzfile($file){
-  $bz = bzopen($file,"r");
-  while (!feof($bz)){
-    //8192 seems to be the maximum buffersize?
-    $str = $str . bzread($bz,8192);
-  }
-  bzclose($bz);
-  return $str;
+    $bz = bzopen($file,"r");
+    while (!feof($bz)){
+        //8192 seems to be the maximum buffersize?
+        $str = $str . bzread($bz,8192);
+    }
+    bzclose($bz);
+    return $str;
 }
 
 
@@ -174,44 +174,44 @@ function _io_writeWikiPage_action($data) {
  * @return bool true on success
  */
 function io_saveFile($file,$content,$append=false){
-  global $conf;
-  $mode = ($append) ? 'ab' : 'wb';
-
-  $fileexists = @file_exists($file);
-  io_makeFileDir($file);
-  io_lock($file);
-  if(substr($file,-3) == '.gz'){
-    $fh = @gzopen($file,$mode.'9');
-    if(!$fh){
-      msg("Writing $file failed",-1);
-      io_unlock($file);
-      return false;
-    }
-    gzwrite($fh, $content);
-    gzclose($fh);
-  }else if(substr($file,-4) == '.bz2'){
-    $fh = @bzopen($file,$mode{0});
-    if(!$fh){
-      msg("Writing $file failed", -1);
-      io_unlock($file);
-      return false;
-    }
-    bzwrite($fh, $content);
-    bzclose($fh);
-  }else{
-    $fh = @fopen($file,$mode);
-    if(!$fh){
-      msg("Writing $file failed",-1);
-      io_unlock($file);
-      return false;
+    global $conf;
+    $mode = ($append) ? 'ab' : 'wb';
+
+    $fileexists = @file_exists($file);
+    io_makeFileDir($file);
+    io_lock($file);
+    if(substr($file,-3) == '.gz'){
+        $fh = @gzopen($file,$mode.'9');
+        if(!$fh){
+            msg("Writing $file failed",-1);
+            io_unlock($file);
+            return false;
+        }
+        gzwrite($fh, $content);
+        gzclose($fh);
+    }else if(substr($file,-4) == '.bz2'){
+        $fh = @bzopen($file,$mode{0});
+        if(!$fh){
+            msg("Writing $file failed", -1);
+            io_unlock($file);
+            return false;
+        }
+        bzwrite($fh, $content);
+        bzclose($fh);
+    }else{
+        $fh = @fopen($file,$mode);
+        if(!$fh){
+            msg("Writing $file failed",-1);
+            io_unlock($file);
+            return false;
+        }
+        fwrite($fh, $content);
+        fclose($fh);
     }
-    fwrite($fh, $content);
-    fclose($fh);
-  }
 
-  if(!$fileexists and !empty($conf['fperm'])) chmod($file, $conf['fperm']);
-  io_unlock($file);
-  return true;
+    if(!$fileexists and !empty($conf['fperm'])) chmod($file, $conf['fperm']);
+    io_unlock($file);
+    return true;
 }
 
 /**
@@ -227,55 +227,55 @@ function io_saveFile($file,$content,$append=false){
  * @return bool true on success
  */
 function io_deleteFromFile($file,$badline,$regex=false){
-  if (!@file_exists($file)) return true;
-
-  io_lock($file);
-
-  // load into array
-  if(substr($file,-3) == '.gz'){
-    $lines = gzfile($file);
-  }else{
-    $lines = file($file);
-  }
-
-  // remove all matching lines
-  if ($regex) {
-    $lines = preg_grep($badline,$lines,PREG_GREP_INVERT);
-  } else {
-    $pos = array_search($badline,$lines); //return null or false if not found
-    while(is_int($pos)){
-      unset($lines[$pos]);
-      $pos = array_search($badline,$lines);
-    }
-  }
+    if (!@file_exists($file)) return true;
+
+    io_lock($file);
 
-  if(count($lines)){
-    $content = join('',$lines);
+    // load into array
     if(substr($file,-3) == '.gz'){
-      $fh = @gzopen($file,'wb9');
-      if(!$fh){
-        msg("Removing content from $file failed",-1);
-        io_unlock($file);
-        return false;
-      }
-      gzwrite($fh, $content);
-      gzclose($fh);
+        $lines = gzfile($file);
     }else{
-      $fh = @fopen($file,'wb');
-      if(!$fh){
-        msg("Removing content from $file failed",-1);
-        io_unlock($file);
-        return false;
-      }
-      fwrite($fh, $content);
-      fclose($fh);
+        $lines = file($file);
     }
-  }else{
-    @unlink($file);
-  }
 
-  io_unlock($file);
-  return true;
+    // remove all matching lines
+    if ($regex) {
+        $lines = preg_grep($badline,$lines,PREG_GREP_INVERT);
+    } else {
+        $pos = array_search($badline,$lines); //return null or false if not found
+        while(is_int($pos)){
+            unset($lines[$pos]);
+            $pos = array_search($badline,$lines);
+        }
+    }
+
+    if(count($lines)){
+        $content = join('',$lines);
+        if(substr($file,-3) == '.gz'){
+            $fh = @gzopen($file,'wb9');
+            if(!$fh){
+                msg("Removing content from $file failed",-1);
+                io_unlock($file);
+                return false;
+            }
+            gzwrite($fh, $content);
+            gzclose($fh);
+        }else{
+            $fh = @fopen($file,'wb');
+            if(!$fh){
+                msg("Removing content from $file failed",-1);
+                io_unlock($file);
+                return false;
+            }
+            fwrite($fh, $content);
+            fclose($fh);
+        }
+    }else{
+        @unlink($file);
+    }
+
+    io_unlock($file);
+    return true;
 }
 
 /**
@@ -290,24 +290,24 @@ function io_deleteFromFile($file,$badline,$regex=false){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function io_lock($file){
-  global $conf;
-  // no locking if safemode hack
-  if($conf['safemodehack']) return;
-
-  $lockDir = $conf['lockdir'].'/'.md5($file);
-  @ignore_user_abort(1);
-
-  $timeStart = time();
-  do {
-    //waited longer than 3 seconds? -> stale lock
-    if ((time() - $timeStart) > 3) break;
-    $locked = @mkdir($lockDir, $conf['dmode']);
-    if($locked){
-      if(!empty($conf['dperm'])) chmod($lockDir, $conf['dperm']);
-      break;
-    }
-    usleep(50);
-  } while ($locked === false);
+    global $conf;
+    // no locking if safemode hack
+    if($conf['safemodehack']) return;
+
+    $lockDir = $conf['lockdir'].'/'.md5($file);
+    @ignore_user_abort(1);
+
+    $timeStart = time();
+    do {
+        //waited longer than 3 seconds? -> stale lock
+        if ((time() - $timeStart) > 3) break;
+        $locked = @mkdir($lockDir, $conf['dmode']);
+        if($locked){
+            if(!empty($conf['dperm'])) chmod($lockDir, $conf['dperm']);
+            break;
+        }
+        usleep(50);
+    } while ($locked === false);
 }
 
 /**
@@ -316,13 +316,13 @@ function io_lock($file){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function io_unlock($file){
-  global $conf;
-  // no locking if safemode hack
-  if($conf['safemodehack']) return;
+    global $conf;
+    // no locking if safemode hack
+    if($conf['safemodehack']) return;
 
-  $lockDir = $conf['lockdir'].'/'.md5($file);
-  @rmdir($lockDir);
-  @ignore_user_abort(0);
+    $lockDir = $conf['lockdir'].'/'.md5($file);
+    @rmdir($lockDir);
+    @ignore_user_abort(0);
 }
 
 /**
@@ -370,12 +370,12 @@ function io_createNamespace($id, $ns_type='pages') {
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function io_makeFileDir($file){
-  global $conf;
+    global $conf;
 
-  $dir = dirname($file);
-  if(!@is_dir($dir)){
-    io_mkdir_p($dir) || msg("Creating directory $dir failed",-1);
-  }
+    $dir = dirname($file);
+    if(!@is_dir($dir)){
+        io_mkdir_p($dir) || msg("Creating directory $dir failed",-1);
+    }
 }
 
 /**
@@ -386,21 +386,21 @@ function io_makeFileDir($file){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function io_mkdir_p($target){
-  global $conf;
-  if (@is_dir($target)||empty($target)) return 1; // best case check first
-  if (@file_exists($target) && !is_dir($target)) return 0;
-  //recursion
-  if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
-    if($conf['safemodehack']){
-      $dir = preg_replace('/^'.preg_quote(fullpath($conf['ftp']['root']),'/').'/','', $target);
-      return io_mkdir_ftp($dir);
-    }else{
-      $ret = @mkdir($target,$conf['dmode']); // crawl back up & create dir tree
-      if($ret && $conf['dperm']) chmod($target, $conf['dperm']);
-      return $ret;
+    global $conf;
+    if (@is_dir($target)||empty($target)) return 1; // best case check first
+    if (@file_exists($target) && !is_dir($target)) return 0;
+    //recursion
+    if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
+        if($conf['safemodehack']){
+            $dir = preg_replace('/^'.preg_quote(fullpath($conf['ftp']['root']),'/').'/','', $target);
+            return io_mkdir_ftp($dir);
+        }else{
+            $ret = @mkdir($target,$conf['dmode']); // crawl back up & create dir tree
+            if($ret && $conf['dperm']) chmod($target, $conf['dperm']);
+            return $ret;
+        }
     }
-  }
-  return 0;
+    return 0;
 }
 
 /**
@@ -411,31 +411,31 @@ function io_mkdir_p($target){
  * @author <andi@splitbrain.org>
  */
 function io_mkdir_ftp($dir){
-  global $conf;
-
-  if(!function_exists('ftp_connect')){
-    msg("FTP support not found - safemode workaround not usable",-1);
-    return false;
-  }
-
-  $conn = @ftp_connect($conf['ftp']['host'],$conf['ftp']['port'],10);
-  if(!$conn){
-    msg("FTP connection failed",-1);
-    return false;
-  }
-
-  if(!@ftp_login($conn, $conf['ftp']['user'], conf_decodeString($conf['ftp']['pass']))){
-    msg("FTP login failed",-1);
-    return false;
-  }
-
-  //create directory
-  $ok = @ftp_mkdir($conn, $dir);
-  //set permissions
-  @ftp_site($conn,sprintf("CHMOD %04o %s",$conf['dmode'],$dir));
-
-  @ftp_close($conn);
-  return $ok;
+    global $conf;
+
+    if(!function_exists('ftp_connect')){
+        msg("FTP support not found - safemode workaround not usable",-1);
+        return false;
+    }
+
+    $conn = @ftp_connect($conf['ftp']['host'],$conf['ftp']['port'],10);
+    if(!$conn){
+        msg("FTP connection failed",-1);
+        return false;
+    }
+
+    if(!@ftp_login($conn, $conf['ftp']['user'], conf_decodeString($conf['ftp']['pass']))){
+        msg("FTP login failed",-1);
+        return false;
+    }
+
+    //create directory
+    $ok = @ftp_mkdir($conn, $dir);
+    //set permissions
+    @ftp_site($conn,sprintf("CHMOD %04o %s",$conf['dmode'],$dir));
+
+    @ftp_close($conn);
+    return $ok;
 }
 
 /**
@@ -464,7 +464,7 @@ function io_mktmpdir() {
  * if $useAttachment is false,
  * - $file is the full filename to save the file, incl. path
  * - if successful will return true, false otherwise
-
+ *
  * if $useAttachment is true,
  * - $file is the directory where the file should be saved
  * - if successful will return the name used for the saved file, false otherwise
@@ -473,43 +473,43 @@ function io_mktmpdir() {
  * @author Chris Smith <chris@jalakai.co.uk>
  */
 function io_download($url,$file,$useAttachment=false,$defaultName='',$maxSize=2097152){
-  global $conf;
-  $http = new DokuHTTPClient();
-  $http->max_bodysize = $maxSize;
-  $http->timeout = 25; //max. 25 sec
+    global $conf;
+    $http = new DokuHTTPClient();
+    $http->max_bodysize = $maxSize;
+    $http->timeout = 25; //max. 25 sec
 
-  $data = $http->get($url);
-  if(!$data) return false;
+    $data = $http->get($url);
+    if(!$data) return false;
 
-  if ($useAttachment) {
-    $name = '';
-      if (isset($http->resp_headers['content-disposition'])) {
-      $content_disposition = $http->resp_headers['content-disposition'];
-      $match=array();
-      if (is_string($content_disposition) &&
-          preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match)) {
+    if ($useAttachment) {
+        $name = '';
+        if (isset($http->resp_headers['content-disposition'])) {
+            $content_disposition = $http->resp_headers['content-disposition'];
+            $match=array();
+            if (is_string($content_disposition) &&
+                    preg_match('/attachment;\s*filename\s*=\s*"([^"]*)"/i', $content_disposition, $match)) {
 
-          $name = basename($match[1]);
-      }
+                $name = basename($match[1]);
+        }
 
-    }
+        }
+
+        if (!$name) {
+            if (!$defaultName) return false;
+            $name = $defaultName;
+        }
 
-    if (!$name) {
-        if (!$defaultName) return false;
-        $name = $defaultName;
+        $file = $file.$name;
     }
 
-    $file = $file.$name;
-  }
-
-  $fileexists = @file_exists($file);
-  $fp = @fopen($file,"w");
-  if(!$fp) return false;
-  fwrite($fp,$data);
-  fclose($fp);
-  if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
-  if ($useAttachment) return $name;
-  return true;
+    $fileexists = @file_exists($file);
+    $fp = @fopen($file,"w");
+    if(!$fp) return false;
+    fwrite($fp,$data);
+    fclose($fp);
+    if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
+    if ($useAttachment) return $name;
+    return true;
 }
 
 /**
@@ -519,16 +519,16 @@ function io_download($url,$file,$useAttachment=false,$defaultName='',$maxSize=20
  * this function will use copy/unlink instead
  */
 function io_rename($from,$to){
-  global $conf;
-  if(!@rename($from,$to)){
-    if(@copy($from,$to)){
-      if($conf['fperm']) chmod($to, $conf['fperm']);
-      @unlink($from);
-      return true;
+    global $conf;
+    if(!@rename($from,$to)){
+        if(@copy($from,$to)){
+            if($conf['fperm']) chmod($to, $conf['fperm']);
+            @unlink($from);
+            return true;
+        }
+        return false;
     }
-    return false;
-  }
-  return true;
+    return true;
 }
 
 
@@ -540,14 +540,14 @@ function io_rename($from,$to){
  * @deprecated
  */
 function io_runcmd($cmd){
-  $fh = popen($cmd, "r");
-  if(!$fh) return false;
-  $ret = '';
-  while (!feof($fh)) {
-    $ret .= fread($fh, 8192);
-  }
-  pclose($fh);
-  return $ret;
+    $fh = popen($cmd, "r");
+    if(!$fh) return false;
+    $ret = '';
+    while (!feof($fh)) {
+        $ret .= fread($fh, 8192);
+    }
+    pclose($fh);
+    return $ret;
 }
 
 /**
@@ -565,30 +565,29 @@ function io_runcmd($cmd){
  * @return matching lines or backref, false on error
  */
 function io_grep($file,$pattern,$max=0,$backref=false){
-  $fh = @fopen($file,'r');
-  if(!$fh) return false;
-  $matches = array();
-
-  $cnt  = 0;
-  $line = '';
-  while (!feof($fh)) {
-    $line .= fgets($fh, 4096);  // read full line
-    if(substr($line,-1) != "\n") continue;
-
-    // check if line matches
-    if(preg_match($pattern,$line,$match)){
-      if($backref){
-        $matches[] = $match;
-      }else{
-        $matches[] = $line;
-      }
-      $cnt++;
-    }
-    if($max && $max == $cnt) break;
+    $fh = @fopen($file,'r');
+    if(!$fh) return false;
+    $matches = array();
+
+    $cnt  = 0;
     $line = '';
-  }
-  fclose($fh);
-  return $matches;
+    while (!feof($fh)) {
+        $line .= fgets($fh, 4096);  // read full line
+        if(substr($line,-1) != "\n") continue;
+
+        // check if line matches
+        if(preg_match($pattern,$line,$match)){
+            if($backref){
+                $matches[] = $match;
+            }else{
+                $matches[] = $line;
+            }
+            $cnt++;
+        }
+        if($max && $max == $cnt) break;
+        $line = '';
+    }
+    fclose($fh);
+    return $matches;
 }
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/mail.php b/inc/mail.php
index 61d938cf888ef6d572e168c347b845b3e759e7a0..3b0592b8bdb5103f21bd5b12ef4798181a1379e6 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -27,7 +27,7 @@ if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n");
  *
  * @author Chris Smith <chris@jalakai.co.uk>
  * Check if a given mail address is valid
-*/
+ */
 if (!defined('RFC2822_ATEXT')) define('RFC2822_ATEXT',"0-9a-zA-Z!#$%&'*+/=?^_`{|}~-");
 if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['.RFC2822_ATEXT.']+(?:\.['.RFC2822_ATEXT.']+)*@(?i:[0-9a-z][0-9a-z-]*\.)+(?i:[a-z]{2,4}|museum|travel)');
 
@@ -54,59 +54,59 @@ if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '['
  */
 function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){
 
-  $message = compact('to','subject','body','from','cc','bcc','headers','params');
-  return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action');
+    $message = compact('to','subject','body','from','cc','bcc','headers','params');
+    return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action');
 }
 
 function _mail_send_action($data) {
 
-  // retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params
-  $to = $data['to'];
-  $subject = $data['subject'];
-  $body = $data['body'];
-
-  // add robustness in case plugin removes any of these optional values
-  $from = isset($data['from']) ? $data['from'] : '';
-  $cc = isset($data['cc']) ? $data['cc'] : '';
-  $bcc = isset($data['bcc']) ? $data['bcc'] : '';
-  $headers = isset($data['headers']) ? $data['headers'] : null;
-  $params = isset($data['params']) ? $data['params'] : null;
-
-  // end additional code to support event ... original mail_send() code from here
-
-  if(defined('MAILHEADER_ASCIIONLY')){
-    $subject = utf8_deaccent($subject);
-    $subject = utf8_strip($subject);
-  }
-
-  if(!utf8_isASCII($subject)) {
-    $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?=';
-    // Spaces must be encoded according to rfc2047. Use the "_" shorthand
-    $subject = preg_replace('/ /', '_', $subject);
-  }
-
-  $header  = '';
-
-  // No named recipients for To: in Windows (see FS#652)
-  $usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
-
-  $to = mail_encode_address($to,'',$usenames);
-  $header .= mail_encode_address($from,'From');
-  $header .= mail_encode_address($cc,'Cc');
-  $header .= mail_encode_address($bcc,'Bcc');
-  $header .= 'MIME-Version: 1.0'.MAILHEADER_EOL;
-  $header .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL;
-  $header .= 'Content-Transfer-Encoding: quoted-printable'.MAILHEADER_EOL;
-  $header .= $headers;
-  $header  = trim($header);
-
-  $body = mail_quotedprintable_encode($body);
-
-  if($params == null){
-    return @mail($to,$subject,$body,$header);
-  }else{
-    return @mail($to,$subject,$body,$header,$params);
-  }
+    // retrieve parameters from event data, $to, $subject, $body, $from, $cc, $bcc, $headers, $params
+    $to = $data['to'];
+    $subject = $data['subject'];
+    $body = $data['body'];
+
+    // add robustness in case plugin removes any of these optional values
+    $from = isset($data['from']) ? $data['from'] : '';
+    $cc = isset($data['cc']) ? $data['cc'] : '';
+    $bcc = isset($data['bcc']) ? $data['bcc'] : '';
+    $headers = isset($data['headers']) ? $data['headers'] : null;
+    $params = isset($data['params']) ? $data['params'] : null;
+
+    // end additional code to support event ... original mail_send() code from here
+
+    if(defined('MAILHEADER_ASCIIONLY')){
+        $subject = utf8_deaccent($subject);
+        $subject = utf8_strip($subject);
+    }
+
+    if(!utf8_isASCII($subject)) {
+        $subject = '=?UTF-8?Q?'.mail_quotedprintable_encode($subject,0).'?=';
+        // Spaces must be encoded according to rfc2047. Use the "_" shorthand
+        $subject = preg_replace('/ /', '_', $subject);
+    }
+
+    $header  = '';
+
+    // No named recipients for To: in Windows (see FS#652)
+    $usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true;
+
+    $to = mail_encode_address($to,'',$usenames);
+    $header .= mail_encode_address($from,'From');
+    $header .= mail_encode_address($cc,'Cc');
+    $header .= mail_encode_address($bcc,'Bcc');
+    $header .= 'MIME-Version: 1.0'.MAILHEADER_EOL;
+    $header .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL;
+    $header .= 'Content-Transfer-Encoding: quoted-printable'.MAILHEADER_EOL;
+    $header .= $headers;
+    $header  = trim($header);
+
+    $body = mail_quotedprintable_encode($body);
+
+    if($params == null){
+        return @mail($to,$subject,$body,$header);
+    }else{
+        return @mail($to,$subject,$body,$header,$params);
+    }
 }
 
 /**
@@ -124,66 +124,66 @@ function _mail_send_action($data) {
  * @param boolean $names  Allow named Recipients?
  */
 function mail_encode_address($string,$header='',$names=true){
-  $headers = '';
-  $parts = explode(',',$string);
-  foreach ($parts as $part){
-    $part = trim($part);
-
-    // parse address
-    if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){
-      $text = trim($matches[1]);
-      $addr = $matches[2];
-    }else{
-      $addr = $part;
+    $headers = '';
+    $parts = explode(',',$string);
+    foreach ($parts as $part){
+        $part = trim($part);
+
+        // parse address
+        if(preg_match('#(.*?)<(.*?)>#',$part,$matches)){
+            $text = trim($matches[1]);
+            $addr = $matches[2];
+        }else{
+            $addr = $part;
+        }
+
+        // skip empty ones
+        if(empty($addr)){
+            continue;
+        }
+
+        // FIXME: is there a way to encode the localpart of a emailaddress?
+        if(!utf8_isASCII($addr)){
+            msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1);
+            continue;
+        }
+
+        if(!mail_isvalid($addr)){
+            msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1);
+            continue;
+        }
+
+        // text was given
+        if(!empty($text) && $names){
+            // add address quotes
+            $addr = "<$addr>";
+
+            if(defined('MAILHEADER_ASCIIONLY')){
+                $text = utf8_deaccent($text);
+                $text = utf8_strip($text);
+            }
+
+            if(!utf8_isASCII($text)){
+                $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?=';
+            }
+        }else{
+            $text = '';
+        }
+
+        // add to header comma seperated
+        if($headers != ''){
+            $headers .= ',';
+            if($header) $headers .= MAILHEADER_EOL.' '; // avoid overlong mail headers
+        }
+        $headers .= $text.' '.$addr;
     }
 
-    // skip empty ones
-    if(empty($addr)){
-      continue;
-    }
+    if(empty($headers)) return null;
 
-    // FIXME: is there a way to encode the localpart of a emailaddress?
-    if(!utf8_isASCII($addr)){
-      msg(htmlspecialchars("E-Mail address <$addr> is not ASCII"),-1);
-      continue;
-    }
-
-    if(!mail_isvalid($addr)){
-      msg(htmlspecialchars("E-Mail address <$addr> is not valid"),-1);
-      continue;
-    }
-
-    // text was given
-    if(!empty($text) && $names){
-      // add address quotes
-      $addr = "<$addr>";
-
-      if(defined('MAILHEADER_ASCIIONLY')){
-        $text = utf8_deaccent($text);
-        $text = utf8_strip($text);
-      }
-
-      if(!utf8_isASCII($text)){
-        $text = '=?UTF-8?Q?'.mail_quotedprintable_encode($text,0).'?=';
-      }
-    }else{
-      $text = '';
-    }
+    //if headername was given add it and close correctly
+    if($header) $headers = $header.': '.$headers.MAILHEADER_EOL;
 
-    // add to header comma seperated
-    if($headers != ''){
-        $headers .= ',';
-        if($header) $headers .= MAILHEADER_EOL.' '; // avoid overlong mail headers
-    }
-    $headers .= $text.' '.$addr;
-  }
-
-  if(empty($headers)) return null;
-
-  //if headername was given add it and close correctly
-  if($header) $headers = $header.': '.$headers.MAILHEADER_EOL;
-
-  return $headers;
+    return $headers;
 }
 
 /**
@@ -204,64 +204,63 @@ function mail_isvalid($email){
  * @link   http://www.php.net/manual/en/function.imap-8bit.php#61216
  */
 function mail_quotedprintable_encode($sText,$maxlen=74,$bEmulate_imap_8bit=true) {
-  // split text into lines
-  $aLines= preg_split("/(?:\r\n|\r|\n)/", $sText);
-
-  for ($i=0;$i<count($aLines);$i++) {
-    $sLine =& $aLines[$i];
-    if (strlen($sLine)===0) continue; // do nothing, if empty
-
-    $sRegExp = '/[^\x09\x20\x21-\x3C\x3E-\x7E]/e';
-
-    // imap_8bit encodes x09 everywhere, not only at lineends,
-    // for EBCDIC safeness encode !"#$@[\]^`{|}~,
-    // for complete safeness encode every character :)
-    if ($bEmulate_imap_8bit)
-      $sRegExp = '/[^\x20\x21-\x3C\x3E-\x7E]/e';
-
-    $sReplmt = 'sprintf( "=%02X", ord ( "$0" ) ) ;';
-    $sLine = preg_replace( $sRegExp, $sReplmt, $sLine );
-
-    // encode x09,x20 at lineends
-    {
-      $iLength = strlen($sLine);
-      $iLastChar = ord($sLine{$iLength-1});
-
-      //              !!!!!!!!
-      // imap_8_bit does not encode x20 at the very end of a text,
-      // here is, where I don't agree with imap_8_bit,
-      // please correct me, if I'm wrong,
-      // or comment next line for RFC2045 conformance, if you like
-      if (!($bEmulate_imap_8bit && ($i==count($aLines)-1)))
-
-      if (($iLastChar==0x09)||($iLastChar==0x20)) {
-        $sLine{$iLength-1}='=';
-        $sLine .= ($iLastChar==0x09)?'09':'20';
-      }
-    }    // imap_8bit encodes x20 before chr(13), too
-    // although IMHO not requested by RFC2045, why not do it safer :)
-    // and why not encode any x20 around chr(10) or chr(13)
-    if ($bEmulate_imap_8bit) {
-      $sLine=str_replace(' =0D','=20=0D',$sLine);
-      //$sLine=str_replace(' =0A','=20=0A',$sLine);
-      //$sLine=str_replace('=0D ','=0D=20',$sLine);
-      //$sLine=str_replace('=0A ','=0A=20',$sLine);
+    // split text into lines
+    $aLines= preg_split("/(?:\r\n|\r|\n)/", $sText);
+    $cnt = count($aLines);
+
+    for ($i=0;$i<$cnt;$i++) {
+        $sLine =& $aLines[$i];
+        if (strlen($sLine)===0) continue; // do nothing, if empty
+
+        $sRegExp = '/[^\x09\x20\x21-\x3C\x3E-\x7E]/e';
+
+        // imap_8bit encodes x09 everywhere, not only at lineends,
+        // for EBCDIC safeness encode !"#$@[\]^`{|}~,
+        // for complete safeness encode every character :)
+        if ($bEmulate_imap_8bit)
+            $sRegExp = '/[^\x20\x21-\x3C\x3E-\x7E]/e';
+
+        $sReplmt = 'sprintf( "=%02X", ord ( "$0" ) ) ;';
+        $sLine = preg_replace( $sRegExp, $sReplmt, $sLine );
+
+        // encode x09,x20 at lineends
+        {
+            $iLength = strlen($sLine);
+            $iLastChar = ord($sLine{$iLength-1});
+
+            //              !!!!!!!!
+            // imap_8_bit does not encode x20 at the very end of a text,
+            // here is, where I don't agree with imap_8_bit,
+            // please correct me, if I'm wrong,
+            // or comment next line for RFC2045 conformance, if you like
+            if (!($bEmulate_imap_8bit && ($i==count($aLines)-1))){
+                if (($iLastChar==0x09)||($iLastChar==0x20)) {
+                    $sLine{$iLength-1}='=';
+                    $sLine .= ($iLastChar==0x09)?'09':'20';
+                }
+            }
+        }    // imap_8bit encodes x20 before chr(13), too
+        // although IMHO not requested by RFC2045, why not do it safer :)
+        // and why not encode any x20 around chr(10) or chr(13)
+        if ($bEmulate_imap_8bit) {
+            $sLine=str_replace(' =0D','=20=0D',$sLine);
+            //$sLine=str_replace(' =0A','=20=0A',$sLine);
+            //$sLine=str_replace('=0D ','=0D=20',$sLine);
+            //$sLine=str_replace('=0A ','=0A=20',$sLine);
+        }
+
+        // finally split into softlines no longer than $maxlen chars,
+        // for even more safeness one could encode x09,x20
+        // at the very first character of the line
+        // and after soft linebreaks, as well,
+        // but this wouldn't be caught by such an easy RegExp
+        if($maxlen){
+            preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch );
+            $sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's
+        }
     }
 
-    // finally split into softlines no longer than $maxlen chars,
-    // for even more safeness one could encode x09,x20
-    // at the very first character of the line
-    // and after soft linebreaks, as well,
-    // but this wouldn't be caught by such an easy RegExp
-    if($maxlen){
-      preg_match_all( '/.{1,'.($maxlen - 2).'}([^=]{0,2})?/', $sLine, $aMatch );
-      $sLine = implode( '=' . MAILHEADER_EOL, $aMatch[0] ); // add soft crlf's
-    }
-  }
-
-  // join lines into text
-  return implode(MAILHEADER_EOL,$aLines);
+    // join lines into text
+    return implode(MAILHEADER_EOL,$aLines);
 }
 
-
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/media.php b/inc/media.php
index 2a45b6d805647801bdf275c2f7f8beaccd9c205d..c9b7cfc5680e1fc4c9ddb19fb809fecc44a8f1f5 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -32,10 +32,10 @@ function media_filesinuse($data,$id){
             echo '<span class="mediaref_ref">'.hsc($row).'</span>';
             echo '</div>';
         }else
-        $hidden++;
+            $hidden++;
     }
     if ($hidden){
-      print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
+        print '<div class="mediaref_hidden">'.$lang['ref_hidden'].'</div>';
     }
 }
 
@@ -86,14 +86,14 @@ function media_metaform($id,$auth){
     static $fields = null;
     if(is_null($fields)){
 
-      foreach (array('default','local') as $config_group) {
-        if (empty($config_cascade['mediameta'][$config_group])) continue;
-        foreach ($config_cascade['mediameta'][$config_group] as $config_file) {
-          if(@file_exists($config_file)){
-            include($config_file);
-          }
+        foreach (array('default','local') as $config_group) {
+            if (empty($config_cascade['mediameta'][$config_group])) continue;
+            foreach ($config_cascade['mediameta'][$config_group] as $config_file) {
+                if(@file_exists($config_file)){
+                    include($config_file);
+                }
+            }
         }
-      }
     }
 
     $src = mediaFN($id);
@@ -136,9 +136,9 @@ function media_metaform($id,$auth){
     echo '<div class="buttons">'.NL;
     echo '<input type="hidden" name="img" value="'.hsc($id).'" />'.NL;
     echo '<input name="do[save]" type="submit" value="'.$lang['btn_save'].
-         '" title="'.$lang['btn_save'].' [S]" accesskey="s" class="button" />'.NL;
+        '" title="'.$lang['btn_save'].' [S]" accesskey="s" class="button" />'.NL;
     echo '<input name="do[cancel]" type="submit" value="'.$lang['btn_cancel'].
-         '" title="'.$lang['btn_cancel'].' [C]" accesskey="c" class="button" />'.NL;
+        '" title="'.$lang['btn_cancel'].' [C]" accesskey="c" class="button" />'.NL;
     echo '</div>'.NL;
     echo '</form>'.NL;
 }
@@ -446,7 +446,7 @@ function media_filelist($ns,$auth=null,$jump=''){
         $dir = utf8_encodeFN(str_replace(':','/',$ns));
         $data = array();
         search($data,$conf['mediadir'],'search_media',
-               array('showmsg'=>true,'depth'=>1),$dir);
+                array('showmsg'=>true,'depth'=>1),$dir);
 
         if(!count($data)){
             echo '<div class="nothing">'.$lang['nothingfound'].'</div>'.NL;
@@ -471,19 +471,19 @@ function media_searchlist($query,$ns,$auth=null){
 
     if ($query) {
         $evdata = array(
-            'ns'    => $ns,
-            'data'  => array(),
-            'query' => $query
-        );
+                'ns'    => $ns,
+                'data'  => array(),
+                'query' => $query
+                );
         $evt = new Doku_Event('MEDIA_SEARCH', $evdata);
         if ($evt->advise_before()) {
             $dir = utf8_encodeFN(str_replace(':','/',$evdata['ns']));
             $pattern = '/'.preg_quote($evdata['query'],'/').'/i';
             search($evdata['data'],
-                   $conf['mediadir'],
-                   'search_media',
-                   array('showmsg'=>false,'pattern'=>$pattern),
-                   $dir);
+                    $conf['mediadir'],
+                    'search_media',
+                    array('showmsg'=>false,'pattern'=>$pattern),
+                    $dir);
         }
         $evt->advise_after();
         unset($evt);
@@ -502,8 +502,6 @@ function media_searchlist($query,$ns,$auth=null){
 /**
  * Print action links for a file depending on filetype
  * and available permissions
- *
- * @todo contains inline javascript
  */
 function media_fileactions($item,$auth){
     global $lang;
@@ -511,8 +509,7 @@ function media_fileactions($item,$auth){
     // view button
     $link = ml($item['id'],'',true);
     echo ' <a href="'.$link.'" target="_blank"><img src="'.DOKU_BASE.'lib/images/magnifier.png" '.
-         'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
-
+        'alt="'.$lang['mediaview'].'" title="'.$lang['mediaview'].'" class="btn" /></a>';
 
     // no further actions if not writable
     if(!$item['writable']) return;
@@ -520,16 +517,16 @@ function media_fileactions($item,$auth){
     // delete button
     if($auth >= AUTH_DELETE){
         echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?delete='.rawurlencode($item['id']).
-             '&amp;sectok='.getSecurityToken().'" class="btn_media_delete" title="'.$item['id'].'">'.
-             '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
-             'title="'.$lang['btn_delete'].'" class="btn" /></a>';
+            '&amp;sectok='.getSecurityToken().'" class="btn_media_delete" title="'.$item['id'].'">'.
+            '<img src="'.DOKU_BASE.'lib/images/trash.png" alt="'.$lang['btn_delete'].'" '.
+            'title="'.$lang['btn_delete'].'" class="btn" /></a>';
     }
 
     // edit button
     if($auth >= AUTH_UPLOAD && $item['isimg'] && $item['meta']->getField('File.Mime') == 'image/jpeg'){
         echo ' <a href="'.DOKU_BASE.'lib/exe/mediamanager.php?edit='.rawurlencode($item['id']).'">'.
-             '<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '.
-             'title="'.$lang['metaedit'].'" class="btn" /></a>';
+            '<img src="'.DOKU_BASE.'lib/images/pencil.png" alt="'.$lang['metaedit'].'" '.
+            'title="'.$lang['metaedit'].'" class="btn" /></a>';
     }
 
 }
@@ -622,8 +619,8 @@ function media_printimgdetail($item){
     // read EXIF/IPTC data
     $t = $item['meta']->getField(array('IPTC.Headline','xmp.dc:title'));
     $d = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment',
-                                       'EXIF.TIFFImageDescription',
-                                       'EXIF.TIFFUserComment'));
+                'EXIF.TIFFImageDescription',
+                'EXIF.TIFFUserComment'));
     if(utf8_strlen($d) > 250) $d = utf8_substr($d,0,250).'...';
     $k = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category','xmp.dc:subject'));
 
@@ -662,47 +659,47 @@ function media_uploadform($ns, $auth){
     $form->addElement(form_makeCloseTag('p'));
 
     if($auth >= AUTH_DELETE){
-      $form->addElement(form_makeOpenTag('p'));
-      $form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check'));
-      $form->addElement(form_makeCloseTag('p'));
+        $form->addElement(form_makeOpenTag('p'));
+        $form->addElement(form_makeCheckboxField('ow', 1, $lang['txt_overwrt'], 'dw__ow', 'check'));
+        $form->addElement(form_makeCloseTag('p'));
     }
     html_form('upload', $form);
 
     // prepare flashvars for multiupload
     $opt = array(
-        'L_gridname'  => $lang['mu_gridname'] ,
-        'L_gridsize'  => $lang['mu_gridsize'] ,
-        'L_gridstat'  => $lang['mu_gridstat'] ,
-        'L_namespace' => $lang['mu_namespace'] ,
-        'L_overwrite' => $lang['txt_overwrt'],
-        'L_browse'    => $lang['mu_browse'],
-        'L_upload'    => $lang['btn_upload'],
-        'L_toobig'    => $lang['mu_toobig'],
-        'L_ready'     => $lang['mu_ready'],
-        'L_done'      => $lang['mu_done'],
-        'L_fail'      => $lang['mu_fail'],
-        'L_authfail'  => $lang['mu_authfail'],
-        'L_progress'  => $lang['mu_progress'],
-        'L_filetypes' => $lang['mu_filetypes'],
-        'L_info'      => $lang['mu_info'],
-        'L_lasterr'   => $lang['mu_lasterr'],
-
-        'O_ns'        => ":$ns",
-        'O_backend'   => 'mediamanager.php?'.session_name().'='.session_id(),
-        'O_maxsize'   => php_to_byte(ini_get('upload_max_filesize')),
-        'O_extensions'=> join('|',array_keys(getMimeTypes())),
-        'O_overwrite' => ($auth >= AUTH_DELETE),
-        'O_sectok'    => getSecurityToken(),
-        'O_authtok'   => auth_createToken(),
-    );
+            'L_gridname'  => $lang['mu_gridname'] ,
+            'L_gridsize'  => $lang['mu_gridsize'] ,
+            'L_gridstat'  => $lang['mu_gridstat'] ,
+            'L_namespace' => $lang['mu_namespace'] ,
+            'L_overwrite' => $lang['txt_overwrt'],
+            'L_browse'    => $lang['mu_browse'],
+            'L_upload'    => $lang['btn_upload'],
+            'L_toobig'    => $lang['mu_toobig'],
+            'L_ready'     => $lang['mu_ready'],
+            'L_done'      => $lang['mu_done'],
+            'L_fail'      => $lang['mu_fail'],
+            'L_authfail'  => $lang['mu_authfail'],
+            'L_progress'  => $lang['mu_progress'],
+            'L_filetypes' => $lang['mu_filetypes'],
+            'L_info'      => $lang['mu_info'],
+            'L_lasterr'   => $lang['mu_lasterr'],
+
+            'O_ns'        => ":$ns",
+            'O_backend'   => 'mediamanager.php?'.session_name().'='.session_id(),
+            'O_maxsize'   => php_to_byte(ini_get('upload_max_filesize')),
+            'O_extensions'=> join('|',array_keys(getMimeTypes())),
+            'O_overwrite' => ($auth >= AUTH_DELETE),
+            'O_sectok'    => getSecurityToken(),
+            'O_authtok'   => auth_createToken(),
+            );
     $var = buildURLparams($opt);
     // output the flash uploader
     ?>
-    <div id="dw__flashupload" style="display:none">
-    <div class="upload"><?php echo $lang['mu_intro']?></div>
-    <?php echo html_flashobject('multipleUpload.swf','500','190',null,$opt); ?>
-    </div>
-    <?php
+        <div id="dw__flashupload" style="display:none">
+        <div class="upload"><?php echo $lang['mu_intro']?></div>
+        <?php echo html_flashobject('multipleUpload.swf','500','190',null,$opt); ?>
+        </div>
+        <?php
 }
 
 /**
@@ -748,7 +745,7 @@ function media_nstree($ns){
 
     // wrap a list with the root level around the other namespaces
     $item = array( 'level' => 0, 'id' => '',
-                   'open' =>'true', 'label' => '['.$lang['mediaroot'].']');
+            'open' =>'true', 'label' => '['.$lang['mediaroot'].']');
 
     echo '<ul class="idx">';
     echo media_nstree_li($item);
@@ -796,7 +793,7 @@ function media_nstree_li($item){
         $alt   = '+';
     }
     return '<li class="'.$class.'">'.
-           '<img src="'.$img.'" alt="'.$alt.'" />';
+        '<img src="'.$img.'" alt="'.$alt.'" />';
 }
 
 /**
@@ -805,28 +802,28 @@ function media_nstree_li($item){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function media_resize_image($file, $ext, $w, $h=0){
-  global $conf;
+    global $conf;
 
-  $info = @getimagesize($file); //get original size
-  if($info == false) return $file; // that's no image - it's a spaceship!
+    $info = @getimagesize($file); //get original size
+    if($info == false) return $file; // that's no image - it's a spaceship!
 
-  if(!$h) $h = round(($w * $info[1]) / $info[0]);
+    if(!$h) $h = round(($w * $info[1]) / $info[0]);
 
-  // we wont scale up to infinity
-  if($w > 2000 || $h > 2000) return $file;
+    // we wont scale up to infinity
+    if($w > 2000 || $h > 2000) return $file;
 
-  //cache
-  $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext);
-  $mtime = @filemtime($local); // 0 if not exists
+    //cache
+    $local = getCacheName($file,'.media.'.$w.'x'.$h.'.'.$ext);
+    $mtime = @filemtime($local); // 0 if not exists
 
-  if( $mtime > filemtime($file) ||
-      media_resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) ||
-      media_resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){
-    if($conf['fperm']) chmod($local, $conf['fperm']);
-    return $local;
-  }
-  //still here? resizing failed
-  return $file;
+    if( $mtime > filemtime($file) ||
+            media_resize_imageIM($ext,$file,$info[0],$info[1],$local,$w,$h) ||
+            media_resize_imageGD($ext,$file,$info[0],$info[1],$local,$w,$h) ){
+        if($conf['fperm']) chmod($local, $conf['fperm']);
+        return $local;
+    }
+    //still here? resizing failed
+    return $file;
 }
 
 /**
@@ -839,49 +836,49 @@ function media_resize_image($file, $ext, $w, $h=0){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function media_crop_image($file, $ext, $w, $h=0){
-  global $conf;
-
-  if(!$h) $h = $w;
-  $info = @getimagesize($file); //get original size
-  if($info == false) return $file; // that's no image - it's a spaceship!
-
-  // calculate crop size
-  $fr = $info[0]/$info[1];
-  $tr = $w/$h;
-  if($tr >= 1){
-    if($tr > $fr){
-        $cw = $info[0];
-        $ch = (int) $info[0]/$tr;
+    global $conf;
+
+    if(!$h) $h = $w;
+    $info = @getimagesize($file); //get original size
+    if($info == false) return $file; // that's no image - it's a spaceship!
+
+    // calculate crop size
+    $fr = $info[0]/$info[1];
+    $tr = $w/$h;
+    if($tr >= 1){
+        if($tr > $fr){
+            $cw = $info[0];
+            $ch = (int) $info[0]/$tr;
+        }else{
+            $cw = (int) $info[1]*$tr;
+            $ch = $info[1];
+        }
     }else{
-        $cw = (int) $info[1]*$tr;
-        $ch = $info[1];
+        if($tr < $fr){
+            $cw = (int) $info[1]*$tr;
+            $ch = $info[1];
+        }else{
+            $cw = $info[0];
+            $ch = (int) $info[0]/$tr;
+        }
     }
-  }else{
-    if($tr < $fr){
-        $cw = (int) $info[1]*$tr;
-        $ch = $info[1];
-    }else{
-        $cw = $info[0];
-        $ch = (int) $info[0]/$tr;
+    // calculate crop offset
+    $cx = (int) ($info[0]-$cw)/2;
+    $cy = (int) ($info[1]-$ch)/3;
+
+    //cache
+    $local = getCacheName($file,'.media.'.$cw.'x'.$ch.'.crop.'.$ext);
+    $mtime = @filemtime($local); // 0 if not exists
+
+    if( $mtime > filemtime($file) ||
+            media_crop_imageIM($ext,$file,$info[0],$info[1],$local,$cw,$ch,$cx,$cy) ||
+            media_resize_imageGD($ext,$file,$cw,$ch,$local,$cw,$ch,$cx,$cy) ){
+        if($conf['fperm']) chmod($local, $conf['fperm']);
+        return media_resize_image($local,$ext, $w, $h);
     }
-  }
-  // calculate crop offset
-  $cx = (int) ($info[0]-$cw)/2;
-  $cy = (int) ($info[1]-$ch)/3;
-
-  //cache
-  $local = getCacheName($file,'.media.'.$cw.'x'.$ch.'.crop.'.$ext);
-  $mtime = @filemtime($local); // 0 if not exists
-
-  if( $mtime > filemtime($file) ||
-      media_crop_imageIM($ext,$file,$info[0],$info[1],$local,$cw,$ch,$cx,$cy) ||
-      media_resize_imageGD($ext,$file,$cw,$ch,$local,$cw,$ch,$cx,$cy) ){
-    if($conf['fperm']) chmod($local, $conf['fperm']);
-    return media_resize_image($local,$ext, $w, $h);
-  }
-
-  //still here? cropping failed
-  return media_resize_image($file,$ext, $w, $h);
+
+    //still here? cropping failed
+    return media_resize_image($file,$ext, $w, $h);
 }
 
 /**
@@ -894,31 +891,31 @@ function media_crop_image($file, $ext, $w, $h=0){
  * @author  Pavel Vitis <Pavel.Vitis@seznam.cz>
  */
 function media_get_from_URL($url,$ext,$cache){
-  global $conf;
+    global $conf;
 
-  // if no cache or fetchsize just redirect
-  if ($cache==0)           return false;
-  if (!$conf['fetchsize']) return false;
+    // if no cache or fetchsize just redirect
+    if ($cache==0)           return false;
+    if (!$conf['fetchsize']) return false;
 
-  $local = getCacheName(strtolower($url),".media.$ext");
-  $mtime = @filemtime($local); // 0 if not exists
+    $local = getCacheName(strtolower($url),".media.$ext");
+    $mtime = @filemtime($local); // 0 if not exists
 
-  //decide if download needed:
-  if( ($mtime == 0) ||                           // cache does not exist
-      ($cache != -1 && $mtime < time()-$cache)   // 'recache' and cache has expired
-    ){
-      if(media_image_download($url,$local)){
-        return $local;
-      }else{
-        return false;
-      }
-  }
+    //decide if download needed:
+    if( ($mtime == 0) ||                           // cache does not exist
+            ($cache != -1 && $mtime < time()-$cache)   // 'recache' and cache has expired
+      ){
+        if(media_image_download($url,$local)){
+            return $local;
+        }else{
+            return false;
+        }
+    }
 
-  //if cache exists use it else
-  if($mtime) return $local;
+    //if cache exists use it else
+    if($mtime) return $local;
 
-  //else return false
-  return false;
+    //else return false
+    return false;
 }
 
 /**
@@ -927,30 +924,30 @@ function media_get_from_URL($url,$ext,$cache){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function media_image_download($url,$file){
-  global $conf;
-  $http = new DokuHTTPClient();
-  $http->max_bodysize = $conf['fetchsize'];
-  $http->timeout = 25; //max. 25 sec
-  $http->header_regexp = '!\r\nContent-Type: image/(jpe?g|gif|png)!i';
-
-  $data = $http->get($url);
-  if(!$data) return false;
-
-  $fileexists = @file_exists($file);
-  $fp = @fopen($file,"w");
-  if(!$fp) return false;
-  fwrite($fp,$data);
-  fclose($fp);
-  if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
-
-  // check if it is really an image
-  $info = @getimagesize($file);
-  if(!$info){
-    @unlink($file);
-    return false;
-  }
+    global $conf;
+    $http = new DokuHTTPClient();
+    $http->max_bodysize = $conf['fetchsize'];
+    $http->timeout = 25; //max. 25 sec
+    $http->header_regexp = '!\r\nContent-Type: image/(jpe?g|gif|png)!i';
+
+    $data = $http->get($url);
+    if(!$data) return false;
+
+    $fileexists = @file_exists($file);
+    $fp = @fopen($file,"w");
+    if(!$fp) return false;
+    fwrite($fp,$data);
+    fclose($fp);
+    if(!$fileexists and $conf['fperm']) chmod($file, $conf['fperm']);
+
+    // check if it is really an image
+    $info = @getimagesize($file);
+    if(!$info){
+        @unlink($file);
+        return false;
+    }
 
-  return true;
+    return true;
 }
 
 /**
@@ -960,22 +957,22 @@ function media_image_download($url,$file){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function media_resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){
-  global $conf;
-
-  // check if convert is configured
-  if(!$conf['im_convert']) return false;
-
-  // prepare command
-  $cmd  = $conf['im_convert'];
-  $cmd .= ' -resize '.$to_w.'x'.$to_h.'!';
-  if ($ext == 'jpg' || $ext == 'jpeg') {
-      $cmd .= ' -quality '.$conf['jpg_quality'];
-  }
-  $cmd .= " $from $to";
-
-  @exec($cmd,$out,$retval);
-  if ($retval == 0) return true;
-  return false;
+    global $conf;
+
+    // check if convert is configured
+    if(!$conf['im_convert']) return false;
+
+    // prepare command
+    $cmd  = $conf['im_convert'];
+    $cmd .= ' -resize '.$to_w.'x'.$to_h.'!';
+    if ($ext == 'jpg' || $ext == 'jpeg') {
+        $cmd .= ' -quality '.$conf['jpg_quality'];
+    }
+    $cmd .= " $from $to";
+
+    @exec($cmd,$out,$retval);
+    if ($retval == 0) return true;
+    return false;
 }
 
 /**
@@ -984,22 +981,22 @@ function media_resize_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function media_crop_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x,$ofs_y){
-  global $conf;
-
-  // check if convert is configured
-  if(!$conf['im_convert']) return false;
-
-  // prepare command
-  $cmd  = $conf['im_convert'];
-  $cmd .= ' -crop '.$to_w.'x'.$to_h.'+'.$ofs_x.'+'.$ofs_y;
-  if ($ext == 'jpg' || $ext == 'jpeg') {
-      $cmd .= ' -quality '.$conf['jpg_quality'];
-  }
-  $cmd .= " $from $to";
-
-  @exec($cmd,$out,$retval);
-  if ($retval == 0) return true;
-  return false;
+    global $conf;
+
+    // check if convert is configured
+    if(!$conf['im_convert']) return false;
+
+    // prepare command
+    $cmd  = $conf['im_convert'];
+    $cmd .= ' -crop '.$to_w.'x'.$to_h.'+'.$ofs_x.'+'.$ofs_y;
+    if ($ext == 'jpg' || $ext == 'jpeg') {
+        $cmd .= ' -quality '.$conf['jpg_quality'];
+    }
+    $cmd .= " $from $to";
+
+    @exec($cmd,$out,$retval);
+    if ($retval == 0) return true;
+    return false;
 }
 
 /**
@@ -1009,98 +1006,98 @@ function media_crop_imageIM($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x,$o
  * @author Sebastian Wienecke <s_wienecke@web.de>
  */
 function media_resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h,$ofs_x=0,$ofs_y=0){
-  global $conf;
+    global $conf;
 
-  if($conf['gdlib'] < 1) return false; //no GDlib available or wanted
+    if($conf['gdlib'] < 1) return false; //no GDlib available or wanted
 
-  // check available memory
-  if(!is_mem_available(($from_w * $from_h * 4) + ($to_w * $to_h * 4))){
-    return false;
-  }
-
-  // create an image of the given filetype
-  if ($ext == 'jpg' || $ext == 'jpeg'){
-    if(!function_exists("imagecreatefromjpeg")) return false;
-    $image = @imagecreatefromjpeg($from);
-  }elseif($ext == 'png') {
-    if(!function_exists("imagecreatefrompng")) return false;
-    $image = @imagecreatefrompng($from);
-
-  }elseif($ext == 'gif') {
-    if(!function_exists("imagecreatefromgif")) return false;
-    $image = @imagecreatefromgif($from);
-  }
-  if(!$image) return false;
-
-  if(($conf['gdlib']>1) && function_exists("imagecreatetruecolor") && $ext != 'gif'){
-    $newimg = @imagecreatetruecolor ($to_w, $to_h);
-  }
-  if(!$newimg) $newimg = @imagecreate($to_w, $to_h);
-  if(!$newimg){
-    imagedestroy($image);
-    return false;
-  }
-
-  //keep png alpha channel if possible
-  if($ext == 'png' && $conf['gdlib']>1 && function_exists('imagesavealpha')){
-    imagealphablending($newimg, false);
-    imagesavealpha($newimg,true);
-  }
-
-  //keep gif transparent color if possible
-  if($ext == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) {
-    if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
-      $transcolorindex = @imagecolortransparent($image);
-      if($transcolorindex >= 0 ) { //transparent color exists
-        $transcolor = @imagecolorsforindex($image, $transcolorindex);
-        $transcolorindex = @imagecolorallocate($newimg, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
-        @imagefill($newimg, 0, 0, $transcolorindex);
-        @imagecolortransparent($newimg, $transcolorindex);
-      }else{ //filling with white
-        $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
-        @imagefill($newimg, 0, 0, $whitecolorindex);
-      }
-    }else{ //filling with white
-      $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
-      @imagefill($newimg, 0, 0, $whitecolorindex);
+    // check available memory
+    if(!is_mem_available(($from_w * $from_h * 4) + ($to_w * $to_h * 4))){
+        return false;
     }
-  }
 
-  //try resampling first
-  if(function_exists("imagecopyresampled")){
-    if(!@imagecopyresampled($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h)) {
-      imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
+    // create an image of the given filetype
+    if ($ext == 'jpg' || $ext == 'jpeg'){
+        if(!function_exists("imagecreatefromjpeg")) return false;
+        $image = @imagecreatefromjpeg($from);
+    }elseif($ext == 'png') {
+        if(!function_exists("imagecreatefrompng")) return false;
+        $image = @imagecreatefrompng($from);
+
+    }elseif($ext == 'gif') {
+        if(!function_exists("imagecreatefromgif")) return false;
+        $image = @imagecreatefromgif($from);
     }
-  }else{
-    imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
-  }
-
-  $okay = false;
-  if ($ext == 'jpg' || $ext == 'jpeg'){
-    if(!function_exists('imagejpeg')){
-      $okay = false;
-    }else{
-      $okay = imagejpeg($newimg, $to, $conf['jpg_quality']);
+    if(!$image) return false;
+
+    if(($conf['gdlib']>1) && function_exists("imagecreatetruecolor") && $ext != 'gif'){
+        $newimg = @imagecreatetruecolor ($to_w, $to_h);
     }
-  }elseif($ext == 'png') {
-    if(!function_exists('imagepng')){
-      $okay = false;
-    }else{
-      $okay =  imagepng($newimg, $to);
+    if(!$newimg) $newimg = @imagecreate($to_w, $to_h);
+    if(!$newimg){
+        imagedestroy($image);
+        return false;
     }
-  }elseif($ext == 'gif') {
-    if(!function_exists('imagegif')){
-      $okay = false;
+
+    //keep png alpha channel if possible
+    if($ext == 'png' && $conf['gdlib']>1 && function_exists('imagesavealpha')){
+        imagealphablending($newimg, false);
+        imagesavealpha($newimg,true);
+    }
+
+    //keep gif transparent color if possible
+    if($ext == 'gif' && function_exists('imagefill') && function_exists('imagecolorallocate')) {
+        if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
+            $transcolorindex = @imagecolortransparent($image);
+            if($transcolorindex >= 0 ) { //transparent color exists
+                $transcolor = @imagecolorsforindex($image, $transcolorindex);
+                $transcolorindex = @imagecolorallocate($newimg, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
+                @imagefill($newimg, 0, 0, $transcolorindex);
+                @imagecolortransparent($newimg, $transcolorindex);
+            }else{ //filling with white
+                $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
+                @imagefill($newimg, 0, 0, $whitecolorindex);
+            }
+        }else{ //filling with white
+            $whitecolorindex = @imagecolorallocate($newimg, 255, 255, 255);
+            @imagefill($newimg, 0, 0, $whitecolorindex);
+        }
+    }
+
+    //try resampling first
+    if(function_exists("imagecopyresampled")){
+        if(!@imagecopyresampled($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h)) {
+            imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
+        }
     }else{
-      $okay = imagegif($newimg, $to);
+        imagecopyresized($newimg, $image, 0, 0, $ofs_x, $ofs_y, $to_w, $to_h, $from_w, $from_h);
+    }
+
+    $okay = false;
+    if ($ext == 'jpg' || $ext == 'jpeg'){
+        if(!function_exists('imagejpeg')){
+            $okay = false;
+        }else{
+            $okay = imagejpeg($newimg, $to, $conf['jpg_quality']);
+        }
+    }elseif($ext == 'png') {
+        if(!function_exists('imagepng')){
+            $okay = false;
+        }else{
+            $okay =  imagepng($newimg, $to);
+        }
+    }elseif($ext == 'gif') {
+        if(!function_exists('imagegif')){
+            $okay = false;
+        }else{
+            $okay = imagegif($newimg, $to);
+        }
     }
-  }
 
-  // destroy GD image ressources
-  if($image) imagedestroy($image);
-  if($newimg) imagedestroy($newimg);
+    // destroy GD image ressources
+    if($image) imagedestroy($image);
+    if($newimg) imagedestroy($newimg);
 
-  return $okay;
+    return $okay;
 }
 
 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 65b140ea30d2c1dbcc2553c22adce11432579899..484516363e2d204e901f41589b60bdb738d7d2a3 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -19,68 +19,68 @@
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function getID($param='id',$clean=true){
-  global $conf;
-
-  $id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null;
-
-  $request = $_SERVER['REQUEST_URI'];
-
-  //construct page id from request URI
-  if(empty($id) && $conf['userewrite'] == 2){
-    //get the script URL
-    if($conf['basedir']){
-      $relpath = '';
-      if($param != 'id') {
-        $relpath = 'lib/exe/';
-      }
-      $script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']);
-
-    }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['PATH_TRANSLATED']){
-      $request = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
-                              $_SERVER['PATH_TRANSLATED']);
-    }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
-      $script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
-                              $_SERVER['SCRIPT_FILENAME']);
-      $script = '/'.$script;
-    }else{
-      $script = $_SERVER['SCRIPT_NAME'];
-    }
+    global $conf;
 
-    //clean script and request (fixes a windows problem)
-    $script  = preg_replace('/\/\/+/','/',$script);
-    $request = preg_replace('/\/\/+/','/',$request);
+    $id = isset($_REQUEST[$param]) ? $_REQUEST[$param] : null;
+
+    $request = $_SERVER['REQUEST_URI'];
+
+    //construct page id from request URI
+    if(empty($id) && $conf['userewrite'] == 2){
+        //get the script URL
+        if($conf['basedir']){
+            $relpath = '';
+            if($param != 'id') {
+                $relpath = 'lib/exe/';
+            }
+            $script = $conf['basedir'].$relpath.basename($_SERVER['SCRIPT_FILENAME']);
+
+        }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['PATH_TRANSLATED']){
+            $request = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
+                    $_SERVER['PATH_TRANSLATED']);
+        }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
+            $script = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
+                    $_SERVER['SCRIPT_FILENAME']);
+            $script = '/'.$script;
+        }else{
+            $script = $_SERVER['SCRIPT_NAME'];
+        }
+
+        //clean script and request (fixes a windows problem)
+        $script  = preg_replace('/\/\/+/','/',$script);
+        $request = preg_replace('/\/\/+/','/',$request);
 
-    //remove script URL and Querystring to gain the id
-    if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){
-      $id = preg_replace ('/\?.*/','',$match[1]);
+        //remove script URL and Querystring to gain the id
+        if(preg_match('/^'.preg_quote($script,'/').'(.*)/',$request, $match)){
+            $id = preg_replace ('/\?.*/','',$match[1]);
+        }
+        $id = urldecode($id);
+        //strip leading slashes
+        $id = preg_replace('!^/+!','',$id);
     }
-    $id = urldecode($id);
-    //strip leading slashes
-    $id = preg_replace('!^/+!','',$id);
-  }
-
-  // Namespace autolinking from URL
-  if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){
-    if(page_exists($id.$conf['start'])){
-      // start page inside namespace
-      $id = $id.$conf['start'];
-    }elseif(page_exists($id.noNS(cleanID($id)))){
-      // page named like the NS inside the NS
-      $id = $id.noNS(cleanID($id));
-    }elseif(page_exists($id)){
-      // page like namespace exists
-      $id = substr($id,0,-1);
-    }else{
-      // fall back to default
-      $id = $id.$conf['start'];
+
+    // Namespace autolinking from URL
+    if(substr($id,-1) == ':' || ($conf['useslash'] && substr($id,-1) == '/')){
+        if(page_exists($id.$conf['start'])){
+            // start page inside namespace
+            $id = $id.$conf['start'];
+        }elseif(page_exists($id.noNS(cleanID($id)))){
+            // page named like the NS inside the NS
+            $id = $id.noNS(cleanID($id));
+        }elseif(page_exists($id)){
+            // page like namespace exists
+            $id = substr($id,0,-1);
+        }else{
+            // fall back to default
+            $id = $id.$conf['start'];
+        }
+        send_redirect(wl($id,'',true));
     }
-    send_redirect(wl($id,'',true));
-  }
 
-  if($clean) $id = cleanID($id);
-  if(empty($id) && $param=='id') $id = $conf['start'];
+    if($clean) $id = cleanID($id);
+    if(empty($id) && $param=='id') $id = $conf['start'];
 
-  return $id;
+    return $id;
 }
 
 /**
@@ -95,49 +95,49 @@ function getID($param='id',$clean=true){
  * @param  boolean $media     Allow leading or trailing _ for media files
  */
 function cleanID($raw_id,$ascii=false,$media=false){
-  global $conf;
-  global $lang;
-  static $sepcharpat = null;
+    global $conf;
+    global $lang;
+    static $sepcharpat = null;
 
-  global $cache_cleanid;
-  $cache = & $cache_cleanid;
+    global $cache_cleanid;
+    $cache = & $cache_cleanid;
 
-  // check if it's already in the memory cache
-  if (isset($cache[(string)$raw_id])) {
-    return $cache[(string)$raw_id];
+    // check if it's already in the memory cache
+    if (isset($cache[(string)$raw_id])) {
+        return $cache[(string)$raw_id];
     }
 
-  $sepchar = $conf['sepchar'];
-  if($sepcharpat == null) // build string only once to save clock cycles
-    $sepcharpat = '#\\'.$sepchar.'+#';
+    $sepchar = $conf['sepchar'];
+    if($sepcharpat == null) // build string only once to save clock cycles
+        $sepcharpat = '#\\'.$sepchar.'+#';
 
-  $id = trim((string)$raw_id);
-  $id = utf8_strtolower($id);
+    $id = trim((string)$raw_id);
+    $id = utf8_strtolower($id);
 
-  //alternative namespace seperator
-  $id = strtr($id,';',':');
-  if($conf['useslash']){
-    $id = strtr($id,'/',':');
-  }else{
-    $id = strtr($id,'/',$sepchar);
-  }
+    //alternative namespace seperator
+    $id = strtr($id,';',':');
+    if($conf['useslash']){
+        $id = strtr($id,'/',':');
+    }else{
+        $id = strtr($id,'/',$sepchar);
+    }
 
-  if($conf['deaccent'] == 2 || $ascii) $id = utf8_romanize($id);
-  if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,-1);
+    if($conf['deaccent'] == 2 || $ascii) $id = utf8_romanize($id);
+    if($conf['deaccent'] || $ascii) $id = utf8_deaccent($id,-1);
 
-  //remove specials
-  $id = utf8_stripspecials($id,$sepchar,'\*');
+    //remove specials
+    $id = utf8_stripspecials($id,$sepchar,'\*');
 
-  if($ascii) $id = utf8_strip($id);
+    if($ascii) $id = utf8_strip($id);
 
-  //clean up
-  $id = preg_replace($sepcharpat,$sepchar,$id);
-  $id = preg_replace('#:+#',':',$id);
-  $id = ($media ? trim($id,':.-') : trim($id,':._-'));
-  $id = preg_replace('#:[:\._\-]+#',':',$id);
+    //clean up
+    $id = preg_replace($sepcharpat,$sepchar,$id);
+    $id = preg_replace('#:+#',':',$id);
+    $id = ($media ? trim($id,':.-') : trim($id,':._-'));
+    $id = preg_replace('#:[:\._\-]+#',':',$id);
 
-  $cache[(string)$raw_id] = $id;
-  return($id);
+    $cache[(string)$raw_id] = $id;
+    return($id);
 }
 
 /**
@@ -146,11 +146,11 @@ function cleanID($raw_id,$ascii=false,$media=false){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function getNS($id){
-  $pos = strrpos((string)$id,':');
-  if($pos!==false){
-    return substr((string)$id,0,$pos);
-  }
-  return false;
+    $pos = strrpos((string)$id,':');
+    if($pos!==false){
+        return substr((string)$id,0,$pos);
+    }
+    return false;
 }
 
 /**
@@ -159,12 +159,12 @@ function getNS($id){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function noNS($id) {
-  $pos = strrpos($id, ':');
-  if ($pos!==false) {
-    return substr($id, $pos+1);
-  } else {
-    return $id;
-  }
+    $pos = strrpos($id, ':');
+    if ($pos!==false) {
+        return substr($id, $pos+1);
+    } else {
+        return $id;
+    }
 }
 
 /**
@@ -225,14 +225,14 @@ function sectionID($title,&$check) {
 
 
 /**
- *  Wiki page existence check
+ * Wiki page existence check
  *
- *  parameters as for wikiFN
+ * parameters as for wikiFN
  *
- *  @author Chris Smith <chris@jalakai.co.uk>
+ * @author Chris Smith <chris@jalakai.co.uk>
  */
 function page_exists($id,$rev='',$clean=true) {
-  return @file_exists(wikiFN($id,$rev,$clean));
+    return @file_exists(wikiFN($id,$rev,$clean));
 }
 
 /**
@@ -248,39 +248,39 @@ function page_exists($id,$rev='',$clean=true) {
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function wikiFN($raw_id,$rev='',$clean=true){
-  global $conf;
-
-  global $cache_wikifn;
-  $cache = & $cache_wikifn;
-
-  if (isset($cache[$raw_id]) && isset($cache[$raw_id][$rev])) {
-    return $cache[$raw_id][$rev];
-  }
-
-  $id = $raw_id;
-
-  if ($clean) $id = cleanID($id);
-  $id = str_replace(':','/',$id);
-  if(empty($rev)){
-    $fn = $conf['datadir'].'/'.utf8_encodeFN($id).'.txt';
-  }else{
-    $fn = $conf['olddir'].'/'.utf8_encodeFN($id).'.'.$rev.'.txt';
-    if($conf['compression']){
-      //test for extensions here, we want to read both compressions
-       if (@file_exists($fn . '.gz')){
-          $fn .= '.gz';
-       }else if(@file_exists($fn . '.bz2')){
-          $fn .= '.bz2';
-       }else{
-          //file doesnt exist yet, so we take the configured extension
-          $fn .= '.' . $conf['compression'];
-       }
+    global $conf;
+
+    global $cache_wikifn;
+    $cache = & $cache_wikifn;
+
+    if (isset($cache[$raw_id]) && isset($cache[$raw_id][$rev])) {
+        return $cache[$raw_id][$rev];
     }
-  }
 
-  if (!isset($cache[$raw_id])) { $cache[$raw_id] = array(); }
-  $cache[$raw_id][$rev] = $fn;
-  return $fn;
+    $id = $raw_id;
+
+    if ($clean) $id = cleanID($id);
+    $id = str_replace(':','/',$id);
+    if(empty($rev)){
+        $fn = $conf['datadir'].'/'.utf8_encodeFN($id).'.txt';
+    }else{
+        $fn = $conf['olddir'].'/'.utf8_encodeFN($id).'.'.$rev.'.txt';
+        if($conf['compression']){
+            //test for extensions here, we want to read both compressions
+            if (@file_exists($fn . '.gz')){
+                $fn .= '.gz';
+            }else if(@file_exists($fn . '.bz2')){
+                $fn .= '.bz2';
+            }else{
+                //file doesnt exist yet, so we take the configured extension
+                $fn .= '.' . $conf['compression'];
+            }
+        }
+    }
+
+    if (!isset($cache[$raw_id])) { $cache[$raw_id] = array(); }
+    $cache[$raw_id][$rev] = $fn;
+    return $fn;
 }
 
 /**
@@ -289,8 +289,8 @@ function wikiFN($raw_id,$rev='',$clean=true){
  * @author Ben Coburn <btcoburn@silicodon.net>
  */
 function wikiLockFN($id) {
-  global $conf;
-  return $conf['lockdir'].'/'.md5(cleanID($id)).'.lock';
+    global $conf;
+    return $conf['lockdir'].'/'.md5(cleanID($id)).'.lock';
 }
 
 
@@ -302,11 +302,11 @@ function wikiLockFN($id) {
  * @author Steven Danz <steven-danz@kc.rr.com>
  */
 function metaFN($id,$ext){
-  global $conf;
-  $id = cleanID($id);
-  $id = str_replace(':','/',$id);
-  $fn = $conf['metadir'].'/'.utf8_encodeFN($id).$ext;
-  return $fn;
+    global $conf;
+    $id = cleanID($id);
+    $id = str_replace(':','/',$id);
+    $fn = $conf['metadir'].'/'.utf8_encodeFN($id).$ext;
+    return $fn;
 }
 
 /**
@@ -315,20 +315,20 @@ function metaFN($id,$ext){
  * @author Esther Brunner <esther@kaffeehaus.ch>
  */
 function metaFiles($id){
-   $name   = noNS($id);
-   $ns     = getNS($id);
-   $dir    = ($ns) ? metaFN($ns,'').'/' : metaFN($ns,'');
-   $files  = array();
-
-   $dh = @opendir($dir);
-   if(!$dh) return $files;
-   while(($file = readdir($dh)) !== false){
-     if(strpos($file,$name.'.') === 0 && !is_dir($dir.$file))
-       $files[] = $dir.$file;
-   }
-   closedir($dh);
-
-   return $files;
+    $name   = noNS($id);
+    $ns     = getNS($id);
+    $dir    = ($ns) ? metaFN($ns,'').'/' : metaFN($ns,'');
+    $files  = array();
+
+    $dh = @opendir($dir);
+    if(!$dh) return $files;
+    while(($file = readdir($dh)) !== false){
+        if(strpos($file,$name.'.') === 0 && !is_dir($dir.$file))
+            $files[] = $dir.$file;
+    }
+    closedir($dh);
+
+    return $files;
 }
 
 /**
@@ -339,11 +339,11 @@ function metaFiles($id){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function mediaFN($id){
-  global $conf;
-  $id = cleanID($id);
-  $id = str_replace(':','/',$id);
+    global $conf;
+    $id = cleanID($id);
+    $id = str_replace(':','/',$id);
     $fn = $conf['mediadir'].'/'.utf8_encodeFN($id);
-  return $fn;
+    return $fn;
 }
 
 /**
@@ -353,13 +353,13 @@ function mediaFN($id){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function localeFN($id){
-  global $conf;
-  $file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.txt';
-  if(!@file_exists($file)){
-    //fall back to english
-    $file = DOKU_INC.'inc/lang/en/'.$id.'.txt';
-  }
-  return $file;
+    global $conf;
+    $file = DOKU_INC.'inc/lang/'.$conf['lang'].'/'.$id.'.txt';
+    if(!@file_exists($file)){
+        //fall back to english
+        $file = DOKU_INC.'inc/lang/en/'.$id.'.txt';
+    }
+    return $file;
 }
 
 /**
@@ -374,43 +374,43 @@ function localeFN($id){
  * @author <bart at mediawave dot nl>
  */
 function resolve_id($ns,$id,$clean=true){
-  global $conf;
-
-  // some pre cleaning for useslash:
-  if($conf['useslash']) $id = str_replace('/',':',$id);
-
-  // if the id starts with a dot we need to handle the
-  // relative stuff
-  if($id{0} == '.'){
-    // normalize initial dots without a colon
-    $id = preg_replace('/^(\.+)(?=[^:\.])/','\1:',$id);
-    // prepend the current namespace
-    $id = $ns.':'.$id;
-
-    // cleanup relatives
-    $result = array();
-    $pathA  = explode(':', $id);
-    if (!$pathA[0]) $result[] = '';
-    foreach ($pathA AS $key => $dir) {
-      if ($dir == '..') {
-        if (end($result) == '..') {
-          $result[] = '..';
-        } elseif (!array_pop($result)) {
-          $result[] = '..';
+    global $conf;
+
+    // some pre cleaning for useslash:
+    if($conf['useslash']) $id = str_replace('/',':',$id);
+
+    // if the id starts with a dot we need to handle the
+    // relative stuff
+    if($id{0} == '.'){
+        // normalize initial dots without a colon
+        $id = preg_replace('/^(\.+)(?=[^:\.])/','\1:',$id);
+        // prepend the current namespace
+        $id = $ns.':'.$id;
+
+        // cleanup relatives
+        $result = array();
+        $pathA  = explode(':', $id);
+        if (!$pathA[0]) $result[] = '';
+        foreach ($pathA AS $key => $dir) {
+            if ($dir == '..') {
+                if (end($result) == '..') {
+                    $result[] = '..';
+                } elseif (!array_pop($result)) {
+                    $result[] = '..';
+                }
+            } elseif ($dir && $dir != '.') {
+                $result[] = $dir;
+            }
         }
-      } elseif ($dir && $dir != '.') {
-        $result[] = $dir;
-      }
+        if (!end($pathA)) $result[] = '';
+        $id = implode(':', $result);
+    }elseif($ns !== false && strpos($id,':') === false){
+        //if link contains no namespace. add current namespace (if any)
+        $id = $ns.':'.$id;
     }
-    if (!end($pathA)) $result[] = '';
-    $id = implode(':', $result);
-  }elseif($ns !== false && strpos($id,':') === false){
-    //if link contains no namespace. add current namespace (if any)
-    $id = $ns.':'.$id;
-  }
-
-  if($clean) $id = cleanID($id);
-  return $id;
+
+    if($clean) $id = cleanID($id);
+    return $id;
 }
 
 /**
@@ -419,9 +419,9 @@ function resolve_id($ns,$id,$clean=true){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function resolve_mediaid($ns,&$page,&$exists){
-  $page   = resolve_id($ns,$page);
-  $file   = mediaFN($page);
-  $exists = @file_exists($file);
+    $page   = resolve_id($ns,$page);
+    $file   = mediaFN($page);
+    $exists = @file_exists($file);
 }
 
 /**
@@ -430,63 +430,63 @@ function resolve_mediaid($ns,&$page,&$exists){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function resolve_pageid($ns,&$page,&$exists){
-  global $conf;
-  $exists = false;
-
-  //keep hashlink if exists then clean both parts
-  if (strpos($page,'#')) {
-    list($page,$hash) = explode('#',$page,2);
-  } else {
-    $hash = '';
-  }
-  $hash = cleanID($hash);
-  $page = resolve_id($ns,$page,false); // resolve but don't clean, yet
-
-  // get filename (calls clean itself)
-  $file = wikiFN($page);
-
-  // if ends with colon or slash we have a namespace link
-  if(substr($page,-1) == ':' || ($conf['useslash'] && substr($page,-1) == '/')){
-    if(page_exists($page.$conf['start'])){
-      // start page inside namespace
-      $page = $page.$conf['start'];
-      $exists = true;
-    }elseif(page_exists($page.noNS(cleanID($page)))){
-      // page named like the NS inside the NS
-      $page = $page.noNS(cleanID($page));
-      $exists = true;
-    }elseif(page_exists($page)){
-      // page like namespace exists
-      $page = $page;
-      $exists = true;
-    }else{
-      // fall back to default
-      $page = $page.$conf['start'];
+    global $conf;
+    $exists = false;
+
+    //keep hashlink if exists then clean both parts
+    if (strpos($page,'#')) {
+        list($page,$hash) = explode('#',$page,2);
+    } else {
+        $hash = '';
     }
-  }else{
-    //check alternative plural/nonplural form
-    if(!@file_exists($file)){
-      if( $conf['autoplural'] ){
-        if(substr($page,-1) == 's'){
-          $try = substr($page,0,-1);
+    $hash = cleanID($hash);
+    $page = resolve_id($ns,$page,false); // resolve but don't clean, yet
+
+    // get filename (calls clean itself)
+    $file = wikiFN($page);
+
+    // if ends with colon or slash we have a namespace link
+    if(substr($page,-1) == ':' || ($conf['useslash'] && substr($page,-1) == '/')){
+        if(page_exists($page.$conf['start'])){
+            // start page inside namespace
+            $page = $page.$conf['start'];
+            $exists = true;
+        }elseif(page_exists($page.noNS(cleanID($page)))){
+            // page named like the NS inside the NS
+            $page = $page.noNS(cleanID($page));
+            $exists = true;
+        }elseif(page_exists($page)){
+            // page like namespace exists
+            $page = $page;
+            $exists = true;
         }else{
-          $try = $page.'s';
-        }
-        if(page_exists($try)){
-          $page   = $try;
-          $exists = true;
+            // fall back to default
+            $page = $page.$conf['start'];
         }
-      }
     }else{
-      $exists = true;
+        //check alternative plural/nonplural form
+        if(!@file_exists($file)){
+            if( $conf['autoplural'] ){
+                if(substr($page,-1) == 's'){
+                    $try = substr($page,0,-1);
+                }else{
+                    $try = $page.'s';
+                }
+                if(page_exists($try)){
+                    $page   = $try;
+                    $exists = true;
+                }
+            }
+        }else{
+            $exists = true;
+        }
     }
-  }
 
-  // now make sure we have a clean page
-  $page = cleanID($page);
+    // now make sure we have a clean page
+    $page = cleanID($page);
 
-  //add hash if any
-  if(!empty($hash)) $page .= '#'.$hash;
+    //add hash if any
+    if(!empty($hash)) $page .= '#'.$hash;
 }
 
 /**
@@ -501,11 +501,11 @@ function resolve_pageid($ns,&$page,&$exists){
  * @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;
+    global $conf;
+    $md5  = md5($data);
+    $file = $conf['cachedir'].'/'.$md5{0}.'/'.$md5.$ext;
+    io_makeFileDir($file);
+    return $file;
 }
 
 /**
@@ -514,15 +514,15 @@ function getCacheName($data,$ext=''){
  * @author Andreas Gohr <gohr@cosmocode.de>
  */
 function isHiddenPage($id){
-  global $conf;
-  global $ACT;
-  if(empty($conf['hidepages'])) return false;
-  if($ACT == 'admin') return false;
-
-  if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){
-    return true;
-  }
-  return false;
+    global $conf;
+    global $ACT;
+    if(empty($conf['hidepages'])) return false;
+    if($ACT == 'admin') return false;
+
+    if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){
+        return true;
+    }
+    return false;
 }
 
 /**
@@ -531,8 +531,7 @@ function isHiddenPage($id){
  * @author Andreas Gohr <gohr@cosmocode.de>
  */
 function isVisiblePage($id){
-  return !isHiddenPage($id);
+    return !isHiddenPage($id);
 }
 
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 7887e7a3ebc08c3bb51507bb3a99b4da063022a2..d17ffaa432200f02fcecb5351ce97a5ae895c968 100644
--- a/inc/parserutils.php
+++ b/inc/parserutils.php
@@ -22,32 +22,32 @@ require_once(DOKU_INC.'inc/cache.php');
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_wiki_xhtml($id, $rev='', $excuse=true){
-  $file = wikiFN($id,$rev);
-  $ret  = '';
-
-  //ensure $id is in global $ID (needed for parsing)
-  global $ID;
-  $keep = $ID;
-  $ID   = $id;
-
-  if($rev){
-    if(@file_exists($file)){
-      $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions
-    }elseif($excuse){
-      $ret = p_locale_xhtml('norev');
-    }
-  }else{
-    if(@file_exists($file)){
-      $ret = p_cached_output($file,'xhtml',$id);
-    }elseif($excuse){
-      $ret = p_locale_xhtml('newpage');
+    $file = wikiFN($id,$rev);
+    $ret  = '';
+
+    //ensure $id is in global $ID (needed for parsing)
+    global $ID;
+    $keep = $ID;
+    $ID   = $id;
+
+    if($rev){
+        if(@file_exists($file)){
+            $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info); //no caching on old revisions
+        }elseif($excuse){
+            $ret = p_locale_xhtml('norev');
+        }
+    }else{
+        if(@file_exists($file)){
+            $ret = p_cached_output($file,'xhtml',$id);
+        }elseif($excuse){
+            $ret = p_locale_xhtml('newpage');
+        }
     }
-  }
 
-  //restore ID (just in case)
-  $ID = $keep;
+    //restore ID (just in case)
+    $ID = $keep;
 
-  return $ret;
+    return $ret;
 }
 
 /**
@@ -63,48 +63,48 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){
  * @author Harry Fuecks <hfuecks@gmail.com>
  */
 function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){
-  $file = wikiFN($id,$rev);
-  $ret  = '';
+    $file = wikiFN($id,$rev);
+    $ret  = '';
+
+    //ensure $id is in global $ID (needed for parsing)
+    global $ID;
+    $keep = $ID;
+    $ID   = $id;
+
+    if($rev){
+        if(@file_exists($file)){
+            //no caching on old revisions
+            $ins = p_get_instructions(io_readWikiPage($file,$id,$rev));
+        }elseif($excuse){
+            $ret = p_locale_xhtml('norev');
+            //restore ID (just in case)
+            $ID = $keep;
+            return $ret;
+        }
 
-  //ensure $id is in global $ID (needed for parsing)
-  global $ID;
-  $keep = $ID;
-  $ID   = $id;
+    }else{
 
-  if($rev){
-    if(@file_exists($file)){
-      //no caching on old revisions
-      $ins = p_get_instructions(io_readWikiPage($file,$id,$rev));
-    }elseif($excuse){
-      $ret = p_locale_xhtml('norev');
-      //restore ID (just in case)
-      $ID = $keep;
-      return $ret;
+        if(@file_exists($file)){
+            // The XHTML for a summary is not cached so use the instruction cache
+            $ins = p_cached_instructions($file);
+        }elseif($excuse){
+            $ret = p_locale_xhtml('newpage');
+            //restore ID (just in case)
+            $ID = $keep;
+            return $ret;
+        }
     }
 
-  }else{
+    $ret = p_render('xhtmlsummary',$ins,$info);
 
-    if(@file_exists($file)){
-      // The XHTML for a summary is not cached so use the instruction cache
-      $ins = p_cached_instructions($file);
-    }elseif($excuse){
-      $ret = p_locale_xhtml('newpage');
-      //restore ID (just in case)
-      $ID = $keep;
-      return $ret;
+    if ( $info['sum_pagetitle'] ) {
+        $title = $info['sum_pagetitle'];
+    } else {
+        $title = $id;
     }
-  }
-
-  $ret = p_render('xhtmlsummary',$ins,$info);
-
-  if ( $info['sum_pagetitle'] ) {
-    $title = $info['sum_pagetitle'];
-  } else {
-    $title = $id;
-  }
 
-  $ID = $keep;
-  return $ret;
+    $ID = $keep;
+    return $ret;
 }
 
 /**
@@ -113,9 +113,9 @@ function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_locale_xhtml($id){
-  //fetch parsed locale
-  $html = p_cached_output(localeFN($id));
-  return $html;
+    //fetch parsed locale
+    $html = p_cached_output(localeFN($id));
+    return $html;
 }
 
 /**
@@ -132,7 +132,7 @@ function p_locale_xhtml($id){
  * @todo   rewrite to use mode instead of hardcoded XHTML
  */
 function p_cached_xhtml($file){
-  return p_cached_output($file);
+    return p_cached_output($file);
 }
 
 /**
@@ -142,25 +142,25 @@ function p_cached_xhtml($file){
  * @author Chris Smith <chris@jalakai.co.uk>
  */
 function p_cached_output($file, $format='xhtml', $id='') {
-  global $conf;
-
-  $cache = new cache_renderer($id, $file, $format);
-  if ($cache->useCache()) {
-    $parsed = $cache->retrieveCache(false);
-    if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n";
-  } else {
-    $parsed = p_render($format, p_cached_instructions($file,false,$id), $info);
-
-    if ($info['cache']) {
-      $cache->storeCache($parsed);               //save cachefile
-      if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, but created {$cache->cache} -->\n";
-    }else{
-      $cache->removeCache();                     //try to delete cachefile
-      if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
+    global $conf;
+
+    $cache = new cache_renderer($id, $file, $format);
+    if ($cache->useCache()) {
+        $parsed = $cache->retrieveCache(false);
+        if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- cachefile {$cache->cache} used -->\n";
+    } else {
+        $parsed = p_render($format, p_cached_instructions($file,false,$id), $info);
+
+        if ($info['cache']) {
+            $cache->storeCache($parsed);               //save cachefile
+            if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, but created {$cache->cache} -->\n";
+        }else{
+            $cache->removeCache();                     //try to delete cachefile
+            if($conf['allowdebug'] && $format=='xhtml') $parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
+        }
     }
-  }
 
-  return $parsed;
+    return $parsed;
 }
 
 /**
@@ -171,26 +171,26 @@ function p_cached_output($file, $format='xhtml', $id='') {
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_cached_instructions($file,$cacheonly=false,$id='') {
-  global $conf;
-  static $run = null;
-  if(is_null($run)) $run = array();
-
-  $cache = new cache_instructions($id, $file);
-
-  if ($cacheonly || $cache->useCache() || isset($run[$file])) {
-    return $cache->retrieveCache();
-  } else if (@file_exists($file)) {
-    // no cache - do some work
-    $ins = p_get_instructions(io_readWikiPage($file,$id));
-    if ($cache->storeCache($ins)) {
-      $run[$file] = true; // we won't rebuild these instructions in the same run again
-    } else {
-      msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1);
+    global $conf;
+    static $run = null;
+    if(is_null($run)) $run = array();
+
+    $cache = new cache_instructions($id, $file);
+
+    if ($cacheonly || $cache->useCache() || isset($run[$file])) {
+        return $cache->retrieveCache();
+    } else if (@file_exists($file)) {
+        // no cache - do some work
+        $ins = p_get_instructions(io_readWikiPage($file,$id));
+        if ($cache->storeCache($ins)) {
+            $run[$file] = true; // we won't rebuild these instructions in the same run again
+        } else {
+            msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.',-1);
+        }
+        return $ins;
     }
-    return $ins;
-  }
 
-  return null;
+    return null;
 }
 
 /**
@@ -201,24 +201,24 @@ function p_cached_instructions($file,$cacheonly=false,$id='') {
  */
 function p_get_instructions($text){
 
-  $modes = p_get_parsermodes();
+    $modes = p_get_parsermodes();
 
-  // Create the parser
-  $Parser = & new Doku_Parser();
+    // Create the parser
+    $Parser = & new Doku_Parser();
 
-  // Add the Handler
-  $Parser->Handler = & new Doku_Handler();
+    // Add the Handler
+    $Parser->Handler = & new Doku_Handler();
 
-  //add modes to parser
-  foreach($modes as $mode){
-    $Parser->addMode($mode['mode'],$mode['obj']);
-  }
+    //add modes to parser
+    foreach($modes as $mode){
+        $Parser->addMode($mode['mode'],$mode['obj']);
+    }
 
-  // Do the parsing
-  trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
-  $p = $Parser->parse($text);
-//  dbg($p);
-  return $p;
+    // Do the parsing
+    trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
+    $p = $Parser->parse($text);
+    //  dbg($p);
+    return $p;
 }
 
 /**
@@ -227,37 +227,37 @@ function p_get_instructions($text){
  * @author Esther Brunner <esther@kaffeehaus.ch>
  */
 function p_get_metadata($id, $key=false, $render=false){
-  global $ID, $INFO, $cache_metadata;
-
-  // cache the current page
-  // Benchmarking shows the current page's metadata is generally the only page metadata
-  // accessed several times. This may catch a few other pages, but that shouldn't be an issue.
-  $cache = ($ID == $id);
-  $meta = p_read_metadata($id, $cache);
-
-  // metadata has never been rendered before - do it! (but not for non-existent pages)
-  if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){
-    $meta = p_render_metadata($id, $meta);
-    io_saveFile(metaFN($id, '.meta'), serialize($meta));
+    global $ID, $INFO, $cache_metadata;
+
+    // cache the current page
+    // Benchmarking shows the current page's metadata is generally the only page metadata
+    // accessed several times. This may catch a few other pages, but that shouldn't be an issue.
+    $cache = ($ID == $id);
+    $meta = p_read_metadata($id, $cache);
+
+    // metadata has never been rendered before - do it! (but not for non-existent pages)
+    if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){
+        $meta = p_render_metadata($id, $meta);
+        io_saveFile(metaFN($id, '.meta'), serialize($meta));
+
+        // sync cached copies, including $INFO metadata
+        if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
+        if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
+    }
 
-    // sync cached copies, including $INFO metadata
-    if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
-    if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
-  }
+    // filter by $key
+    if ($key){
+        list($key, $subkey) = explode(' ', $key, 2);
+        $subkey = trim($subkey);
 
-  // filter by $key
-  if ($key){
-    list($key, $subkey) = explode(' ', $key, 2);
-    $subkey = trim($subkey);
+        if ($subkey) {
+            return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null;
+        }
 
-    if ($subkey) {
-      return isset($meta['current'][$key][$subkey]) ? $meta['current'][$key][$subkey] : null;
+        return isset($meta['current'][$key]) ? $meta['current'][$key] : null;
     }
 
-    return isset($meta['current'][$key]) ? $meta['current'][$key] : null;
-  }
-
-  return $meta['current'];
+    return $meta['current'];
 }
 
 /**
@@ -266,59 +266,59 @@ function p_get_metadata($id, $key=false, $render=false){
  * @author Esther Brunner <esther@kaffeehaus.ch>
  */
 function p_set_metadata($id, $data, $render=false, $persistent=true){
-  if (!is_array($data)) return false;
+    if (!is_array($data)) return false;
 
-  global $ID;
+    global $ID;
 
-  // cache the current page
-  $cache = ($ID == $id);
-  $orig = p_read_metadata($id, $cache);
+    // cache the current page
+    $cache = ($ID == $id);
+    $orig = p_read_metadata($id, $cache);
 
-  // render metadata first?
-  $meta = $render ? p_render_metadata($id, $orig) : $orig;
+    // render metadata first?
+    $meta = $render ? p_render_metadata($id, $orig) : $orig;
 
-  // now add the passed metadata
-  $protected = array('description', 'date', 'contributor');
-  foreach ($data as $key => $value){
+    // now add the passed metadata
+    $protected = array('description', 'date', 'contributor');
+    foreach ($data as $key => $value){
 
-    // be careful with sub-arrays of $meta['relation']
-    if ($key == 'relation'){
+        // be careful with sub-arrays of $meta['relation']
+        if ($key == 'relation'){
 
-      foreach ($value as $subkey => $subvalue){
-        $meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue;
-        if ($persistent)
-          $meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue;
-      }
+            foreach ($value as $subkey => $subvalue){
+                $meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue;
+                if ($persistent)
+                    $meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue;
+            }
 
-    // be careful with some senisitive arrays of $meta
-    } elseif (in_array($key, $protected)){
+            // be careful with some senisitive arrays of $meta
+        } elseif (in_array($key, $protected)){
 
-      // these keys, must have subkeys - a legitimate value must be an array
-      if (is_array($value)) {
-        $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value;
+            // these keys, must have subkeys - a legitimate value must be an array
+            if (is_array($value)) {
+                $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value;
 
-        if ($persistent) {
-          $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value;
-        }
-      }
+                if ($persistent) {
+                    $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value;
+                }
+            }
 
-    // no special treatment for the rest
-    } else {
-      $meta['current'][$key] = $value;
-      if ($persistent) $meta['persistent'][$key] = $value;
+            // no special treatment for the rest
+        } else {
+            $meta['current'][$key] = $value;
+            if ($persistent) $meta['persistent'][$key] = $value;
+        }
     }
-  }
 
-  // save only if metadata changed
-  if ($meta == $orig) return true;
+    // save only if metadata changed
+    if ($meta == $orig) return true;
 
-  // sync cached copies, including $INFO metadata
-  global $cache_metadata, $INFO;
+    // sync cached copies, including $INFO metadata
+    global $cache_metadata, $INFO;
 
-  if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
-  if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
+    if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
+    if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
 
-  return io_saveFile(metaFN($id, '.meta'), serialize($meta));
+    return io_saveFile(metaFN($id, '.meta'), serialize($meta));
 }
 
 /**
@@ -356,38 +356,38 @@ function p_purge_metadata($id) {
  * @return   array             metadata
  */
 function p_read_metadata($id,$cache=false) {
-  global $cache_metadata;
+    global $cache_metadata;
 
-  if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id];
+    if (isset($cache_metadata[(string)$id])) return $cache_metadata[(string)$id];
 
-  $file = metaFN($id, '.meta');
-  $meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array());
+    $file = metaFN($id, '.meta');
+    $meta = @file_exists($file) ? unserialize(io_readFile($file, false)) : array('current'=>array(),'persistent'=>array());
 
-  // convert $meta from old format to new (current+persistent) format
-  if (!isset($meta['current'])) {
-    $meta = array('current'=>$meta,'persistent'=>$meta);
+    // convert $meta from old format to new (current+persistent) format
+    if (!isset($meta['current'])) {
+        $meta = array('current'=>$meta,'persistent'=>$meta);
 
-    // remove non-persistent keys
-    unset($meta['persistent']['title']);
-    unset($meta['persistent']['description']['abstract']);
-    unset($meta['persistent']['description']['tableofcontents']);
-    unset($meta['persistent']['relation']['haspart']);
-    unset($meta['persistent']['relation']['references']);
-    unset($meta['persistent']['date']['valid']);
+        // remove non-persistent keys
+        unset($meta['persistent']['title']);
+        unset($meta['persistent']['description']['abstract']);
+        unset($meta['persistent']['description']['tableofcontents']);
+        unset($meta['persistent']['relation']['haspart']);
+        unset($meta['persistent']['relation']['references']);
+        unset($meta['persistent']['date']['valid']);
 
-    if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']);
-    if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']);
-    if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']);
+        if (empty($meta['persistent']['description'])) unset($meta['persistent']['description']);
+        if (empty($meta['persistent']['relation'])) unset($meta['persistent']['relation']);
+        if (empty($meta['persistent']['date'])) unset($meta['persistent']['date']);
 
-    // save converted metadata
-    io_saveFile($file, serialize($meta));
-  }
+        // save converted metadata
+        io_saveFile($file, serialize($meta));
+    }
 
-  if ($cache) {
-    $cache_metadata[(string)$id] = $meta;
-  }
+    if ($cache) {
+        $cache_metadata[(string)$id] = $meta;
+    }
 
-  return $meta;
+    return $meta;
 }
 
 /**
@@ -396,43 +396,42 @@ function p_read_metadata($id,$cache=false) {
  * @author Esther Brunner <esther@kaffeehaus.ch>
  */
 function p_render_metadata($id, $orig){
-  // make sure the correct ID is in global ID
-  global $ID;
-  $keep = $ID;
-  $ID   = $id;
-
-
-  // add an extra key for the event - to tell event handlers the page whose metadata this is
-  $orig['page'] = $id;
-  $evt = new Doku_Event('PARSER_METADATA_RENDER', $orig);
-  if ($evt->advise_before()) {
-
-    require_once DOKU_INC."inc/parser/metadata.php";
+    // make sure the correct ID is in global ID
+    global $ID;
+    $keep = $ID;
+    $ID   = $id;
+
+    // add an extra key for the event - to tell event handlers the page whose metadata this is
+    $orig['page'] = $id;
+    $evt = new Doku_Event('PARSER_METADATA_RENDER', $orig);
+    if ($evt->advise_before()) {
+
+        require_once DOKU_INC."inc/parser/metadata.php";
+
+        // get instructions
+        $instructions = p_cached_instructions(wikiFN($id),false,$id);
+        if(is_null($instructions)){
+            $ID = $keep;
+            return null; // something went wrong with the instructions
+        }
 
-    // get instructions
-    $instructions = p_cached_instructions(wikiFN($id),false,$id);
-    if(is_null($instructions)){
-      $ID = $keep;
-      return null; // something went wrong with the instructions
-    }
+        // set up the renderer
+        $renderer = & new Doku_Renderer_metadata();
+        $renderer->meta = $orig['current'];
+        $renderer->persistent = $orig['persistent'];
 
-    // set up the renderer
-    $renderer = & new Doku_Renderer_metadata();
-    $renderer->meta = $orig['current'];
-    $renderer->persistent = $orig['persistent'];
+        // loop through the instructions
+        foreach ($instructions as $instruction){
+            // execute the callback against the renderer
+            call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]);
+        }
 
-    // loop through the instructions
-    foreach ($instructions as $instruction){
-      // execute the callback against the renderer
-      call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]);
+        $evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent);
     }
+    $evt->advise_after();
 
-    $evt->result = array('current'=>$renderer->meta,'persistent'=>$renderer->persistent);
-  }
-  $evt->advise_after();
-
-  $ID = $keep;
-  return $evt->result;
+    $ID = $keep;
+    return $evt->result;
 }
 
 /**
@@ -441,90 +440,89 @@ function p_render_metadata($id, $orig){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_get_parsermodes(){
-  global $conf;
+    global $conf;
 
-  //reuse old data
-  static $modes = null;
-  if($modes != null){
-    return $modes;
-  }
-
-  //import parser classes and mode definitions
-  require_once DOKU_INC . 'inc/parser/parser.php';
-
-  // we now collect all syntax modes and their objects, then they will
-  // be sorted and added to the parser in correct order
-  $modes = array();
-
-  // add syntax plugins
-  $pluginlist = plugin_list('syntax');
-  if(count($pluginlist)){
-    global $PARSER_MODES;
-    $obj = null;
-    foreach($pluginlist as $p){
-      if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj
-      $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type
-      //add to modes
-      $modes[] = array(
-                   'sort' => $obj->getSort(),
-                   'mode' => "plugin_$p",
-                   'obj'  => $obj,
-                 );
-      unset($obj); //remove the reference
+    //reuse old data
+    static $modes = null;
+    if($modes != null){
+        return $modes;
     }
-  }
-
-  // add default modes
-  $std_modes = array('listblock','preformatted','notoc','nocache',
-                     'header','table','linebreak','footnote','hr',
-                     'unformatted','php','html','code','file','quote',
-                     'internallink','rss','media','externallink',
-                     'emaillink','windowssharelink','eol');
-  if($conf['typography']){
-    $std_modes[] = 'quotes';
-    $std_modes[] = 'multiplyentity';
-  }
-  foreach($std_modes as $m){
-    $class = "Doku_Parser_Mode_$m";
-    $obj   = new $class();
-    $modes[] = array(
-                 'sort' => $obj->getSort(),
-                 'mode' => $m,
-                 'obj'  => $obj
-               );
-  }
-
-  // add formatting modes
-  $fmt_modes = array('strong','emphasis','underline','monospace',
-                     'subscript','superscript','deleted');
-  foreach($fmt_modes as $m){
-    $obj   = new Doku_Parser_Mode_formatting($m);
-    $modes[] = array(
-                 'sort' => $obj->getSort(),
-                 'mode' => $m,
-                 'obj'  => $obj
-               );
-  }
-
-  // add modes which need files
-  $obj     = new Doku_Parser_Mode_smiley(array_keys(getSmileys()));
-  $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj'  => $obj );
-  $obj     = new Doku_Parser_Mode_acronym(array_keys(getAcronyms()));
-  $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj'  => $obj );
-  $obj     = new Doku_Parser_Mode_entity(array_keys(getEntities()));
-  $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj'  => $obj );
-
-
-  // add optional camelcase mode
-  if($conf['camelcase']){
-    $obj     = new Doku_Parser_Mode_camelcaselink();
-    $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj'  => $obj );
-  }
-
-  //sort modes
-  usort($modes,'p_sort_modes');
-
-  return $modes;
+
+    //import parser classes and mode definitions
+    require_once DOKU_INC . 'inc/parser/parser.php';
+
+    // we now collect all syntax modes and their objects, then they will
+    // be sorted and added to the parser in correct order
+    $modes = array();
+
+    // add syntax plugins
+    $pluginlist = plugin_list('syntax');
+    if(count($pluginlist)){
+        global $PARSER_MODES;
+        $obj = null;
+        foreach($pluginlist as $p){
+            if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj
+            $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type
+            //add to modes
+            $modes[] = array(
+                    'sort' => $obj->getSort(),
+                    'mode' => "plugin_$p",
+                    'obj'  => $obj,
+                    );
+            unset($obj); //remove the reference
+        }
+    }
+
+    // add default modes
+    $std_modes = array('listblock','preformatted','notoc','nocache',
+            'header','table','linebreak','footnote','hr',
+            'unformatted','php','html','code','file','quote',
+            'internallink','rss','media','externallink',
+            'emaillink','windowssharelink','eol');
+    if($conf['typography']){
+        $std_modes[] = 'quotes';
+        $std_modes[] = 'multiplyentity';
+    }
+    foreach($std_modes as $m){
+        $class = "Doku_Parser_Mode_$m";
+        $obj   = new $class();
+        $modes[] = array(
+                'sort' => $obj->getSort(),
+                'mode' => $m,
+                'obj'  => $obj
+                );
+    }
+
+    // add formatting modes
+    $fmt_modes = array('strong','emphasis','underline','monospace',
+            'subscript','superscript','deleted');
+    foreach($fmt_modes as $m){
+        $obj   = new Doku_Parser_Mode_formatting($m);
+        $modes[] = array(
+                'sort' => $obj->getSort(),
+                'mode' => $m,
+                'obj'  => $obj
+                );
+    }
+
+    // add modes which need files
+    $obj     = new Doku_Parser_Mode_smiley(array_keys(getSmileys()));
+    $modes[] = array('sort' => $obj->getSort(), 'mode' => 'smiley','obj'  => $obj );
+    $obj     = new Doku_Parser_Mode_acronym(array_keys(getAcronyms()));
+    $modes[] = array('sort' => $obj->getSort(), 'mode' => 'acronym','obj'  => $obj );
+    $obj     = new Doku_Parser_Mode_entity(array_keys(getEntities()));
+    $modes[] = array('sort' => $obj->getSort(), 'mode' => 'entity','obj'  => $obj );
+
+    // add optional camelcase mode
+    if($conf['camelcase']){
+        $obj     = new Doku_Parser_Mode_camelcaselink();
+        $modes[] = array('sort' => $obj->getSort(), 'mode' => 'camelcaselink','obj'  => $obj );
+    }
+
+    //sort modes
+    usort($modes,'p_sort_modes');
+
+    return $modes;
 }
 
 /**
@@ -533,8 +531,8 @@ function p_get_parsermodes(){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_sort_modes($a, $b){
-  if($a['sort'] == $b['sort']) return 0;
-  return ($a['sort'] < $b['sort']) ? -1 : 1;
+    if($a['sort'] == $b['sort']) return 0;
+    return ($a['sort'] < $b['sort']) ? -1 : 1;
 }
 
 /**
@@ -546,64 +544,63 @@ function p_sort_modes($a, $b){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_render($mode,$instructions,&$info){
-  if(is_null($instructions)) return '';
+    if(is_null($instructions)) return '';
 
-  $Renderer =& p_get_renderer($mode);
-  if (is_null($Renderer)) return null;
+    $Renderer =& p_get_renderer($mode);
+    if (is_null($Renderer)) return null;
 
-  $Renderer->reset();
+    $Renderer->reset();
 
-  $Renderer->smileys = getSmileys();
-  $Renderer->entities = getEntities();
-  $Renderer->acronyms = getAcronyms();
-  $Renderer->interwiki = getInterwiki();
-  #$Renderer->badwords = getBadWords();
+    $Renderer->smileys = getSmileys();
+    $Renderer->entities = getEntities();
+    $Renderer->acronyms = getAcronyms();
+    $Renderer->interwiki = getInterwiki();
 
-  // Loop through the instructions
-  foreach ( $instructions as $instruction ) {
-      // Execute the callback against the Renderer
-      call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
-  }
+    // Loop through the instructions
+    foreach ( $instructions as $instruction ) {
+        // Execute the callback against the Renderer
+        call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]);
+    }
 
-  //set info array
-  $info = $Renderer->info;
+    //set info array
+    $info = $Renderer->info;
 
-  // Post process and return the output
-  $data = array($mode,& $Renderer->doc);
-  trigger_event('RENDERER_CONTENT_POSTPROCESS',$data);
-  return $Renderer->doc;
+    // Post process and return the output
+    $data = array($mode,& $Renderer->doc);
+    trigger_event('RENDERER_CONTENT_POSTPROCESS',$data);
+    return $Renderer->doc;
 }
 
 function & p_get_renderer($mode) {
-  global $conf, $plugin_controller;
+    global $conf, $plugin_controller;
 
-  $rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode;
+    $rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode;
 
-  // try default renderer first:
-  $file = DOKU_INC."inc/parser/$rname.php";
-  if(@file_exists($file)){
-    require_once $file;
-    $rclass = "Doku_Renderer_$rname";
+    // try default renderer first:
+    $file = DOKU_INC."inc/parser/$rname.php";
+    if(@file_exists($file)){
+        require_once $file;
+        $rclass = "Doku_Renderer_$rname";
 
-    if ( !class_exists($rclass) ) {
-      trigger_error("Unable to resolve render class $rclass",E_USER_WARNING);
-      msg("Renderer '$rname' for $mode not valid",-1);
-      return null;
-    }
-    $Renderer = & new $rclass();
-  }else{
-    // Maybe a plugin is available?
-    if (!$plugin_controller->isdisabled($rname)){
-      $Renderer =& $plugin_controller->load('renderer',$rname, true);
-    }
+        if ( !class_exists($rclass) ) {
+            trigger_error("Unable to resolve render class $rclass",E_USER_WARNING);
+            msg("Renderer '$rname' for $mode not valid",-1);
+            return null;
+        }
+        $Renderer = & new $rclass();
+    }else{
+        // Maybe a plugin is available?
+        if (!$plugin_controller->isdisabled($rname)){
+            $Renderer =& $plugin_controller->load('renderer',$rname, true);
+        }
 
-    if(is_null($Renderer)){
-      msg("No renderer '$rname' found for mode '$mode'",-1);
-      return null;
+        if(is_null($Renderer)){
+            msg("No renderer '$rname' found for mode '$mode'",-1);
+            return null;
+        }
     }
-  }
 
-  return $Renderer;
+    return $Renderer;
 }
 
 /**
@@ -620,7 +617,7 @@ function & p_get_renderer($mode) {
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_get_first_heading($id, $render=true){
-  return p_get_metadata($id,'title',$render);
+    return p_get_metadata($id,'title',$render);
 }
 
 /**
@@ -634,42 +631,41 @@ function p_get_first_heading($id, $render=true){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function p_xhtml_cached_geshi($code, $language, $wrapper='pre') {
-  global $conf, $config_cascade;
-  $language = strtolower($language);
-
-  // remove any leading or trailing blank lines
-  $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code);
-
-  $cache = getCacheName($language.$code,".code");
-  $ctime = @filemtime($cache);
-  if($ctime && !$_REQUEST['purge'] &&
-     $ctime > filemtime(DOKU_INC.'inc/geshi.php') &&                 // geshi changed
-     $ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') &&  // language syntax definition changed
-     $ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed
-    $highlighted_code = io_readFile($cache, false);
-
-  } else {
-
-    require_once(DOKU_INC . 'inc/geshi.php');
-
-    $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi');
-    $geshi->set_encoding('utf-8');
-    $geshi->enable_classes();
-    $geshi->set_header_type(GESHI_HEADER_PRE);
-    $geshi->set_link_target($conf['target']['extern']);
-
-    // remove GeSHi's wrapper element (we'll replace it with our own later)
-    // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text
-    $highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()),"\n\r");
-    io_saveFile($cache,$highlighted_code);
-  }
-
-  // add a wrapper element if required
-  if ($wrapper) {
-    return "<$wrapper class=\"code $language\">$highlighted_code</$wrapper>";
-  } else {
-    return $highlighted_code;
-  }
+    global $conf, $config_cascade;
+    $language = strtolower($language);
+
+    // remove any leading or trailing blank lines
+    $code = preg_replace('/^\s*?\n|\s*?\n$/','',$code);
+
+    $cache = getCacheName($language.$code,".code");
+    $ctime = @filemtime($cache);
+    if($ctime && !$_REQUEST['purge'] &&
+            $ctime > filemtime(DOKU_INC.'inc/geshi.php') &&                 // geshi changed
+            $ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') &&  // language syntax definition changed
+            $ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed
+        $highlighted_code = io_readFile($cache, false);
+
+    } else {
+
+        require_once(DOKU_INC . 'inc/geshi.php');
+
+        $geshi = new GeSHi($code, $language, DOKU_INC . 'inc/geshi');
+        $geshi->set_encoding('utf-8');
+        $geshi->enable_classes();
+        $geshi->set_header_type(GESHI_HEADER_PRE);
+        $geshi->set_link_target($conf['target']['extern']);
+
+        // remove GeSHi's wrapper element (we'll replace it with our own later)
+        // we need to use a GeSHi wrapper to avoid <BR> throughout the highlighted text
+        $highlighted_code = trim(preg_replace('!^<pre[^>]*>|</pre>$!','',$geshi->parse_code()),"\n\r");
+        io_saveFile($cache,$highlighted_code);
+    }
+
+    // add a wrapper element if required
+    if ($wrapper) {
+        return "<$wrapper class=\"code $language\">$highlighted_code</$wrapper>";
+    } else {
+        return $highlighted_code;
+    }
 }
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/plugin.php b/inc/plugin.php
index 33cb06c877310d99f0726322795acdad2085cdfe..54d2580e9ab7c988c157a36a7a74a4f8c611e183 100644
--- a/inc/plugin.php
+++ b/inc/plugin.php
@@ -12,222 +12,234 @@
  */
 class DokuWiki_Plugin {
 
-  var $localised = false;        // set to true by setupLocale() after loading language dependent strings
-  var $lang = array();           // array to hold language dependent strings, best accessed via ->getLang()
-  var $configloaded = false;     // set to true by loadConfig() after loading plugin configuration variables
-  var $conf = array();           // array to hold plugin settings, best accessed via ->getConf()
-
-  /**
-   * General Info
-   *
-   * Needs to return a associative array with the following values:
-   *
-   * author - Author of the plugin
-   * email  - Email address to contact the author
-   * date   - Last modified date of the plugin in YYYY-MM-DD format
-   * name   - Name of the plugin
-   * desc   - Short description of the plugin (Text only)
-   * url    - Website with more information on the plugin (eg. syntax description)
-   */
-  function getInfo(){
-    trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING);
-  }
-
-  // plugin introspection methods
-  // extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
-  function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t;  }
-  function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; }
-  function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); }
-
-  // localisation methods
-  /**
-   * getLang($id)
-   * use this function to access plugin language strings
-   * to try to minimise unnecessary loading of the strings when the plugin doesn't require them
-   * e.g. when info plugin is querying plugins for information about themselves.
-   *
-   * @param   $id     id of the string to be retrieved
-   * @return  string  string in appropriate language or english if not available
-   */
-  function getLang($id) {
-    if (!$this->localised) $this->setupLocale();
-
-    return (isset($this->lang[$id]) ? $this->lang[$id] : '');
-  }
-
-  /**
-   * locale_xhtml($id)
-   *
-   * retrieve a language dependent file and pass to xhtml renderer for display
-   * plugin equivalent of p_locale_xhtml()
-   *
-   * @param   $id     id of language dependent wiki page
-   * @return  string  parsed contents of the wiki page in xhtml format
-   */
-  function locale_xhtml($id) {
-    return p_cached_output($this->localFN($id));
-  }
-
-  /**
-   * localFN($id)
-   * prepends appropriate path for a language dependent filename
-   * plugin equivalent of localFN()
-   */
-  function localFN($id) {
-    global $conf;
-    $plugin = $this->getPluginName();
-    $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt';
-    if(!@file_exists($file)){
-      //fall back to english
-      $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt';
-    }
-    return $file;
-  }
-
-  /**
-   *  setupLocale()
-   *  reads all the plugins language dependent strings into $this->lang
-   *  this function is automatically called by getLang()
-   */
-  function setupLocale() {
-    if ($this->localised) return;
-
-    global $conf;            // definitely don't invoke "global $lang"
-    $path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
-
-    $lang = array();
-
-    // don't include once, in case several plugin components require the same language file
-    @include($path.'en/lang.php');
-    if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
-
-    $this->lang = $lang;
-    $this->localised = true;
-  }
-
-  // configuration methods
-  /**
-   * getConf($setting)
-   *
-   * use this function to access plugin configuration variables
-   */
-  function getConf($setting){
-
-    if (!$this->configloaded){ $this->loadConfig(); }
-
-    return $this->conf[$setting];
-  }
-
-  /**
-   * loadConfig()
-   * merges the plugin's default settings with any local settings
-   * this function is automatically called through getConf()
-   */
-  function loadConfig(){
-    global $conf;
-
-    $defaults = $this->readDefaultSettings();
-    $plugin = $this->getPluginName();
-
-    foreach ($defaults as $key => $value) {
-      if (isset($conf['plugin'][$plugin][$key])) continue;
-      $conf['plugin'][$plugin][$key] = $value;
-    }
-
-    $this->configloaded = true;
-    $this->conf =& $conf['plugin'][$plugin];
-  }
-
-  /**
-   * read the plugin's default configuration settings from conf/default.php
-   * this function is automatically called through getConf()
-   *
-   * @return    array    setting => value
-   */
-  function readDefaultSettings() {
-
-    $path = DOKU_PLUGIN.$this->getPluginName().'/conf/';
-    $conf = array();
-
-    if (@file_exists($path.'default.php')) {
-      include($path.'default.php');
-    }
-
-    return $conf;
-  }
-
-  /**
-   * Loads a given helper plugin (if enabled)
-   *
-   * @author  Esther Brunner <wikidesign@gmail.com>
-   *
-   * @param   $name   name of plugin to load
-   * @param   $msg    message to display in case the plugin is not available
-   *
-   * @return  object  helper plugin object
-   */
-  function loadHelper($name, $msg){
-    if (!plugin_isdisabled($name)) $obj =& plugin_load('helper',$name);
-    else $obj = NULL;
-    if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1);
-    return $obj;
-  }
-
-  // standard functions for outputing email addresses and links
-  // use these to avoid having to duplicate code to produce links in line with the installation configuration
-
-  /**
-   * email
-   * standardised function to generate an email link according to obfuscation settings
-   */
-  function email($email, $name='', $class='', $more='') {
-    if (!$email) return $name;
-    $email = obfuscate($email);
-    if (!$name) $name = $email;
-    $class = "class='".($class ? $class : 'mail')."'";
-    return "<a href='mailto:$email' $class title='$email' $more>$name</a>";
-  }
-
-  /**
-   * external_link
-   * standardised function to generate an external link according to conf settings
-   */
-  function external_link($link, $title='', $class='', $target='', $more='') {
-    global $conf;
-
-    $link = htmlentities($link);
-    if (!$title) $title = $link;
-    if (!$target) $target = $conf['target']['extern'];
-    if ($conf['relnofollow']) $more .= ' rel="nofollow"';
-
-    if ($class) $class = " class='$class'";
-    if ($target) $target = " target='$target'";
-    if ($more) $more = " ".trim($more);
-
-    return "<a href='$link'$class$target$more>$title</a>";
-  }
-
-  /**
-   * output text string through the parser, allows dokuwiki markup to be used
-   * very ineffecient for small pieces of data - try not to use
-   */
-  function render($text, $format='xhtml') {
-    return p_render($format, p_get_instructions($text),$info);
-  }
-
-  /**
-   * Allow the plugin to prevent DokuWiki creating a second instance of itself
-   *
-   * @return bool   true if the plugin can not be instantiated more than once
-   */
-  function isSingleton() {
-    return false;
-  }
-
-  // deprecated functions
-  function plugin_localFN($id) { return $this->localFN($id); }
-  function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); }
-  function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); }
-  function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); }
-  function plugin_render($t, $f='xhtml') { return $this->render($t, $f); }
+    var $localised = false;        // set to true by setupLocale() after loading language dependent strings
+    var $lang = array();           // array to hold language dependent strings, best accessed via ->getLang()
+    var $configloaded = false;     // set to true by loadConfig() after loading plugin configuration variables
+    var $conf = array();           // array to hold plugin settings, best accessed via ->getConf()
+
+    /**
+     * General Info
+     *
+     * Needs to return a associative array with the following values:
+     *
+     * author - Author of the plugin
+     * email  - Email address to contact the author
+     * date   - Last modified date of the plugin in YYYY-MM-DD format
+     * name   - Name of the plugin
+     * desc   - Short description of the plugin (Text only)
+     * url    - Website with more information on the plugin (eg. syntax description)
+     */
+    function getInfo(){
+        trigger_error('getInfo() not implemented in '.get_class($this), E_USER_WARNING);
+    }
+
+    // plugin introspection methods
+    // extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
+    function getPluginType() {
+        list($t) = explode('_', get_class($this), 2);
+        return $t;
+    }
+    function getPluginName() {
+        list($t, $p, $n) = explode('_', get_class($this), 4);
+        return $n;
+    }
+    function getPluginComponent() {
+        list($t, $p, $n, $c) = explode('_', get_class($this), 4);
+        return (isset($c)?$c:'');
+    }
+
+    // localisation methods
+    /**
+     * getLang($id)
+     * use this function to access plugin language strings
+     * to try to minimise unnecessary loading of the strings when the plugin doesn't require them
+     * e.g. when info plugin is querying plugins for information about themselves.
+     *
+     * @param   $id     id of the string to be retrieved
+     * @return  string  string in appropriate language or english if not available
+     */
+    function getLang($id) {
+        if (!$this->localised) $this->setupLocale();
+
+        return (isset($this->lang[$id]) ? $this->lang[$id] : '');
+    }
+
+    /**
+     * locale_xhtml($id)
+     *
+     * retrieve a language dependent file and pass to xhtml renderer for display
+     * plugin equivalent of p_locale_xhtml()
+     *
+     * @param   $id     id of language dependent wiki page
+     * @return  string  parsed contents of the wiki page in xhtml format
+     */
+    function locale_xhtml($id) {
+        return p_cached_output($this->localFN($id));
+    }
+
+    /**
+     * localFN($id)
+     * prepends appropriate path for a language dependent filename
+     * plugin equivalent of localFN()
+     */
+    function localFN($id) {
+        global $conf;
+        $plugin = $this->getPluginName();
+        $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt';
+        if(!@file_exists($file)){
+            //fall back to english
+            $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt';
+        }
+        return $file;
+    }
+
+    /**
+     *  setupLocale()
+     *  reads all the plugins language dependent strings into $this->lang
+     *  this function is automatically called by getLang()
+     */
+    function setupLocale() {
+        if ($this->localised) return;
+
+        global $conf;            // definitely don't invoke "global $lang"
+        $path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
+
+        $lang = array();
+
+        // don't include once, in case several plugin components require the same language file
+        @include($path.'en/lang.php');
+        if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
+
+        $this->lang = $lang;
+        $this->localised = true;
+    }
+
+    // configuration methods
+    /**
+     * getConf($setting)
+     *
+     * use this function to access plugin configuration variables
+     */
+    function getConf($setting){
+
+        if (!$this->configloaded){ $this->loadConfig(); }
+
+        return $this->conf[$setting];
+    }
+
+    /**
+     * loadConfig()
+     * merges the plugin's default settings with any local settings
+     * this function is automatically called through getConf()
+     */
+    function loadConfig(){
+        global $conf;
+
+        $defaults = $this->readDefaultSettings();
+        $plugin = $this->getPluginName();
+
+        foreach ($defaults as $key => $value) {
+            if (isset($conf['plugin'][$plugin][$key])) continue;
+            $conf['plugin'][$plugin][$key] = $value;
+        }
+
+        $this->configloaded = true;
+        $this->conf =& $conf['plugin'][$plugin];
+    }
+
+    /**
+     * read the plugin's default configuration settings from conf/default.php
+     * this function is automatically called through getConf()
+     *
+     * @return    array    setting => value
+     */
+    function readDefaultSettings() {
+
+        $path = DOKU_PLUGIN.$this->getPluginName().'/conf/';
+        $conf = array();
+
+        if (@file_exists($path.'default.php')) {
+            include($path.'default.php');
+        }
+
+        return $conf;
+    }
+
+    /**
+     * Loads a given helper plugin (if enabled)
+     *
+     * @author  Esther Brunner <wikidesign@gmail.com>
+     *
+     * @param   $name   name of plugin to load
+     * @param   $msg    message to display in case the plugin is not available
+     *
+     * @return  object  helper plugin object
+     */
+    function loadHelper($name, $msg){
+        if (!plugin_isdisabled($name)){
+            $obj =& plugin_load('helper',$name);
+        }else{
+            $obj = null;
+        }
+        if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1);
+        return $obj;
+    }
+
+    // standard functions for outputing email addresses and links
+    // use these to avoid having to duplicate code to produce links in line with the installation configuration
+
+    /**
+     * email
+     * standardised function to generate an email link according to obfuscation settings
+     */
+    function email($email, $name='', $class='', $more='') {
+        if (!$email) return $name;
+        $email = obfuscate($email);
+        if (!$name) $name = $email;
+        $class = "class='".($class ? $class : 'mail')."'";
+        return "<a href='mailto:$email' $class title='$email' $more>$name</a>";
+    }
+
+    /**
+     * external_link
+     * standardised function to generate an external link according to conf settings
+     */
+    function external_link($link, $title='', $class='', $target='', $more='') {
+        global $conf;
+
+        $link = htmlentities($link);
+        if (!$title) $title = $link;
+        if (!$target) $target = $conf['target']['extern'];
+        if ($conf['relnofollow']) $more .= ' rel="nofollow"';
+
+        if ($class) $class = " class='$class'";
+        if ($target) $target = " target='$target'";
+        if ($more) $more = " ".trim($more);
+
+        return "<a href='$link'$class$target$more>$title</a>";
+    }
+
+    /**
+     * output text string through the parser, allows dokuwiki markup to be used
+     * very ineffecient for small pieces of data - try not to use
+     */
+    function render($text, $format='xhtml') {
+        return p_render($format, p_get_instructions($text),$info);
+    }
+
+    /**
+     * Allow the plugin to prevent DokuWiki creating a second instance of itself
+     *
+     * @return bool   true if the plugin can not be instantiated more than once
+     */
+    function isSingleton() {
+        return false;
+    }
+
+    // deprecated functions
+    function plugin_localFN($id) { return $this->localFN($id); }
+    function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); }
+    function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); }
+    function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); }
+    function plugin_render($t, $f='xhtml') { return $this->render($t, $f); }
 }
diff --git a/inc/plugincontroller.class.php b/inc/plugincontroller.class.php
index 707d90856b0010703751296c9fc4baec0a53e6f6..4400a41870c7ef6f55afdb9ea49d1ea2accf9146 100644
--- a/inc/plugincontroller.class.php
+++ b/inc/plugincontroller.class.php
@@ -11,162 +11,162 @@ if(!defined('DOKU_PLUGIN'))  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
 class Doku_Plugin_Controller {
 
-  var $list_enabled = array();
-  var $list_disabled = array();
-  var $list_bytype = array();
-
-  function Doku_Plugin_Controller() {
-    $this->_populateMasterList();
-  }
-
-  /**
-   * Returns a list of available plugins of given type
-   *
-   * @param $type  string, plugin_type name;
-   *               the type of plugin to return,
-   *               use empty string for all types
-   * @param $all   bool;
-   *               false to only return enabled plugins,
-   *               true to return both enabled and disabled plugins
-   *
-   * @return       array of plugin names
-   *
-   * @author Andreas Gohr <andi@splitbrain.org>
-   */
-  function getList($type='',$all=false){
-
-    // request the complete list
-    if (!$type) {
-      return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled;
-    }
+    var $list_enabled = array();
+    var $list_disabled = array();
+    var $list_bytype = array();
 
-    if (!isset($this->list_bytype[$type]['enabled'])) {
-      $this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true);
-    }
-    if ($all && !isset($this->list_bytype[$type]['disabled'])) {
-      $this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false);
+    function Doku_Plugin_Controller() {
+        $this->_populateMasterList();
     }
 
-    return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled'];
-  }
-
-  /**
-   * Loads the given plugin and creates an object of it
-   *
-   * @author Andreas Gohr <andi@splitbrain.org>
-   *
-   * @param  $type string     type of plugin to load
-   * @param  $name string     name of the plugin to load
-   * @param  $new  bool       true to return a new instance of the plugin, false to use an already loaded instance
-   * @return objectreference  the plugin object or null on failure
-   */
-  function &load($type,$name,$new=false){
-    //we keep all loaded plugins available in global scope for reuse
-    global $DOKU_PLUGINS;
-
-    //plugin already loaded?
-    if(!empty($DOKU_PLUGINS[$type][$name])){
-      if ($new  && !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
-        $class = $type.'_plugin_'.$name;
-        return class_exists($class) ? new $class : null;
-      } else {
-        return $DOKU_PLUGINS[$type][$name];
-      }
-    }
+    /**
+     * Returns a list of available plugins of given type
+     *
+     * @param $type  string, plugin_type name;
+     *               the type of plugin to return,
+     *               use empty string for all types
+     * @param $all   bool;
+     *               false to only return enabled plugins,
+     *               true to return both enabled and disabled plugins
+     *
+     * @return       array of plugin names
+     *
+     * @author Andreas Gohr <andi@splitbrain.org>
+     */
+    function getList($type='',$all=false){
+
+        // request the complete list
+        if (!$type) {
+            return $all ? array_merge($this->list_enabled,$this->list_disabled) : $this->list_enabled;
+        }
 
-    //try to load the wanted plugin file
-    list($plugin,$component) = $this->_splitName($name);
-    $dir = $this->get_directory($plugin);
-    $file = $component ? "$type/$component.php" : "$type.php";
+        if (!isset($this->list_bytype[$type]['enabled'])) {
+            $this->list_bytype[$type]['enabled'] = $this->_getListByType($type,true);
+        }
+        if ($all && !isset($this->list_bytype[$type]['disabled'])) {
+            $this->list_bytype[$type]['disabled'] = $this->_getListByType($type,false);
+        }
 
-    if(!is_file(DOKU_PLUGIN."$dir/$file")){
-      return null;
+        return $all ? array_merge($this->list_bytype[$type]['enabled'],$this->list_bytype[$type]['disabled']) : $this->list_bytype[$type]['enabled'];
     }
 
-    if (!include_once(DOKU_PLUGIN."$dir/$file")) {
-      return null;
-    }
+    /**
+     * Loads the given plugin and creates an object of it
+     *
+     * @author Andreas Gohr <andi@splitbrain.org>
+     *
+     * @param  $type string     type of plugin to load
+     * @param  $name string     name of the plugin to load
+     * @param  $new  bool       true to return a new instance of the plugin, false to use an already loaded instance
+     * @return objectreference  the plugin object or null on failure
+     */
+    function &load($type,$name,$new=false){
+        //we keep all loaded plugins available in global scope for reuse
+        global $DOKU_PLUGINS;
+
+        //plugin already loaded?
+        if(!empty($DOKU_PLUGINS[$type][$name])){
+            if ($new  && !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
+                $class = $type.'_plugin_'.$name;
+                return class_exists($class) ? new $class : null;
+            } else {
+                return $DOKU_PLUGINS[$type][$name];
+            }
+        }
+
+        //try to load the wanted plugin file
+        list($plugin,$component) = $this->_splitName($name);
+        $dir = $this->get_directory($plugin);
+        $file = $component ? "$type/$component.php" : "$type.php";
+
+        if(!is_file(DOKU_PLUGIN."$dir/$file")){
+            return null;
+        }
 
-    //construct class and instantiate
-    $class = $type.'_plugin_'.$name;
-    if (!class_exists($class)) return null;
+        if (!include_once(DOKU_PLUGIN."$dir/$file")) {
+            return null;
+        }
 
-    $DOKU_PLUGINS[$type][$name] = new $class;
-    return $DOKU_PLUGINS[$type][$name];
-  }
+        //construct class and instantiate
+        $class = $type.'_plugin_'.$name;
+        if (!class_exists($class)) return null;
 
-  function isdisabled($plugin) {
-    return (array_search($plugin, $this->list_enabled) === false);
-  }
+        $DOKU_PLUGINS[$type][$name] = new $class;
+        return $DOKU_PLUGINS[$type][$name];
+    }
 
-  function enable($plugin) {
-    if (array_search($plugin, $this->list_disabled) !== false) {
-      return @unlink(DOKU_PLUGIN.$plugin.'/disabled');
+    function isdisabled($plugin) {
+        return (array_search($plugin, $this->list_enabled) === false);
     }
-    return false;
-  }
 
-  function disable($plugin) {
-    if (array_search($plugin, $this->list_enabled) !== false) {
-      return @touch(DOKU_PLUGIN.$plugin.'/disabled');
+    function enable($plugin) {
+        if (array_search($plugin, $this->list_disabled) !== false) {
+            return @unlink(DOKU_PLUGIN.$plugin.'/disabled');
+        }
+        return false;
     }
-    return false;
-  }
-
-  function get_directory($plugin) {
-    return $plugin;
-  }
-
-  function _populateMasterList() {
-    if ($dh = opendir(DOKU_PLUGIN)) {
-      while (false !== ($plugin = readdir($dh))) {
-        if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue;
-        if (is_file(DOKU_PLUGIN.$plugin)) continue;
-
-        if (substr($plugin,-9) == '.disabled') {
-          // the plugin was disabled by rc2009-01-26
-          // disabling mechanism was changed back very soon again
-          // to keep everything simple we just skip the plugin completely
-        }elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){
-          $this->list_disabled[] = $plugin;
-        } else {
-          $this->list_enabled[] = $plugin;
+
+    function disable($plugin) {
+        if (array_search($plugin, $this->list_enabled) !== false) {
+            return @touch(DOKU_PLUGIN.$plugin.'/disabled');
         }
-      }
+        return false;
+    }
+
+    function get_directory($plugin) {
+        return $plugin;
     }
-  }
-
-  function _getListByType($type, $enabled) {
-    $master_list = $enabled ? $this->list_enabled : $this->list_disabled;
-
-    $plugins = array();
-    foreach ($master_list as $plugin) {
-      $dir = $this->get_directory($plugin);
-
-      if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){
-        $plugins[] = $plugin;
-      } else {
-        if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) {
-          while (false !== ($component = readdir($dp))) {
-            if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue;
-            if (is_file(DOKU_PLUGIN."$dir/$type/$component")) {
-                $plugins[] = $plugin.'_'.substr($component, 0, -4);
+
+    function _populateMasterList() {
+        if ($dh = opendir(DOKU_PLUGIN)) {
+            while (false !== ($plugin = readdir($dh))) {
+                if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp') continue;
+                if (is_file(DOKU_PLUGIN.$plugin)) continue;
+
+                if (substr($plugin,-9) == '.disabled') {
+                    // the plugin was disabled by rc2009-01-26
+                    // disabling mechanism was changed back very soon again
+                    // to keep everything simple we just skip the plugin completely
+                }elseif(@file_exists(DOKU_PLUGIN.$plugin.'/disabled')){
+                    $this->list_disabled[] = $plugin;
+                } else {
+                    $this->list_enabled[] = $plugin;
+                }
             }
-          }
-        closedir($dp);
         }
-      }
     }
 
-    return $plugins;
-  }
+    function _getListByType($type, $enabled) {
+        $master_list = $enabled ? $this->list_enabled : $this->list_disabled;
+
+        $plugins = array();
+        foreach ($master_list as $plugin) {
+            $dir = $this->get_directory($plugin);
+
+            if (@file_exists(DOKU_PLUGIN."$dir/$type.php")){
+                $plugins[] = $plugin;
+            } else {
+                if ($dp = @opendir(DOKU_PLUGIN."$dir/$type/")) {
+                    while (false !== ($component = readdir($dp))) {
+                        if (substr($component,0,1) == '.' || strtolower(substr($component, -4)) != ".php") continue;
+                        if (is_file(DOKU_PLUGIN."$dir/$type/$component")) {
+                            $plugins[] = $plugin.'_'.substr($component, 0, -4);
+                        }
+                    }
+                    closedir($dp);
+                }
+            }
+        }
 
-  function _splitName($name) {
-    if (array_search($name, $this->list_enabled + $this->list_disabled) === false) {
-      return explode('_',$name,2);
+        return $plugins;
     }
 
-    return array($name,'');
-  }
+    function _splitName($name) {
+        if (array_search($name, $this->list_enabled + $this->list_disabled) === false) {
+            return explode('_',$name,2);
+        }
+
+        return array($name,'');
+    }
 
 }
diff --git a/inc/pluginutils.php b/inc/pluginutils.php
index db152195d50814bb371478140b656854dc34496a..8294d1ec85165c74768416a2f8952d719d6ebf5f 100644
--- a/inc/pluginutils.php
+++ b/inc/pluginutils.php
@@ -20,10 +20,28 @@ $plugin_controller = new $plugin_controller_class();
 /**
  * Original plugin functions, remain for backwards compatibility
  */
-function plugin_list($type='',$all=false) { global $plugin_controller; return $plugin_controller->getList($type,$all); }
-function &plugin_load($type,$name,$new=false) { global $plugin_controller; return $plugin_controller->load($type,$name,$new); }
-function plugin_isdisabled($plugin) { global $plugin_controller; return $plugin_controller->isdisabled($plugin); }
-function plugin_enable($plugin) { global $plugin_controller; return $plugin_controller->enable($plugin); }
-function plugin_disable($plugin) { global $plugin_controller; return $plugin_controller->disable($plugin); }
-function plugin_directory($plugin) { global $plugin_controller; return $plugin_controller->get_directory($plugin); }
+function plugin_list($type='',$all=false) {
+    global $plugin_controller;
+    return $plugin_controller->getList($type,$all);
+}
+function &plugin_load($type,$name,$new=false) {
+    global $plugin_controller;
+    return $plugin_controller->load($type,$name,$new);
+}
+function plugin_isdisabled($plugin) {
+    global $plugin_controller;
+    return $plugin_controller->isdisabled($plugin);
+}
+function plugin_enable($plugin) {
+    global $plugin_controller;
+    return $plugin_controller->enable($plugin);
+}
+function plugin_disable($plugin) {
+    global $plugin_controller;
+    return $plugin_controller->disable($plugin);
+}
+function plugin_directory($plugin) {
+    global $plugin_controller;
+    return $plugin_controller->get_directory($plugin);
+}
 
diff --git a/inc/search.php b/inc/search.php
index e29f977ad2f8dae786d1d9b16c731f0bdbb9a0f2..547e15bcab5ddac5471664b85a13c2e65dffbc44 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -23,34 +23,34 @@ require_once(DOKU_INC.'inc/common.php');
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
-  $dirs   = array();
-  $files  = array();
-
-  //read in directories and files
-  $dh = @opendir($base.'/'.$dir);
-  if(!$dh) return;
-  while(($file = readdir($dh)) !== false){
-    if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
-    if(is_dir($base.'/'.$dir.'/'.$file)){
-      $dirs[] = $dir.'/'.$file;
-      continue;
+    $dirs   = array();
+    $files  = array();
+
+    //read in directories and files
+    $dh = @opendir($base.'/'.$dir);
+    if(!$dh) return;
+    while(($file = readdir($dh)) !== false){
+        if(preg_match('/^[\._]/',$file)) continue; //skip hidden files and upper dirs
+        if(is_dir($base.'/'.$dir.'/'.$file)){
+            $dirs[] = $dir.'/'.$file;
+            continue;
+        }
+        $files[] = $dir.'/'.$file;
+    }
+    closedir($dh);
+    sort($files);
+    sort($dirs);
+
+    //give directories to userfunction then recurse
+    foreach($dirs as $dir){
+        if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){
+            search($data,$base,$func,$opts,$dir,$lvl+1);
+        }
     }
-    $files[] = $dir.'/'.$file;
-  }
-  closedir($dh);
-  sort($files);
-  sort($dirs);
-
-  //give directories to userfunction then recurse
-  foreach($dirs as $dir){
-    if (call_user_func_array($func, array(&$data,$base,$dir,'d',$lvl,$opts))){
-      search($data,$base,$func,$opts,$dir,$lvl+1);
+    //now handle the files
+    foreach($files as $file){
+        call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts));
     }
-  }
-  //now handle the files
-  foreach($files as $file){
-    call_user_func_array($func, array(&$data,$base,$file,'f',$lvl,$opts));
-  }
 }
 
 /**
@@ -59,7 +59,7 @@ function search(&$data,$base,$func,$opts,$dir='',$lvl=1){
  * @deprecated
  */
 function search_callback($func,&$data,$base,$file,$type,$lvl,$opts){
-  return call_user_func_array($func, array(&$data,$base,$file,$type,$lvl,$opts));
+    return call_user_func_array($func, array(&$data,$base,$file,$type,$lvl,$opts));
 }
 
 /**
@@ -92,10 +92,10 @@ function search_callback($func,&$data,$base,$file,$type,$lvl,$opts){
  */
 function search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
     $opts = array(
-        'idmatch'   => '(^|:)'.preg_quote($opts['query'],'/').'/',
-        'listfiles' => true,
-        'pagesonly' => true,
-    );
+            'idmatch'   => '(^|:)'.preg_quote($opts['query'],'/').'/',
+            'listfiles' => true,
+            'pagesonly' => true,
+            );
     return search_universal($data,$base,$file,$type,$lvl,$opts);
 }
 
@@ -107,40 +107,40 @@ function search_qsearch(&$data,$base,$file,$type,$lvl,$opts){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function search_index(&$data,$base,$file,$type,$lvl,$opts){
-  global $conf;
-  $return = true;
+    global $conf;
+    $return = true;
 
-  $item = array();
+    $item = array();
 
-  if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
-    //add but don't recurse
-    $return = false;
-  }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
-    //don't add
-    return false;
-  }
+    if($type == 'd' && !preg_match('#^'.$file.'(/|$)#','/'.$opts['ns'])){
+        //add but don't recurse
+        $return = false;
+    }elseif($type == 'f' && ($opts['nofiles'] || substr($file,-4) != '.txt')){
+        //don't add
+        return false;
+    }
 
-  $id = pathID($file);
+    $id = pathID($file);
 
-  if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
-    return false;
-  }
+    if($type=='d' && $conf['sneaky_index'] && auth_quickaclcheck($id.':') < AUTH_READ){
+        return false;
+    }
 
-  //check hidden
-  if(isHiddenPage($id)){
-    return false;
-  }
+    //check hidden
+    if(isHiddenPage($id)){
+        return false;
+    }
 
-  //check ACL
-  if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
-    return false;
-  }
+    //check ACL
+    if($type=='f' && auth_quickaclcheck($id) < AUTH_READ){
+        return false;
+    }
 
-  $data[]=array( 'id'    => $id,
-                 'type'  => $type,
-                 'level' => $lvl,
-                 'open'  => $return );
-  return $return;
+    $data[]=array( 'id'    => $id,
+            'type'  => $type,
+            'level' => $lvl,
+            'open'  => $return );
+    return $return;
 }
 
 /**
@@ -150,8 +150,8 @@ function search_index(&$data,$base,$file,$type,$lvl,$opts){
  */
 function search_namespaces(&$data,$base,$file,$type,$lvl,$opts){
     $opts = array(
-        'listdirs' => true,
-    );
+            'listdirs' => true,
+            );
     return search_universal($data,$base,$file,$type,$lvl,$opts);
 }
 
@@ -215,18 +215,18 @@ function search_media(&$data,$base,$file,$type,$lvl,$opts){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function search_list(&$data,$base,$file,$type,$lvl,$opts){
-  //we do nothing with directories
-  if($type == 'd') return false;
-  //only search txt files
-  if(substr($file,-4) == '.txt'){
-    //check ACL
-    $id = pathID($file);
-    if(auth_quickaclcheck($id) < AUTH_READ){
-      return false;
+    //we do nothing with directories
+    if($type == 'd') return false;
+    //only search txt files
+    if(substr($file,-4) == '.txt'){
+        //check ACL
+        $id = pathID($file);
+        if(auth_quickaclcheck($id) < AUTH_READ){
+            return false;
+        }
+        $data[]['id'] = $id;
     }
-    $data[]['id'] = $id;
-  }
-  return false;
+    return false;
 }
 
 /**
@@ -237,23 +237,23 @@ function search_list(&$data,$base,$file,$type,$lvl,$opts){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function search_pagename(&$data,$base,$file,$type,$lvl,$opts){
-  //we do nothing with directories
-  if($type == 'd') return true;
-  //only search txt files
-  if(substr($file,-4) != '.txt') return true;
-
-  //simple stringmatching
-  if (!empty($opts['query'])){
-    if(strpos($file,$opts['query']) !== false){
-      //check ACL
-      $id = pathID($file);
-      if(auth_quickaclcheck($id) < AUTH_READ){
-        return false;
-      }
-      $data[]['id'] = $id;
+    //we do nothing with directories
+    if($type == 'd') return true;
+    //only search txt files
+    if(substr($file,-4) != '.txt') return true;
+
+    //simple stringmatching
+    if (!empty($opts['query'])){
+        if(strpos($file,$opts['query']) !== false){
+            //check ACL
+            $id = pathID($file);
+            if(auth_quickaclcheck($id) < AUTH_READ){
+                return false;
+            }
+            $data[]['id'] = $id;
+        }
     }
-  }
-  return true;
+    return true;
 }
 
 /**
@@ -279,7 +279,7 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
 
     $item['id']   = pathID($file);
     if(!$opts['skipacl'] && auth_quickaclcheck($item['id']) < AUTH_READ){
-      return false;
+        return false;
     }
 
     $item['rev']   = filemtime($base.'/'.$file);
@@ -303,42 +303,42 @@ function search_allpages(&$data,$base,$file,$type,$lvl,$opts){
  * @deprecated Replaced by ft_backlinks()
  */
 function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
-  //we do nothing with directories
-  if($type == 'd') return true;
-  //only search txt files
-  if(substr($file,-4) != '.txt') return true;
+    //we do nothing with directories
+    if($type == 'd') return true;
+    //only search txt files
+    if(substr($file,-4) != '.txt') return true;
 
-  //absolute search id
-  $sid = cleanID($opts['ns'].':'.$opts['name']);
+    //absolute search id
+    $sid = cleanID($opts['ns'].':'.$opts['name']);
 
-  //current id and namespace
-  $cid = pathID($file);
-  $cns = getNS($cid);
+    //current id and namespace
+    $cid = pathID($file);
+    $cns = getNS($cid);
 
-  //check ACL
-  if(auth_quickaclcheck($cid) < AUTH_READ){
-    return false;
-  }
-
-  //fetch instructions
-  require_once(DOKU_INC.'inc/parserutils.php');
-  $instructions = p_cached_instructions($base.$file,true);
-  if(is_null($instructions)) return false;
-
-  //check all links for match
-  foreach($instructions as $ins){
-    if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
-      $mid = $ins[1][0];
-      resolve_pageid($cns,$mid,$exists); //exists is not used
-      if($mid == $sid){
-        //we have a match - finish
-        $data[]['id'] = $cid;
-        break;
-      }
+    //check ACL
+    if(auth_quickaclcheck($cid) < AUTH_READ){
+        return false;
+    }
+
+    //fetch instructions
+    require_once(DOKU_INC.'inc/parserutils.php');
+    $instructions = p_cached_instructions($base.$file,true);
+    if(is_null($instructions)) return false;
+
+    //check all links for match
+    foreach($instructions as $ins){
+        if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
+            $mid = $ins[1][0];
+            resolve_pageid($cns,$mid,$exists); //exists is not used
+            if($mid == $sid){
+                //we have a match - finish
+                $data[]['id'] = $cid;
+                break;
+            }
+        }
     }
-  }
 
-  return false;
+    return false;
 }
 
 /**
@@ -350,86 +350,86 @@ function search_backlinks(&$data,$base,$file,$type,$lvl,$opts){
  * @deprecated - fulltext indexer is used instead
  */
 function search_fulltext(&$data,$base,$file,$type,$lvl,$opts){
-  //we do nothing with directories
-  if($type == 'd') return true;
-  //only search txt files
-  if(substr($file,-4) != '.txt') return true;
-
-  //check ACL
-  $id = pathID($file);
-  if(auth_quickaclcheck($id) < AUTH_READ){
-    return false;
-  }
-
-  //create regexp from queries
-  $poswords = array();
-  $negwords = array();
-  $qpreg = preg_split('/\s+/',$opts['query']);
-
-  foreach($qpreg as $word){
-    switch(substr($word,0,1)){
-      case '-':
-        if(strlen($word) > 1){  // catch single '-'
-          array_push($negwords,preg_quote(substr($word,1),'#'));
-        }
-        break;
-      case '+':
-        if(strlen($word) > 1){  // catch single '+'
-          array_push($poswords,preg_quote(substr($word,1),'#'));
+    //we do nothing with directories
+    if($type == 'd') return true;
+    //only search txt files
+    if(substr($file,-4) != '.txt') return true;
+
+    //check ACL
+    $id = pathID($file);
+    if(auth_quickaclcheck($id) < AUTH_READ){
+        return false;
+    }
+
+    //create regexp from queries
+    $poswords = array();
+    $negwords = array();
+    $qpreg = preg_split('/\s+/',$opts['query']);
+
+    foreach($qpreg as $word){
+        switch(substr($word,0,1)){
+            case '-':
+                if(strlen($word) > 1){  // catch single '-'
+                    array_push($negwords,preg_quote(substr($word,1),'#'));
+                }
+                break;
+            case '+':
+                if(strlen($word) > 1){  // catch single '+'
+                    array_push($poswords,preg_quote(substr($word,1),'#'));
+                }
+                break;
+            default:
+                array_push($poswords,preg_quote($word,'#'));
+                break;
         }
-        break;
-      default:
-        array_push($poswords,preg_quote($word,'#'));
-        break;
     }
-  }
 
-  // a search without any posword is useless
-  if (!count($poswords)) return true;
+    // a search without any posword is useless
+    if (!count($poswords)) return true;
 
-  $reg  = '^(?=.*?'.join(')(?=.*?',$poswords).')';
-  $reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
-  search_regex($data,$base,$file,$reg,$poswords);
-  return true;
-}
+    $reg  = '^(?=.*?'.join(')(?=.*?',$poswords).')';
+            $reg .= count($negwords) ? '((?!'.join('|',$negwords).').)*$' : '.*$';
+            search_regex($data,$base,$file,$reg,$poswords);
+            return true;
+            }
 
-/**
- * Reference search
- * This fuction searches for existing references to a given media file
- * and returns an array with the found pages. It doesn't pay any
- * attention to ACL permissions to find every reference. The caller
- * must check if the user has the appropriate rights to see the found
- * page and eventually have to prevent the result from displaying.
- *
- * @param array  $data Reference to the result data structure
- * @param string $base Base usually $conf['datadir']
- * @param string $file current file or directory relative to $base
- * @param char   $type Type either 'd' for directory or 'f' for file
- * @param int    $lvl  Current recursion depht
- * @param mixed  $opts option array as given to search()
- *
- * $opts['query'] is the demanded media file name
- *
- * @author  Andreas Gohr <andi@splitbrain.org>
- * @author  Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+            /**
+             * Reference search
+             * This fuction searches for existing references to a given media file
+             * and returns an array with the found pages. It doesn't pay any
+             * attention to ACL permissions to find every reference. The caller
+             * must check if the user has the appropriate rights to see the found
+             * page and eventually have to prevent the result from displaying.
+             *
+             * @param array  $data Reference to the result data structure
+             * @param string $base Base usually $conf['datadir']
+             * @param string $file current file or directory relative to $base
+             * @param char   $type Type either 'd' for directory or 'f' for file
+             * @param int    $lvl  Current recursion depht
+             * @param mixed  $opts option array as given to search()
+             *
+             * $opts['query'] is the demanded media file name
+             *
+             * @author  Andreas Gohr <andi@splitbrain.org>
+             * @author  Matthias Grimm <matthiasgrimm@users.sourceforge.net>
+             */
 function search_reference(&$data,$base,$file,$type,$lvl,$opts){
-  global $conf;
+    global $conf;
 
-  //we do nothing with directories
-  if($type == 'd') return true;
+    //we do nothing with directories
+    if($type == 'd') return true;
 
-  //only search txt files
-  if(substr($file,-4) != '.txt') return true;
+    //only search txt files
+    if(substr($file,-4) != '.txt') return true;
 
-  //we finish after 'cnt' references found. The return value
-  //'false' will skip subdirectories to speed search up.
-  $cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
-  if(count($data) >= $cnt) return false;
+    //we finish after 'cnt' references found. The return value
+    //'false' will skip subdirectories to speed search up.
+    $cnt = $conf['refshow'] > 0 ? $conf['refshow'] : 1;
+    if(count($data) >= $cnt) return false;
 
-  $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
-  search_regex($data,$base,$file,$reg,array($opts['query']));
-  return true;
+    $reg = '\{\{ *\:?'.$opts['query'].' *(\|.*)?\}\}';
+    search_regex($data,$base,$file,$reg,array($opts['query']));
+    return true;
 }
 
 /* ------------- helper functions below -------------- */
@@ -453,35 +453,35 @@ function search_reference(&$data,$base,$file,$type,$lvl,$opts){
  */
 function search_regex(&$data,$base,$file,$reg,$words){
 
-  //get text
-  $text = io_readfile($base.'/'.$file);
-  //lowercase text (u modifier does not help with case)
-  $lctext = utf8_strtolower($text);
-
-  //do the fulltext search
-  $matches = array();
-  if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
-    //this is not the best way for snippet generation but the fastest I could find
-    $q = $words[0];  //use first word for snippet creation
-    $p = utf8_strpos($lctext,$q);
-    $f = $p - 100;
-    $l = utf8_strlen($q) + 200;
-    if($f < 0) $f = 0;
-    $snippet = '<span class="search_sep"> ... </span>'.
-               htmlspecialchars(utf8_substr($text,$f,$l)).
-               '<span class="search_sep"> ... </span>';
-    $mark    = '('.join('|', $words).')';
-    $snippet = preg_replace('#'.$mark.'#si','<strong class="search_hit">\\1</strong>',$snippet);
-
-    $data[] = array(
-      'id'       => pathID($file),
-      'count'    => preg_match_all('#'.$mark.'#usi',$lctext,$matches),
-      'poswords' => join(' ',$words),
-      'snippet'  => $snippet,
-    );
-  }
-
-  return true;
+    //get text
+    $text = io_readfile($base.'/'.$file);
+    //lowercase text (u modifier does not help with case)
+    $lctext = utf8_strtolower($text);
+
+    //do the fulltext search
+    $matches = array();
+    if($cnt = preg_match_all('#'.$reg.'#usi',$lctext,$matches)){
+        //this is not the best way for snippet generation but the fastest I could find
+        $q = $words[0];  //use first word for snippet creation
+        $p = utf8_strpos($lctext,$q);
+        $f = $p - 100;
+        $l = utf8_strlen($q) + 200;
+        if($f < 0) $f = 0;
+        $snippet = '<span class="search_sep"> ... </span>'.
+            htmlspecialchars(utf8_substr($text,$f,$l)).
+            '<span class="search_sep"> ... </span>';
+        $mark    = '('.join('|', $words).')';
+        $snippet = preg_replace('#'.$mark.'#si','<strong class="search_hit">\\1</strong>',$snippet);
+
+        $data[] = array(
+                'id'       => pathID($file),
+                'count'    => preg_match_all('#'.$mark.'#usi',$lctext,$matches),
+                'poswords' => join(' ',$words),
+                'snippet'  => $snippet,
+                );
+    }
+
+    return true;
 }
 
 
@@ -494,13 +494,13 @@ function search_regex(&$data,$base,$file,$reg,$words){
  * @author  Andreas Gohr <andi@splitbrain.org>
  */
 function sort_search_fulltext($a,$b){
-  if($a['count'] > $b['count']){
-    return -1;
-  }elseif($a['count'] < $b['count']){
-    return 1;
-  }else{
-    return strcmp($a['id'],$b['id']);
-  }
+    if($a['count'] > $b['count']){
+        return -1;
+    }elseif($a['count'] < $b['count']){
+        return 1;
+    }else{
+        return strcmp($a['id'],$b['id']);
+    }
 }
 
 /**
@@ -510,12 +510,12 @@ function sort_search_fulltext($a,$b){
  * @todo    move to pageutils
  */
 function pathID($path,$keeptxt=false){
-  $id = utf8_decodeFN($path);
-  $id = str_replace('/',':',$id);
-  if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
-  $id = preg_replace('#^:+#','',$id);
-  $id = preg_replace('#:+$#','',$id);
-  return $id;
+    $id = utf8_decodeFN($path);
+    $id = str_replace('/',':',$id);
+    if(!$keeptxt) $id = preg_replace('#\.txt$#','',$id);
+    $id = preg_replace('#^:+#','',$id);
+    $id = preg_replace('#:+$#','',$id);
+    return $id;
 }
 
 
diff --git a/inc/toolbar.php b/inc/toolbar.php
index 701723b583adf57e08abfbd6124de78367eb8fd7..66945cbc4dfca55809e9401fa3d2dccbc4fde7a0 100644
--- a/inc/toolbar.php
+++ b/inc/toolbar.php
@@ -13,7 +13,7 @@ require_once(DOKU_INC.'inc/JSON.php');
 /**
  * Prepares and prints an JavaScript array with all toolbar buttons
  *
- * @todo add toolbar plugins
+ * @emits  TOOLBAR_DEFINE
  * @param  string $varname Name of the JS variable to fill
  * @author Andreas Gohr <andi@splitbrain.org>
  */
@@ -209,9 +209,6 @@ function toolbar_JSdefines($varname){
                 'icon'   => 'sig.png',
                 'key'    => 'y',
                ),
-
-
-
         ));
     } // end event TOOLBAR_DEFINE default action
     $evt->advise_after();
@@ -228,17 +225,17 @@ function toolbar_JSdefines($varname){
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function toolbar_signature(){
-  global $conf;
-  global $INFO;
-
-  $sig = $conf['signature'];
-  $sig = strftime($sig);
-  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
-  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
-  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
-  $sig = str_replace('@DATE@',dformat(),$sig);
-  $sig = str_replace('\\\\n','\\n',addslashes($sig));
-  return $sig;
+    global $conf;
+    global $INFO;
+
+    $sig = $conf['signature'];
+    $sig = strftime($sig);
+    $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
+    $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
+    $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
+    $sig = str_replace('@DATE@',dformat(),$sig);
+    $sig = str_replace('\\\\n','\\n',addslashes($sig));
+    return $sig;
 }
 
 //Setup VIM: ex: et ts=4 enc=utf-8 :
diff --git a/inc/utf8.php b/inc/utf8.php
index a438783f7524f91fbd65e00b025e90e04ad56e18..b078540d208d6bfb001788489c046a16ba2cca03 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -10,11 +10,11 @@
  * check for mb_string support
  */
 if(!defined('UTF8_MBSTRING')){
-  if(function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')){
-    define('UTF8_MBSTRING',1);
-  }else{
-    define('UTF8_MBSTRING',0);
-  }
+    if(function_exists('mb_substr') && !defined('UTF8_NOMBSTRING')){
+        define('UTF8_MBSTRING',1);
+    }else{
+        define('UTF8_MBSTRING',0);
+    }
 }
 
 if(UTF8_MBSTRING){ mb_internal_encoding('UTF-8'); }
@@ -34,12 +34,12 @@ if(!function_exists('utf8_encodeFN')){
      * @see    urlencode
      */
     function utf8_encodeFN($file,$safe=true){
-      if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){
+        if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){
+            return $file;
+        }
+        $file = urlencode($file);
+        $file = str_replace('%2F','/',$file);
         return $file;
-      }
-      $file = urlencode($file);
-      $file = str_replace('%2F','/',$file);
-      return $file;
     }
 }
 
@@ -184,53 +184,53 @@ if(!function_exists('utf8_substr')){
 
         // normalise -ve offsets (we could use a tail anchored pattern, but they are horribly slow!)
         if ($offset < 0) {
-          $strlen = strlen(utf8_decode($str));        // see notes
-          $offset = $strlen + $offset;
-          if ($offset < 0) $offset = 0;
+            $strlen = strlen(utf8_decode($str));        // see notes
+            $offset = $strlen + $offset;
+            if ($offset < 0) $offset = 0;
         }
 
         // establish a pattern for offset, a non-captured group equal in length to offset
         if ($offset > 0) {
-          $Ox = (int)($offset/65535);
-          $Oy = $offset%65535;
+            $Ox = (int)($offset/65535);
+            $Oy = $offset%65535;
 
-          if ($Ox) $offset_pattern = '(?:.{65535}){'.$Ox.'}';
-          $offset_pattern = '^(?:'.$offset_pattern.'.{'.$Oy.'})';
+            if ($Ox) $offset_pattern = '(?:.{65535}){'.$Ox.'}';
+            $offset_pattern = '^(?:'.$offset_pattern.'.{'.$Oy.'})';
         } else {
-          $offset_pattern = '^';                      // offset == 0; just anchor the pattern
+            $offset_pattern = '^';                      // offset == 0; just anchor the pattern
         }
 
         // establish a pattern for length
         if (is_null($length)) {
-          $length_pattern = '(.*)$';                  // the rest of the string
+            $length_pattern = '(.*)$';                  // the rest of the string
         } else {
 
-          if (!isset($strlen)) $strlen = strlen(utf8_decode($str));    // see notes
-          if ($offset > $strlen) return '';           // another trivial case
+            if (!isset($strlen)) $strlen = strlen(utf8_decode($str));    // see notes
+            if ($offset > $strlen) return '';           // another trivial case
 
-          if ($length > 0) {
+            if ($length > 0) {
 
-            $length = min($strlen-$offset, $length);  // reduce any length that would go passed the end of the string
+                $length = min($strlen-$offset, $length);  // reduce any length that would go passed the end of the string
 
-            $Lx = (int)($length/65535);
-            $Ly = $length%65535;
+                $Lx = (int)($length/65535);
+                $Ly = $length%65535;
 
-            // +ve length requires ... a captured group of length characters
-            if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
-            $length_pattern = '('.$length_pattern.'.{'.$Ly.'})';
+                // +ve length requires ... a captured group of length characters
+                if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
+                    $length_pattern = '('.$length_pattern.'.{'.$Ly.'})';
 
-          } else if ($length < 0) {
+            } else if ($length < 0) {
 
-            if ($length < ($offset - $strlen)) return '';
+                if ($length < ($offset - $strlen)) return '';
 
-            $Lx = (int)((-$length)/65535);
-            $Ly = (-$length)%65535;
+                $Lx = (int)((-$length)/65535);
+                $Ly = (-$length)%65535;
 
-            // -ve length requires ... capture everything except a group of -length characters
-            //                         anchored at the tail-end of the string
-            if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
-            $length_pattern = '(.*)(?:'.$length_pattern.'.{'.$Ly.'})$';
-          }
+                // -ve length requires ... capture everything except a group of -length characters
+                //                         anchored at the tail-end of the string
+                if ($Lx) $length_pattern = '(?:.{65535}){'.$Lx.'}';
+                $length_pattern = '(.*)(?:'.$length_pattern.'.{'.$Ly.'})$';
+            }
         }
 
         if (!preg_match('#'.$offset_pattern.$length_pattern.'#us',$str,$match)) return '';
@@ -246,11 +246,11 @@ if(!function_exists('utf8_substr_replace')){
      * @see    substr_replace()
      */
     function utf8_substr_replace($string, $replacement, $start , $length=0 ){
-      $ret = '';
-      if($start>0) $ret .= utf8_substr($string, 0, $start);
-      $ret .= $replacement;
-      $ret .= utf8_substr($string, $start+$length);
-      return $ret;
+        $ret = '';
+        if($start>0) $ret .= utf8_substr($string, 0, $start);
+        $ret .= $replacement;
+        $ret .= utf8_substr($string, $start+$length);
+        return $ret;
     }
 }
 
@@ -263,12 +263,12 @@ if(!function_exists('utf8_ltrim')){
      * @return string
      */
     function utf8_ltrim($str,$charlist=''){
-      if($charlist == '') return ltrim($str);
+        if($charlist == '') return ltrim($str);
 
-      //quote charlist for use in a characterclass
-      $charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
+        //quote charlist for use in a characterclass
+        $charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
 
-      return preg_replace('/^['.$charlist.']+/u','',$str);
+        return preg_replace('/^['.$charlist.']+/u','',$str);
     }
 }
 
@@ -281,12 +281,12 @@ if(!function_exists('utf8_rtrim')){
      * @return string
      */
     function  utf8_rtrim($str,$charlist=''){
-      if($charlist == '') return rtrim($str);
+        if($charlist == '') return rtrim($str);
 
-      //quote charlist for use in a characterclass
-      $charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
+        //quote charlist for use in a characterclass
+        $charlist = preg_replace('!([\\\\\\-\\]\\[/])!','\\\${1}',$charlist);
 
-      return preg_replace('/['.$charlist.']+$/u','',$str);
+        return preg_replace('/['.$charlist.']+$/u','',$str);
     }
 }
 
@@ -299,9 +299,9 @@ if(!function_exists('utf8_trim')){
      * @return string
      */
     function  utf8_trim($str,$charlist='') {
-      if($charlist == '') return trim($str);
+        if($charlist == '') return trim($str);
 
-      return utf8_ltrim(utf8_rtrim($str,$charlist),$charlist);
+        return utf8_ltrim(utf8_rtrim($str,$charlist),$charlist);
     }
 }
 
@@ -316,10 +316,10 @@ if(!function_exists('utf8_strtolower')){
      * @see    utf8_strtoupper()
      */
     function utf8_strtolower($string){
-      if(UTF8_MBSTRING) return mb_strtolower($string,'utf-8');
+        if(UTF8_MBSTRING) return mb_strtolower($string,'utf-8');
 
-      global $UTF8_UPPER_TO_LOWER;
-      return strtr($string,$UTF8_UPPER_TO_LOWER);
+        global $UTF8_UPPER_TO_LOWER;
+        return strtr($string,$UTF8_UPPER_TO_LOWER);
     }
 }
 
@@ -334,10 +334,10 @@ if(!function_exists('utf8_strtoupper')){
      * @see    utf8_strtoupper()
      */
     function utf8_strtoupper($string){
-      if(UTF8_MBSTRING) return mb_strtoupper($string,'utf-8');
+        if(UTF8_MBSTRING) return mb_strtoupper($string,'utf-8');
 
-      global $UTF8_LOWER_TO_UPPER;
-      return strtr($string,$UTF8_LOWER_TO_UPPER);
+        global $UTF8_LOWER_TO_UPPER;
+        return strtr($string,$UTF8_LOWER_TO_UPPER);
     }
 }
 
@@ -351,15 +351,15 @@ if(!function_exists('utf8_ucfirst')){
      * @return string with first character as upper case (if applicable)
      */
     function utf8_ucfirst($str){
-      switch ( utf8_strlen($str) ) {
-        case 0:
-            return '';
-        case 1:
-            return utf8_strtoupper($str);
-        default:
-            preg_match('/^(.{1})(.*)$/us', $str, $matches);
-            return utf8_strtoupper($matches[1]).$matches[2];
-      }
+        switch ( utf8_strlen($str) ) {
+            case 0:
+                return '';
+            case 1:
+                return utf8_strtoupper($str);
+            default:
+                preg_match('/^(.{1})(.*)$/us', $str, $matches);
+                return utf8_strtoupper($matches[1]).$matches[2];
+        }
     }
 }
 
@@ -374,12 +374,12 @@ if(!function_exists('utf8_ucwords')){
      * @see http://www.php.net/ucwords
      */
     function utf8_ucwords($str) {
-      // Note: [\x0c\x09\x0b\x0a\x0d\x20] matches;
-      // form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns
-      // This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
-      $pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
+        // Note: [\x0c\x09\x0b\x0a\x0d\x20] matches;
+        // form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns
+        // This corresponds to the definition of a "word" defined at http://www.php.net/ucwords
+        $pattern = '/(^|([\x0c\x09\x0b\x0a\x0d\x20]+))([^\x0c\x09\x0b\x0a\x0d\x20]{1})[^\x0c\x09\x0b\x0a\x0d\x20]*/u';
 
-      return preg_replace_callback($pattern, 'utf8_ucwords_callback',$str);
+        return preg_replace_callback($pattern, 'utf8_ucwords_callback',$str);
     }
 
     /**
@@ -393,10 +393,10 @@ if(!function_exists('utf8_ucwords')){
      * @see utf8_strtoupper
      */
     function utf8_ucwords_callback($matches) {
-      $leadingws = $matches[2];
-      $ucfirst = utf8_strtoupper($matches[3]);
-      $ucword = utf8_substr_replace(ltrim($matches[0]),$ucfirst,0,1);
-      return $leadingws . $ucword;
+        $leadingws = $matches[2];
+        $ucfirst = utf8_strtoupper($matches[3]);
+        $ucword = utf8_substr_replace(ltrim($matches[0]),$ucfirst,0,1);
+        return $leadingws . $ucword;
     }
 }
 
@@ -550,13 +550,13 @@ if(!function_exists('utf8_unhtml')){
 if(!function_exists('utf8_decode_numeric')){
     function utf8_decode_numeric($ent) {
         switch ($ent[2]) {
-          case 'X':
-          case 'x':
-              $cp = hexdec($ent[3]);
-              break;
-          default:
-              $cp = intval($ent[3]);
-              break;
+            case 'X':
+            case 'x':
+                $cp = hexdec($ent[3]);
+                break;
+            default:
+                $cp = intval($ent[3]);
+                break;
         }
         return unicode_to_utf8(array($cp));
     }
@@ -789,24 +789,24 @@ if(!function_exists('unicode_to_utf8')){
 
         foreach (array_keys($arr) as $k) {
 
-            # ASCII range (including control chars)
             if ( ($arr[$k] >= 0) && ($arr[$k] <= 0x007f) ) {
+                # ASCII range (including control chars)
 
                 echo chr($arr[$k]);
 
-            # 2 byte sequence
             } else if ($arr[$k] <= 0x07ff) {
+                # 2 byte sequence
 
                 echo chr(0xc0 | ($arr[$k] >> 6));
                 echo chr(0x80 | ($arr[$k] & 0x003f));
 
-            # Byte order mark (skip)
             } else if($arr[$k] == 0xFEFF) {
+                # Byte order mark (skip)
 
                 // nop -- zap the BOM
 
-            # Test for illegal surrogates
             } else if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
+                # Test for illegal surrogates
 
                 // found a surrogate
                 if($strict){
@@ -818,15 +818,15 @@ if(!function_exists('unicode_to_utf8')){
                     return false;
                 }
 
-            # 3 byte sequence
             } else if ($arr[$k] <= 0xffff) {
+                # 3 byte sequence
 
                 echo chr(0xe0 | ($arr[$k] >> 12));
                 echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
                 echo chr(0x80 | ($arr[$k] & 0x003f));
 
-            # 4 byte sequence
             } else if ($arr[$k] <= 0x10ffff) {
+                # 4 byte sequence
 
                 echo chr(0xf0 | ($arr[$k] >> 18));
                 echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
@@ -957,163 +957,163 @@ if(!function_exists('utf8_correctIdx')){
 
 // only needed if no mb_string available
 if(!UTF8_MBSTRING){
-  /**
-   * UTF-8 Case lookup table
-   *
-   * This lookuptable defines the upper case letters to their correspponding
-   * lower case letter in UTF-8
-   *
-   * @author Andreas Gohr <andi@splitbrain.org>
-   */
-  global $UTF8_LOWER_TO_UPPER;
-  if(empty($UTF8_LOWER_TO_UPPER)) $UTF8_LOWER_TO_UPPER = array(
-    "z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T","s"=>"S","r"=>"R","q"=>"Q",
-    "p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J","i"=>"I","h"=>"H","g"=>"G",
-    "f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A","ῳ"=>"ῼ","ῥ"=>"Ῥ","ῡ"=>"Ῡ","ῑ"=>"Ῑ",
-    "ῐ"=>"Ῐ","ῃ"=>"ῌ","ι"=>"Ι","ᾳ"=>"ᾼ","ᾱ"=>"Ᾱ","ᾰ"=>"Ᾰ","ᾧ"=>"ᾯ","ᾦ"=>"ᾮ","ᾥ"=>"ᾭ","ᾤ"=>"ᾬ",
-    "ᾣ"=>"ᾫ","ᾢ"=>"ᾪ","ᾡ"=>"ᾩ","ᾗ"=>"ᾟ","ᾖ"=>"ᾞ","ᾕ"=>"ᾝ","ᾔ"=>"ᾜ","ᾓ"=>"ᾛ","ᾒ"=>"ᾚ","ᾑ"=>"ᾙ",
-    "ᾐ"=>"ᾘ","ᾇ"=>"ᾏ","ᾆ"=>"ᾎ","ᾅ"=>"ᾍ","ᾄ"=>"ᾌ","ᾃ"=>"ᾋ","ᾂ"=>"ᾊ","ᾁ"=>"ᾉ","ᾀ"=>"ᾈ","ώ"=>"Ώ",
-    "ὼ"=>"Ὼ","ύ"=>"Ύ","ὺ"=>"Ὺ","ό"=>"Ό","ὸ"=>"Ὸ","ί"=>"Ί","ὶ"=>"Ὶ","ή"=>"Ή","ὴ"=>"Ὴ","έ"=>"Έ",
-    "ὲ"=>"Ὲ","ά"=>"Ά","ὰ"=>"Ὰ","ὧ"=>"Ὧ","ὦ"=>"Ὦ","ὥ"=>"Ὥ","ὤ"=>"Ὤ","ὣ"=>"Ὣ","ὢ"=>"Ὢ","ὡ"=>"Ὡ",
-    "ὗ"=>"Ὗ","ὕ"=>"Ὕ","ὓ"=>"Ὓ","ὑ"=>"Ὑ","ὅ"=>"Ὅ","ὄ"=>"Ὄ","ὃ"=>"Ὃ","ὂ"=>"Ὂ","ὁ"=>"Ὁ","ὀ"=>"Ὀ",
-    "ἷ"=>"Ἷ","ἶ"=>"Ἶ","ἵ"=>"Ἵ","ἴ"=>"Ἴ","ἳ"=>"Ἳ","ἲ"=>"Ἲ","ἱ"=>"Ἱ","ἰ"=>"Ἰ","ἧ"=>"Ἧ","ἦ"=>"Ἦ",
-    "ἥ"=>"Ἥ","ἤ"=>"Ἤ","ἣ"=>"Ἣ","ἢ"=>"Ἢ","ἡ"=>"Ἡ","ἕ"=>"Ἕ","ἔ"=>"Ἔ","ἓ"=>"Ἓ","ἒ"=>"Ἒ","ἑ"=>"Ἑ",
-    "ἐ"=>"Ἐ","ἇ"=>"Ἇ","ἆ"=>"Ἆ","ἅ"=>"Ἅ","ἄ"=>"Ἄ","ἃ"=>"Ἃ","ἂ"=>"Ἂ","ἁ"=>"Ἁ","ἀ"=>"Ἀ","ỹ"=>"Ỹ",
-    "ỷ"=>"Ỷ","ỵ"=>"Ỵ","ỳ"=>"Ỳ","ự"=>"Ự","ữ"=>"Ữ","ử"=>"Ử","ừ"=>"Ừ","ứ"=>"Ứ","ủ"=>"Ủ","ụ"=>"Ụ",
-    "ợ"=>"Ợ","ỡ"=>"Ỡ","ở"=>"Ở","ờ"=>"Ờ","ớ"=>"Ớ","ộ"=>"Ộ","ỗ"=>"Ỗ","ổ"=>"Ổ","ồ"=>"Ồ","ố"=>"Ố",
-    "ỏ"=>"Ỏ","ọ"=>"Ọ","ị"=>"Ị","ỉ"=>"Ỉ","ệ"=>"Ệ","ễ"=>"Ễ","ể"=>"Ể","ề"=>"Ề","ế"=>"Ế","ẽ"=>"Ẽ",
-    "ẻ"=>"Ẻ","ẹ"=>"Ẹ","ặ"=>"Ặ","ẵ"=>"Ẵ","ẳ"=>"Ẳ","ằ"=>"Ằ","ắ"=>"Ắ","ậ"=>"Ậ","ẫ"=>"Ẫ","ẩ"=>"Ẩ",
-    "ầ"=>"Ầ","ấ"=>"Ấ","ả"=>"Ả","ạ"=>"Ạ","ẛ"=>"Ṡ","ẕ"=>"Ẕ","ẓ"=>"Ẓ","ẑ"=>"Ẑ","ẏ"=>"Ẏ","ẍ"=>"Ẍ",
-    "ẋ"=>"Ẋ","ẉ"=>"Ẉ","ẇ"=>"Ẇ","ẅ"=>"Ẅ","ẃ"=>"Ẃ","ẁ"=>"Ẁ","ṿ"=>"Ṿ","ṽ"=>"Ṽ","ṻ"=>"Ṻ","ṹ"=>"Ṹ",
-    "ṷ"=>"Ṷ","ṵ"=>"Ṵ","ṳ"=>"Ṳ","ṱ"=>"Ṱ","ṯ"=>"Ṯ","ṭ"=>"Ṭ","ṫ"=>"Ṫ","ṩ"=>"Ṩ","ṧ"=>"Ṧ","ṥ"=>"Ṥ",
-    "ṣ"=>"Ṣ","ṡ"=>"Ṡ","ṟ"=>"Ṟ","ṝ"=>"Ṝ","ṛ"=>"Ṛ","ṙ"=>"Ṙ","ṗ"=>"Ṗ","ṕ"=>"Ṕ","ṓ"=>"Ṓ","ṑ"=>"Ṑ",
-    "ṏ"=>"Ṏ","ṍ"=>"Ṍ","ṋ"=>"Ṋ","ṉ"=>"Ṉ","ṇ"=>"Ṇ","ṅ"=>"Ṅ","ṃ"=>"Ṃ","ṁ"=>"Ṁ","ḿ"=>"Ḿ","ḽ"=>"Ḽ",
-    "ḻ"=>"Ḻ","ḹ"=>"Ḹ","ḷ"=>"Ḷ","ḵ"=>"Ḵ","ḳ"=>"Ḳ","ḱ"=>"Ḱ","ḯ"=>"Ḯ","ḭ"=>"Ḭ","ḫ"=>"Ḫ","ḩ"=>"Ḩ",
-    "ḧ"=>"Ḧ","ḥ"=>"Ḥ","ḣ"=>"Ḣ","ḡ"=>"Ḡ","ḟ"=>"Ḟ","ḝ"=>"Ḝ","ḛ"=>"Ḛ","ḙ"=>"Ḙ","ḗ"=>"Ḗ","ḕ"=>"Ḕ",
-    "ḓ"=>"Ḓ","ḑ"=>"Ḑ","ḏ"=>"Ḏ","ḍ"=>"Ḍ","ḋ"=>"Ḋ","ḉ"=>"Ḉ","ḇ"=>"Ḇ","ḅ"=>"Ḅ","ḃ"=>"Ḃ","ḁ"=>"Ḁ",
-    "ֆ"=>"Ֆ","օ"=>"Օ","ք"=>"Ք","փ"=>"Փ","ւ"=>"Ւ","ց"=>"Ց","ր"=>"Ր","տ"=>"Տ","վ"=>"Վ","ս"=>"Ս",
-    "ռ"=>"Ռ","ջ"=>"Ջ","պ"=>"Պ","չ"=>"Չ","ո"=>"Ո","շ"=>"Շ","ն"=>"Ն","յ"=>"Յ","մ"=>"Մ","ճ"=>"Ճ",
-    "ղ"=>"Ղ","ձ"=>"Ձ","հ"=>"Հ","կ"=>"Կ","ծ"=>"Ծ","խ"=>"Խ","լ"=>"Լ","ի"=>"Ի","ժ"=>"Ժ","թ"=>"Թ",
-    "ը"=>"Ը","է"=>"Է","զ"=>"Զ","ե"=>"Ե","դ"=>"Դ","գ"=>"Գ","բ"=>"Բ","ա"=>"Ա","ԏ"=>"Ԏ","ԍ"=>"Ԍ",
-    "ԋ"=>"Ԋ","ԉ"=>"Ԉ","ԇ"=>"Ԇ","ԅ"=>"Ԅ","ԃ"=>"Ԃ","ԁ"=>"Ԁ","ӹ"=>"Ӹ","ӵ"=>"Ӵ","ӳ"=>"Ӳ","ӱ"=>"Ӱ",
-    "ӯ"=>"Ӯ","ӭ"=>"Ӭ","ӫ"=>"Ӫ","ө"=>"Ө","ӧ"=>"Ӧ","ӥ"=>"Ӥ","ӣ"=>"Ӣ","ӡ"=>"Ӡ","ӟ"=>"Ӟ","ӝ"=>"Ӝ",
-    "ӛ"=>"Ӛ","ә"=>"Ә","ӗ"=>"Ӗ","ӕ"=>"Ӕ","ӓ"=>"Ӓ","ӑ"=>"Ӑ","ӎ"=>"Ӎ","ӌ"=>"Ӌ","ӊ"=>"Ӊ","ӈ"=>"Ӈ",
-    "ӆ"=>"Ӆ","ӄ"=>"Ӄ","ӂ"=>"Ӂ","ҿ"=>"Ҿ","ҽ"=>"Ҽ","һ"=>"Һ","ҹ"=>"Ҹ","ҷ"=>"Ҷ","ҵ"=>"Ҵ","ҳ"=>"Ҳ",
-    "Ò±"=>"Ò°","Ò¯"=>"Ò®","Ò­"=>"Ò¬","Ò«"=>"Òª","Ò©"=>"Ò¨","Ò§"=>"Ò¦","Ò¥"=>"Ò¤","Ò£"=>"Ò¢","Ò¡"=>"Ò ","ÒŸ"=>"Òž",
-    "ҝ"=>"Ҝ","қ"=>"Қ","ҙ"=>"Ҙ","җ"=>"Җ","ҕ"=>"Ҕ","ғ"=>"Ғ","ґ"=>"Ґ","ҏ"=>"Ҏ","ҍ"=>"Ҍ","ҋ"=>"Ҋ",
-    "ҁ"=>"Ҁ","ѿ"=>"Ѿ","ѽ"=>"Ѽ","ѻ"=>"Ѻ","ѹ"=>"Ѹ","ѷ"=>"Ѷ","ѵ"=>"Ѵ","ѳ"=>"Ѳ","ѱ"=>"Ѱ","ѯ"=>"Ѯ",
-    "ѭ"=>"Ѭ","ѫ"=>"Ѫ","ѩ"=>"Ѩ","ѧ"=>"Ѧ","ѥ"=>"Ѥ","ѣ"=>"Ѣ","ѡ"=>"Ѡ","џ"=>"Џ","ў"=>"Ў","ѝ"=>"Ѝ",
-    "ќ"=>"Ќ","ћ"=>"Ћ","њ"=>"Њ","љ"=>"Љ","ј"=>"Ј","ї"=>"Ї","і"=>"І","ѕ"=>"Ѕ","є"=>"Є","ѓ"=>"Ѓ",
-    "ђ"=>"Ђ","ё"=>"Ё","ѐ"=>"Ѐ","я"=>"Я","ю"=>"Ю","э"=>"Э","ь"=>"Ь","ы"=>"Ы","ъ"=>"Ъ","щ"=>"Щ",
-    "ш"=>"Ш","ч"=>"Ч","ц"=>"Ц","х"=>"Х","ф"=>"Ф","у"=>"У","т"=>"Т","с"=>"С","р"=>"Р","п"=>"П",
-    "о"=>"О","н"=>"Н","м"=>"М","л"=>"Л","к"=>"К","й"=>"Й","и"=>"И","з"=>"З","ж"=>"Ж","е"=>"Е",
-    "д"=>"Д","г"=>"Г","в"=>"В","б"=>"Б","а"=>"А","ϵ"=>"Ε","ϲ"=>"Σ","ϱ"=>"Ρ","ϰ"=>"Κ","ϯ"=>"Ϯ",
-    "ϭ"=>"Ϭ","ϫ"=>"Ϫ","ϩ"=>"Ϩ","ϧ"=>"Ϧ","ϥ"=>"Ϥ","ϣ"=>"Ϣ","ϡ"=>"Ϡ","ϟ"=>"Ϟ","ϝ"=>"Ϝ","ϛ"=>"Ϛ",
-    "ϙ"=>"Ϙ","ϖ"=>"Π","ϕ"=>"Φ","ϑ"=>"Θ","ϐ"=>"Β","ώ"=>"Ώ","ύ"=>"Ύ","ό"=>"Ό","ϋ"=>"Ϋ","ϊ"=>"Ϊ",
-    "ω"=>"Ω","ψ"=>"Ψ","χ"=>"Χ","φ"=>"Φ","υ"=>"Υ","τ"=>"Τ","σ"=>"Σ","ς"=>"Σ","ρ"=>"Ρ","π"=>"Π",
-    "ο"=>"Ο","ξ"=>"Ξ","ν"=>"Ν","μ"=>"Μ","λ"=>"Λ","κ"=>"Κ","ι"=>"Ι","θ"=>"Θ","η"=>"Η","ζ"=>"Ζ",
-    "ε"=>"Ε","δ"=>"Δ","γ"=>"Γ","β"=>"Β","α"=>"Α","ί"=>"Ί","ή"=>"Ή","έ"=>"Έ","ά"=>"Ά","ʒ"=>"Ʒ",
-    "ʋ"=>"Ʋ","ʊ"=>"Ʊ","ʈ"=>"Ʈ","ʃ"=>"Ʃ","ʀ"=>"Ʀ","ɵ"=>"Ɵ","ɲ"=>"Ɲ","ɯ"=>"Ɯ","ɩ"=>"Ɩ","ɨ"=>"Ɨ",
-    "ɣ"=>"Ɣ","ɛ"=>"Ɛ","ə"=>"Ə","ɗ"=>"Ɗ","ɖ"=>"Ɖ","ɔ"=>"Ɔ","ɓ"=>"Ɓ","ȳ"=>"Ȳ","ȱ"=>"Ȱ","ȯ"=>"Ȯ",
-    "ȭ"=>"Ȭ","ȫ"=>"Ȫ","ȩ"=>"Ȩ","ȧ"=>"Ȧ","ȥ"=>"Ȥ","ȣ"=>"Ȣ","ȟ"=>"Ȟ","ȝ"=>"Ȝ","ț"=>"Ț","ș"=>"Ș",
-    "ȗ"=>"Ȗ","ȕ"=>"Ȕ","ȓ"=>"Ȓ","ȑ"=>"Ȑ","ȏ"=>"Ȏ","ȍ"=>"Ȍ","ȋ"=>"Ȋ","ȉ"=>"Ȉ","ȇ"=>"Ȇ","ȅ"=>"Ȅ",
-    "ȃ"=>"Ȃ","ȁ"=>"Ȁ","ǿ"=>"Ǿ","ǽ"=>"Ǽ","ǻ"=>"Ǻ","ǹ"=>"Ǹ","ǵ"=>"Ǵ","dz"=>"Dz","ǯ"=>"Ǯ","ǭ"=>"Ǭ",
-    "ǫ"=>"Ǫ","ǩ"=>"Ǩ","ǧ"=>"Ǧ","ǥ"=>"Ǥ","ǣ"=>"Ǣ","ǡ"=>"Ǡ","ǟ"=>"Ǟ","ǝ"=>"Ǝ","ǜ"=>"Ǜ","ǚ"=>"Ǚ",
-    "ǘ"=>"Ǘ","ǖ"=>"Ǖ","ǔ"=>"Ǔ","ǒ"=>"Ǒ","ǐ"=>"Ǐ","ǎ"=>"Ǎ","nj"=>"Nj","lj"=>"Lj","dž"=>"Dž","ƿ"=>"Ƿ",
-    "ƽ"=>"Ƽ","ƹ"=>"Ƹ","ƶ"=>"Ƶ","ƴ"=>"Ƴ","ư"=>"Ư","ƭ"=>"Ƭ","ƨ"=>"Ƨ","ƥ"=>"Ƥ","ƣ"=>"Ƣ","ơ"=>"Ơ",
-    "ƞ"=>"Ƞ","ƙ"=>"Ƙ","ƕ"=>"Ƕ","ƒ"=>"Ƒ","ƌ"=>"Ƌ","ƈ"=>"Ƈ","ƅ"=>"Ƅ","ƃ"=>"Ƃ","ſ"=>"S","ž"=>"Ž",
-    "ż"=>"Ż","ź"=>"Ź","ŷ"=>"Ŷ","ŵ"=>"Ŵ","ų"=>"Ų","ű"=>"Ű","ů"=>"Ů","ŭ"=>"Ŭ","ū"=>"Ū","ũ"=>"Ũ",
-    "ŧ"=>"Ŧ","ť"=>"Ť","ţ"=>"Ţ","š"=>"Š","ş"=>"Ş","ŝ"=>"Ŝ","ś"=>"Ś","ř"=>"Ř","ŗ"=>"Ŗ","ŕ"=>"Ŕ",
-    "œ"=>"Œ","ő"=>"Ő","ŏ"=>"Ŏ","ō"=>"Ō","ŋ"=>"Ŋ","ň"=>"Ň","ņ"=>"Ņ","ń"=>"Ń","ł"=>"Ł","ŀ"=>"Ŀ",
-    "ľ"=>"Ľ","ļ"=>"Ļ","ĺ"=>"Ĺ","ķ"=>"Ķ","ĵ"=>"Ĵ","ij"=>"IJ","ı"=>"I","į"=>"Į","ĭ"=>"Ĭ","ī"=>"Ī",
-    "ĩ"=>"Ĩ","ħ"=>"Ħ","ĥ"=>"Ĥ","ģ"=>"Ģ","ġ"=>"Ġ","ğ"=>"Ğ","ĝ"=>"Ĝ","ě"=>"Ě","ę"=>"Ę","ė"=>"Ė",
-    "ĕ"=>"Ĕ","ē"=>"Ē","đ"=>"Đ","ď"=>"Ď","č"=>"Č","ċ"=>"Ċ","ĉ"=>"Ĉ","ć"=>"Ć","ą"=>"Ą","ă"=>"Ă",
-    "ā"=>"Ā","ÿ"=>"Ÿ","þ"=>"Þ","ý"=>"Ý","ü"=>"Ü","û"=>"Û","ú"=>"Ú","ù"=>"Ù","ø"=>"Ø","ö"=>"Ö",
-    "õ"=>"Õ","ô"=>"Ô","ó"=>"Ó","ò"=>"Ò","ñ"=>"Ñ","ð"=>"Ð","ï"=>"Ï","î"=>"Î","í"=>"Í","ì"=>"Ì",
-    "ë"=>"Ë","ê"=>"Ê","é"=>"É","è"=>"È","ç"=>"Ç","æ"=>"Æ","å"=>"Å","ä"=>"Ä","ã"=>"Ã","â"=>"Â",
-    "á"=>"Á","à"=>"À","µ"=>"Μ","z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T",
-    "s"=>"S","r"=>"R","q"=>"Q","p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J",
-    "i"=>"I","h"=>"H","g"=>"G","f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A"
-  );
-
-  /**
-   * UTF-8 Case lookup table
-   *
-   * This lookuptable defines the lower case letters to their correspponding
-   * upper case letter in UTF-8
-   *
-   * @author Andreas Gohr <andi@splitbrain.org>
-   */
-  global $UTF8_UPPER_TO_LOWER;
-  if(empty($UTF8_UPPER_TO_LOWER)) $UTF8_UPPER_TO_LOWER = array (
-    "Z"=>"z","Y"=>"y","X"=>"x","W"=>"w","V"=>"v","U"=>"u","T"=>"t","S"=>"s","R"=>"r","Q"=>"q",
-    "P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j","I"=>"i","H"=>"h","G"=>"g",
-    "F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a","ῼ"=>"ῳ","Ῥ"=>"ῥ","Ῡ"=>"ῡ","Ῑ"=>"ῑ",
-    "Ῐ"=>"ῐ","ῌ"=>"ῃ","Ι"=>"ι","ᾼ"=>"ᾳ","Ᾱ"=>"ᾱ","Ᾰ"=>"ᾰ","ᾯ"=>"ᾧ","ᾮ"=>"ᾦ","ᾭ"=>"ᾥ","ᾬ"=>"ᾤ",
-    "ᾫ"=>"ᾣ","ᾪ"=>"ᾢ","ᾩ"=>"ᾡ","ᾟ"=>"ᾗ","ᾞ"=>"ᾖ","ᾝ"=>"ᾕ","ᾜ"=>"ᾔ","ᾛ"=>"ᾓ","ᾚ"=>"ᾒ","ᾙ"=>"ᾑ",
-    "ᾘ"=>"ᾐ","ᾏ"=>"ᾇ","ᾎ"=>"ᾆ","ᾍ"=>"ᾅ","ᾌ"=>"ᾄ","ᾋ"=>"ᾃ","ᾊ"=>"ᾂ","ᾉ"=>"ᾁ","ᾈ"=>"ᾀ","Ώ"=>"ώ",
-    "Ὼ"=>"ὼ","Ύ"=>"ύ","Ὺ"=>"ὺ","Ό"=>"ό","Ὸ"=>"ὸ","Ί"=>"ί","Ὶ"=>"ὶ","Ή"=>"ή","Ὴ"=>"ὴ","Έ"=>"έ",
-    "Ὲ"=>"ὲ","Ά"=>"ά","Ὰ"=>"ὰ","Ὧ"=>"ὧ","Ὦ"=>"ὦ","Ὥ"=>"ὥ","Ὤ"=>"ὤ","Ὣ"=>"ὣ","Ὢ"=>"ὢ","Ὡ"=>"ὡ",
-    "Ὗ"=>"ὗ","Ὕ"=>"ὕ","Ὓ"=>"ὓ","Ὑ"=>"ὑ","Ὅ"=>"ὅ","Ὄ"=>"ὄ","Ὃ"=>"ὃ","Ὂ"=>"ὂ","Ὁ"=>"ὁ","Ὀ"=>"ὀ",
-    "Ἷ"=>"ἷ","Ἶ"=>"ἶ","Ἵ"=>"ἵ","Ἴ"=>"ἴ","Ἳ"=>"ἳ","Ἲ"=>"ἲ","Ἱ"=>"ἱ","Ἰ"=>"ἰ","Ἧ"=>"ἧ","Ἦ"=>"ἦ",
-    "Ἥ"=>"ἥ","Ἤ"=>"ἤ","Ἣ"=>"ἣ","Ἢ"=>"ἢ","Ἡ"=>"ἡ","Ἕ"=>"ἕ","Ἔ"=>"ἔ","Ἓ"=>"ἓ","Ἒ"=>"ἒ","Ἑ"=>"ἑ",
-    "Ἐ"=>"ἐ","Ἇ"=>"ἇ","Ἆ"=>"ἆ","Ἅ"=>"ἅ","Ἄ"=>"ἄ","Ἃ"=>"ἃ","Ἂ"=>"ἂ","Ἁ"=>"ἁ","Ἀ"=>"ἀ","Ỹ"=>"ỹ",
-    "Ỷ"=>"ỷ","Ỵ"=>"ỵ","Ỳ"=>"ỳ","Ự"=>"ự","Ữ"=>"ữ","Ử"=>"ử","Ừ"=>"ừ","Ứ"=>"ứ","Ủ"=>"ủ","Ụ"=>"ụ",
-    "Ợ"=>"ợ","Ỡ"=>"ỡ","Ở"=>"ở","Ờ"=>"ờ","Ớ"=>"ớ","Ộ"=>"ộ","Ỗ"=>"ỗ","Ổ"=>"ổ","Ồ"=>"ồ","Ố"=>"ố",
-    "Ỏ"=>"ỏ","Ọ"=>"ọ","Ị"=>"ị","Ỉ"=>"ỉ","Ệ"=>"ệ","Ễ"=>"ễ","Ể"=>"ể","Ề"=>"ề","Ế"=>"ế","Ẽ"=>"ẽ",
-    "Ẻ"=>"ẻ","Ẹ"=>"ẹ","Ặ"=>"ặ","Ẵ"=>"ẵ","Ẳ"=>"ẳ","Ằ"=>"ằ","Ắ"=>"ắ","Ậ"=>"ậ","Ẫ"=>"ẫ","Ẩ"=>"ẩ",
-    "Ầ"=>"ầ","Ấ"=>"ấ","Ả"=>"ả","Ạ"=>"ạ","Ṡ"=>"ẛ","Ẕ"=>"ẕ","Ẓ"=>"ẓ","Ẑ"=>"ẑ","Ẏ"=>"ẏ","Ẍ"=>"ẍ",
-    "Ẋ"=>"ẋ","Ẉ"=>"ẉ","Ẇ"=>"ẇ","Ẅ"=>"ẅ","Ẃ"=>"ẃ","Ẁ"=>"ẁ","Ṿ"=>"ṿ","Ṽ"=>"ṽ","Ṻ"=>"ṻ","Ṹ"=>"ṹ",
-    "Ṷ"=>"ṷ","Ṵ"=>"ṵ","Ṳ"=>"ṳ","Ṱ"=>"ṱ","Ṯ"=>"ṯ","Ṭ"=>"ṭ","Ṫ"=>"ṫ","Ṩ"=>"ṩ","Ṧ"=>"ṧ","Ṥ"=>"ṥ",
-    "Ṣ"=>"ṣ","Ṡ"=>"ṡ","Ṟ"=>"ṟ","Ṝ"=>"ṝ","Ṛ"=>"ṛ","Ṙ"=>"ṙ","Ṗ"=>"ṗ","Ṕ"=>"ṕ","Ṓ"=>"ṓ","Ṑ"=>"ṑ",
-    "Ṏ"=>"ṏ","Ṍ"=>"ṍ","Ṋ"=>"ṋ","Ṉ"=>"ṉ","Ṇ"=>"ṇ","Ṅ"=>"ṅ","Ṃ"=>"ṃ","Ṁ"=>"ṁ","Ḿ"=>"ḿ","Ḽ"=>"ḽ",
-    "Ḻ"=>"ḻ","Ḹ"=>"ḹ","Ḷ"=>"ḷ","Ḵ"=>"ḵ","Ḳ"=>"ḳ","Ḱ"=>"ḱ","Ḯ"=>"ḯ","Ḭ"=>"ḭ","Ḫ"=>"ḫ","Ḩ"=>"ḩ",
-    "Ḧ"=>"ḧ","Ḥ"=>"ḥ","Ḣ"=>"ḣ","Ḡ"=>"ḡ","Ḟ"=>"ḟ","Ḝ"=>"ḝ","Ḛ"=>"ḛ","Ḙ"=>"ḙ","Ḗ"=>"ḗ","Ḕ"=>"ḕ",
-    "Ḓ"=>"ḓ","Ḑ"=>"ḑ","Ḏ"=>"ḏ","Ḍ"=>"ḍ","Ḋ"=>"ḋ","Ḉ"=>"ḉ","Ḇ"=>"ḇ","Ḅ"=>"ḅ","Ḃ"=>"ḃ","Ḁ"=>"ḁ",
-    "Ֆ"=>"ֆ","Օ"=>"օ","Ք"=>"ք","Փ"=>"փ","Ւ"=>"ւ","Ց"=>"ց","Ր"=>"ր","Տ"=>"տ","Վ"=>"վ","Ս"=>"ս",
-    "Ռ"=>"ռ","Ջ"=>"ջ","Պ"=>"պ","Չ"=>"չ","Ո"=>"ո","Շ"=>"շ","Ն"=>"ն","Յ"=>"յ","Մ"=>"մ","Ճ"=>"ճ",
-    "Ղ"=>"ղ","Ձ"=>"ձ","Հ"=>"հ","Կ"=>"կ","Ծ"=>"ծ","Խ"=>"խ","Լ"=>"լ","Ի"=>"ի","Ժ"=>"ժ","Թ"=>"թ",
-    "Ը"=>"ը","Է"=>"է","Զ"=>"զ","Ե"=>"ե","Դ"=>"դ","Գ"=>"գ","Բ"=>"բ","Ա"=>"ա","Ԏ"=>"ԏ","Ԍ"=>"ԍ",
-    "Ԋ"=>"ԋ","Ԉ"=>"ԉ","Ԇ"=>"ԇ","Ԅ"=>"ԅ","Ԃ"=>"ԃ","Ԁ"=>"ԁ","Ӹ"=>"ӹ","Ӵ"=>"ӵ","Ӳ"=>"ӳ","Ӱ"=>"ӱ",
-    "Ӯ"=>"ӯ","Ӭ"=>"ӭ","Ӫ"=>"ӫ","Ө"=>"ө","Ӧ"=>"ӧ","Ӥ"=>"ӥ","Ӣ"=>"ӣ","Ӡ"=>"ӡ","Ӟ"=>"ӟ","Ӝ"=>"ӝ",
-    "Ӛ"=>"ӛ","Ә"=>"ә","Ӗ"=>"ӗ","Ӕ"=>"ӕ","Ӓ"=>"ӓ","Ӑ"=>"ӑ","Ӎ"=>"ӎ","Ӌ"=>"ӌ","Ӊ"=>"ӊ","Ӈ"=>"ӈ",
-    "Ӆ"=>"ӆ","Ӄ"=>"ӄ","Ӂ"=>"ӂ","Ҿ"=>"ҿ","Ҽ"=>"ҽ","Һ"=>"һ","Ҹ"=>"ҹ","Ҷ"=>"ҷ","Ҵ"=>"ҵ","Ҳ"=>"ҳ",
-    "Ò°"=>"Ò±","Ò®"=>"Ò¯","Ò¬"=>"Ò­","Òª"=>"Ò«","Ò¨"=>"Ò©","Ò¦"=>"Ò§","Ò¤"=>"Ò¥","Ò¢"=>"Ò£","Ò "=>"Ò¡","Òž"=>"ÒŸ",
-    "Ҝ"=>"ҝ","Қ"=>"қ","Ҙ"=>"ҙ","Җ"=>"җ","Ҕ"=>"ҕ","Ғ"=>"ғ","Ґ"=>"ґ","Ҏ"=>"ҏ","Ҍ"=>"ҍ","Ҋ"=>"ҋ",
-    "Ҁ"=>"ҁ","Ѿ"=>"ѿ","Ѽ"=>"ѽ","Ѻ"=>"ѻ","Ѹ"=>"ѹ","Ѷ"=>"ѷ","Ѵ"=>"ѵ","Ѳ"=>"ѳ","Ѱ"=>"ѱ","Ѯ"=>"ѯ",
-    "Ѭ"=>"ѭ","Ѫ"=>"ѫ","Ѩ"=>"ѩ","Ѧ"=>"ѧ","Ѥ"=>"ѥ","Ѣ"=>"ѣ","Ѡ"=>"ѡ","Џ"=>"џ","Ў"=>"ў","Ѝ"=>"ѝ",
-    "Ќ"=>"ќ","Ћ"=>"ћ","Њ"=>"њ","Љ"=>"љ","Ј"=>"ј","Ї"=>"ї","І"=>"і","Ѕ"=>"ѕ","Є"=>"є","Ѓ"=>"ѓ",
-    "Ђ"=>"ђ","Ё"=>"ё","Ѐ"=>"ѐ","Я"=>"я","Ю"=>"ю","Э"=>"э","Ь"=>"ь","Ы"=>"ы","Ъ"=>"ъ","Щ"=>"щ",
-    "Ш"=>"ш","Ч"=>"ч","Ц"=>"ц","Х"=>"х","Ф"=>"ф","У"=>"у","Т"=>"т","С"=>"с","Р"=>"р","П"=>"п",
-    "О"=>"о","Н"=>"н","М"=>"м","Л"=>"л","К"=>"к","Й"=>"й","И"=>"и","З"=>"з","Ж"=>"ж","Е"=>"е",
-    "Д"=>"д","Г"=>"г","В"=>"в","Б"=>"б","А"=>"а","Ε"=>"ϵ","Σ"=>"ϲ","Ρ"=>"ϱ","Κ"=>"ϰ","Ϯ"=>"ϯ",
-    "Ϭ"=>"ϭ","Ϫ"=>"ϫ","Ϩ"=>"ϩ","Ϧ"=>"ϧ","Ϥ"=>"ϥ","Ϣ"=>"ϣ","Ϡ"=>"ϡ","Ϟ"=>"ϟ","Ϝ"=>"ϝ","Ϛ"=>"ϛ",
-    "Ϙ"=>"ϙ","Π"=>"ϖ","Φ"=>"ϕ","Θ"=>"ϑ","Β"=>"ϐ","Ώ"=>"ώ","Ύ"=>"ύ","Ό"=>"ό","Ϋ"=>"ϋ","Ϊ"=>"ϊ",
-    "Ω"=>"ω","Ψ"=>"ψ","Χ"=>"χ","Φ"=>"φ","Υ"=>"υ","Τ"=>"τ","Σ"=>"σ","Σ"=>"ς","Ρ"=>"ρ","Π"=>"π",
-    "Ο"=>"ο","Ξ"=>"ξ","Ν"=>"ν","Μ"=>"μ","Λ"=>"λ","Κ"=>"κ","Ι"=>"ι","Θ"=>"θ","Η"=>"η","Ζ"=>"ζ",
-    "Ε"=>"ε","Δ"=>"δ","Γ"=>"γ","Β"=>"β","Α"=>"α","Ί"=>"ί","Ή"=>"ή","Έ"=>"έ","Ά"=>"ά","Ʒ"=>"ʒ",
-    "Ʋ"=>"ʋ","Ʊ"=>"ʊ","Ʈ"=>"ʈ","Ʃ"=>"ʃ","Ʀ"=>"ʀ","Ɵ"=>"ɵ","Ɲ"=>"ɲ","Ɯ"=>"ɯ","Ɩ"=>"ɩ","Ɨ"=>"ɨ",
-    "Ɣ"=>"ɣ","Ɛ"=>"ɛ","Ə"=>"ə","Ɗ"=>"ɗ","Ɖ"=>"ɖ","Ɔ"=>"ɔ","Ɓ"=>"ɓ","Ȳ"=>"ȳ","Ȱ"=>"ȱ","Ȯ"=>"ȯ",
-    "Ȭ"=>"ȭ","Ȫ"=>"ȫ","Ȩ"=>"ȩ","Ȧ"=>"ȧ","Ȥ"=>"ȥ","Ȣ"=>"ȣ","Ȟ"=>"ȟ","Ȝ"=>"ȝ","Ț"=>"ț","Ș"=>"ș",
-    "Ȗ"=>"ȗ","Ȕ"=>"ȕ","Ȓ"=>"ȓ","Ȑ"=>"ȑ","Ȏ"=>"ȏ","Ȍ"=>"ȍ","Ȋ"=>"ȋ","Ȉ"=>"ȉ","Ȇ"=>"ȇ","Ȅ"=>"ȅ",
-    "Ȃ"=>"ȃ","Ȁ"=>"ȁ","Ǿ"=>"ǿ","Ǽ"=>"ǽ","Ǻ"=>"ǻ","Ǹ"=>"ǹ","Ǵ"=>"ǵ","Dz"=>"dz","Ǯ"=>"ǯ","Ǭ"=>"ǭ",
-    "Ǫ"=>"ǫ","Ǩ"=>"ǩ","Ǧ"=>"ǧ","Ǥ"=>"ǥ","Ǣ"=>"ǣ","Ǡ"=>"ǡ","Ǟ"=>"ǟ","Ǝ"=>"ǝ","Ǜ"=>"ǜ","Ǚ"=>"ǚ",
-    "Ǘ"=>"ǘ","Ǖ"=>"ǖ","Ǔ"=>"ǔ","Ǒ"=>"ǒ","Ǐ"=>"ǐ","Ǎ"=>"ǎ","Nj"=>"nj","Lj"=>"lj","Dž"=>"dž","Ƿ"=>"ƿ",
-    "Ƽ"=>"ƽ","Ƹ"=>"ƹ","Ƶ"=>"ƶ","Ƴ"=>"ƴ","Ư"=>"ư","Ƭ"=>"ƭ","Ƨ"=>"ƨ","Ƥ"=>"ƥ","Ƣ"=>"ƣ","Ơ"=>"ơ",
-    "Ƞ"=>"ƞ","Ƙ"=>"ƙ","Ƕ"=>"ƕ","Ƒ"=>"ƒ","Ƌ"=>"ƌ","Ƈ"=>"ƈ","Ƅ"=>"ƅ","Ƃ"=>"ƃ","S"=>"ſ","Ž"=>"ž",
-    "Ż"=>"ż","Ź"=>"ź","Ŷ"=>"ŷ","Ŵ"=>"ŵ","Ų"=>"ų","Ű"=>"ű","Ů"=>"ů","Ŭ"=>"ŭ","Ū"=>"ū","Ũ"=>"ũ",
-    "Ŧ"=>"ŧ","Ť"=>"ť","Ţ"=>"ţ","Š"=>"š","Ş"=>"ş","Ŝ"=>"ŝ","Ś"=>"ś","Ř"=>"ř","Ŗ"=>"ŗ","Ŕ"=>"ŕ",
-    "Œ"=>"œ","Ő"=>"ő","Ŏ"=>"ŏ","Ō"=>"ō","Ŋ"=>"ŋ","Ň"=>"ň","Ņ"=>"ņ","Ń"=>"ń","Ł"=>"ł","Ŀ"=>"ŀ",
-    "Ľ"=>"ľ","Ļ"=>"ļ","Ĺ"=>"ĺ","Ķ"=>"ķ","Ĵ"=>"ĵ","IJ"=>"ij","I"=>"ı","Į"=>"į","Ĭ"=>"ĭ","Ī"=>"ī",
-    "Ĩ"=>"ĩ","Ħ"=>"ħ","Ĥ"=>"ĥ","Ģ"=>"ģ","Ġ"=>"ġ","Ğ"=>"ğ","Ĝ"=>"ĝ","Ě"=>"ě","Ę"=>"ę","Ė"=>"ė",
-    "Ĕ"=>"ĕ","Ē"=>"ē","Đ"=>"đ","Ď"=>"ď","Č"=>"č","Ċ"=>"ċ","Ĉ"=>"ĉ","Ć"=>"ć","Ą"=>"ą","Ă"=>"ă",
-    "Ā"=>"ā","Ÿ"=>"ÿ","Þ"=>"þ","Ý"=>"ý","Ü"=>"ü","Û"=>"û","Ú"=>"ú","Ù"=>"ù","Ø"=>"ø","Ö"=>"ö",
-    "Õ"=>"õ","Ô"=>"ô","Ó"=>"ó","Ò"=>"ò","Ñ"=>"ñ","Ð"=>"ð","Ï"=>"ï","Î"=>"î","Í"=>"í","Ì"=>"ì",
-    "Ë"=>"ë","Ê"=>"ê","É"=>"é","È"=>"è","Ç"=>"ç","Æ"=>"æ","Å"=>"å","Ä"=>"ä","Ã"=>"ã","Â"=>"â",
-    "Á"=>"á","À"=>"à","Μ"=>"µ","Z"=>"z","Y"=>"y","X"=>"x","W"=>"w","V"=>"v","U"=>"u","T"=>"t",
-    "S"=>"s","R"=>"r","Q"=>"q","P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j",
-    "I"=>"i","H"=>"h","G"=>"g","F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a"
-  );
+    /**
+     * UTF-8 Case lookup table
+     *
+     * This lookuptable defines the upper case letters to their correspponding
+     * lower case letter in UTF-8
+     *
+     * @author Andreas Gohr <andi@splitbrain.org>
+     */
+    global $UTF8_LOWER_TO_UPPER;
+    if(empty($UTF8_LOWER_TO_UPPER)) $UTF8_LOWER_TO_UPPER = array(
+            "z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T","s"=>"S","r"=>"R","q"=>"Q",
+            "p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J","i"=>"I","h"=>"H","g"=>"G",
+            "f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A","ῳ"=>"ῼ","ῥ"=>"Ῥ","ῡ"=>"Ῡ","ῑ"=>"Ῑ",
+            "ῐ"=>"Ῐ","ῃ"=>"ῌ","ι"=>"Ι","ᾳ"=>"ᾼ","ᾱ"=>"Ᾱ","ᾰ"=>"Ᾰ","ᾧ"=>"ᾯ","ᾦ"=>"ᾮ","ᾥ"=>"ᾭ","ᾤ"=>"ᾬ",
+            "ᾣ"=>"ᾫ","ᾢ"=>"ᾪ","ᾡ"=>"ᾩ","ᾗ"=>"ᾟ","ᾖ"=>"ᾞ","ᾕ"=>"ᾝ","ᾔ"=>"ᾜ","ᾓ"=>"ᾛ","ᾒ"=>"ᾚ","ᾑ"=>"ᾙ",
+            "ᾐ"=>"ᾘ","ᾇ"=>"ᾏ","ᾆ"=>"ᾎ","ᾅ"=>"ᾍ","ᾄ"=>"ᾌ","ᾃ"=>"ᾋ","ᾂ"=>"ᾊ","ᾁ"=>"ᾉ","ᾀ"=>"ᾈ","ώ"=>"Ώ",
+            "ὼ"=>"Ὼ","ύ"=>"Ύ","ὺ"=>"Ὺ","ό"=>"Ό","ὸ"=>"Ὸ","ί"=>"Ί","ὶ"=>"Ὶ","ή"=>"Ή","ὴ"=>"Ὴ","έ"=>"Έ",
+            "ὲ"=>"Ὲ","ά"=>"Ά","ὰ"=>"Ὰ","ὧ"=>"Ὧ","ὦ"=>"Ὦ","ὥ"=>"Ὥ","ὤ"=>"Ὤ","ὣ"=>"Ὣ","ὢ"=>"Ὢ","ὡ"=>"Ὡ",
+            "ὗ"=>"Ὗ","ὕ"=>"Ὕ","ὓ"=>"Ὓ","ὑ"=>"Ὑ","ὅ"=>"Ὅ","ὄ"=>"Ὄ","ὃ"=>"Ὃ","ὂ"=>"Ὂ","ὁ"=>"Ὁ","ὀ"=>"Ὀ",
+            "ἷ"=>"Ἷ","ἶ"=>"Ἶ","ἵ"=>"Ἵ","ἴ"=>"Ἴ","ἳ"=>"Ἳ","ἲ"=>"Ἲ","ἱ"=>"Ἱ","ἰ"=>"Ἰ","ἧ"=>"Ἧ","ἦ"=>"Ἦ",
+            "ἥ"=>"Ἥ","ἤ"=>"Ἤ","ἣ"=>"Ἣ","ἢ"=>"Ἢ","ἡ"=>"Ἡ","ἕ"=>"Ἕ","ἔ"=>"Ἔ","ἓ"=>"Ἓ","ἒ"=>"Ἒ","ἑ"=>"Ἑ",
+            "ἐ"=>"Ἐ","ἇ"=>"Ἇ","ἆ"=>"Ἆ","ἅ"=>"Ἅ","ἄ"=>"Ἄ","ἃ"=>"Ἃ","ἂ"=>"Ἂ","ἁ"=>"Ἁ","ἀ"=>"Ἀ","ỹ"=>"Ỹ",
+            "ỷ"=>"Ỷ","ỵ"=>"Ỵ","ỳ"=>"Ỳ","ự"=>"Ự","ữ"=>"Ữ","ử"=>"Ử","ừ"=>"Ừ","ứ"=>"Ứ","ủ"=>"Ủ","ụ"=>"Ụ",
+            "ợ"=>"Ợ","ỡ"=>"Ỡ","ở"=>"Ở","ờ"=>"Ờ","ớ"=>"Ớ","ộ"=>"Ộ","ỗ"=>"Ỗ","ổ"=>"Ổ","ồ"=>"Ồ","ố"=>"Ố",
+            "ỏ"=>"Ỏ","ọ"=>"Ọ","ị"=>"Ị","ỉ"=>"Ỉ","ệ"=>"Ệ","ễ"=>"Ễ","ể"=>"Ể","ề"=>"Ề","ế"=>"Ế","ẽ"=>"Ẽ",
+            "ẻ"=>"Ẻ","ẹ"=>"Ẹ","ặ"=>"Ặ","ẵ"=>"Ẵ","ẳ"=>"Ẳ","ằ"=>"Ằ","ắ"=>"Ắ","ậ"=>"Ậ","ẫ"=>"Ẫ","ẩ"=>"Ẩ",
+            "ầ"=>"Ầ","ấ"=>"Ấ","ả"=>"Ả","ạ"=>"Ạ","ẛ"=>"Ṡ","ẕ"=>"Ẕ","ẓ"=>"Ẓ","ẑ"=>"Ẑ","ẏ"=>"Ẏ","ẍ"=>"Ẍ",
+            "ẋ"=>"Ẋ","ẉ"=>"Ẉ","ẇ"=>"Ẇ","ẅ"=>"Ẅ","ẃ"=>"Ẃ","ẁ"=>"Ẁ","ṿ"=>"Ṿ","ṽ"=>"Ṽ","ṻ"=>"Ṻ","ṹ"=>"Ṹ",
+            "ṷ"=>"Ṷ","ṵ"=>"Ṵ","ṳ"=>"Ṳ","ṱ"=>"Ṱ","ṯ"=>"Ṯ","ṭ"=>"Ṭ","ṫ"=>"Ṫ","ṩ"=>"Ṩ","ṧ"=>"Ṧ","ṥ"=>"Ṥ",
+            "ṣ"=>"Ṣ","ṡ"=>"Ṡ","ṟ"=>"Ṟ","ṝ"=>"Ṝ","ṛ"=>"Ṛ","ṙ"=>"Ṙ","ṗ"=>"Ṗ","ṕ"=>"Ṕ","ṓ"=>"Ṓ","ṑ"=>"Ṑ",
+            "ṏ"=>"Ṏ","ṍ"=>"Ṍ","ṋ"=>"Ṋ","ṉ"=>"Ṉ","ṇ"=>"Ṇ","ṅ"=>"Ṅ","ṃ"=>"Ṃ","ṁ"=>"Ṁ","ḿ"=>"Ḿ","ḽ"=>"Ḽ",
+            "ḻ"=>"Ḻ","ḹ"=>"Ḹ","ḷ"=>"Ḷ","ḵ"=>"Ḵ","ḳ"=>"Ḳ","ḱ"=>"Ḱ","ḯ"=>"Ḯ","ḭ"=>"Ḭ","ḫ"=>"Ḫ","ḩ"=>"Ḩ",
+            "ḧ"=>"Ḧ","ḥ"=>"Ḥ","ḣ"=>"Ḣ","ḡ"=>"Ḡ","ḟ"=>"Ḟ","ḝ"=>"Ḝ","ḛ"=>"Ḛ","ḙ"=>"Ḙ","ḗ"=>"Ḗ","ḕ"=>"Ḕ",
+            "ḓ"=>"Ḓ","ḑ"=>"Ḑ","ḏ"=>"Ḏ","ḍ"=>"Ḍ","ḋ"=>"Ḋ","ḉ"=>"Ḉ","ḇ"=>"Ḇ","ḅ"=>"Ḅ","ḃ"=>"Ḃ","ḁ"=>"Ḁ",
+            "ֆ"=>"Ֆ","օ"=>"Օ","ք"=>"Ք","փ"=>"Փ","ւ"=>"Ւ","ց"=>"Ց","ր"=>"Ր","տ"=>"Տ","վ"=>"Վ","ս"=>"Ս",
+            "ռ"=>"Ռ","ջ"=>"Ջ","պ"=>"Պ","չ"=>"Չ","ո"=>"Ո","շ"=>"Շ","ն"=>"Ն","յ"=>"Յ","մ"=>"Մ","ճ"=>"Ճ",
+            "ղ"=>"Ղ","ձ"=>"Ձ","հ"=>"Հ","կ"=>"Կ","ծ"=>"Ծ","խ"=>"Խ","լ"=>"Լ","ի"=>"Ի","ժ"=>"Ժ","թ"=>"Թ",
+            "ը"=>"Ը","է"=>"Է","զ"=>"Զ","ե"=>"Ե","դ"=>"Դ","գ"=>"Գ","բ"=>"Բ","ա"=>"Ա","ԏ"=>"Ԏ","ԍ"=>"Ԍ",
+            "ԋ"=>"Ԋ","ԉ"=>"Ԉ","ԇ"=>"Ԇ","ԅ"=>"Ԅ","ԃ"=>"Ԃ","ԁ"=>"Ԁ","ӹ"=>"Ӹ","ӵ"=>"Ӵ","ӳ"=>"Ӳ","ӱ"=>"Ӱ",
+            "ӯ"=>"Ӯ","ӭ"=>"Ӭ","ӫ"=>"Ӫ","ө"=>"Ө","ӧ"=>"Ӧ","ӥ"=>"Ӥ","ӣ"=>"Ӣ","ӡ"=>"Ӡ","ӟ"=>"Ӟ","ӝ"=>"Ӝ",
+            "ӛ"=>"Ӛ","ә"=>"Ә","ӗ"=>"Ӗ","ӕ"=>"Ӕ","ӓ"=>"Ӓ","ӑ"=>"Ӑ","ӎ"=>"Ӎ","ӌ"=>"Ӌ","ӊ"=>"Ӊ","ӈ"=>"Ӈ",
+            "ӆ"=>"Ӆ","ӄ"=>"Ӄ","ӂ"=>"Ӂ","ҿ"=>"Ҿ","ҽ"=>"Ҽ","һ"=>"Һ","ҹ"=>"Ҹ","ҷ"=>"Ҷ","ҵ"=>"Ҵ","ҳ"=>"Ҳ",
+            "Ò±"=>"Ò°","Ò¯"=>"Ò®","Ò­"=>"Ò¬","Ò«"=>"Òª","Ò©"=>"Ò¨","Ò§"=>"Ò¦","Ò¥"=>"Ò¤","Ò£"=>"Ò¢","Ò¡"=>"Ò ","ÒŸ"=>"Òž",
+            "ҝ"=>"Ҝ","қ"=>"Қ","ҙ"=>"Ҙ","җ"=>"Җ","ҕ"=>"Ҕ","ғ"=>"Ғ","ґ"=>"Ґ","ҏ"=>"Ҏ","ҍ"=>"Ҍ","ҋ"=>"Ҋ",
+            "ҁ"=>"Ҁ","ѿ"=>"Ѿ","ѽ"=>"Ѽ","ѻ"=>"Ѻ","ѹ"=>"Ѹ","ѷ"=>"Ѷ","ѵ"=>"Ѵ","ѳ"=>"Ѳ","ѱ"=>"Ѱ","ѯ"=>"Ѯ",
+            "ѭ"=>"Ѭ","ѫ"=>"Ѫ","ѩ"=>"Ѩ","ѧ"=>"Ѧ","ѥ"=>"Ѥ","ѣ"=>"Ѣ","ѡ"=>"Ѡ","џ"=>"Џ","ў"=>"Ў","ѝ"=>"Ѝ",
+            "ќ"=>"Ќ","ћ"=>"Ћ","њ"=>"Њ","љ"=>"Љ","ј"=>"Ј","ї"=>"Ї","і"=>"І","ѕ"=>"Ѕ","є"=>"Є","ѓ"=>"Ѓ",
+            "ђ"=>"Ђ","ё"=>"Ё","ѐ"=>"Ѐ","я"=>"Я","ю"=>"Ю","э"=>"Э","ь"=>"Ь","ы"=>"Ы","ъ"=>"Ъ","щ"=>"Щ",
+            "ш"=>"Ш","ч"=>"Ч","ц"=>"Ц","х"=>"Х","ф"=>"Ф","у"=>"У","т"=>"Т","с"=>"С","р"=>"Р","п"=>"П",
+            "о"=>"О","н"=>"Н","м"=>"М","л"=>"Л","к"=>"К","й"=>"Й","и"=>"И","з"=>"З","ж"=>"Ж","е"=>"Е",
+            "д"=>"Д","г"=>"Г","в"=>"В","б"=>"Б","а"=>"А","ϵ"=>"Ε","ϲ"=>"Σ","ϱ"=>"Ρ","ϰ"=>"Κ","ϯ"=>"Ϯ",
+            "ϭ"=>"Ϭ","ϫ"=>"Ϫ","ϩ"=>"Ϩ","ϧ"=>"Ϧ","ϥ"=>"Ϥ","ϣ"=>"Ϣ","ϡ"=>"Ϡ","ϟ"=>"Ϟ","ϝ"=>"Ϝ","ϛ"=>"Ϛ",
+            "ϙ"=>"Ϙ","ϖ"=>"Π","ϕ"=>"Φ","ϑ"=>"Θ","ϐ"=>"Β","ώ"=>"Ώ","ύ"=>"Ύ","ό"=>"Ό","ϋ"=>"Ϋ","ϊ"=>"Ϊ",
+            "ω"=>"Ω","ψ"=>"Ψ","χ"=>"Χ","φ"=>"Φ","υ"=>"Υ","τ"=>"Τ","σ"=>"Σ","ς"=>"Σ","ρ"=>"Ρ","π"=>"Π",
+            "ο"=>"Ο","ξ"=>"Ξ","ν"=>"Ν","μ"=>"Μ","λ"=>"Λ","κ"=>"Κ","ι"=>"Ι","θ"=>"Θ","η"=>"Η","ζ"=>"Ζ",
+            "ε"=>"Ε","δ"=>"Δ","γ"=>"Γ","β"=>"Β","α"=>"Α","ί"=>"Ί","ή"=>"Ή","έ"=>"Έ","ά"=>"Ά","ʒ"=>"Ʒ",
+            "ʋ"=>"Ʋ","ʊ"=>"Ʊ","ʈ"=>"Ʈ","ʃ"=>"Ʃ","ʀ"=>"Ʀ","ɵ"=>"Ɵ","ɲ"=>"Ɲ","ɯ"=>"Ɯ","ɩ"=>"Ɩ","ɨ"=>"Ɨ",
+            "ɣ"=>"Ɣ","ɛ"=>"Ɛ","ə"=>"Ə","ɗ"=>"Ɗ","ɖ"=>"Ɖ","ɔ"=>"Ɔ","ɓ"=>"Ɓ","ȳ"=>"Ȳ","ȱ"=>"Ȱ","ȯ"=>"Ȯ",
+            "ȭ"=>"Ȭ","ȫ"=>"Ȫ","ȩ"=>"Ȩ","ȧ"=>"Ȧ","ȥ"=>"Ȥ","ȣ"=>"Ȣ","ȟ"=>"Ȟ","ȝ"=>"Ȝ","ț"=>"Ț","ș"=>"Ș",
+            "ȗ"=>"Ȗ","ȕ"=>"Ȕ","ȓ"=>"Ȓ","ȑ"=>"Ȑ","ȏ"=>"Ȏ","ȍ"=>"Ȍ","ȋ"=>"Ȋ","ȉ"=>"Ȉ","ȇ"=>"Ȇ","ȅ"=>"Ȅ",
+            "ȃ"=>"Ȃ","ȁ"=>"Ȁ","ǿ"=>"Ǿ","ǽ"=>"Ǽ","ǻ"=>"Ǻ","ǹ"=>"Ǹ","ǵ"=>"Ǵ","dz"=>"Dz","ǯ"=>"Ǯ","ǭ"=>"Ǭ",
+            "ǫ"=>"Ǫ","ǩ"=>"Ǩ","ǧ"=>"Ǧ","ǥ"=>"Ǥ","ǣ"=>"Ǣ","ǡ"=>"Ǡ","ǟ"=>"Ǟ","ǝ"=>"Ǝ","ǜ"=>"Ǜ","ǚ"=>"Ǚ",
+            "ǘ"=>"Ǘ","ǖ"=>"Ǖ","ǔ"=>"Ǔ","ǒ"=>"Ǒ","ǐ"=>"Ǐ","ǎ"=>"Ǎ","nj"=>"Nj","lj"=>"Lj","dž"=>"Dž","ƿ"=>"Ƿ",
+            "ƽ"=>"Ƽ","ƹ"=>"Ƹ","ƶ"=>"Ƶ","ƴ"=>"Ƴ","ư"=>"Ư","ƭ"=>"Ƭ","ƨ"=>"Ƨ","ƥ"=>"Ƥ","ƣ"=>"Ƣ","ơ"=>"Ơ",
+            "ƞ"=>"Ƞ","ƙ"=>"Ƙ","ƕ"=>"Ƕ","ƒ"=>"Ƒ","ƌ"=>"Ƌ","ƈ"=>"Ƈ","ƅ"=>"Ƅ","ƃ"=>"Ƃ","ſ"=>"S","ž"=>"Ž",
+            "ż"=>"Ż","ź"=>"Ź","ŷ"=>"Ŷ","ŵ"=>"Ŵ","ų"=>"Ų","ű"=>"Ű","ů"=>"Ů","ŭ"=>"Ŭ","ū"=>"Ū","ũ"=>"Ũ",
+            "ŧ"=>"Ŧ","ť"=>"Ť","ţ"=>"Ţ","š"=>"Š","ş"=>"Ş","ŝ"=>"Ŝ","ś"=>"Ś","ř"=>"Ř","ŗ"=>"Ŗ","ŕ"=>"Ŕ",
+            "œ"=>"Œ","ő"=>"Ő","ŏ"=>"Ŏ","ō"=>"Ō","ŋ"=>"Ŋ","ň"=>"Ň","ņ"=>"Ņ","ń"=>"Ń","ł"=>"Ł","ŀ"=>"Ŀ",
+            "ľ"=>"Ľ","ļ"=>"Ļ","ĺ"=>"Ĺ","ķ"=>"Ķ","ĵ"=>"Ĵ","ij"=>"IJ","ı"=>"I","į"=>"Į","ĭ"=>"Ĭ","ī"=>"Ī",
+            "ĩ"=>"Ĩ","ħ"=>"Ħ","ĥ"=>"Ĥ","ģ"=>"Ģ","ġ"=>"Ġ","ğ"=>"Ğ","ĝ"=>"Ĝ","ě"=>"Ě","ę"=>"Ę","ė"=>"Ė",
+            "ĕ"=>"Ĕ","ē"=>"Ē","đ"=>"Đ","ď"=>"Ď","č"=>"Č","ċ"=>"Ċ","ĉ"=>"Ĉ","ć"=>"Ć","ą"=>"Ą","ă"=>"Ă",
+            "ā"=>"Ā","ÿ"=>"Ÿ","þ"=>"Þ","ý"=>"Ý","ü"=>"Ü","û"=>"Û","ú"=>"Ú","ù"=>"Ù","ø"=>"Ø","ö"=>"Ö",
+            "õ"=>"Õ","ô"=>"Ô","ó"=>"Ó","ò"=>"Ò","ñ"=>"Ñ","ð"=>"Ð","ï"=>"Ï","î"=>"Î","í"=>"Í","ì"=>"Ì",
+            "ë"=>"Ë","ê"=>"Ê","é"=>"É","è"=>"È","ç"=>"Ç","æ"=>"Æ","å"=>"Å","ä"=>"Ä","ã"=>"Ã","â"=>"Â",
+            "á"=>"Á","à"=>"À","µ"=>"Μ","z"=>"Z","y"=>"Y","x"=>"X","w"=>"W","v"=>"V","u"=>"U","t"=>"T",
+            "s"=>"S","r"=>"R","q"=>"Q","p"=>"P","o"=>"O","n"=>"N","m"=>"M","l"=>"L","k"=>"K","j"=>"J",
+            "i"=>"I","h"=>"H","g"=>"G","f"=>"F","e"=>"E","d"=>"D","c"=>"C","b"=>"B","a"=>"A"
+                );
+
+    /**
+     * UTF-8 Case lookup table
+     *
+     * This lookuptable defines the lower case letters to their correspponding
+     * upper case letter in UTF-8
+     *
+     * @author Andreas Gohr <andi@splitbrain.org>
+     */
+    global $UTF8_UPPER_TO_LOWER;
+    if(empty($UTF8_UPPER_TO_LOWER)) $UTF8_UPPER_TO_LOWER = array (
+            "Z"=>"z","Y"=>"y","X"=>"x","W"=>"w","V"=>"v","U"=>"u","T"=>"t","S"=>"s","R"=>"r","Q"=>"q",
+            "P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j","I"=>"i","H"=>"h","G"=>"g",
+            "F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a","ῼ"=>"ῳ","Ῥ"=>"ῥ","Ῡ"=>"ῡ","Ῑ"=>"ῑ",
+            "Ῐ"=>"ῐ","ῌ"=>"ῃ","Ι"=>"ι","ᾼ"=>"ᾳ","Ᾱ"=>"ᾱ","Ᾰ"=>"ᾰ","ᾯ"=>"ᾧ","ᾮ"=>"ᾦ","ᾭ"=>"ᾥ","ᾬ"=>"ᾤ",
+            "ᾫ"=>"ᾣ","ᾪ"=>"ᾢ","ᾩ"=>"ᾡ","ᾟ"=>"ᾗ","ᾞ"=>"ᾖ","ᾝ"=>"ᾕ","ᾜ"=>"ᾔ","ᾛ"=>"ᾓ","ᾚ"=>"ᾒ","ᾙ"=>"ᾑ",
+            "ᾘ"=>"ᾐ","ᾏ"=>"ᾇ","ᾎ"=>"ᾆ","ᾍ"=>"ᾅ","ᾌ"=>"ᾄ","ᾋ"=>"ᾃ","ᾊ"=>"ᾂ","ᾉ"=>"ᾁ","ᾈ"=>"ᾀ","Ώ"=>"ώ",
+            "Ὼ"=>"ὼ","Ύ"=>"ύ","Ὺ"=>"ὺ","Ό"=>"ό","Ὸ"=>"ὸ","Ί"=>"ί","Ὶ"=>"ὶ","Ή"=>"ή","Ὴ"=>"ὴ","Έ"=>"έ",
+            "Ὲ"=>"ὲ","Ά"=>"ά","Ὰ"=>"ὰ","Ὧ"=>"ὧ","Ὦ"=>"ὦ","Ὥ"=>"ὥ","Ὤ"=>"ὤ","Ὣ"=>"ὣ","Ὢ"=>"ὢ","Ὡ"=>"ὡ",
+            "Ὗ"=>"ὗ","Ὕ"=>"ὕ","Ὓ"=>"ὓ","Ὑ"=>"ὑ","Ὅ"=>"ὅ","Ὄ"=>"ὄ","Ὃ"=>"ὃ","Ὂ"=>"ὂ","Ὁ"=>"ὁ","Ὀ"=>"ὀ",
+            "Ἷ"=>"ἷ","Ἶ"=>"ἶ","Ἵ"=>"ἵ","Ἴ"=>"ἴ","Ἳ"=>"ἳ","Ἲ"=>"ἲ","Ἱ"=>"ἱ","Ἰ"=>"ἰ","Ἧ"=>"ἧ","Ἦ"=>"ἦ",
+            "Ἥ"=>"ἥ","Ἤ"=>"ἤ","Ἣ"=>"ἣ","Ἢ"=>"ἢ","Ἡ"=>"ἡ","Ἕ"=>"ἕ","Ἔ"=>"ἔ","Ἓ"=>"ἓ","Ἒ"=>"ἒ","Ἑ"=>"ἑ",
+            "Ἐ"=>"ἐ","Ἇ"=>"ἇ","Ἆ"=>"ἆ","Ἅ"=>"ἅ","Ἄ"=>"ἄ","Ἃ"=>"ἃ","Ἂ"=>"ἂ","Ἁ"=>"ἁ","Ἀ"=>"ἀ","Ỹ"=>"ỹ",
+            "Ỷ"=>"ỷ","Ỵ"=>"ỵ","Ỳ"=>"ỳ","Ự"=>"ự","Ữ"=>"ữ","Ử"=>"ử","Ừ"=>"ừ","Ứ"=>"ứ","Ủ"=>"ủ","Ụ"=>"ụ",
+            "Ợ"=>"ợ","Ỡ"=>"ỡ","Ở"=>"ở","Ờ"=>"ờ","Ớ"=>"ớ","Ộ"=>"ộ","Ỗ"=>"ỗ","Ổ"=>"ổ","Ồ"=>"ồ","Ố"=>"ố",
+            "Ỏ"=>"ỏ","Ọ"=>"ọ","Ị"=>"ị","Ỉ"=>"ỉ","Ệ"=>"ệ","Ễ"=>"ễ","Ể"=>"ể","Ề"=>"ề","Ế"=>"ế","Ẽ"=>"ẽ",
+            "Ẻ"=>"ẻ","Ẹ"=>"ẹ","Ặ"=>"ặ","Ẵ"=>"ẵ","Ẳ"=>"ẳ","Ằ"=>"ằ","Ắ"=>"ắ","Ậ"=>"ậ","Ẫ"=>"ẫ","Ẩ"=>"ẩ",
+            "Ầ"=>"ầ","Ấ"=>"ấ","Ả"=>"ả","Ạ"=>"ạ","Ṡ"=>"ẛ","Ẕ"=>"ẕ","Ẓ"=>"ẓ","Ẑ"=>"ẑ","Ẏ"=>"ẏ","Ẍ"=>"ẍ",
+            "Ẋ"=>"ẋ","Ẉ"=>"ẉ","Ẇ"=>"ẇ","Ẅ"=>"ẅ","Ẃ"=>"ẃ","Ẁ"=>"ẁ","Ṿ"=>"ṿ","Ṽ"=>"ṽ","Ṻ"=>"ṻ","Ṹ"=>"ṹ",
+            "Ṷ"=>"ṷ","Ṵ"=>"ṵ","Ṳ"=>"ṳ","Ṱ"=>"ṱ","Ṯ"=>"ṯ","Ṭ"=>"ṭ","Ṫ"=>"ṫ","Ṩ"=>"ṩ","Ṧ"=>"ṧ","Ṥ"=>"ṥ",
+            "Ṣ"=>"ṣ","Ṡ"=>"ṡ","Ṟ"=>"ṟ","Ṝ"=>"ṝ","Ṛ"=>"ṛ","Ṙ"=>"ṙ","Ṗ"=>"ṗ","Ṕ"=>"ṕ","Ṓ"=>"ṓ","Ṑ"=>"ṑ",
+            "Ṏ"=>"ṏ","Ṍ"=>"ṍ","Ṋ"=>"ṋ","Ṉ"=>"ṉ","Ṇ"=>"ṇ","Ṅ"=>"ṅ","Ṃ"=>"ṃ","Ṁ"=>"ṁ","Ḿ"=>"ḿ","Ḽ"=>"ḽ",
+            "Ḻ"=>"ḻ","Ḹ"=>"ḹ","Ḷ"=>"ḷ","Ḵ"=>"ḵ","Ḳ"=>"ḳ","Ḱ"=>"ḱ","Ḯ"=>"ḯ","Ḭ"=>"ḭ","Ḫ"=>"ḫ","Ḩ"=>"ḩ",
+            "Ḧ"=>"ḧ","Ḥ"=>"ḥ","Ḣ"=>"ḣ","Ḡ"=>"ḡ","Ḟ"=>"ḟ","Ḝ"=>"ḝ","Ḛ"=>"ḛ","Ḙ"=>"ḙ","Ḗ"=>"ḗ","Ḕ"=>"ḕ",
+            "Ḓ"=>"ḓ","Ḑ"=>"ḑ","Ḏ"=>"ḏ","Ḍ"=>"ḍ","Ḋ"=>"ḋ","Ḉ"=>"ḉ","Ḇ"=>"ḇ","Ḅ"=>"ḅ","Ḃ"=>"ḃ","Ḁ"=>"ḁ",
+            "Ֆ"=>"ֆ","Օ"=>"օ","Ք"=>"ք","Փ"=>"փ","Ւ"=>"ւ","Ց"=>"ց","Ր"=>"ր","Տ"=>"տ","Վ"=>"վ","Ս"=>"ս",
+            "Ռ"=>"ռ","Ջ"=>"ջ","Պ"=>"պ","Չ"=>"չ","Ո"=>"ո","Շ"=>"շ","Ն"=>"ն","Յ"=>"յ","Մ"=>"մ","Ճ"=>"ճ",
+            "Ղ"=>"ղ","Ձ"=>"ձ","Հ"=>"հ","Կ"=>"կ","Ծ"=>"ծ","Խ"=>"խ","Լ"=>"լ","Ի"=>"ի","Ժ"=>"ժ","Թ"=>"թ",
+            "Ը"=>"ը","Է"=>"է","Զ"=>"զ","Ե"=>"ե","Դ"=>"դ","Գ"=>"գ","Բ"=>"բ","Ա"=>"ա","Ԏ"=>"ԏ","Ԍ"=>"ԍ",
+            "Ԋ"=>"ԋ","Ԉ"=>"ԉ","Ԇ"=>"ԇ","Ԅ"=>"ԅ","Ԃ"=>"ԃ","Ԁ"=>"ԁ","Ӹ"=>"ӹ","Ӵ"=>"ӵ","Ӳ"=>"ӳ","Ӱ"=>"ӱ",
+            "Ӯ"=>"ӯ","Ӭ"=>"ӭ","Ӫ"=>"ӫ","Ө"=>"ө","Ӧ"=>"ӧ","Ӥ"=>"ӥ","Ӣ"=>"ӣ","Ӡ"=>"ӡ","Ӟ"=>"ӟ","Ӝ"=>"ӝ",
+            "Ӛ"=>"ӛ","Ә"=>"ә","Ӗ"=>"ӗ","Ӕ"=>"ӕ","Ӓ"=>"ӓ","Ӑ"=>"ӑ","Ӎ"=>"ӎ","Ӌ"=>"ӌ","Ӊ"=>"ӊ","Ӈ"=>"ӈ",
+            "Ӆ"=>"ӆ","Ӄ"=>"ӄ","Ӂ"=>"ӂ","Ҿ"=>"ҿ","Ҽ"=>"ҽ","Һ"=>"һ","Ҹ"=>"ҹ","Ҷ"=>"ҷ","Ҵ"=>"ҵ","Ҳ"=>"ҳ",
+            "Ò°"=>"Ò±","Ò®"=>"Ò¯","Ò¬"=>"Ò­","Òª"=>"Ò«","Ò¨"=>"Ò©","Ò¦"=>"Ò§","Ò¤"=>"Ò¥","Ò¢"=>"Ò£","Ò "=>"Ò¡","Òž"=>"ÒŸ",
+            "Ҝ"=>"ҝ","Қ"=>"қ","Ҙ"=>"ҙ","Җ"=>"җ","Ҕ"=>"ҕ","Ғ"=>"ғ","Ґ"=>"ґ","Ҏ"=>"ҏ","Ҍ"=>"ҍ","Ҋ"=>"ҋ",
+            "Ҁ"=>"ҁ","Ѿ"=>"ѿ","Ѽ"=>"ѽ","Ѻ"=>"ѻ","Ѹ"=>"ѹ","Ѷ"=>"ѷ","Ѵ"=>"ѵ","Ѳ"=>"ѳ","Ѱ"=>"ѱ","Ѯ"=>"ѯ",
+            "Ѭ"=>"ѭ","Ѫ"=>"ѫ","Ѩ"=>"ѩ","Ѧ"=>"ѧ","Ѥ"=>"ѥ","Ѣ"=>"ѣ","Ѡ"=>"ѡ","Џ"=>"џ","Ў"=>"ў","Ѝ"=>"ѝ",
+            "Ќ"=>"ќ","Ћ"=>"ћ","Њ"=>"њ","Љ"=>"љ","Ј"=>"ј","Ї"=>"ї","І"=>"і","Ѕ"=>"ѕ","Є"=>"є","Ѓ"=>"ѓ",
+            "Ђ"=>"ђ","Ё"=>"ё","Ѐ"=>"ѐ","Я"=>"я","Ю"=>"ю","Э"=>"э","Ь"=>"ь","Ы"=>"ы","Ъ"=>"ъ","Щ"=>"щ",
+            "Ш"=>"ш","Ч"=>"ч","Ц"=>"ц","Х"=>"х","Ф"=>"ф","У"=>"у","Т"=>"т","С"=>"с","Р"=>"р","П"=>"п",
+            "О"=>"о","Н"=>"н","М"=>"м","Л"=>"л","К"=>"к","Й"=>"й","И"=>"и","З"=>"з","Ж"=>"ж","Е"=>"е",
+            "Д"=>"д","Г"=>"г","В"=>"в","Б"=>"б","А"=>"а","Ε"=>"ϵ","Σ"=>"ϲ","Ρ"=>"ϱ","Κ"=>"ϰ","Ϯ"=>"ϯ",
+            "Ϭ"=>"ϭ","Ϫ"=>"ϫ","Ϩ"=>"ϩ","Ϧ"=>"ϧ","Ϥ"=>"ϥ","Ϣ"=>"ϣ","Ϡ"=>"ϡ","Ϟ"=>"ϟ","Ϝ"=>"ϝ","Ϛ"=>"ϛ",
+            "Ϙ"=>"ϙ","Π"=>"ϖ","Φ"=>"ϕ","Θ"=>"ϑ","Β"=>"ϐ","Ώ"=>"ώ","Ύ"=>"ύ","Ό"=>"ό","Ϋ"=>"ϋ","Ϊ"=>"ϊ",
+            "Ω"=>"ω","Ψ"=>"ψ","Χ"=>"χ","Φ"=>"φ","Υ"=>"υ","Τ"=>"τ","Σ"=>"σ","Σ"=>"ς","Ρ"=>"ρ","Π"=>"π",
+            "Ο"=>"ο","Ξ"=>"ξ","Ν"=>"ν","Μ"=>"μ","Λ"=>"λ","Κ"=>"κ","Ι"=>"ι","Θ"=>"θ","Η"=>"η","Ζ"=>"ζ",
+            "Ε"=>"ε","Δ"=>"δ","Γ"=>"γ","Β"=>"β","Α"=>"α","Ί"=>"ί","Ή"=>"ή","Έ"=>"έ","Ά"=>"ά","Ʒ"=>"ʒ",
+            "Ʋ"=>"ʋ","Ʊ"=>"ʊ","Ʈ"=>"ʈ","Ʃ"=>"ʃ","Ʀ"=>"ʀ","Ɵ"=>"ɵ","Ɲ"=>"ɲ","Ɯ"=>"ɯ","Ɩ"=>"ɩ","Ɨ"=>"ɨ",
+            "Ɣ"=>"ɣ","Ɛ"=>"ɛ","Ə"=>"ə","Ɗ"=>"ɗ","Ɖ"=>"ɖ","Ɔ"=>"ɔ","Ɓ"=>"ɓ","Ȳ"=>"ȳ","Ȱ"=>"ȱ","Ȯ"=>"ȯ",
+            "Ȭ"=>"ȭ","Ȫ"=>"ȫ","Ȩ"=>"ȩ","Ȧ"=>"ȧ","Ȥ"=>"ȥ","Ȣ"=>"ȣ","Ȟ"=>"ȟ","Ȝ"=>"ȝ","Ț"=>"ț","Ș"=>"ș",
+            "Ȗ"=>"ȗ","Ȕ"=>"ȕ","Ȓ"=>"ȓ","Ȑ"=>"ȑ","Ȏ"=>"ȏ","Ȍ"=>"ȍ","Ȋ"=>"ȋ","Ȉ"=>"ȉ","Ȇ"=>"ȇ","Ȅ"=>"ȅ",
+            "Ȃ"=>"ȃ","Ȁ"=>"ȁ","Ǿ"=>"ǿ","Ǽ"=>"ǽ","Ǻ"=>"ǻ","Ǹ"=>"ǹ","Ǵ"=>"ǵ","Dz"=>"dz","Ǯ"=>"ǯ","Ǭ"=>"ǭ",
+            "Ǫ"=>"ǫ","Ǩ"=>"ǩ","Ǧ"=>"ǧ","Ǥ"=>"ǥ","Ǣ"=>"ǣ","Ǡ"=>"ǡ","Ǟ"=>"ǟ","Ǝ"=>"ǝ","Ǜ"=>"ǜ","Ǚ"=>"ǚ",
+            "Ǘ"=>"ǘ","Ǖ"=>"ǖ","Ǔ"=>"ǔ","Ǒ"=>"ǒ","Ǐ"=>"ǐ","Ǎ"=>"ǎ","Nj"=>"nj","Lj"=>"lj","Dž"=>"dž","Ƿ"=>"ƿ",
+            "Ƽ"=>"ƽ","Ƹ"=>"ƹ","Ƶ"=>"ƶ","Ƴ"=>"ƴ","Ư"=>"ư","Ƭ"=>"ƭ","Ƨ"=>"ƨ","Ƥ"=>"ƥ","Ƣ"=>"ƣ","Ơ"=>"ơ",
+            "Ƞ"=>"ƞ","Ƙ"=>"ƙ","Ƕ"=>"ƕ","Ƒ"=>"ƒ","Ƌ"=>"ƌ","Ƈ"=>"ƈ","Ƅ"=>"ƅ","Ƃ"=>"ƃ","S"=>"ſ","Ž"=>"ž",
+            "Ż"=>"ż","Ź"=>"ź","Ŷ"=>"ŷ","Ŵ"=>"ŵ","Ų"=>"ų","Ű"=>"ű","Ů"=>"ů","Ŭ"=>"ŭ","Ū"=>"ū","Ũ"=>"ũ",
+            "Ŧ"=>"ŧ","Ť"=>"ť","Ţ"=>"ţ","Š"=>"š","Ş"=>"ş","Ŝ"=>"ŝ","Ś"=>"ś","Ř"=>"ř","Ŗ"=>"ŗ","Ŕ"=>"ŕ",
+            "Œ"=>"œ","Ő"=>"ő","Ŏ"=>"ŏ","Ō"=>"ō","Ŋ"=>"ŋ","Ň"=>"ň","Ņ"=>"ņ","Ń"=>"ń","Ł"=>"ł","Ŀ"=>"ŀ",
+            "Ľ"=>"ľ","Ļ"=>"ļ","Ĺ"=>"ĺ","Ķ"=>"ķ","Ĵ"=>"ĵ","IJ"=>"ij","I"=>"ı","Į"=>"į","Ĭ"=>"ĭ","Ī"=>"ī",
+            "Ĩ"=>"ĩ","Ħ"=>"ħ","Ĥ"=>"ĥ","Ģ"=>"ģ","Ġ"=>"ġ","Ğ"=>"ğ","Ĝ"=>"ĝ","Ě"=>"ě","Ę"=>"ę","Ė"=>"ė",
+            "Ĕ"=>"ĕ","Ē"=>"ē","Đ"=>"đ","Ď"=>"ď","Č"=>"č","Ċ"=>"ċ","Ĉ"=>"ĉ","Ć"=>"ć","Ą"=>"ą","Ă"=>"ă",
+            "Ā"=>"ā","Ÿ"=>"ÿ","Þ"=>"þ","Ý"=>"ý","Ü"=>"ü","Û"=>"û","Ú"=>"ú","Ù"=>"ù","Ø"=>"ø","Ö"=>"ö",
+            "Õ"=>"õ","Ô"=>"ô","Ó"=>"ó","Ò"=>"ò","Ñ"=>"ñ","Ð"=>"ð","Ï"=>"ï","Î"=>"î","Í"=>"í","Ì"=>"ì",
+            "Ë"=>"ë","Ê"=>"ê","É"=>"é","È"=>"è","Ç"=>"ç","Æ"=>"æ","Å"=>"å","Ä"=>"ä","Ã"=>"ã","Â"=>"â",
+            "Á"=>"á","À"=>"à","Μ"=>"µ","Z"=>"z","Y"=>"y","X"=>"x","W"=>"w","V"=>"v","U"=>"u","T"=>"t",
+            "S"=>"s","R"=>"r","Q"=>"q","P"=>"p","O"=>"o","N"=>"n","M"=>"m","L"=>"l","K"=>"k","J"=>"j",
+            "I"=>"i","H"=>"h","G"=>"g","F"=>"f","E"=>"e","D"=>"d","C"=>"c","B"=>"b","A"=>"a"
+                );
 }; // end of case lookup tables
 
 /**
@@ -1642,7 +1642,7 @@ if(empty($UTF8_ROMANIZATION)) $UTF8_ROMANIZATION = array(
   '่'=>'','้'=>'','๊'=>'','๋'=>'','็'=>'',
   '์'=>'','๎'=>'','ํ'=>'','ฺ'=>'',
   'ๆ'=>'2','๏'=>'o','ฯ'=>'-','๚'=>'-','๛'=>'-',
-	'๐'=>'0','๑'=>'1','๒'=>'2','๓'=>'3','๔'=>'4',
+  '๐'=>'0','๑'=>'1','๒'=>'2','๓'=>'3','๔'=>'4',
   '๕'=>'5','๖'=>'6','๗'=>'7','๘'=>'8','๙'=>'9',
 
   // Korean
@@ -1654,5 +1654,4 @@ if(empty($UTF8_ROMANIZATION)) $UTF8_ROMANIZATION = array(
   'ã… '=>'yu','ã…’'=>'yay','ã…–'=>'yey',
 );
 
-//Setup VIM: ex: et ts=2 enc=utf-8 :
 
diff --git a/install.php b/install.php
index 07f69f24bfafbdd46524e5e4ef20192b92d8eb15..e11ba1d4a7b1414cfde119e1d1337959d8e741c9 100644
--- a/install.php
+++ b/install.php
@@ -1,8 +1,8 @@
 <?php
 /**
- *  Dokuwiki installation assistance
+ * Dokuwiki installation assistance
  *
- *  @author      Chris Smith <chris@jalakai.co.uk>
+ * @author      Chris Smith <chris@jalakai.co.uk>
  */
 
 if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
@@ -286,7 +286,6 @@ EOT;
     }
     $ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
 
-
     if ($d['acl']) {
         // create users.auth.php
         // --- user:MD5password:Real Name:email:groups,comma,seperated
@@ -473,7 +472,6 @@ function langsel(){
     closedir($dh);
     sort($langs);
 
-
     echo '<form action="">';
     echo $lang['i_chooselang'];
     echo ': <select name="l" onchange="submit()">';