Move defines to their own file
[dokuwiki.git] / inc / load.php
blob46cd91f4c35ccdbc43d062a0eadf2ddb1e61a471
1 <?php
2 /**
3 * Load all internal libraries and setup class autoloader
5 * @author Andreas Gohr <andi@splitbrain.org>
6 */
8 use dokuwiki\Extension\PluginController;
10 // setup class autoloader
11 spl_autoload_register('load_autoload');
13 // require all the common libraries
14 // for a few of these order does matter
15 require_once(DOKU_INC.'inc/defines.php');
16 require_once(DOKU_INC.'inc/actions.php');
17 require_once(DOKU_INC.'inc/changelog.php');
18 require_once(DOKU_INC.'inc/common.php');
19 require_once(DOKU_INC.'inc/confutils.php');
20 require_once(DOKU_INC.'inc/pluginutils.php');
21 require_once(DOKU_INC.'inc/form.php');
22 require_once(DOKU_INC.'inc/fulltext.php');
23 require_once(DOKU_INC.'inc/html.php');
24 require_once(DOKU_INC.'inc/httputils.php');
25 require_once(DOKU_INC.'inc/indexer.php');
26 require_once(DOKU_INC.'inc/infoutils.php');
27 require_once(DOKU_INC.'inc/io.php');
28 require_once(DOKU_INC.'inc/mail.php');
29 require_once(DOKU_INC.'inc/media.php');
30 require_once(DOKU_INC.'inc/pageutils.php');
31 require_once(DOKU_INC.'inc/parserutils.php');
32 require_once(DOKU_INC.'inc/search.php');
33 require_once(DOKU_INC.'inc/template.php');
34 require_once(DOKU_INC.'inc/toolbar.php');
35 require_once(DOKU_INC.'inc/utf8.php');
36 require_once(DOKU_INC.'inc/auth.php');
37 require_once(DOKU_INC.'inc/compatibility.php');
38 require_once(DOKU_INC.'inc/deprecated.php');
39 require_once(DOKU_INC.'inc/legacy.php');
41 /**
42 * spl_autoload_register callback
44 * Contains a static list of DokuWiki's core classes and automatically
45 * require()s their associated php files when an object is instantiated.
47 * @author Andreas Gohr <andi@splitbrain.org>
48 * @todo add generic loading of renderers and auth backends
50 * @param string $name
52 * @return bool
54 function load_autoload($name){
55 static $classes = null;
56 if($classes === null) $classes = array(
57 'Diff' => DOKU_INC.'inc/DifferenceEngine.php',
58 'UnifiedDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php',
59 'TableDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php',
60 'cache' => DOKU_INC.'inc/cache.php',
61 'cache_parser' => DOKU_INC.'inc/cache.php',
62 'cache_instructions' => DOKU_INC.'inc/cache.php',
63 'cache_renderer' => DOKU_INC.'inc/cache.php',
64 'Input' => DOKU_INC.'inc/Input.class.php',
65 'JpegMeta' => DOKU_INC.'inc/JpegMeta.php',
66 'SimplePie' => DOKU_INC.'inc/SimplePie.php',
67 'FeedParser' => DOKU_INC.'inc/FeedParser.php',
68 'IXR_Server' => DOKU_INC.'inc/IXR_Library.php',
69 'IXR_Client' => DOKU_INC.'inc/IXR_Library.php',
70 'IXR_Error' => DOKU_INC.'inc/IXR_Library.php',
71 'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php',
72 'SafeFN' => DOKU_INC.'inc/SafeFN.class.php',
73 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php',
74 'Mailer' => DOKU_INC.'inc/Mailer.class.php',
76 'Doku_Handler' => DOKU_INC.'inc/parser/handler.php',
77 'Doku_Renderer' => DOKU_INC.'inc/parser/renderer.php',
78 'Doku_Renderer_xhtml' => DOKU_INC.'inc/parser/xhtml.php',
79 'Doku_Renderer_code' => DOKU_INC.'inc/parser/code.php',
80 'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
81 'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',
83 'DokuCLI' => DOKU_INC.'inc/cli.php',
84 'DokuCLI_Options' => DOKU_INC.'inc/cli.php',
85 'DokuCLI_Colors' => DOKU_INC.'inc/cli.php',
89 if(isset($classes[$name])){
90 require ($classes[$name]);
91 return true;
94 // namespace to directory conversion
95 $name = str_replace('\\', '/', $name);
97 // test namespace
98 if(substr($name, 0, 14) === 'dokuwiki/test/') {
99 $file = DOKU_INC . '_test/' . substr($name, 14) . '.php';
100 if(file_exists($file)) {
101 require $file;
102 return true;
106 // plugin namespace
107 if(substr($name, 0, 16) === 'dokuwiki/plugin/') {
108 $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
109 $file = DOKU_PLUGIN . substr($name, 16) . '.php';
110 if(file_exists($file)) {
111 require $file;
112 return true;
116 // template namespace
117 if(substr($name, 0, 18) === 'dokuwiki/template/') {
118 $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
119 $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
120 if(file_exists($file)) {
121 require $file;
122 return true;
126 // our own namespace
127 if(substr($name, 0, 9) === 'dokuwiki/') {
128 $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
129 if(file_exists($file)) {
130 require $file;
131 return true;
135 // Plugin loading
136 if(preg_match(
137 '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' .
138 DOKU_PLUGIN_NAME_REGEX .
139 ')(?:_([^_]+))?$/',
140 $name,
142 )) {
143 // try to load the wanted plugin file
144 $c = ((count($m) === 4) ? "/{$m[3]}" : '');
145 $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
146 if(file_exists($plg)){
147 require $plg;
149 return true;
151 return false;