code style: line breaks
[dokuwiki.git] / inc / load.php
blob31d9bc9f3c7841d35650f4628916d2e7248b8679
1 <?php
3 /**
4 * Load all internal libraries and setup class autoloader
6 * @author Andreas Gohr <andi@splitbrain.org>
7 */
9 use dokuwiki\ErrorHandler;
10 use dokuwiki\Extension\PluginController;
12 // setup class autoloader
13 spl_autoload_register('load_autoload');
15 // require all the common libraries
16 // for a few of these order does matter
17 require_once(DOKU_INC . 'inc/defines.php');
18 require_once(DOKU_INC . 'inc/actions.php');
19 require_once(DOKU_INC . 'inc/changelog.php');
20 require_once(DOKU_INC . 'inc/common.php');
21 require_once(DOKU_INC . 'inc/confutils.php');
22 require_once(DOKU_INC . 'inc/pluginutils.php');
23 require_once(DOKU_INC . 'inc/form.php');
24 require_once(DOKU_INC . 'inc/fulltext.php');
25 require_once(DOKU_INC . 'inc/html.php');
26 require_once(DOKU_INC . 'inc/httputils.php');
27 require_once(DOKU_INC . 'inc/indexer.php');
28 require_once(DOKU_INC . 'inc/infoutils.php');
29 require_once(DOKU_INC . 'inc/io.php');
30 require_once(DOKU_INC . 'inc/mail.php');
31 require_once(DOKU_INC . 'inc/media.php');
32 require_once(DOKU_INC . 'inc/pageutils.php');
33 require_once(DOKU_INC . 'inc/parserutils.php');
34 require_once(DOKU_INC . 'inc/search.php');
35 require_once(DOKU_INC . 'inc/template.php');
36 require_once(DOKU_INC . 'inc/toolbar.php');
37 require_once(DOKU_INC . 'inc/utf8.php');
38 require_once(DOKU_INC . 'inc/auth.php');
39 require_once(DOKU_INC . 'inc/compatibility.php');
40 require_once(DOKU_INC . 'inc/deprecated.php');
41 require_once(DOKU_INC . 'inc/legacy.php');
43 /**
44 * spl_autoload_register callback
46 * Contains a static list of DokuWiki's core classes and automatically
47 * require()s their associated php files when an object is instantiated.
49 * @author Andreas Gohr <andi@splitbrain.org>
50 * @todo add generic loading of renderers and auth backends
52 * @param string $name
54 * @return bool
56 function load_autoload($name)
58 static $classes = null;
59 if ($classes === null) $classes = [
60 'Diff' => DOKU_INC . 'inc/DifferenceEngine.php',
61 'UnifiedDiffFormatter' => DOKU_INC . 'inc/DifferenceEngine.php',
62 'TableDiffFormatter' => DOKU_INC . 'inc/DifferenceEngine.php',
63 'cache' => DOKU_INC . 'inc/cache.php',
64 'cache_parser' => DOKU_INC . 'inc/cache.php',
65 'cache_instructions' => DOKU_INC . 'inc/cache.php',
66 'cache_renderer' => DOKU_INC . 'inc/cache.php',
67 'Input' => DOKU_INC . 'inc/Input.class.php',
68 'JpegMeta' => DOKU_INC . 'inc/JpegMeta.php',
69 'SimplePie' => DOKU_INC . 'inc/SimplePie.php',
70 'FeedParser' => DOKU_INC . 'inc/FeedParser.php',
71 'SafeFN' => DOKU_INC . 'inc/SafeFN.class.php',
72 'Mailer' => DOKU_INC . 'inc/Mailer.class.php',
73 'Doku_Handler' => DOKU_INC . 'inc/parser/handler.php',
74 'Doku_Renderer' => DOKU_INC . 'inc/parser/renderer.php',
75 'Doku_Renderer_xhtml' => DOKU_INC . 'inc/parser/xhtml.php',
76 'Doku_Renderer_code' => DOKU_INC . 'inc/parser/code.php',
77 'Doku_Renderer_xhtmlsummary' => DOKU_INC . 'inc/parser/xhtmlsummary.php',
78 'Doku_Renderer_metadata' => DOKU_INC . 'inc/parser/metadata.php'
81 if (isset($classes[$name])) {
82 require($classes[$name]);
83 return true;
86 // namespace to directory conversion
87 $name = str_replace('\\', '/', $name);
89 // test mock namespace
90 if (substr($name, 0, 19) === 'dokuwiki/test/mock/') {
91 $file = DOKU_INC . '_test/mock/' . substr($name, 19) . '.php';
92 if (file_exists($file)) {
93 require $file;
94 return true;
98 // tests namespace
99 if (substr($name, 0, 14) === 'dokuwiki/test/') {
100 $file = DOKU_INC . '_test/tests/' . substr($name, 14) . '.php';
101 if (file_exists($file)) {
102 require $file;
103 return true;
107 // plugin namespace
108 if (substr($name, 0, 16) === 'dokuwiki/plugin/') {
109 $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
110 $file = DOKU_PLUGIN . substr($name, 16) . '.php';
111 if (file_exists($file)) {
112 try {
113 require $file;
114 } catch (\Throwable $e) {
115 ErrorHandler::showExceptionMsg($e, "Error loading plugin $name");
117 return true;
121 // template namespace
122 if (substr($name, 0, 18) === 'dokuwiki/template/') {
123 $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
124 $file = DOKU_INC . 'lib/tpl/' . substr($name, 18) . '.php';
125 if (file_exists($file)) {
126 try {
127 require $file;
128 } catch (\Throwable $e) {
129 ErrorHandler::showExceptionMsg($e, "Error loading template $name");
131 return true;
135 // our own namespace
136 if (substr($name, 0, 9) === 'dokuwiki/') {
137 $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
138 if (file_exists($file)) {
139 require $file;
140 return true;
144 // Plugin loading
145 if (
146 preg_match(
147 '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' .
148 DOKU_PLUGIN_NAME_REGEX .
149 ')(?:_([^_]+))?$/',
150 $name,
154 // try to load the wanted plugin file
155 $c = ((count($m) === 4) ? "/{$m[3]}" : '');
156 $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
157 if (file_exists($plg)) {
158 try {
159 require $plg;
160 } catch (\Throwable $e) {
161 ErrorHandler::showExceptionMsg($e, "Error loading plugin {$m[2]}");
164 return true;
166 return false;