diff --git a/inc/actions.php b/inc/actions.php index 9fb186b00984f848054748a388de0a81be36641d..3f7cc8c946c3c9750cdb9aba18318492d03c2406 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -242,7 +242,7 @@ function act_export($act){ // try to run renderer #FIXME use cached instructions $mode = substr($act,7); - $text = p_render($mode,p_get_instructions(rawWiki($ID,$REV))); + $text = p_render($mode,p_get_instructions(rawWiki($ID,$REV)),$info); if(!is_null($text)){ print $text; exit; diff --git a/inc/html.php b/inc/html.php index c03e9d31ce5a51fc067f93a7f8d31f3870e32170..9e736f7026f8f68a25c221425b271c89b39d7595 100644 --- a/inc/html.php +++ b/inc/html.php @@ -272,7 +272,7 @@ function html_show($txt=''){ //PreviewHeader print p_locale_xhtml('preview'); print '<div class="preview">'; - print html_secedit(p_render('xhtml',p_get_instructions($txt)),$secedit); + print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); print '</div>'; }else{ diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 91d8843450236cf4ca91b266a7cdaf165ce488f8..ce0fb5d4c03b5799146c2f06e9c03a6f3f650715 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -12,6 +12,7 @@ class Doku_Handler { var $meta = array( 'section' => FALSE, 'toc' => TRUE, + 'cache' => TRUE, ); var $rewriteBlocks = TRUE; @@ -97,6 +98,11 @@ class Doku_Handler { $this->meta['toc'] = FALSE; return TRUE; } + + function nocache($match, $state, $pos) { + $this->_addCall('nocache',array(),$pos); + return TRUE; + } function linebreak($match, $state, $pos) { $this->_addCall('linebreak',array(),$pos); diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 8c6b7329bd41d5d2159c265e8267acfa37cda59b..7de715b954c378c20fd6b06807b993e719a8d858 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -197,6 +197,15 @@ class Doku_Parser_Mode_NoToc extends Doku_Parser_Mode { } +//------------------------------------------------------------------- +class Doku_Parser_Mode_NoCache extends Doku_Parser_Mode { + + function connectTo($mode) { + $this->Lexer->addSpecialPattern('~~NOCACHE~~',$mode,'nocache'); + } + +} + //------------------------------------------------------------------- class Doku_Parser_Mode_Linebreak extends Doku_Parser_Mode { @@ -816,7 +825,7 @@ function Doku_Parser_Substition() { $modes = array( 'acronym','smiley','wordblock','entity','camelcaselink', 'internallink','media','externallink','linebreak','emaillink', - 'windowssharelink','filelink','notoc','multiplyentity', + 'windowssharelink','filelink','notoc','nocache','multiplyentity', 'quotes','rss', ); return $modes; diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 2fd5bfe6f8d447c67fb4ca1ce36fabf3589271d4..89b28f2487814a9ec14b5507d3f0d6280e2f5b01 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -1,5 +1,13 @@ <?php class Doku_Renderer { + var $info = array( + 'cache' => TRUE, // may the rendered result cached? + ); + + + function nocache() { + $this->info['cache'] = FALSE; + } function document_start() {} @@ -167,4 +175,4 @@ class Doku_Renderer { } -//Setup VIM: ex: et ts=2 enc=utf-8 : +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/parserutils.php b/inc/parserutils.php index c44351fed20bde4598158acaa721f9e8fadc233c..a3402e4bc98d20e083d50aed3255942692a5030c 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -30,7 +30,7 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){ if($rev){ if(@file_exists($file)){ - $ret = p_render('xhtml',p_get_instructions(io_readfile($file))); //no caching on old revisions + $ret = p_render('xhtml',p_get_instructions(io_readfile($file)),$info); //no caching on old revisions }elseif($excuse){ $ret = p_locale_xhtml('norev'); } @@ -62,6 +62,7 @@ function p_locale_xhtml($id){ * Uses and creates a cachefile * * @author Andreas Gohr <andi@splitbrain.org> + * @todo rewrite to use mode instead of hardcoded XHTML */ function p_cached_xhtml($file){ global $conf; @@ -87,19 +88,15 @@ function p_cached_xhtml($file){ $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"; + $parsed = p_render('xhtml', p_cached_instructions($file),$info); //try to use cached instructions - /* FIXME add nocache directive handling like this: - if($parser['cache']){ + if($info['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; @@ -170,6 +167,7 @@ function p_get_instructions($text){ $Parser->addMode('listblock',new Doku_Parser_Mode_ListBlock()); $Parser->addMode('preformatted',new Doku_Parser_Mode_Preformatted()); $Parser->addMode('notoc',new Doku_Parser_Mode_NoToc()); + $Parser->addMode('nocache',new Doku_Parser_Mode_NoCache()); $Parser->addMode('header',new Doku_Parser_Mode_Header()); $Parser->addMode('table',new Doku_Parser_Mode_Table()); @@ -222,10 +220,12 @@ function p_get_instructions($text){ /** * Renders a list of instruction to the specified output mode * + * In the $info array are informations from the renderer returned + * * @author Harry Fuecks <hfuecks@gmail.com> * @author Andreas Gohr <andi@splitbrain.org> */ -function p_render($mode,$instructions){ +function p_render($mode,$instructions,& $info){ if(is_null($instructions)) return ''; // Create the renderer @@ -249,6 +249,10 @@ function p_render($mode,$instructions){ // Execute the callback against the Renderer call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); } + + //set info array + $info = $Renderer->info; + // Return the output return $Renderer->doc; }