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