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