Skip to content

Commit

Permalink
~~NOCACHE~~ added
Browse files Browse the repository at this point in the history
darcs-hash:20050501193908-9977f-e65b9b9bd123efaccc167f2e1ad9a1d4f51ba681.gz
  • Loading branch information
splitbrain committed May 1, 2005
1 parent 5e10074 commit 9dc2c2a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion inc/actions.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion inc/html.php
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions inc/parser/handler.php
Expand Up @@ -12,6 +12,7 @@ class Doku_Handler {
var $meta = array(
'section' => FALSE,
'toc' => TRUE,
'cache' => TRUE,
);

var $rewriteBlocks = TRUE;
Expand Down Expand Up @@ -97,6 +98,11 @@ function notoc($match, $state, $pos) {
$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);
Expand Down
11 changes: 10 additions & 1 deletion inc/parser/parser.php
Expand Up @@ -197,6 +197,15 @@ function connectTo($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 {

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion 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() {}

Expand Down Expand Up @@ -167,4 +175,4 @@ function tablecell_close(){}
}


//Setup VIM: ex: et ts=2 enc=utf-8 :
//Setup VIM: ex: et ts=4 enc=utf-8 :
20 changes: 12 additions & 8 deletions inc/parserutils.php
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 9dc2c2a

Please sign in to comment.