[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/ -> doku.php (source)

   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 = "50";
  13  
  14  //  xdebug_start_profiling();
  15  
  16  if(!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)
  19  global  $ACT,  $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
  20          $DATE, $RANGE, $HIGH, $TEXT, $PRE, $SUF, $SUM, $INFO, $JSINFO;
  21  
  22  
  23  if(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
  34  require_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('q'));
  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');
  47  if(empty($HIGH)) $HIGH = getGoogleQuery();
  48  
  49  if($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
  58  if($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'], hsc($DATE_AT)));
  66              $DATE_AT = null;
  67          }
  68      }
  69  }
  70  
  71  //check for existing $REV related to $DATE_AT
  72  if($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  // handle debugging
  94  if($conf['allowdebug'] && $ACT == 'debug') {
  95      html_debug();
  96      exit;
  97  }
  98  
  99  //send 404 for missing pages if configured or ID has special meaning to bots
 100  if(!$INFO['exists'] &&
 101      ($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
 102      ($ACT == 'show' || (!is_array($ACT) && substr($ACT, 0, 7) == 'export_'))
 103  ) {
 104      header('HTTP/1.0 404 Not Found');
 105  }
 106  
 107  //prepare breadcrumbs (initialize a static var)
 108  if($conf['breadcrumbs']) breadcrumbs();
 109  
 110  // check upstream
 111  checkUpdateMessages();
 112  
 113  $tmp = array(); // No event data
 114  trigger_event('DOKUWIKI_STARTED', $tmp);
 115  
 116  //close session
 117  session_write_close();
 118  
 119  //do the work (picks up what to do from global env)
 120  act_dispatch();
 121  
 122  $tmp = array(); // No event data
 123  trigger_event('DOKUWIKI_DONE', $tmp);
 124  
 125  //  xdebug_dump_function_profile(1);