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