summaryrefslogtreecommitdiff
path: root/inc/parserutils.php
diff options
context:
space:
mode:
authorGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
committerGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
commit0f8ac4e8c5872a6b68b350f96a9ecde0291edefa (patch)
treead7938bb4143d5e5a38fd7a8d131e4171aec657d /inc/parserutils.php
parent58ec8fa9128e4581749955de87530f432e387588 (diff)
parentb31fcef02fd24b3e746c9618e77152c7b84c2f2a (diff)
downloadrpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.gz
rpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.bz2
Merge branch 'master' into stable
Diffstat (limited to 'inc/parserutils.php')
-rw-r--r--inc/parserutils.php59
1 files changed, 42 insertions, 17 deletions
diff --git a/inc/parserutils.php b/inc/parserutils.php
index 9384929bf..3dbfc726f 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,15 +314,18 @@ 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
if ($meta == $old_meta || p_save_metadata($id, $meta)) {
// store a timestamp in order to make sure that the cachefile is touched
+ // this timestamp is also stored when the meta data is still the same
$cachefile->storeCache(time());
- } elseif ($meta != $old_meta) {
+ } else {
msg('Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.',-1);
}
}
@@ -380,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
@@ -390,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;
}
}
@@ -546,7 +561,7 @@ function p_get_parsermodes(){
//reuse old data
static $modes = null;
- if($modes != null){
+ if($modes != null && !defined('DOKU_UNITTEST')){
return $modes;
}
@@ -563,6 +578,7 @@ function p_get_parsermodes(){
global $PARSER_MODES;
$obj = null;
foreach($pluginlist as $p){
+ /** @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
@@ -661,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
@@ -673,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;
@@ -701,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;
}
@@ -721,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>
*/
@@ -735,11 +759,12 @@ 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>
*/
function p_xhtml_cached_geshi($code, $language, $wrapper='pre') {
- global $conf, $config_cascade;
+ global $conf, $config_cascade, $INPUT;
$language = strtolower($language);
// remove any leading or trailing blank lines
@@ -747,7 +772,7 @@ function p_xhtml_cached_geshi($code, $language, $wrapper='pre') {
$cache = getCacheName($language.$code,".code");
$ctime = @filemtime($cache);
- if($ctime && !$_REQUEST['purge'] &&
+ if($ctime && !$INPUT->bool('purge') &&
$ctime > filemtime(DOKU_INC.'inc/geshi.php') && // geshi changed
$ctime > @filemtime(DOKU_INC.'inc/geshi/'.$language.'.php') && // language syntax definition changed
$ctime > filemtime(reset($config_cascade['main']['default']))){ // dokuwiki changed