diff --git a/doku.php b/doku.php
index 3963a5aa040b33aa5ea7b848c40e155dfc0b5575..990bb43d3791a98d9ce0f58ffd202d55541bc149 100644
--- a/doku.php
+++ b/doku.php
@@ -20,13 +20,8 @@ if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])){
     $ACT = 'show';
 }
 
+// load and initialize the core system
 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']);
diff --git a/inc/FeedParser.php b/inc/FeedParser.php
index f37888f01264a05fbd13b3f950389e9f8aad1b9e..9d00e7abf88ec9dacbfd2fc6de86e718bd0faf46 100644
--- a/inc/FeedParser.php
+++ b/inc/FeedParser.php
@@ -6,9 +6,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/HTTPClient.php');
-require_once(DOKU_INC.'inc/SimplePie.php');
-
 
 /**
  * We override some methods of the original SimplePie class here
diff --git a/inc/JSON.php b/inc/JSON.php
index 7ec40009283265b2c05a0ae719c62265c2e30e51..332827f4ca08ea63911298956b0a317234bc483a 100644
--- a/inc/JSON.php
+++ b/inc/JSON.php
@@ -59,7 +59,6 @@
 
 // for DokuWiki
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/utf8.php');
 
 /**
  * Marker constant for JSON::decode(), used to flag stack state
diff --git a/inc/actions.php b/inc/actions.php
index 1fda0584e1dd2353d450ddae424767cb01847c78..7f9cb26d00e900e6ecb631346986cc66a608df0d 100644
--- a/inc/actions.php
+++ b/inc/actions.php
@@ -7,8 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/template.php');
-
 
 /**
  * Call the needed action handlers
diff --git a/inc/auth.php b/inc/auth.php
index c18104487ccdcc510f0e50c835bd37e79321605d..33626cf80a93467a65ecb845fc9647ffab99ddc1 100644
--- a/inc/auth.php
+++ b/inc/auth.php
@@ -10,8 +10,6 @@
  */
 
 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);
@@ -22,15 +20,23 @@ 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');
-
+/**
+ * Initialize the auth system.
+ *
+ * This function is automatically called at the end of init.php
+ *
+ * This used to be the main() of the auth.php
+ *
+ * @todo backend loading maybe should be handled by the class autoloader
+ * @todo maybe split into multiple functions at the XXX marked positions
+ */
+function auth_setup(){
+    global $conf;
     global $auth;
 
-    // load the the backend auth functions and instantiate the auth object
+    if(!$conf['useacl']) return false;
+
+    // load the the backend auth functions and instantiate the auth object XXX
     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');
@@ -50,51 +56,49 @@ if($conf['useacl']){
     } else {
         nice_die($lang['authmodfailed']);
     }
-}
 
-// 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(!$auth) return;
 
-        // 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;
-        }
+    // do the login either by cookie or provided credentials XXX
+    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;
 
-        // apply cleaning
-        $_REQUEST['u'] = $auth->cleanUser($_REQUEST['u']);
+    // 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(isset($_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(
-                    'user'     => $_REQUEST['u'],
-                    'password' => $_REQUEST['p'],
-                    'sticky'   => $_REQUEST['r'],
-                    'silent'   => $_REQUEST['http_credentials'],
-                    );
-            trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper');
-        }
+    // 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;
+    }
+
+    // apply cleaning
+    $_REQUEST['u'] = $auth->cleanUser($_REQUEST['u']);
+
+    if(isset($_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(
+                'user'     => $_REQUEST['u'],
+                'password' => $_REQUEST['p'],
+                'sticky'   => $_REQUEST['r'],
+                'silent'   => $_REQUEST['http_credentials'],
+                );
+        trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper');
     }
 
-    //load ACL into a global array
+    //load ACL into a global array XXX
     global $AUTH_ACL;
     if(is_readable(DOKU_CONF.'acl.auth.php')){
         $AUTH_ACL = file(DOKU_CONF.'acl.auth.php');
diff --git a/inc/cache.php b/inc/cache.php
index 2e22edfb11555b5390b2c7354e48cdcbc7553704..571b314cde1842f5d16bc363e54911ed96c387dc 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -7,9 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/io.php');
-require_once(DOKU_INC.'inc/pageutils.php');
-require_once(DOKU_INC.'inc/parserutils.php');
 
 class cache {
     var $key = '';          // primary identifier for this item
diff --git a/inc/common.php b/inc/common.php
index 9cadb56fdb7ed5f7a348e71c619b291bc56e68fb..ef35ca863bb405e01e7d5101295085e4957866d4 100644
--- a/inc/common.php
+++ b/inc/common.php
@@ -7,13 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/io.php');
-require_once(DOKU_INC.'inc/changelog.php');
-require_once(DOKU_INC.'inc/utf8.php');
-require_once(DOKU_INC.'inc/mail.php');
-require_once(DOKU_INC.'inc/parserutils.php');
-require_once(DOKU_INC.'inc/infoutils.php');
-require_once DOKU_INC.'inc/subscription.php';
 
 /**
  * These constants are used with the recents function
diff --git a/inc/events.php b/inc/events.php
index e6b608f20abd9c66b2ef94fa9dce449763d8d9bd..1c82af003007f1e6f70fadf534b4a14963fa5909 100644
--- a/inc/events.php
+++ b/inc/events.php
@@ -7,7 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/pluginutils.php');
 
 class Doku_Event {
 
diff --git a/inc/form.php b/inc/form.php
index 0a6bc2bba2958c8e266eecfebc27ffb08b10b6a8..cebaf4608e8cbd5eeb45fcb44b1a20038e79d60d 100644
--- a/inc/form.php
+++ b/inc/form.php
@@ -7,7 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/html.php');
 
 /**
  * Class for creating simple HTML forms.
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 94c68d675db50fa791ac214c46d33e43b4a6146c..58d17422aed917c109342ded60ee93de1186047a 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -7,8 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/indexer.php');
-
 
 /**
  * The fulltext search
diff --git a/inc/html.php b/inc/html.php
index 8a215f4406629c8caf39a315938a37f0efb5fa3d..5e1d0bab37f0633e6c8a6d5d66c32c6027caba18 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -8,8 +8,6 @@
 
 if(!defined('DOKU_INC')) die('meh.');
 if(!defined('NL')) define('NL',"\n");
-require_once(DOKU_INC.'inc/parserutils.php');
-require_once(DOKU_INC.'inc/form.php');
 
 /**
  * Convenience function to quickly build a wikilink
diff --git a/inc/indexer.php b/inc/indexer.php
index 39592e8f4e40df286c1d4af23b2291cce2a1e796..07b67c014793a9f300475c319a4285d179289f9a 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -7,9 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/io.php');
-require_once(DOKU_INC.'inc/utf8.php');
-require_once(DOKU_INC.'inc/parserutils.php');
 
 // set the minimum token length to use in the index (note, this doesn't apply to numeric tokens)
 if (!defined('IDX_MINWORDLENGTH')) define('IDX_MINWORDLENGTH',2);
diff --git a/inc/infoutils.php b/inc/infoutils.php
index d5356969bb91bdbaa16afa9eda97e8912be7f9f3..6f2874fe589e306fef78f46d3d86a6b1c2eac55c 100644
--- a/inc/infoutils.php
+++ b/inc/infoutils.php
@@ -7,7 +7,6 @@
  */
 if(!defined('DOKU_INC')) die('meh.');
 if(!defined('DOKU_MESSAGEURL')) define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/');
-require_once(DOKU_INC.'inc/HTTPClient.php');
 
 /**
  * Check for new messages from upstream
diff --git a/inc/init.php b/inc/init.php
index 6fb9559ceab5853a0f112591b5088edd56bd164b..3cff40073343a4d654842ece70217b12fc8c625a 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -37,6 +37,9 @@ if (!defined('DOKU_E_LEVEL')) {
     error_reporting(DOKU_E_LEVEL);
 }
 
+// load libraries
+require_once(DOKU_INC.'inc/load.php');
+
 // init memory caches
 global $cache_revinfo;
        $cache_revinfo = array();
@@ -245,6 +248,8 @@ init_files();
 scriptify(DOKU_CONF.'users.auth');
 scriptify(DOKU_CONF.'acl.auth');
 
+// setup authentication system
+auth_setup();
 
 /**
  * Checks paths from config file
@@ -526,7 +531,6 @@ EOT;
     exit;
 }
 
-
 /**
  * A realpath() replacement
  *
@@ -588,5 +592,3 @@ function fullpath($path,$exists=false){
     return $finalpath;
 }
 
-
-
diff --git a/inc/io.php b/inc/io.php
index 32a6f7b8e0a07f32f0c1c7bd8db4dde18d97c774..1d69dabc916015742ef3f75824f6c188437c2508 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -7,10 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/common.php');
-require_once(DOKU_INC.'inc/HTTPClient.php');
-require_once(DOKU_INC.'inc/events.php');
-require_once(DOKU_INC.'inc/utf8.php');
 
 /**
  * Removes empty directories
diff --git a/inc/load.php b/inc/load.php
new file mode 100644
index 0000000000000000000000000000000000000000..9d305e3a962e8afb99de4b85df2fb349aca5c426
--- /dev/null
+++ b/inc/load.php
@@ -0,0 +1,98 @@
+<?php
+/**
+ * Load all internal libraries and setup class autoloader
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+// setup class autoloader
+spl_autoload_register('load_autoload');
+
+// require all the common libraries
+// for a e few of these order does matter
+require_once(DOKU_INC.'inc/DifferenceEngine.php');
+require_once(DOKU_INC.'inc/EmailAddressValidator.php');
+require_once(DOKU_INC.'inc/SimplePie.php');
+require_once(DOKU_INC.'inc/FeedParser.php');
+require_once(DOKU_INC.'inc/HTTPClient.php');
+require_once(DOKU_INC.'inc/IXR_Library.php');
+require_once(DOKU_INC.'inc/JSON.php');
+require_once(DOKU_INC.'inc/JpegMeta.php');
+require_once(DOKU_INC.'inc/TarLib.class.php');
+require_once(DOKU_INC.'inc/ZipLib.class.php');
+require_once(DOKU_INC.'inc/adLDAP.php');
+require_once(DOKU_INC.'inc/blowfish.php');
+require_once(DOKU_INC.'inc/feedcreator.class.php');
+require_once(DOKU_INC.'inc/geshi.php');
+require_once(DOKU_INC.'inc/actions.php');
+require_once(DOKU_INC.'inc/cache.php');
+require_once(DOKU_INC.'inc/changelog.php');
+require_once(DOKU_INC.'inc/cliopts.php');
+require_once(DOKU_INC.'inc/common.php');
+require_once(DOKU_INC.'inc/confutils.php');
+require_once(DOKU_INC.'inc/pluginutils.php');
+require_once(DOKU_INC.'inc/plugin.php');
+require_once(DOKU_INC.'inc/plugincontroller.class.php');
+require_once(DOKU_INC.'inc/events.php');
+require_once(DOKU_INC.'inc/form.php');
+require_once(DOKU_INC.'inc/fulltext.php');
+require_once(DOKU_INC.'inc/html.php');
+require_once(DOKU_INC.'inc/httputils.php');
+require_once(DOKU_INC.'inc/indexer.php');
+require_once(DOKU_INC.'inc/infoutils.php');
+require_once(DOKU_INC.'inc/init.php');
+require_once(DOKU_INC.'inc/io.php');
+require_once(DOKU_INC.'inc/load.php');
+require_once(DOKU_INC.'inc/mail.php');
+require_once(DOKU_INC.'inc/media.php');
+require_once(DOKU_INC.'inc/pageutils.php');
+require_once(DOKU_INC.'inc/parserutils.php');
+require_once(DOKU_INC.'inc/search.php');
+require_once(DOKU_INC.'inc/subscription.php');
+require_once(DOKU_INC.'inc/template.php');
+require_once(DOKU_INC.'inc/toolbar.php');
+require_once(DOKU_INC.'inc/utf8.php');
+require_once(DOKU_INC.'inc/auth.php');
+
+/**
+ * spl_autoload_register callback
+ *
+ * Contains a static list of DokuWiki's core classes and automatically
+ * requires their associated php files when an object is instantiated.
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @todo   add generic loading of plugins here
+ */
+function load_autoload($name){
+    static $classes = null;
+    if(is_null($classes)) $classes = array(
+        'DokuHTTPClient'        => DOKU_INC.'inc/HTTPClient.php',
+        'DokuEvent'             => DOKU_INC.'inc/',
+        'JSON'                  => DOKU_INC.'inc/JSON.php',
+        'adLDAP'                => DOKU_INC.'inc/adLDAP.php',
+        'Diff'                  => DOKU_INC.'inc/DifferenceEngine.php',
+        'UnifiedDiffFormatter'  => DOKU_INC.'inc/DifferenceEngine.php',
+        'TableDiffFormatter'    => DOKU_INC.'inc/DifferenceEngine.php',
+        'cache'                 => DOKU_INC.'inc/cache.php',
+        'cache_parser'          => DOKU_INC.'inc/cache.php',
+        'cache_instructions'    => DOKU_INC.'inc/cache.php',
+        'cache_renderer'        => DOKU_INC.'inc/cache.php',
+        'Doku_Event'            => DOKU_INC.'inc/events.php',
+        'Doku_Event_Handler'    => DOKU_INC.'inc/events.php',
+        'Doku_Form'             => DOKU_INC.'inc/form.php',
+        'EmailAddressValidator' => DOKU_INC.'inc/EmailAddressValidator.php',
+        'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
+        'FeedParser'            => DOKU_INC.'inc/FeedParser.php',
+        'utf8_entity_decoder'   => DOKU_INC.'inc/utf8.php',
+        'IXR_Server'            => DOKU_INC.'inc/IXR_Library.php',
+        'IXR_Client'            => DOKU_INC.'inc/IXR_Library.php',
+        'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php',
+        'GeSHi'                 => DOKU_INC.'inc/geshi.php',
+    );
+
+    if(isset($classes[$name])){
+        require_once($classes[$name]);
+        return;
+    }
+}
+
diff --git a/inc/mail.php b/inc/mail.php
index 3b0592b8bdb5103f21bd5b12ef4798181a1379e6..6d1652fc0b6b4f6f7550fbb4b043404cbbc614f0 100644
--- a/inc/mail.php
+++ b/inc/mail.php
@@ -7,8 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/utf8.php');
-require_once(DOKU_INC.'inc/EmailAddressValidator.php');
 
 // end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?)
 // think different
diff --git a/inc/media.php b/inc/media.php
index 3850f4e333272a478bacedf7e71fe625bbd8d306..444e6d432891d51d4eea063fe40a6c96bc4c0803 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -8,9 +8,6 @@
 
 if(!defined('DOKU_INC')) die('meh.');
 if(!defined('NL')) define('NL',"\n");
-require_once(DOKU_INC.'inc/html.php');
-require_once(DOKU_INC.'inc/search.php');
-require_once(DOKU_INC.'inc/JpegMeta.php');
 
 /**
  * Lists pages which currently use a media file selected for deletion
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 471d46903a0f72d602978a018a007afc0d226ebc..34d9e5282f1fd59f769bb634936d684b1680bc50 100644
--- a/inc/parserutils.php
+++ b/inc/parserutils.php
@@ -8,10 +8,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/confutils.php');
-require_once(DOKU_INC.'inc/pageutils.php');
-require_once(DOKU_INC.'inc/pluginutils.php');
-require_once(DOKU_INC.'inc/cache.php');
 
 /**
  * Returns the parsed Wikitext in XHTML for the given id and revision.
diff --git a/inc/pluginutils.php b/inc/pluginutils.php
index 8294d1ec85165c74768416a2f8952d719d6ebf5f..a8656a96a24301ce81a37eb2caed76ee8f055a59 100644
--- a/inc/pluginutils.php
+++ b/inc/pluginutils.php
@@ -8,7 +8,6 @@
 
 // plugin related constants
 if(!defined('DOKU_PLUGIN'))  define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
-require_once(DOKU_INC.'inc/plugincontroller.class.php');
 
 $plugin_types = array('admin','syntax','action','renderer', 'helper');
 
diff --git a/inc/search.php b/inc/search.php
index 2b9a51fb36b107006c20a100c5823e37181008ec..ce4fefe0649951df229f82de9c305fd7fb3c4e73 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -7,7 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/common.php');
 
 /**
  * recurse direcory
diff --git a/inc/subscription.php b/inc/subscription.php
index f7614014fe4ffa6764b161cd54a1ae45147c1b3f..e98129b77049bcc853b4c217d32554bccf09db0d 100644
--- a/inc/subscription.php
+++ b/inc/subscription.php
@@ -14,8 +14,6 @@
  * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  */
 
-require_once DOKU_INC.'/inc/pageutils.php';
-
 /**
  * Get the name of the metafile tracking subscriptions to target page or
  * namespace
diff --git a/inc/toolbar.php b/inc/toolbar.php
index 9140970d1b8a8690f1c00a67d45e3115ba2e1cab..5d1149df35918edfa84db22b2b1af8229915500e 100644
--- a/inc/toolbar.php
+++ b/inc/toolbar.php
@@ -7,8 +7,6 @@
  */
 
 if(!defined('DOKU_INC')) die('meh.');
-require_once(DOKU_INC.'inc/JSON.php');
-
 
 /**
  * Prepares and prints an JavaScript array with all toolbar buttons