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