doku.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * DokuWiki mainscript
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. *
  8. * @global Input $INPUT
  9. */
  10. // update message version - always use a string to avoid localized floats!
  11. use dokuwiki\Extension\Event;
  12. $updateVersion = "54.1";
  13. // xdebug_start_profiling();
  14. if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
  15. // define all DokuWiki globals here (needed within test requests but also helps to keep track)
  16. global $ACT, $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
  17. $DATE, $RANGE, $HIGH, $TEXT, $PRE, $SUF, $SUM, $INFO, $JSINFO;
  18. if(isset($_SERVER['HTTP_X_DOKUWIKI_DO'])) {
  19. $ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
  20. } elseif(!empty($_REQUEST['idx'])) {
  21. $ACT = 'index';
  22. } elseif(isset($_REQUEST['do'])) {
  23. $ACT = $_REQUEST['do'];
  24. } else {
  25. $ACT = 'show';
  26. }
  27. // load and initialize the core system
  28. require_once(DOKU_INC.'inc/init.php');
  29. //import variables
  30. $INPUT->set('id', str_replace("\xC2\xAD", '', $INPUT->str('id'))); //soft-hyphen
  31. $QUERY = trim($INPUT->str('q'));
  32. $ID = getID();
  33. $REV = $INPUT->int('rev');
  34. $DATE_AT = $INPUT->str('at');
  35. $IDX = $INPUT->str('idx');
  36. $DATE = $INPUT->int('date');
  37. $RANGE = $INPUT->str('range');
  38. $HIGH = $INPUT->param('s');
  39. if(empty($HIGH)) $HIGH = getGoogleQuery();
  40. if($INPUT->post->has('wikitext')) {
  41. $TEXT = cleanText($INPUT->post->str('wikitext'));
  42. }
  43. $PRE = cleanText(substr($INPUT->post->str('prefix'), 0, -1));
  44. $SUF = cleanText($INPUT->post->str('suffix'));
  45. $SUM = $INPUT->post->str('summary');
  46. //parse DATE_AT
  47. if($DATE_AT) {
  48. $date_parse = strtotime($DATE_AT);
  49. if($date_parse) {
  50. $DATE_AT = $date_parse;
  51. } else { // check for UNIX Timestamp
  52. $date_parse = @date('Ymd',$DATE_AT);
  53. if(!$date_parse || $date_parse === '19700101') {
  54. msg(sprintf($lang['unable_to_parse_date'], hsc($DATE_AT)));
  55. $DATE_AT = null;
  56. }
  57. }
  58. }
  59. //check for existing $REV related to $DATE_AT
  60. if($DATE_AT) {
  61. $pagelog = new \dokuwiki\ChangeLog\PageChangeLog($ID);
  62. $rev_t = $pagelog->getLastRevisionAt($DATE_AT);
  63. if($rev_t === '') { //current revision
  64. $REV = null;
  65. $DATE_AT = null;
  66. } else if ($rev_t === false) { //page did not exist
  67. $rev_n = $pagelog->getRelativeRevision($DATE_AT,+1);
  68. msg(
  69. sprintf(
  70. $lang['page_nonexist_rev'],
  71. dformat($DATE_AT),
  72. wl($ID, array('rev' => $rev_n)),
  73. dformat($rev_n)
  74. )
  75. );
  76. $REV = $DATE_AT; //will result in a page not exists message
  77. } else {
  78. $REV = $rev_t;
  79. }
  80. }
  81. //make infos about the selected page available
  82. $INFO = pageinfo();
  83. // handle debugging
  84. if($conf['allowdebug'] && $ACT == 'debug') {
  85. html_debug();
  86. exit;
  87. }
  88. //send 404 for missing pages if configured or ID has special meaning to bots
  89. if(!$INFO['exists'] &&
  90. ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
  91. ($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
  92. ) {
  93. header('HTTP/1.0 404 Not Found');
  94. }
  95. //prepare breadcrumbs (initialize a static var)
  96. if($conf['breadcrumbs']) breadcrumbs();
  97. // check upstream
  98. checkUpdateMessages();
  99. $tmp = array(); // No event data
  100. Event::createAndTrigger('DOKUWIKI_STARTED', $tmp);
  101. //close session
  102. session_write_close();
  103. //do the work (picks up what to do from global env)
  104. act_dispatch();
  105. $tmp = array(); // No event data
  106. Event::createAndTrigger('DOKUWIKI_DONE', $tmp);
  107. // xdebug_dump_function_profile(1);