diff --git a/inc/parser/handler.php b/inc/parser/handler.php index a3609609c..3538c78b0 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -30,6 +30,9 @@ class Doku_Handler { /** @var bool should blocks be rewritten? FIXME seems to always be true */ protected $rewriteBlocks = true; + /** @var string|null the currently processed page, null for on the fly renders */ + protected $page = null; + /** * Doku_Handler constructor. */ @@ -37,6 +40,29 @@ class Doku_Handler { $this->callWriter = new CallWriter($this); } + /** + * Set the currently processed page + * + * @param string $id + */ + public function setPage($id) + { + $this->page = $id; + } + + /** + * Get the currently processed page + * + * This may return null when the parsing/handling process is called "on the fly", eg. to + * render a wiki text snippet somewhere. + * + * @return string|null + */ + public function getPage() + { + return $this->page; + } + /** * Add a new call by passing it to the current CallWriter * diff --git a/inc/parserutils.php b/inc/parserutils.php index 846be54db..ffbcc872c 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -80,7 +80,7 @@ function p_wiki_xhtml($id, $rev='', $excuse=true,$date_at=''){ if($rev || $date_at){ if(file_exists($file)){ //no caching on old revisions - $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev)),$info,$date_at); + $ret = p_render('xhtml',p_get_instructions(io_readWikiPage($file,$id,$rev), $id),$info,$date_at); }elseif($excuse){ $ret = p_locale_xhtml('norev'); } @@ -193,27 +193,32 @@ function p_cached_instructions($file,$cacheonly=false,$id='') { /** * turns a page into a list of instructions * - * @author Harry Fuecks + * @param string $text raw wiki syntax text + * @param string $id optional hint on the currently processed page + * @return array a list of instruction arrays * @author Andreas Gohr * - * @param string $text raw wiki syntax text - * @return array a list of instruction arrays + * @author Harry Fuecks */ -function p_get_instructions($text){ +function p_get_instructions($text, $id=''){ $modes = p_get_parsermodes(); // Create the parser and handler - $Parser = new Parser(new Doku_Handler()); + $handler = new Doku_Handler(); + if($id !== '') { + $handler->setPage($id); + } + $parser = new Parser($handler); //add modes to parser foreach($modes as $mode){ - $Parser->addMode($mode['mode'],$mode['obj']); + $parser->addMode($mode['mode'],$mode['obj']); } // Do the parsing Event::createAndTrigger('PARSER_WIKITEXT_PREPROCESS', $text); - $p = $Parser->parse($text); + $p = $parser->parse($text); // dbg($p); return $p; }