xref: /dokuwiki/doku.php (revision 7b62b42de1887c3627c727f0483aea41556742d4)
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
12$updateVersion = 43;
13
14//  xdebug_start_profiling();
15
16if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/');
17
18if(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
28// load and initialize the core system
29require_once(DOKU_INC.'inc/init.php');
30
31//import variables
32$INPUT->set('id', str_replace("\xC2\xAD", '', $INPUT->str('id'))); //soft-hyphen
33$QUERY          = trim($INPUT->str('id'));
34$ID             = getID();
35
36$REV   = $INPUT->int('rev');
37$DATE_AT = $INPUT->str('at');
38$IDX   = $INPUT->str('idx');
39$DATE  = $INPUT->int('date');
40$RANGE = $INPUT->str('range');
41$HIGH  = $INPUT->param('s');
42if(empty($HIGH)) $HIGH = getGoogleQuery();
43
44if($INPUT->post->has('wikitext')) {
45    $TEXT = cleanText($INPUT->post->str('wikitext'));
46}
47$PRE = cleanText(substr($INPUT->post->str('prefix'), 0, -1));
48$SUF = cleanText($INPUT->post->str('suffix'));
49$SUM = $INPUT->post->str('summary');
50
51
52//parse DATE_AT
53if($DATE_AT && $conf['date_at_format']) {
54    $date_o = DateTime::createFromFormat($conf['date_at_format'],$DATE_AT);
55    if(!$date_o) {
56        msg(sprintf($lang['unable_to_parse_date'], $DATE_AT,$conf['date_at_format']));
57        $DATE_AT = null;
58    } else {
59        $DATE_AT = $date_o->getTimestamp();
60    }
61}
62
63//check for existing $REV related to $DATE_AT
64if($DATE_AT) {
65    $pagelog = new PageChangeLog($ID);
66    $rev_t = $pagelog->getLastRevisionAt($DATE_AT);
67    if($rev_t === '') {
68        $REV = '';
69    } else if ($rev_t === false) {
70        $rev_n = $pagelog->getRelativeRevision($DATE_AT,+1);
71        if($conf['date_at_format']) {
72            msg(sprintf($lang['page_nonexist_rev'], date($conf['date_at_format'],$DATE_AT),date($conf['date_at_format'],$rev_n)));
73        } else {
74            msg(sprintf($lang['page_nonexist_rev'], $DATE_AT,$rev_n));
75        }
76        $REV = $DATE_AT;
77    } else {
78        $REV = $rev_t;
79    }
80}
81
82//make infos about the selected page available
83$INFO = pageinfo();
84
85//export minimal info to JS, plugins can add more
86$JSINFO['id']        = $ID;
87$JSINFO['namespace'] = (string) $INFO['namespace'];
88
89// handle debugging
90if($conf['allowdebug'] && $ACT == 'debug') {
91    html_debug();
92    exit;
93}
94
95//send 404 for missing pages if configured or ID has special meaning to bots
96if(!$INFO['exists'] &&
97    ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
98    ($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
99) {
100    header('HTTP/1.0 404 Not Found');
101}
102
103//prepare breadcrumbs (initialize a static var)
104if($conf['breadcrumbs']) breadcrumbs();
105
106// check upstream
107checkUpdateMessages();
108
109$tmp = array(); // No event data
110trigger_event('DOKUWIKI_STARTED', $tmp);
111
112//close session
113session_write_close();
114
115//do the work (picks up what to do from global env)
116act_dispatch();
117
118$tmp = array(); // No event data
119trigger_event('DOKUWIKI_DONE', $tmp);
120
121//  xdebug_dump_function_profile(1);
122