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