load.php 5.6 KB

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