[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Load all internal libraries and setup class autoloader 5 * 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 use dokuwiki\ErrorHandler; 10 use dokuwiki\Extension\PluginController; 11 12 // setup class autoloader 13 spl_autoload_register('load_autoload'); 14 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/compatibility.php'); // load early so we can use it everywhere 19 require_once (DOKU_INC . 'inc/actions.php'); 20 require_once (DOKU_INC . 'inc/changelog.php'); 21 require_once (DOKU_INC . 'inc/common.php'); 22 require_once (DOKU_INC . 'inc/confutils.php'); 23 require_once (DOKU_INC . 'inc/pluginutils.php'); 24 require_once (DOKU_INC . 'inc/form.php'); 25 require_once (DOKU_INC . 'inc/fulltext.php'); 26 require_once (DOKU_INC . 'inc/html.php'); 27 require_once (DOKU_INC . 'inc/httputils.php'); 28 require_once (DOKU_INC . 'inc/indexer.php'); 29 require_once (DOKU_INC . 'inc/infoutils.php'); 30 require_once (DOKU_INC . 'inc/io.php'); 31 require_once (DOKU_INC . 'inc/mail.php'); 32 require_once (DOKU_INC . 'inc/media.php'); 33 require_once (DOKU_INC . 'inc/pageutils.php'); 34 require_once (DOKU_INC . 'inc/parserutils.php'); 35 require_once (DOKU_INC . 'inc/search.php'); 36 require_once (DOKU_INC . 'inc/template.php'); 37 require_once (DOKU_INC . 'inc/toolbar.php'); 38 require_once (DOKU_INC . 'inc/utf8.php'); 39 require_once (DOKU_INC . 'inc/auth.php'); 40 require_once (DOKU_INC . 'inc/deprecated.php'); 41 require_once (DOKU_INC . 'inc/legacy.php'); 42 43 /** 44 * spl_autoload_register callback 45 * 46 * Contains a static list of DokuWiki's core classes and automatically 47 * require()s their associated php files when an object is instantiated. 48 * 49 * @author Andreas Gohr <andi@splitbrain.org> 50 * @todo add generic loading of renderers and auth backends 51 * 52 * @param string $name 53 * 54 * @return bool 55 */ 56 function load_autoload($name) 57 { 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' 79 ]; 80 81 if (isset($classes[$name])) { 82 require($classes[$name]); 83 return true; 84 } 85 86 // namespace to directory conversion 87 $name = str_replace('\\', '/', $name); 88 89 // test mock namespace 90 if (str_starts_with($name, 'dokuwiki/test/mock/')) { 91 $file = DOKU_INC . '_test/mock/' . substr($name, 19) . '.php'; 92 if (file_exists($file)) { 93 require $file; 94 return true; 95 } 96 } 97 98 // tests namespace 99 if (str_starts_with($name, 'dokuwiki/test/')) { 100 $file = DOKU_INC . '_test/tests/' . substr($name, 14) . '.php'; 101 if (file_exists($file)) { 102 require $file; 103 return true; 104 } 105 } 106 107 // plugin namespace 108 if (str_starts_with($name, '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"); 116 } 117 return true; 118 } 119 } 120 121 // template namespace 122 if (str_starts_with($name, '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"); 130 } 131 return true; 132 } 133 } 134 135 // our own namespace 136 if (str_starts_with($name, 'dokuwiki/')) { 137 $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php'; 138 if (file_exists($file)) { 139 require $file; 140 return true; 141 } 142 } 143 144 // Plugin loading 145 if ( 146 preg_match( 147 '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' . 148 DOKU_PLUGIN_NAME_REGEX . 149 ')(?:_([^_]+))?$/', 150 $name, 151 $m 152 ) 153 ) { 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]}"); 162 } 163 } 164 return true; 165 } 166 return false; 167 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body