From e8b5a4f91c8a6e230a6cfe13c43dc9ddce31e253 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 12:02:06 +0200 Subject: fix E_STRICT errors FS#2427 This commit fixes all E_STRICT messages shown when running the test suite. There might be more problems not covered by tests, yet. For compatibility reasons with plugins, E_STRICT errors are still supressed. --- inc/SafeFN.class.php | 12 ++++++------ inc/events.php | 2 +- inc/parser/metadata.php | 41 ----------------------------------------- inc/parser/renderer.php | 2 +- inc/parserutils.php | 2 +- inc/plugin.php | 2 +- 6 files changed, 10 insertions(+), 51 deletions(-) (limited to 'inc') diff --git a/inc/SafeFN.class.php b/inc/SafeFN.class.php index ab05b9eae..b9e4a2b2a 100644 --- a/inc/SafeFN.class.php +++ b/inc/SafeFN.class.php @@ -44,7 +44,7 @@ class SafeFN { * * @author Christopher Smith */ - public function encode($filename) { + public static function encode($filename) { return self::unicode_to_safe(utf8_to_unicode($filename)); } @@ -73,15 +73,15 @@ class SafeFN { * * @author Christopher Smith */ - public function decode($filename) { + public static function decode($filename) { return unicode_to_utf8(self::safe_to_unicode(strtolower($filename))); } - public function validate_printable_utf8($printable_utf8) { + public static function validate_printable_utf8($printable_utf8) { return !preg_match('#[\x01-\x1f]#',$printable_utf8); } - public function validate_safe($safe) { + public static function validate_safe($safe) { return !preg_match('#[^'.self::$plain.self::$post_indicator.self::$pre_indicator.']#',$safe); } @@ -93,7 +93,7 @@ class SafeFN { * * @author Christopher Smith */ - private function unicode_to_safe($unicode) { + private static function unicode_to_safe($unicode) { $safe = ''; $converted = false; @@ -126,7 +126,7 @@ class SafeFN { * * @author Christopher Smith */ - private function safe_to_unicode($safe) { + private static function safe_to_unicode($safe) { $unicode = array(); $split = preg_split('#(?=['.self::$post_indicator.self::$pre_indicator.'])#',$safe,-1,PREG_SPLIT_NO_EMPTY); diff --git a/inc/events.php b/inc/events.php index 4e81f85c8..f7b1a7a16 100644 --- a/inc/events.php +++ b/inc/events.php @@ -132,7 +132,7 @@ class Doku_Event_Handler { $pluginlist = plugin_list('action'); foreach ($pluginlist as $plugin_name) { - $plugin =& plugin_load('action',$plugin_name); + $plugin = plugin_load('action',$plugin_name); if ($plugin !== null) $plugin->register($this); } diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8bfdc3b9c..8638ffa6a 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -133,27 +133,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function strong_open(){} - function strong_close(){} - - function emphasis_open(){} - function emphasis_close(){} - - function underline_open(){} - function underline_close(){} - - function monospace_open(){} - function monospace_close(){} - - function subscript_open(){} - function subscript_close(){} - - function superscript_open(){} - function superscript_close(){} - - function deleted_open(){} - function deleted_close(){} - /** * Callback for footnote start syntax * @@ -218,14 +197,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { if ($this->capture) $this->doc .= $text; } - function php($text){} - - function phpblock($text){} - - function html($text){} - - function htmlblock($text){} - function preformatted($text){ if ($this->capture) $this->doc .= $text; } @@ -393,18 +364,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { $params['refresh']; } - function table_open($maxcols = NULL, $numrows = NULL){} - function table_close(){} - - function tablerow_open(){} - function tablerow_close(){} - - function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} - function tableheader_close(){} - - function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} - function tablecell_close(){} - //---------------------------------------------------------- // Utils diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 0923e6896..2c78f220a 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -62,7 +62,7 @@ class Doku_Renderer extends DokuWiki_Plugin { //handle plugin rendering function plugin($name,$data){ - $plugin =& plugin_load('syntax',$name); + $plugin = plugin_load('syntax',$name); if($plugin != null){ $plugin->render($this->getFormat(),$this,$data); } diff --git a/inc/parserutils.php b/inc/parserutils.php index 20f992ba2..58920cbea 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -570,7 +570,7 @@ function p_get_parsermodes(){ $obj = null; foreach($pluginlist as $p){ /** @var DokuWiki_Syntax_Plugin $obj */ - if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $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( diff --git a/inc/plugin.php b/inc/plugin.php index d2fe3818d..b0518346d 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -191,7 +191,7 @@ class DokuWiki_Plugin { */ function loadHelper($name, $msg){ if (!plugin_isdisabled($name)){ - $obj =& plugin_load('helper',$name); + $obj = plugin_load('helper',$name); }else{ $obj = null; } -- cgit v1.2.3 From 31b10b49cde775ab7d0196b7824403dc45fcf370 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 28 Jul 2012 13:58:00 +0200 Subject: Be more careful when setting metadata values FS#2514 This fixes a warning when setting $meta['relation']['firstimage'] using p_set_metadata. --- inc/parserutils.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/parserutils.php b/inc/parserutils.php index 20f992ba2..54ccb05f3 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -386,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 @@ -396,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; } } -- cgit v1.2.3 From 09f791c4e279f87c9445eb80a194c43208037f52 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 28 Jul 2012 14:00:46 +0200 Subject: fixed script blocks CDATA for ie on TPL_METAHEADER_OUTPUT --- inc/template.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/template.php b/inc/template.php index 5b6260155..78d9dd748 100644 --- a/inc/template.php +++ b/inc/template.php @@ -393,9 +393,9 @@ function _tpl_metaheaders_action($data){ echo '<',$tag,' ',buildAttributes($attr); if(isset($attr['_data']) || $tag == 'script'){ if($tag == 'script' && $attr['_data']) - $attr['_data'] = ""; + "\n/*!]]>*/"; echo '>',$attr['_data'],''; }else{ -- cgit v1.2.3 From 677d27850f5ab9d4f761a87f37314d54e923f24f Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 28 Jul 2012 14:03:49 +0200 Subject: fixed script blocks CDATA for ie on TPL_METAHEADER_OUTPUT FS#2563 --- inc/html.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 410b59e49..708461c6a 100644 --- a/inc/html.php +++ b/inc/html.php @@ -328,9 +328,9 @@ function html_search(){ //show progressbar print '
'.NL; - print ''.NL; + print '/*!]]>*/'.NL; print '
'.NL; flush(); @@ -390,9 +390,9 @@ function html_search(){ } //hide progressbar - print ''.NL; + print '/*!]]>*/'.NL; flush(); } @@ -1424,9 +1424,9 @@ function html_edit(){ if ($wr) { // sets changed to true when previewed - echo '' . NL; + echo '/*!]]>*/' . NL; } ?>
-- cgit v1.2.3 From 90658f383dc174c5e6c715c3bf676dda5ee70ce7 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 28 Jul 2012 14:21:45 +0200 Subject: Respect useheading setting on revisions page FS#2139 --- inc/html.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 708461c6a..af047a107 100644 --- a/inc/html.php +++ b/inc/html.php @@ -466,6 +466,8 @@ function html_revisions($first=0, $media_id = false){ if (!$media_id) $exists = $INFO['exists']; else $exists = @file_exists(mediaFN($id)); + $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id; + if($exists && $first==0){ if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); @@ -488,7 +490,7 @@ function html_revisions($first=0, $media_id = false){ $form->addElement(form_makeOpenTag('a', array( 'class' => 'wikilink1', 'href' => $href))); - $form->addElement($id); + $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); if ($media_id) $form->addElement(form_makeOpenTag('div')); @@ -563,11 +565,11 @@ function html_revisions($first=0, $media_id = false){ if (!$media_id) $href = wl($id,"rev=$rev",false,'&'); else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); - $form->addElement($id); + $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); }else{ $form->addElement(''); - $form->addElement($id); + $form->addElement($display_name); } if ($media_id) $form->addElement(form_makeOpenTag('div')); -- cgit v1.2.3 From 84e581a6fc319435b4b46835b63cb4dccf05195b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 16:57:15 +0200 Subject: fix word boundary matching on broken platforms FS#2440 Seems like matching \b on unicode strings is unreliable across different platforms (Debian). Using Unicode class lookahed/behinds seems to work though. --- inc/fulltext.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/fulltext.php b/inc/fulltext.php index 8f4db111d..eab8850dc 100644 --- a/inc/fulltext.php +++ b/inc/fulltext.php @@ -394,19 +394,24 @@ function ft_snippet_re_preprocess($term) { return $term; } + // unicode word boundaries + // see http://stackoverflow.com/a/2449017/172068 + $BL = '(? Date: Sat, 28 Jul 2012 17:15:20 +0200 Subject: highlight queries from popular serch engines only FS#2448 --- inc/common.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 33da2523a..ac7e744d8 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1197,8 +1197,10 @@ function getGoogleQuery() { } $url = parse_url($_SERVER['HTTP_REFERER']); - $query = array(); + // only handle common SEs + if(!preg_match('/(google|bing|yahoo|ask|duckduckgo|babylon|aol|yandex)/',$url['host'])) return ''; + $query = array(); // temporary workaround against PHP bug #49733 // see http://bugs.php.net/bug.php?id=49733 if(UTF8_MBSTRING) $enc = mb_internal_encoding(); @@ -1206,16 +1208,16 @@ function getGoogleQuery() { if(UTF8_MBSTRING) mb_internal_encoding($enc); $q = ''; - if(isset($query['q'])) - $q = $query['q']; // google, live/msn, aol, ask, altavista, alltheweb, gigablast - elseif(isset($query['p'])) - $q = $query['p']; // yahoo - elseif(isset($query['query'])) - $q = $query['query']; // lycos, netscape, clusty, hotbot - elseif(preg_match("#a9\.com#i", $url['host'])) // a9 - $q = urldecode(ltrim($url['path'], '/')); - - if($q === '') return ''; + if(isset($query['q'])){ + $q = $query['q']; + }elseif(isset($query['p'])){ + $q = $query['p']; + }elseif(isset($query['query'])){ + $q = $query['query']; + } + $q = trim($q); + + if(!$q) return ''; $q = preg_split('/[\s\'"\\\\`()\]\[?:!\.{};,#+*<>\\/]+/', $q, -1, PREG_SPLIT_NO_EMPTY); return $q; } -- cgit v1.2.3 From 17dcc4abef4e2415a31bf7072744bdec1f862cd7 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 17:49:47 +0200 Subject: decode utf8 filenames in JpegMeta FS#2553 --- inc/JpegMeta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/JpegMeta.php b/inc/JpegMeta.php index ce643a7e6..ba6a2b5bb 100644 --- a/inc/JpegMeta.php +++ b/inc/JpegMeta.php @@ -1209,7 +1209,7 @@ class JpegMeta { function _parseFileInfo() { if (file_exists($this->_fileName) && is_file($this->_fileName)) { $this->_info['file'] = array(); - $this->_info['file']['Name'] = utf8_basename($this->_fileName); + $this->_info['file']['Name'] = utf8_decodeFN(utf8_basename($this->_fileName)); $this->_info['file']['Path'] = fullpath($this->_fileName); $this->_info['file']['Size'] = filesize($this->_fileName); if ($this->_info['file']['Size'] < 1024) { -- cgit v1.2.3 From 7c62086b7b95a10cc08ceb137ea5861d7cd78437 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 18:37:24 +0200 Subject: only execute valid instructions FS#2432 --- inc/parserutils.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/parserutils.php b/inc/parserutils.php index 54ccb05f3..3dbfc726f 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -677,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] ? $instruction[1] : array()); + if(method_exists($Renderer, $instruction[0])){ + call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array()); + } } //set info array -- cgit v1.2.3 From b7e5821df12f9556ef3e9d19e7a2a63a21718468 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 20:11:28 +0200 Subject: added missing include --- inc/media.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/media.php b/inc/media.php index 35112f274..794aab8aa 100644 --- a/inc/media.php +++ b/inc/media.php @@ -646,6 +646,7 @@ function media_tab_files_options(){ global $lang; global $NS; global $INPUT; + global $ID; $form = new Doku_Form(array('class' => 'options', 'method' => 'get', 'action' => wl($ID))); $media_manager_params = media_managerURL(array(), '', false, true); -- cgit v1.2.3 From 00c2d4a9d8fcb38b6a2294749b395d528952fde5 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 28 Jul 2012 20:51:59 +0100 Subject: fixed some RTL+IE7 bugs, mainly background icons and search form (FS#2569) --- inc/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/template.php b/inc/template.php index 78d9dd748..7d09f7dd4 100644 --- a/inc/template.php +++ b/inc/template.php @@ -1226,7 +1226,7 @@ function tpl_mediaFileDetails($image, $rev){ list($ext,$mime,$dl) = mimetype($image,false); $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); $class = 'select mediafile mf_'.$class; - $tabTitle = ''.$image.''.''; + $tabTitle = ''.$image.''.''; if ($opened_tab === 'view' && $rev) { printf($lang['media_viewold'], $tabTitle, dformat($rev)); } else { -- cgit v1.2.3 From 420addb2e4aefb77d089e776672d40c18f86b2ac Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 29 Jul 2012 10:45:53 +0200 Subject: fix utf8_basename for file names without any directory --- inc/utf8.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc') diff --git a/inc/utf8.php b/inc/utf8.php index 227fa830a..273c344c6 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -92,14 +92,14 @@ if(!function_exists('utf8_basename')){ */ function utf8_basename($path, $suffix=''){ $rpos = max(strrpos($path, '/'), strrpos($path, '\\')); - $file = substr($path, $rpos+1); + if($rpos) $path = substr($path, $rpos+1); $suflen = strlen($suffix); - if($suflen && (substr($file, -$suflen) == $suffix)){ - $file = substr($file, 0, -$suflen); + if($suflen && (substr($path, -$suflen) == $suffix)){ + $path = substr($path, 0, -$suflen); } - return $file; + return $path; } } -- cgit v1.2.3 From a8c343f2838765f8034ee6b91263b1b417f3a7ec Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 29 Jul 2012 12:09:31 +0200 Subject: Fix utf8_basename for files in the root directory --- inc/utf8.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/utf8.php b/inc/utf8.php index 273c344c6..e3e7e8c1a 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -91,8 +91,10 @@ if(!function_exists('utf8_basename')){ * @return string */ function utf8_basename($path, $suffix=''){ - $rpos = max(strrpos($path, '/'), strrpos($path, '\\')); - if($rpos) $path = substr($path, $rpos+1); + $slashrpos = strrpos($path, '/'); + $bslashrpos = strrpos($path, '\\'); + $rpos = max($slashrpos === false ? -1 : $slashrpos, $bslashrpos === false ? -1 : $bslashrpos); + $path = substr($path, $rpos+1); $suflen = strlen($suffix); if($suflen && (substr($path, -$suflen) == $suffix)){ -- cgit v1.2.3 From fa446926c63aef4f4f394967b84d20e2da0dad6d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 29 Jul 2012 12:09:42 +0200 Subject: more utf8_basename fixes --- inc/utf8.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'inc') diff --git a/inc/utf8.php b/inc/utf8.php index e3e7e8c1a..6fab8502c 100644 --- a/inc/utf8.php +++ b/inc/utf8.php @@ -91,10 +91,9 @@ if(!function_exists('utf8_basename')){ * @return string */ function utf8_basename($path, $suffix=''){ - $slashrpos = strrpos($path, '/'); - $bslashrpos = strrpos($path, '\\'); - $rpos = max($slashrpos === false ? -1 : $slashrpos, $bslashrpos === false ? -1 : $bslashrpos); - $path = substr($path, $rpos+1); + $path = trim($path,'\\/'); + $rpos = max(strrpos($path, '/'), strrpos($path, '\\')); + if($rpos) $path = substr($path, $rpos+1); $suflen = strlen($suffix); if($suflen && (substr($path, -$suflen) == $suffix)){ -- cgit v1.2.3 From 71f17ac4602c2b6b1e3b46130c4c6cb7c3f8702e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 29 Jul 2012 12:25:32 +0200 Subject: copy not move uploaded files FS#2465 This fixes problems with setgid bits on the media directory --- inc/media.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/media.php b/inc/media.php index 794aab8aa..6941aa61a 100644 --- a/inc/media.php +++ b/inc/media.php @@ -296,7 +296,7 @@ function media_upload($ns,$auth,$file=false){ $res = media_save(array('name' => $file['tmp_name'], 'mime' => $imime, 'ext' => $iext), $ns.':'.$id, - $INPUT->post->bool('ow'), $auth, 'move_uploaded_file'); + $INPUT->post->bool('ow'), $auth, 'copy_uploaded_file'); if (is_array($res)) { msg($res[0], $res[1]); return false; @@ -304,6 +304,23 @@ function media_upload($ns,$auth,$file=false){ return $res; } +/** + * An alternative to move_uploaded_file that copies + * + * Using copy, makes sure any setgid bits on the media directory are honored + * + * @see move_uploaded_file() + * @param string $from + * @param string $to + * @return bool + */ +function copy_uploaded_file($from, $to){ + if(!is_uploaded_file($from)) return false; + $ok = copy($from, $to); + @unlink($from); + return $ok; +} + /** * This generates an action event and delegates to _media_upload_action(). * Action plugins are allowed to pre/postprocess the uploaded file. -- cgit v1.2.3 From 63e967bdfd6d3bd52960647f8490dfd9678353f9 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 5 Aug 2012 13:04:35 +0100 Subject: html validity fixes (removed name and align in some plugins) --- inc/media.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/media.php b/inc/media.php index 6941aa61a..6335bf210 100644 --- a/inc/media.php +++ b/inc/media.php @@ -1383,9 +1383,9 @@ function media_printfile($item,$auth,$jump,$display_namespace=false){ // output echo '
'.NL; if (!$display_namespace) { - echo ''.hsc($file).' '; + echo ''.hsc($file).' '; } else { - echo ''.hsc($item['id']).'
'; + echo ''.hsc($item['id']).'
'; } echo '('.$info.')'.NL; @@ -1449,7 +1449,7 @@ function media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false media_printimgdetail($item, true); } else { - echo ''; echo media_printicon($item['id']); @@ -1462,7 +1462,7 @@ function media_printfile_thumbs($item,$auth,$jump=false,$display_namespace=false $name = hsc($item['id']); } echo '
'.$name.'
'.NL; + 'tab_details' => 'view')).'" id="h_:'.$item['id'].'">'.$name.''.NL; if($item['isimg']){ $size = ''; @@ -1510,7 +1510,7 @@ function media_printimgdetail($item, $fullscreen=false){ // output if ($fullscreen) { - echo ''; echo ''; echo ''; @@ -1520,7 +1520,7 @@ function media_printimgdetail($item, $fullscreen=false){ echo '
'; echo '
'; - echo ''; + echo ''; echo ''; echo ''; echo '
'; -- cgit v1.2.3 From f7cefc02a20fa93edb9fdf171c47c6abbcb20552 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 5 Aug 2012 20:48:55 +0200 Subject: added mailfromnone internal option FS#2170 --- inc/mail.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'inc') diff --git a/inc/mail.php b/inc/mail.php index bec0c5b10..fd040a8ce 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -32,20 +32,25 @@ if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '[' /** * Prepare mailfrom replacement patterns * + * Also prepares a mailfromnone config that contains an autoconstructed address + * if the mailfrom one is userdependent and this might not be wanted (subscriptions) + * * @author Andreas Gohr */ function mail_setup(){ global $conf; global $USERINFO; - $replace = array(); + // auto constructed address + $host = @parse_url(DOKU_URL,PHP_URL_HOST); + if(!$host) $host = 'example.com'; + $noreply = 'noreply@'.$host; + $replace = array(); if(!empty($USERINFO['mail'])){ $replace['@MAIL@'] = $USERINFO['mail']; }else{ - $host = @parse_url(DOKU_URL,PHP_URL_HOST); - if(!$host) $host = 'example.com'; - $replace['@MAIL@'] = 'noreply@'.$host; + $replace['@MAIL@'] = $noreply; } if(!empty($_SERVER['REMOTE_USER'])){ @@ -60,9 +65,18 @@ function mail_setup(){ $replace['@NAME@'] = ''; } - $conf['mailfrom'] = str_replace(array_keys($replace), - array_values($replace), - $conf['mailfrom']); + // apply replacements + $from = str_replace(array_keys($replace), + array_values($replace), + $conf['mailfrom']); + + // any replacements done? set different mailfromnone + if($from != $conf['mailfrom']){ + $conf['mailfromnone'] = $noreply; + }else{ + $conf['mailfromnone'] = $from; + } + $conf['mailfrom'] = $from; } /** -- cgit v1.2.3 From 465e809be9a7b9bbf06feb7f47814582eadb0cf4 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 5 Aug 2012 20:59:58 +0200 Subject: renamed mailfromnon to mailfromnobody, use in subscriptions --- inc/mail.php | 6 +++--- inc/subscription.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/mail.php b/inc/mail.php index fd040a8ce..d0ea651bf 100644 --- a/inc/mail.php +++ b/inc/mail.php @@ -32,7 +32,7 @@ if (!defined('PREG_PATTERN_VALID_EMAIL')) define('PREG_PATTERN_VALID_EMAIL', '[' /** * Prepare mailfrom replacement patterns * - * Also prepares a mailfromnone config that contains an autoconstructed address + * Also prepares a mailfromnobody config that contains an autoconstructed address * if the mailfrom one is userdependent and this might not be wanted (subscriptions) * * @author Andreas Gohr @@ -72,9 +72,9 @@ function mail_setup(){ // any replacements done? set different mailfromnone if($from != $conf['mailfrom']){ - $conf['mailfromnone'] = $noreply; + $conf['mailfromnobody'] = $noreply; }else{ - $conf['mailfromnone'] = $from; + $conf['mailfromnobody'] = $from; } $conf['mailfrom'] = $from; } diff --git a/inc/subscription.php b/inc/subscription.php index d1ee0397a..b4e5d2edd 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -373,6 +373,7 @@ function subscription_send_list($subscriber_mail, $ids, $ns_id) { * @param string $id The page or namespace id * @param string $template The name of the mail template * + * @return bool * @author Adrian Lang */ function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { @@ -387,6 +388,7 @@ function subscription_send($subscriber_mail, $replaces, $subject, $id, $template $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text,$trep); + $mail->from($conf['mailfromnobody']); $mail->setHeader( 'List-Unsubscribe', '<'.wl($id,array('do'=>'subscribe'),true,'&').'>', -- cgit v1.2.3 From d9e9c1bb60342ce88be150cc05de21dabfe130b2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 9 Aug 2012 23:28:11 +0200 Subject: extract method for Input class makes it easier to access our do parameters --- inc/Input.class.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'inc') diff --git a/inc/Input.class.php b/inc/Input.class.php index f4174404a..35aecdb45 100644 --- a/inc/Input.class.php +++ b/inc/Input.class.php @@ -175,6 +175,40 @@ class Input { return (array) $this->access[$name]; } + /** + * Create a simple key from an array key + * + * This is useful to access keys where the information is given as an array key or as a single array value. + * For example when the information was submitted as the name of a submit button. + * + * This function directly changes the access array. + * + * Eg. $_REQUEST['do']['save']='Speichern' becomes $_REQUEST['do'] = 'save' + * + * This function returns the $INPUT object itself for easy chaining + * + * @param $name + * @return Input + */ + public function extract($name){ + if(!isset($this->access[$name])) return $this; + if(!is_array($this->access[$name])) return $this; + $keys = array_keys($this->access[$name]); + if(!$keys){ + // this was an empty array + $this->remove($name); + return $this; + } + // get the first key + $value = array_shift($keys); + if($value === 0){ + // we had a numeric array, assume the value is not in the key + $value = array_shift($this->access[$name]); + } + + $this->set($name, $value); + return $this; + } } /** -- cgit v1.2.3 From ac7a515f564d088e043bf190c9a4ced1d5c309db Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 9 Aug 2012 23:32:58 +0200 Subject: code cleanup in template.php * make use of $INPUT * clean up coding style * add phpdoc comments --- inc/template.php | 925 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 511 insertions(+), 414 deletions(-) (limited to 'inc') diff --git a/inc/template.php b/inc/template.php index 7d09f7dd4..2dc58b36d 100644 --- a/inc/template.php +++ b/inc/template.php @@ -9,29 +9,33 @@ if(!defined('DOKU_INC')) die('meh.'); /** - * Returns the path to the given template, uses - * default one if the custom version doesn't exist. + * Access a template file + * + * Returns the path to the given file inside the current template, uses + * default template if the custom version doesn't exist. * * @author Andreas Gohr + * @param string $file + * @return string */ -function template($tpl){ +function template($file) { global $conf; - if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) - return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl; + if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file)) + return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file; - return DOKU_INC.'lib/tpl/default/'.$tpl; + return DOKU_INC.'lib/tpl/dokuwiki/'.$file; } - /** * Convenience function to access template dir from local FS * * This replaces the deprecated DOKU_TPLINC constant * * @author Andreas Gohr + * @return string */ -function tpl_incdir(){ +function tpl_incdir() { global $conf; return DOKU_INC.'lib/tpl/'.$conf['template'].'/'; } @@ -42,8 +46,9 @@ function tpl_incdir(){ * This replaces the deprecated DOKU_TPL constant * * @author Andreas Gohr + * @return string */ -function tpl_basedir(){ +function tpl_basedir() { global $conf; return DOKU_BASE.'lib/tpl/'.$conf['template'].'/'; } @@ -59,32 +64,43 @@ function tpl_basedir(){ * handled by this function. ACL stuff is not done here either. * * @author Andreas Gohr + * @triggers TPL_ACT_RENDER + * @triggers TPL_CONTENT_DISPLAY + * @param bool $prependTOC should the TOC be displayed here? + * @return bool true if any output */ -function tpl_content($prependTOC=true) { +function tpl_content($prependTOC = true) { global $ACT; global $INFO; $INFO['prependTOC'] = $prependTOC; ob_start(); - trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core'); + trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); $html_output = ob_get_clean(); - trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln'); + trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); return !empty($html_output); } -function tpl_content_core(){ +/** + * Default Action of TPL_ACT_RENDER + * + * @return bool + */ +function tpl_content_core() { global $ACT; global $TEXT; global $PRE; global $SUF; global $SUM; global $IDX; + global $INPUT; - switch($ACT){ + switch($ACT) { case 'show': html_show(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'locked': html_locked(); case 'edit': @@ -102,20 +118,13 @@ function tpl_content_core(){ html_search(); break; case 'revisions': - $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - html_revisions($first); + html_revisions($INPUT->int('first')); break; case 'diff': html_diff(); break; case 'recent': - if (is_array($_REQUEST['first'])) { - $_REQUEST['first'] = array_keys($_REQUEST['first']); - $_REQUEST['first'] = $_REQUEST['first'][0]; - } - $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0; - $show_changes = $_REQUEST['show_changes']; - html_recent($first, $show_changes); + html_recent($INPUT->extract('first')->int('first'), $INPUT->str('show_changes')); break; case 'index': html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly? @@ -124,8 +133,8 @@ function tpl_content_core(){ html_backlinks(); break; case 'conflict': - html_conflict(con($PRE,$TEXT,$SUF),$SUM); - html_diff(con($PRE,$TEXT,$SUF),false); + html_conflict(con($PRE, $TEXT, $SUF), $SUM); + html_diff(con($PRE, $TEXT, $SUF), false); break; case 'login': html_login(); @@ -152,9 +161,9 @@ function tpl_content_core(){ tpl_media(); break; default: - $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT); - if ($evt->advise_before()) - msg("Failed to handle command: ".hsc($ACT),-1); + $evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT); + if($evt->advise_before()) + msg("Failed to handle command: ".hsc($ACT), -1); $evt->advise_after(); unset($evt); return false; @@ -169,43 +178,47 @@ function tpl_content_core(){ * a false argument * * @author Andreas Gohr + * @param bool $return Should the TOC be returned instead to be printed? + * @return string */ -function tpl_toc($return=false){ +function tpl_toc($return = false) { global $TOC; global $ACT; global $ID; global $REV; global $INFO; global $conf; + global $INPUT; $toc = array(); - if(is_array($TOC)){ + if(is_array($TOC)) { // if a TOC was prepared in global scope, always use it $toc = $TOC; - }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){ + } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) { // get TOC from metadata, render if neccessary $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE); - if(isset($meta['internal']['toc'])){ + if(isset($meta['internal']['toc'])) { $tocok = $meta['internal']['toc']; - }else{ + } else { $tocok = true; } - $toc = $meta['description']['tableofcontents']; - if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){ + $toc = $meta['description']['tableofcontents']; + if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) { $toc = array(); } - }elseif($ACT == 'admin'){ + } elseif($ACT == 'admin') { // try to load admin plugin TOC FIXME: duplicates code from tpl_admin $plugin = null; - if (!empty($_REQUEST['page'])) { + $class = $INPUT->str('page'); + if(!empty($class)) { $pluginlist = plugin_list('admin'); - if (in_array($_REQUEST['page'], $pluginlist)) { + if(in_array($class, $pluginlist)) { // attempt to load the plugin - $plugin =& plugin_load('admin',$_REQUEST['page']); + /** @var $plugin DokuWiki_Admin_Plugin */ + $plugin =& plugin_load('admin', $class); } } - if ( ($plugin !== null) && - (!$plugin->forAdminOnly() || $INFO['isadmin']) ){ + if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) { $toc = $plugin->getTOC(); $TOC = $toc; // avoid later rebuild } @@ -215,6 +228,7 @@ function tpl_toc($return=false){ $html = html_TOC($toc); if($return) return $html; echo $html; + return ''; } /** @@ -222,26 +236,28 @@ function tpl_toc($return=false){ * * @author Andreas Gohr */ -function tpl_admin(){ +function tpl_admin() { global $INFO; global $TOC; + global $INPUT; $plugin = null; - if (!empty($_REQUEST['page'])) { + $class = $INPUT->str('page'); + if(!empty($class)) { $pluginlist = plugin_list('admin'); - if (in_array($_REQUEST['page'], $pluginlist)) { - + if(in_array($class, $pluginlist)) { // attempt to load the plugin - $plugin =& plugin_load('admin',$_REQUEST['page']); + /** @var $plugin DokuWiki_Admin_Plugin */ + $plugin =& plugin_load('admin', $class); } } - if ($plugin !== null){ + if($plugin !== null) { if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet if($INFO['prependTOC']) tpl_toc(); $plugin->html(); - }else{ + } else { html_admin(); } return true; @@ -252,11 +268,12 @@ function tpl_admin(){ * * This has to go into the head section of your template. * - * @triggers TPL_METAHEADER_OUTPUT - * @param boolean $alt Should feeds and alternative format links be added? * @author Andreas Gohr + * @triggers TPL_METAHEADER_OUTPUT + * @param bool $alt Should feeds and alternative format links be added? + * @return bool */ -function tpl_metaheaders($alt=true){ +function tpl_metaheaders($alt = true) { global $ID; global $REV; global $INFO; @@ -265,13 +282,12 @@ function tpl_metaheaders($alt=true){ global $QUERY; global $lang; global $conf; - $it=2; // prepare the head array $head = array(); // prepare seed for js and css - $tseed = 0; + $tseed = 0; $depends = getConfigFiles('main'); foreach($depends as $f) { $time = @filemtime($f); @@ -279,99 +295,119 @@ function tpl_metaheaders($alt=true){ } // the usual stuff - $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki'); - $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml', - 'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] ); - $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE ); - if(actionOK('index')){ - $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'), - 'title'=>$lang['btn_index'] ); + $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki'); + $head['link'][] = array( + 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml', + 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title'] + ); + $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE); + if(actionOK('index')) { + $head['link'][] = array( + 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'), + 'title'=> $lang['btn_index'] + ); } - if($alt){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php'); - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Current Namespace', - 'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']); - if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){ - $head['link'][] = array( 'rel'=>'edit', - 'title'=>$lang['btn_edit'], - 'href'=> wl($ID,'do=edit',false,'&')); + if($alt) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Recent Changes', 'href'=> DOKU_BASE.'feed.php' + ); + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Current Namespace', + 'href' => DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace'] + ); + if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) { + $head['link'][] = array( + 'rel' => 'edit', + 'title'=> $lang['btn_edit'], + 'href' => wl($ID, 'do=edit', false, '&') + ); } - if($ACT == 'search'){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml', - 'title'=>'Search Result', - 'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY); + if($ACT == 'search') { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'application/rss+xml', + 'title'=> 'Search Result', + 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY + ); } - if(actionOK('export_xhtml')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML', - 'href'=>exportlink($ID, 'xhtml', '', false, '&')); + if(actionOK('export_xhtml')) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> 'Plain HTML', + 'href'=> exportlink($ID, 'xhtml', '', false, '&') + ); } - if(actionOK('export_raw')){ - $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup', - 'href'=>exportlink($ID, 'raw', '', false, '&')); + if(actionOK('export_raw')) { + $head['link'][] = array( + 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> 'Wiki Markup', + 'href'=> exportlink($ID, 'raw', '', false, '&') + ); } } // setup robot tags apropriate for different modes - if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){ - if($INFO['exists']){ + if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) { + if($INFO['exists']) { //delay indexing: - if((time() - $INFO['lastmod']) >= $conf['indexdelay']){ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); + if((time() - $INFO['lastmod']) >= $conf['indexdelay']) { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); } - $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') ); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow'); + $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&')); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow'); } - }elseif(defined('DOKU_MEDIADETAIL')){ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow'); - }else{ - $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow'); + } elseif(defined('DOKU_MEDIADETAIL')) { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow'); + } else { + $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow'); } // set metadata - if($ACT == 'show' || $ACT=='export_xhtml'){ + if($ACT == 'show' || $ACT == 'export_xhtml') { // date of modification - if($REV){ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV)); - }else{ - $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod'])); + if($REV) { + $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV)); + } else { + $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod'])); } // keywords (explicit or implicit) - if(!empty($INFO['meta']['subject'])){ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject'])); - }else{ - $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID)); + if(!empty($INFO['meta']['subject'])) { + $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject'])); + } else { + $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID)); } } // load stylesheets - $head['link'][] = array('rel'=>'stylesheet', 'type'=>'text/css', - 'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed); + $head['link'][] = array( + 'rel' => 'stylesheet', 'type'=> 'text/css', + 'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed + ); // make $INFO and other vars available to JavaScripts - $json = new JSON(); + $json = new JSON(); $script = "var NS='".$INFO['namespace']."';"; - if($conf['useacl'] && $_SERVER['REMOTE_USER']){ + if($conf['useacl'] && $_SERVER['REMOTE_USER']) { $script .= "var SIG='".toolbar_signature()."';"; } $script .= 'var JSINFO = '.$json->encode($JSINFO).';'; - $head['script'][] = array( 'type'=>'text/javascript', '_data'=> $script); + $head['script'][] = array('type'=> 'text/javascript', '_data'=> $script); // load external javascript - $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'', - 'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed); + $head['script'][] = array( + 'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '', + 'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed + ); // trigger event here - trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true); + trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); return true; } @@ -387,18 +423,18 @@ function tpl_metaheaders($alt=true){ * * @author Andreas Gohr */ -function _tpl_metaheaders_action($data){ - foreach($data as $tag => $inst){ - foreach($inst as $attr){ - echo '<',$tag,' ',buildAttributes($attr); - if(isset($attr['_data']) || $tag == 'script'){ +function _tpl_metaheaders_action($data) { + foreach($data as $tag => $inst) { + foreach($inst as $attr) { + echo '<', $tag, ' ', buildAttributes($attr); + if(isset($attr['_data']) || $tag == 'script') { if($tag == 'script' && $attr['_data']) $attr['_data'] = "/**/"; - echo '>',$attr['_data'],''; - }else{ + echo '>', $attr['_data'], ''; + } else { echo '/>'; } echo "\n"; @@ -413,11 +449,11 @@ function _tpl_metaheaders_action($data){ * * @author Andreas Gohr */ -function tpl_link($url,$name,$more='',$return=false){ +function tpl_link($url, $name, $more = '', $return = false) { $out = ' */ -function tpl_pagelink($id,$name=null){ - print html_wikilink($id,$name); +function tpl_pagelink($id, $name = null) { + print html_wikilink($id, $name); return true; } @@ -442,14 +478,13 @@ function tpl_pagelink($id,$name=null){ * * @author Andreas Gohr */ -function tpl_getparent($id){ - global $conf; +function tpl_getparent($id) { $parent = getNS($id).':'; - resolve_pageid('',$parent,$exists); + resolve_pageid('', $parent, $exists); if($parent == $id) { - $pos = strrpos (getNS($id),':'); - $parent = substr($parent,0,$pos).':'; - resolve_pageid('',$parent,$exists); + $pos = strrpos(getNS($id), ':'); + $parent = substr($parent, 0, $pos).':'; + resolve_pageid('', $parent, $exists); if($parent == $id) return false; } return $parent; @@ -461,21 +496,27 @@ function tpl_getparent($id){ * @author Adrian Lang * @see tpl_get_action */ -function tpl_button($type,$return=false){ +function tpl_button($type, $return = false) { $data = tpl_get_action($type); - if ($data === false) { + if($data === false) { return false; - } elseif (!is_array($data)) { + } elseif(!is_array($data)) { $out = sprintf($data, 'button'); } else { + /** + * @var string $accesskey + * @var string $id + * @var string $method + * @var array $params + */ extract($data); - if ($id === '#dokuwiki__top') { + if($id === '#dokuwiki__top') { $out = html_topbtn(); } else { $out = html_btn($type, $id, $accesskey, $params, $method); } } - if ($return) return $out; + if($return) return $out; echo $out; return true; } @@ -486,32 +527,40 @@ function tpl_button($type,$return=false){ * @author Adrian Lang * @see tpl_get_action */ -function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ +function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) { global $lang; $data = tpl_get_action($type); - if ($data === false) { + if($data === false) { return false; - } elseif (!is_array($data)) { + } elseif(!is_array($data)) { $out = sprintf($data, 'link'); } else { + /** + * @var string $accesskey + * @var string $id + * @var string $method + * @var array $params + */ extract($data); - if (strpos($id, '#') === 0) { + if(strpos($id, '#') === 0) { $linktarget = $id; } else { $linktarget = wl($id, $params); } - $caption = $lang['btn_' . $type]; - $akey = $addTitle = ''; - if($accesskey){ - $akey = 'accesskey="'.$accesskey.'" '; + $caption = $lang['btn_'.$type]; + $akey = $addTitle = ''; + if($accesskey) { + $akey = 'accesskey="'.$accesskey.'" '; $addTitle = ' ['.strtoupper($accesskey).']'; } - $out = tpl_link($linktarget, $pre.(($inner)?$inner:$caption).$suf, - 'class="action ' . $type . '" ' . - $akey . 'rel="nofollow" ' . - 'title="' . hsc($caption).$addTitle . '"', 1); + $out = tpl_link( + $linktarget, $pre.(($inner) ? $inner : $caption).$suf, + 'class="action '.$type.'" '. + $akey.'rel="nofollow" '. + 'title="'.hsc($caption).$addTitle.'"', 1 + ); } - if ($return) return $out; + if($return) return $out; echo $out; return true; } @@ -536,53 +585,53 @@ function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){ * @author Andreas Gohr * @author Matthias Grimm * @author Adrian Lang + * @param string $type + * @return array|bool|string */ function tpl_get_action($type) { global $ID; global $INFO; global $REV; global $ACT; - global $conf; - global $auth; // check disabled actions and fix the badly named ones - if($type == 'history') $type='revisions'; + if($type == 'history') $type = 'revisions'; if(!actionOK($type)) return false; $accesskey = null; $id = $ID; $method = 'get'; $params = array('do' => $type); - switch($type){ + switch($type) { case 'edit': // most complicated type - we need to decide on current action - if($ACT == 'show' || $ACT == 'search'){ + if($ACT == 'show' || $ACT == 'search') { $method = 'post'; - if($INFO['writable']){ + if($INFO['writable']) { $accesskey = 'e'; if(!empty($INFO['draft'])) { - $type = 'draft'; + $type = 'draft'; $params['do'] = 'draft'; } else { $params['rev'] = $REV; - if(!$INFO['exists']){ - $type = 'create'; + if(!$INFO['exists']) { + $type = 'create'; } } - }else{ + } else { if(!actionOK('source')) return false; //pseudo action $params['rev'] = $REV; - $type = 'source'; - $accesskey = 'v'; + $type = 'source'; + $accesskey = 'v'; } - }else{ - $params = array(); - $type = 'show'; + } else { + $params = array(); + $type = 'show'; $accesskey = 'v'; } break; case 'revisions': - $type = 'revs'; + $type = 'revs'; $accesskey = 'o'; break; case 'recent': @@ -593,40 +642,40 @@ function tpl_get_action($type) { break; case 'top': $accesskey = 't'; - $params = array(); - $id = '#dokuwiki__top'; + $params = array(); + $id = '#dokuwiki__top'; break; case 'back': $parent = tpl_getparent($ID); - if (!$parent) { + if(!$parent) { return false; } - $id = $parent; - $params = array(); + $id = $parent; + $params = array(); $accesskey = 'b'; break; case 'login': $params['sectok'] = getSecurityToken(); - if(isset($_SERVER['REMOTE_USER'])){ - if (!actionOK('logout')) { + if(isset($_SERVER['REMOTE_USER'])) { + if(!actionOK('logout')) { return false; } $params['do'] = 'logout'; - $type = 'logout'; + $type = 'logout'; } break; case 'register': - if($_SERVER['REMOTE_USER']){ + if($_SERVER['REMOTE_USER']) { return false; } break; case 'resendpwd': - if($_SERVER['REMOTE_USER']){ + if($_SERVER['REMOTE_USER']) { return false; } break; case 'admin': - if(!$INFO['ismanager']){ + if(!$INFO['ismanager']) { return false; } break; @@ -634,21 +683,22 @@ function tpl_get_action($type) { if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) { return false; } - $params['rev'] = $REV; + $params['rev'] = $REV; $params['sectok'] = getSecurityToken(); break; + /** @noinspection PhpMissingBreakStatementInspection */ case 'subscription': - $type = 'subscribe'; + $type = 'subscribe'; $params['do'] = 'subscribe'; case 'subscribe': - if(!$_SERVER['REMOTE_USER']){ + if(!$_SERVER['REMOTE_USER']) { return false; } break; case 'backlink': break; case 'profile': - if(!isset($_SERVER['REMOTE_USER'])){ + if(!isset($_SERVER['REMOTE_USER'])) { return false; } break; @@ -665,14 +715,25 @@ function tpl_get_action($type) { * Wrapper around tpl_button() and tpl_actionlink() * * @author Anika Henke + * @param + * @param bool $link link or form button? + * @param bool $wrapper HTML element wrapper + * @param bool $return return or print + * @param string $pre prefix for links + * @param string $suf suffix for links + * @param string $inner inner HTML for links + * @return bool|string */ -function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') { +function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') { $out = ''; - if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1); - else $out .= tpl_button($type,1); - if ($out && $wrapper) $out = "<$wrapper>$out"; + if($link) { + $out .= tpl_actionlink($type, $pre, $suf, $inner, 1); + } else { + $out .= tpl_button($type, 1); + } + if($out && $wrapper) $out = "<$wrapper>$out"; - if ($return) return $out; + if($return) return $out; print $out; return $out ? true : false; } @@ -688,14 +749,17 @@ function tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$ * autocompletion feature (MSIE and Firefox) * * @author Andreas Gohr + * @param bool $ajax + * @param bool $autocomplete + * @return bool */ -function tpl_searchform($ajax=true,$autocomplete=true){ +function tpl_searchform($ajax = true, $autocomplete = true) { global $lang; global $ACT; global $QUERY; // don't print the search form if search action has been disabled - if (!actionOk('search')) return false; + if(!actionOk('search')) return false; print '