Skip to content
Snippets Groups Projects
Commit c112d578 authored by andi's avatar andi
Browse files

new parser now default, caching added

darcs-hash:20050416171733-9977f-61a66a56862c4126c6987cdc19609b4e5504da9b.gz
parent f54a290c
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,6 @@
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/html.php');
require_once(DOKU_INC.'inc/parser.php');
require_once(DOKU_INC.'lang/en/lang.php');
require_once(DOKU_INC.'lang/'.$conf['lang'].'/lang.php');
require_once(DOKU_INC.'inc/auth.php');
......
......@@ -11,6 +11,7 @@
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/utf8.php');
require_once(DOKU_INC.'inc/mail.php');
require_once(DOKU_INC.'inc/parserutils.php');
/**
* Return info about the current document as associative
......@@ -46,6 +47,7 @@ function pageinfo(){
$REV = '';
}
}
$info['rev'] = $REV;
if($info['exists']){
$info['writable'] = (is_writable($info['filepath']) &&
($info['perm'] >= AUTH_EDIT));
......@@ -358,23 +360,6 @@ function formText($text){
return htmlspecialchars($text);
}
/**
* Returns the specified local text in parsed format
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function parsedLocale($id){
//disable section editing
global $parser;
$se = $parser['secedit'];
$parser['secedit'] = false;
//fetch parsed locale
$html = io_cacheParse(localeFN($id));
//reset section editing
$parser['secedit'] = $se;
return $html;
}
/**
* Returns the specified local text in raw format
*
......@@ -384,46 +369,6 @@ function rawLocale($id){
return io_readFile(localeFN($id));
}
/**
* Returns the parsed Wikitext for the given id and revision.
*
* If $excuse is true an explanation is returned if the file
* wasn't found
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function parsedWiki($id,$rev='',$excuse=true){
$file = wikiFN($id,$rev);
$ret = '';
//ensure $id is in global $ID (needed for parsing)
global $ID;
$ID = $id;
if($rev){
if(@file_exists($file)){
$ret = parse(io_readFile($file));
}elseif($excuse){
$ret = parsedLocale('norev');
}
}else{
if(@file_exists($file)){
if(!defined('DOKU_USENEWPARSER')){
$ret = io_cacheParse($file);
}else{
msg('using new parser');
require_once(DOKU_INC.'inc/parser/action.php');
$ret = render_as_xhtml(parse_to_instructions(io_readFile($file)));
}
}elseif($excuse){
$ret = parsedLocale('newpage');
}
}
return $ret;
}
/**
* Returns the raw WikiText
*
......
......@@ -7,6 +7,8 @@
* @deprecated part of the XHTML renderer
*/
trigger_error('deprecated parser.php included');
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'conf/dokuwiki.php');
require_once(DOKU_INC.'inc/common.php');
......
......@@ -7,7 +7,6 @@
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/format.php');
/**
* Convenience function to quickly build a wikilink
......@@ -52,7 +51,7 @@ function html_login(){
global $conf;
global $ID;
print parsedLocale('login');
print p_locale_xhtml('login');
?>
<div align="center">
<form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post">
......@@ -144,7 +143,7 @@ function html_secedit_button($section,$p){
*/
function html_secedit($text,$show=true){
global $INFO;
if($INFO['writable'] && $show){
if($INFO['writable'] && $show && !$INFO['rev']){
$text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
"html_secedit_button('\\1',true)",
$text);
......@@ -270,13 +269,13 @@ function html_show($text=''){
if ($text){
//PreviewHeader
print parsedLocale('preview');
print p_locale_xhtml('preview');
print '<div class="preview">';
print html_secedit(parse($text),false);
print '</div>';
}else{
if ($REV) print parsedLocale('showrev');
$html = parsedWiki($ID,$REV,true);
if ($REV) print p_locale_xhtml('showrev');
$html = p_wiki_xhtml($ID,$REV,true);
$html = html_secedit($html);
print html_hilight($html,$HIGH);
}
......@@ -308,7 +307,7 @@ function html_search(){
global $ID;
global $lang;
print parsedLocale('searchpage');
print p_locale_xhtml('searchpage');
flush();
//show progressbar
......@@ -372,7 +371,7 @@ function html_locked($ip){
$expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
$min = round(($conf['locktime'] - (time() - $locktime) )/60);
print parsedLocale('locked');
print p_locale_xhtml('locked');
print '<ul>';
print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
......@@ -392,7 +391,7 @@ function html_revisions(){
$revisions = getRevisions($ID);
$date = @date($conf['dformat'],$INFO['lastmod']);
print parsedLocale('revisions');
print p_locale_xhtml('revisions');
print '<ul>';
if($INFO['exists']){
print '<li>';
......@@ -437,7 +436,7 @@ function html_recent(){
global $conf;
$recents = getRecents(0,true);
print parsedLocale('recent');
print p_locale_xhtml('recent');
print '<ul>';
foreach(array_keys($recents) as $id){
$date = date($conf['dformat'],$recents[$id]['date']);
......@@ -470,7 +469,7 @@ function html_index($ns){
}
$ns = utf8_encodeFN(str_replace(':','/',$ns));
print parsedLocale('index');
print p_locale_xhtml('index');
$data = array();
search($data,$conf['datadir'],'search_index',array('ns' => $ns));
......@@ -599,7 +598,7 @@ function html_backlinks(){
$opts['name'] = $ID;
}
print parsedLocale('backlinks');
print p_locale_xhtml('backlinks');
$data = array();
search($data,$conf['datadir'],'search_backlinks',$opts);
......@@ -642,7 +641,7 @@ function html_diff($text='',$intro=true){
$lang['current'];
}
$tdf = new TableDiffFormatter();
if($intro) print parsedLocale('diff');
if($intro) print p_locale_xhtml('diff');
?>
<table class="diff" width="100%">
<tr>
......@@ -667,7 +666,7 @@ function html_conflict($text,$summary){
global $ID;
global $lang;
print parsedLocale('conflict');
print p_locale_xhtml('conflict');
?>
<form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
<input type="hidden" name="id" value="<?=$ID?>" />
......@@ -709,7 +708,7 @@ function html_register(){
global $lang;
global $ID;
print parsedLocale('register');
print p_locale_xhtml('register');
?>
<div align="center">
<form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
......@@ -776,10 +775,10 @@ function html_edit($text=null,$include='edit'){ //FIXME: include needed?
$wr = $INFO['writable'];
if($wr){
if ($REV) print parsedLocale('editrev');
print parsedLocale($include);
if ($REV) print p_locale_xhtml('editrev');
print p_locale_xhtml($include);
}else{
print parsedLocale('read');
print p_locale_xhtml('read');
$ro='readonly="readonly"';
}
if(!$DATE) $DATE = $INFO['lastmod'];
......@@ -952,7 +951,7 @@ function html_admin(){
global $ID;
global $lang;
print parsedLocale('admin');
print p_locale_xhtml('admin');
ptln('<ul class="admin">');
......
......@@ -8,13 +8,13 @@
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/parser.php');
/**
* Returns the parsed text from the given sourcefile. Uses cache
* if exists. Creates it if not.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @deprecated -> parserutils
*/
function io_cacheParse($file){
global $conf;
......
......@@ -7,6 +7,8 @@
* @deprecated replaced by the new parser
*/
trigger_error('deprecated parser.php included');
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
include_once(DOKU_INC.'inc/common.php');
include_once(DOKU_INC.'inc/html.php');
......
<?php
/**
* Utilities for collecting data from config files
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/confutils.php');
require_once(DOKU_INC.'inc/pageutils.php');
/**
* Returns the parsed Wikitext in XHTML for the given id and revision.
*
* If $excuse is true an explanation is returned if the file
* wasn't found
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_wiki_xhtml($id, $rev='', $excuse=true){
$file = wikiFN($id,$rev);
$ret = '';
//ensure $id is in global $ID (needed for parsing)
global $ID;
$ID = $id;
if($rev){
if(@file_exists($file)){
$ret = p_render_xhtml(p_get_instructions($file)); //no caching on old revisions
}elseif($excuse){
$ret = p_locale_xhtml('norev');
}
}else{
if(@file_exists($file)){
$ret = p_cached_xhtml($file);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
}
}
return $ret;
}
/**
* Returns the specified local text in parsed format
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_locale_xhtml($id){
//fetch parsed locale
$html = p_cached_xhtml(localeFN($id));
return $html;
}
/**
* Returns the given file parsed to XHTML
*
* @todo maybe wrap in class
* @todo rename to helper
* Uses and creates a cachefile
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_cached_xhtml($file){
global $conf;
$cache = $conf['datadir'].'/_cache/xhtml/';
$cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']);
// check if cache can be used
$cachetime = @filemtime($cache); // 0 if not exists
if( @file_exists($file) // does the source exist
&& $cachetime > @filemtime($file) // cache is fresh
&& ((time() - $cachetime) < $conf['cachetime']) // and is cachefile young enough
&& !isset($_REQUEST['purge']) // no purge param was set
&& ($cachetime > @filemtime(DOKU_INC.'conf/dokuwiki.php')) // newer than the config file
&& ($cachetime > @filemtime(DOKU_INC.'conf/local.php')) // newer than the local config file
&& ($cachetime > @filemtime(DOKU_INC.'inc/parser/xhtml.php')) // newer than the renderer
&& ($cachetime > @filemtime(DOKU_INC.'inc/parser/parser.php')) // newer than the parser
&& ($cachetime > @filemtime(DOKU_INC.'inc/parser/handler.php')))// newer than the handler
{
//well then use the cache
$parsed = io_readfile($cache);
$parsed .= "\n<!-- cachefile $cache used -->\n";
}else{
$parsed = p_render_xhtml(p_cached_instructions($file)); //try to use cached instructions
io_saveFile($cache,$parsed); //save cachefile
$parsed .= "\n<!-- no cachefile used, but created -->\n";
/* FIXME add nocache directive handling like this:
if($parser['cache']){
io_saveFile($cache,$parsed); //save cachefile
$parsed .= "\n<!-- no cachefile used, but created -->\n";
}else{
@unlink($cache); //try to delete cachefile
$parsed .= "\n<!-- no cachefile used, caching forbidden -->\n";
}
*/
}
return $parsed;
}
/**
* Returns the render instructions for a file
*
* Uses and creates a serialized cache file
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function p_cached_instructions($file){
global $conf;
$cache = $conf['datadir'].'/_cache/instructions/';
$cache .= md5($file.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT']);
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
// check if cache can be used
$cachetime = @filemtime($cache); // 0 if not exists
require_once(DOKU_INC.'inc/confutils.php');
if( @file_exists($file) // does the source exist
&& $cachetime > @filemtime($file) // cache is fresh
&& !isset($_REQUEST['purge']) // no purge param was set
&& ($cachetime > @filemtime(DOKU_INC.'conf/dokuwiki.php')) // newer than the config file
&& ($cachetime > @filemtime(DOKU_INC.'conf/local.php')) // newer than the local config file
&& ($cachetime > @filemtime(DOKU_INC.'inc/parser/parser.php')) // newer than the parser
&& ($cachetime > @filemtime(DOKU_INC.'inc/parser/handler.php')))// newer than the handler
{
//well then use the cache
return unserialize(io_readfile($cache));
}elseif(@file_exists($file)){
// no cache - do some work
$ins = p_get_instructions($file);
io_savefile($cache,serialize($ins));
return $ins;
}
return NULL;
}
/**
* turns a page into a list of instructions
......@@ -15,9 +145,11 @@ require_once(DOKU_INC.'inc/confutils.php');
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
function parse_to_instructions($text){
function p_get_instructions($file){
global $conf;
$text = io_readfile($file);
require_once DOKU_INC . 'inc/parser/parser.php';
// Create the parser
......@@ -83,9 +215,8 @@ function parse_to_instructions($text){
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
function render_as_xhtml($instructions){
#dbg($instructions);
function p_render_xhtml($instructions){
if(is_null($instructions)) return '';
// Create the renderer
require_once DOKU_INC . 'inc/parser/xhtml.php';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment