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 = "51.3";
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(sprintf($lang['page_nonexist_rev'],
83            strftime($conf['dformat'],$DATE_AT),
84            wl($ID, array('rev' => $rev_n)),
85            strftime($conf['dformat'],$rev_n)));
86        $REV = $DATE_AT; //will result in a page not exists message
87    } else {
88        $REV = $rev_t;
89    }
90}
91
92//make infos about the selected page available
93$INFO = pageinfo();
94
95// handle debugging
96if($conf['allowdebug'] && $ACT == 'debug') {
97    html_debug();
98    exit;
99}
100
101//send 404 for missing pages if configured or ID has special meaning to bots
102if(!$INFO['exists'] &&
103    ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
104    ($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
105) {
106    header('HTTP/1.0 404 Not Found');
107}
108
109//prepare breadcrumbs (initialize a static var)
110if($conf['breadcrumbs']) breadcrumbs();
111
112// check upstream
113checkUpdateMessages();
114
115$tmp = array(); // No event data
116Event::createAndTrigger('DOKUWIKI_STARTED', $tmp);
117
118//close session
119session_write_close();
120
121//do the work (picks up what to do from global env)
122act_dispatch();
123
124$tmp = array(); // No event data
125Event::createAndTrigger('DOKUWIKI_DONE', $tmp);
126
127//  xdebug_dump_function_profile(1);
128