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