dokuwiki/doku.php

137 lines
3.6 KiB
PHP
Raw Permalink Normal View History

<?php
2023-08-31 22:44:40 +02:00
/**
* DokuWiki mainscript
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
2012-06-24 14:42:45 +02:00
*
* @global Input $INPUT
*/
2023-08-30 14:48:22 +02:00
use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\Event;
2023-08-30 14:48:22 +02:00
// update message version - always use a string to avoid localized floats!
$updateVersion = "55";
// xdebug_start_profiling();
2023-08-31 00:55:36 +02:00
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/');
// define all DokuWiki globals here (needed within test requests but also helps to keep track)
2023-08-31 00:55:36 +02:00
global $ACT, $INPUT, $QUERY, $ID, $REV, $DATE_AT, $IDX,
$DATE, $RANGE, $HIGH, $TEXT, $PRE, $SUF, $SUM, $INFO, $JSINFO;
2023-08-31 00:55:36 +02:00
if (isset($_SERVER['HTTP_X_DOKUWIKI_DO'])) {
$ACT = trim(strtolower($_SERVER['HTTP_X_DOKUWIKI_DO']));
2023-08-31 00:55:36 +02:00
} elseif (!empty($_REQUEST['idx'])) {
$ACT = 'index';
2023-08-31 00:55:36 +02:00
} elseif (isset($_REQUEST['do'])) {
$ACT = $_REQUEST['do'];
} else {
$ACT = 'show';
}
// load and initialize the core system
2023-08-31 00:55:36 +02:00
require_once(DOKU_INC . 'inc/init.php');
//import variables
$INPUT->set('id', str_replace("\xC2\xAD", '', $INPUT->str('id'))); //soft-hyphen
2023-08-31 00:55:36 +02:00
$QUERY = trim($INPUT->str('q'));
$ID = getID();
2023-08-31 00:55:36 +02:00
$REV = $INPUT->int('rev');
$DATE_AT = $INPUT->str('at');
2023-08-31 00:55:36 +02:00
$IDX = $INPUT->str('idx');
$DATE = $INPUT->int('date');
2012-06-24 14:42:45 +02:00
$RANGE = $INPUT->str('range');
2023-08-31 00:55:36 +02:00
$HIGH = $INPUT->param('s');
if (empty($HIGH)) $HIGH = getGoogleQuery();
2023-08-31 00:55:36 +02:00
if ($INPUT->post->has('wikitext')) {
2012-06-24 14:43:51 +02:00
$TEXT = cleanText($INPUT->post->str('wikitext'));
}
2012-06-24 14:43:51 +02:00
$PRE = cleanText(substr($INPUT->post->str('prefix'), 0, -1));
$SUF = cleanText($INPUT->post->str('suffix'));
$SUM = $INPUT->post->str('summary');
//parse DATE_AT
2023-08-31 00:55:36 +02:00
if ($DATE_AT) {
$date_parse = strtotime($DATE_AT);
2023-08-31 00:55:36 +02:00
if ($date_parse) {
$DATE_AT = $date_parse;
} else { // check for UNIX Timestamp
$date_parse = @date('Ymd', $DATE_AT);
2023-08-31 00:55:36 +02:00
if (!$date_parse || $date_parse === '19700101') {
msg(sprintf($lang['unable_to_parse_date'], hsc($DATE_AT)));
$DATE_AT = null;
}
}
}
//check for existing $REV related to $DATE_AT
2023-08-31 00:55:36 +02:00
if ($DATE_AT) {
2023-08-30 14:48:22 +02:00
$pagelog = new PageChangeLog($ID);
$rev_t = $pagelog->getLastRevisionAt($DATE_AT);
2023-08-30 14:48:22 +02:00
if ($rev_t === '') {
//current revision
$REV = null;
$DATE_AT = null;
2023-08-30 14:48:22 +02:00
} elseif ($rev_t === false) {
//page did not exist
$rev_n = $pagelog->getRelativeRevision($DATE_AT, +1);
msg(
sprintf(
$lang['page_nonexist_rev'],
dformat($DATE_AT),
2023-08-30 14:48:22 +02:00
wl($ID, ['rev' => $rev_n]),
dformat($rev_n)
)
);
$REV = $DATE_AT; //will result in a page not exists message
} else {
$REV = $rev_t;
}
}
//make infos about the selected page available
$INFO = pageinfo();
// handle debugging
2023-08-31 00:55:36 +02:00
if ($conf['allowdebug'] && $ACT == 'debug') {
html_debug();
exit;
}
//send 404 for missing pages if configured or ID has special meaning to bots
2023-08-31 15:04:10 +02:00
if (
!$INFO['exists'] &&
2012-06-24 14:43:51 +02:00
($conf['send404'] || preg_match('/^(robots\.txt|sitemap\.xml(\.gz)?|favicon\.ico|crossdomain\.xml)$/', $ID)) &&
2023-09-15 16:25:49 +02:00
($ACT == 'show' || (!is_array($ACT) && str_starts_with($ACT, 'export_')))
2012-06-24 14:43:51 +02:00
) {
header('HTTP/1.0 404 Not Found');
}
//prepare breadcrumbs (initialize a static var)
2023-08-31 00:55:36 +02:00
if ($conf['breadcrumbs']) breadcrumbs();
// check upstream
checkUpdateMessages();
2023-08-30 14:48:22 +02:00
$tmp = []; // No event data
Event::createAndTrigger('DOKUWIKI_STARTED', $tmp);
//close session
session_write_close();
//do the work (picks up what to do from global env)
act_dispatch();
2023-08-30 14:48:22 +02:00
$tmp = []; // No event data
Event::createAndTrigger('DOKUWIKI_DONE', $tmp);
// xdebug_dump_function_profile(1);