diff options
Diffstat (limited to 'inc/parserutils.php')
-rw-r--r-- | inc/parserutils.php | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/inc/parserutils.php b/inc/parserutils.php index 55b451c76..1733fcf09 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -92,14 +92,18 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){ * If $excuse is true an explanation is returned if the file * wasn't found * - * @param string wiki page id - * @param reference populated with page title from heading or page id + * @param string $id wiki page id + * @param string $title populated with page title from heading or page id + * @param string $rev revision string + * @param bool $excuse if an excuse shall be renderer when no content is found + * @return string xhtml code * @deprecated * @author Harry Fuecks <hfuecks@gmail.com> */ function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){ $file = wikiFN($id,$rev); $ret = ''; + $ins = null; //ensure $id is in global $ID (needed for parsing) global $ID; @@ -206,13 +210,12 @@ function p_cached_output($file, $format='xhtml', $id='') { * @author Andreas Gohr <andi@splitbrain.org> */ function p_cached_instructions($file,$cacheonly=false,$id='') { - global $conf; static $run = null; if(is_null($run)) $run = array(); $cache = new cache_instructions($id, $file); - if ($cacheonly || $cache->useCache() || isset($run[$file])) { + if ($cacheonly || $cache->useCache() || (isset($run[$file]) && !defined('DOKU_UNITTEST'))) { return $cache->retrieveCache(); } else if (@file_exists($file)) { // no cache - do some work @@ -311,8 +314,10 @@ function p_get_metadata($id, $key='', $render=METADATA_RENDER_USING_CACHE){ } } if ($do_render) { - ++$render_count; - $rendered_pages[$id] = true; + if (!defined('DOKU_UNITTEST')) { + ++$render_count; + $rendered_pages[$id] = true; + } $old_meta = $meta; $meta = p_render_metadata($id, $meta); // only update the file when the metadata has been changed @@ -381,9 +386,18 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){ if ($key == 'relation'){ foreach ($value as $subkey => $subvalue){ - $meta['current'][$key][$subkey] = !empty($meta['current'][$key][$subkey]) ? array_merge($meta['current'][$key][$subkey], $subvalue) : $subvalue; - if ($persistent) - $meta['persistent'][$key][$subkey] = !empty($meta['persistent'][$key][$subkey]) ? array_merge($meta['persistent'][$key][$subkey], $subvalue) : $subvalue; + if(isset($meta['current'][$key][$subkey]) && is_array($meta['current'][$key][$subkey])) { + $meta['current'][$key][$subkey] = array_merge($meta['current'][$key][$subkey], (array)$subvalue); + } else { + $meta['current'][$key][$subkey] = $subvalue; + } + if($persistent) { + if(isset($meta['persistent'][$key][$subkey]) && is_array($meta['persistent'][$key][$subkey])) { + $meta['persistent'][$key][$subkey] = array_merge($meta['persistent'][$key][$subkey], (array)$subvalue); + } else { + $meta['persistent'][$key][$subkey] = $subvalue; + } + } } // be careful with some senisitive arrays of $meta @@ -391,10 +405,10 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){ // these keys, must have subkeys - a legitimate value must be an array if (is_array($value)) { - $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge($meta['current'][$key],$value) : $value; + $meta['current'][$key] = !empty($meta['current'][$key]) ? array_merge((array)$meta['current'][$key],$value) : $value; if ($persistent) { - $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge($meta['persistent'][$key],$value) : $value; + $meta['persistent'][$key] = !empty($meta['persistent'][$key]) ? array_merge((array)$meta['persistent'][$key],$value) : $value; } } @@ -547,7 +561,7 @@ function p_get_parsermodes(){ //reuse old data static $modes = null; - if($modes != null){ + if($modes != null && !defined('DOKU_UNITTEST')){ return $modes; } @@ -564,7 +578,8 @@ function p_get_parsermodes(){ global $PARSER_MODES; $obj = null; foreach($pluginlist as $p){ - if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj + /** @var DokuWiki_Syntax_Plugin $obj */ + if(!$obj = plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type //add to modes $modes[] = array( @@ -662,7 +677,9 @@ function p_render($mode,$instructions,&$info){ // Loop through the instructions foreach ( $instructions as $instruction ) { // Execute the callback against the Renderer - call_user_func_array(array(&$Renderer, $instruction[0]),$instruction[1]); + if(method_exists($Renderer, $instruction[0])){ + call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array()); + } } //set info array @@ -674,7 +691,12 @@ function p_render($mode,$instructions,&$info){ return $Renderer->doc; } +/** + * @param $mode string Mode of the renderer to get + * @return null|Doku_Renderer The renderer + */ function & p_get_renderer($mode) { + /** @var Doku_Plugin_Controller $plugin_controller */ global $conf, $plugin_controller; $rname = !empty($conf['renderer_'.$mode]) ? $conf['renderer_'.$mode] : $mode; @@ -702,7 +724,7 @@ function & p_get_renderer($mode) { $Renderer =& $plugin_controller->load('renderer',$rname); } - if(is_null($Renderer)){ + if(!isset($Renderer) || is_null($Renderer)){ msg("No renderer '$rname' found for mode '$mode'",-1); return null; } @@ -722,6 +744,7 @@ function & p_get_renderer($mode) { * METADATA_RENDER_USING_CACHE, * METADATA_RENDER_UNLIMITED * + * @return string|null The first heading * @author Andreas Gohr <andi@splitbrain.org> * @author Michael Hamann <michael@content-space.de> */ @@ -736,6 +759,7 @@ function p_get_first_heading($id, $render=METADATA_RENDER_USING_SIMPLE_CACHE){ * @param string $language language to provide highlighting * @param string $wrapper html element to wrap the returned highlighted text * + * @return string xhtml code * @author Christopher Smith <chris@jalakai.co.uk> * @author Andreas Gohr <andi@splitbrain.org> */ |