xref: /dokuwiki/doku.php (revision 29eba4294ec095d7a6fe677fb8b8e64e98655bcc)
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 = 47;
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) {
54    $date_parse = strtotime($DATE_AT);
55    if($date_parse) {
56        $DATE_AT = $date_parse;
57    } else { // check for UNIX Timestamp
58        $date_parse = @date('Ymd',$DATE_AT);
59        if(!$date_parse || $date_parse === '19700101') {
60            msg(sprintf($lang['unable_to_parse_date'], $DATE_AT));
61            $DATE_AT = null;
62        }
63    }
64}
65
66//check for existing $REV related to $DATE_AT
67if($DATE_AT) {
68    $pagelog = new PageChangeLog($ID);
69    $rev_t = $pagelog->getLastRevisionAt($DATE_AT);
70    if($rev_t === '') { //current revision
71        $REV = null;
72        $DATE_AT = null;
73    } else if ($rev_t === false) { //page did not exist
74        $rev_n = $pagelog->getRelativeRevision($DATE_AT,+1);
75        msg(sprintf($lang['page_nonexist_rev'],
76            strftime($conf['dformat'],$DATE_AT),
77            wl($ID, array('rev' => $rev_n)),
78            strftime($conf['dformat'],$rev_n)));
79        $REV = $DATE_AT; //will result in a page not exists message
80    } else {
81        $REV = $rev_t;
82    }
83}
84
85//make infos about the selected page available
86$INFO = pageinfo();
87
88//export minimal info to JS, plugins can add more
89$JSINFO['id']        = $ID;
90$JSINFO['namespace'] = (string) $INFO['namespace'];
91
92// handle debugging
93if($conf['allowdebug'] && $ACT == 'debug') {
94    html_debug();
95    exit;
96}
97
98//send 404 for missing pages if configured or ID has special meaning to bots
99if(!$INFO['exists'] &&
100    ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
101    ($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
102) {
103    header('HTTP/1.0 404 Not Found');
104}
105
106//prepare breadcrumbs (initialize a static var)
107if($conf['breadcrumbs']) breadcrumbs();
108
109// check upstream
110checkUpdateMessages();
111
112$tmp = array(); // No event data
113trigger_event('DOKUWIKI_STARTED', $tmp);
114
115//close session
116session_write_close();
117
118//do the work (picks up what to do from global env)
119act_dispatch();
120
121$tmp = array(); // No event data
122trigger_event('DOKUWIKI_DONE', $tmp);
123
124//  xdebug_dump_function_profile(1);
125