From e0c26282a603881e8d2f839d94c28dbbfc57d71b Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 29 Sep 2014 03:34:17 +0200 Subject: scrutinizer documentations issues --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index e56285f62..95ea4e72d 100644 --- a/inc/common.php +++ b/inc/common.php @@ -968,7 +968,7 @@ function rawLocale($id, $ext = 'txt') { * @author Andreas Gohr * * @param string $id page id - * @param string $rev timestamp when a revision of wikitext is desired + * @param string|int $rev timestamp when a revision of wikitext is desired * @return string */ function rawWiki($id, $rev = '') { -- cgit v1.2.3 From 59bc3b48fdffb76ee65a4b630be3ffa1f6c20c80 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 29 Sep 2014 21:45:27 +0200 Subject: more scrutinizer issue improvements --- inc/common.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 95ea4e72d..91a068bb0 100644 --- a/inc/common.php +++ b/inc/common.php @@ -120,6 +120,7 @@ function basicinfo($id, $htmlClient=true){ global $INPUT; // set info about manager/admin status. + $info = array(); $info['isadmin'] = false; $info['ismanager'] = false; if($INPUT->server->has('REMOTE_USER')) { @@ -685,6 +686,7 @@ function checkwordblock($text = '') { } if(count($re) && preg_match('#('.join('|', $re).')#si', $text, $matches)) { // prepare event data + $data = array(); $data['matches'] = $matches; $data['userinfo']['ip'] = $INPUT->server->str('REMOTE_ADDR'); if($INPUT->server->str('REMOTE_USER')) { @@ -1119,6 +1121,7 @@ function rawWikiSlices($range, $id, $rev = '') { $from = !$from ? 0 : ($from - 1); $to = !$to ? strlen($text) : ($to - 1); + $slices = array(); $slices[0] = substr($text, 0, $from); $slices[1] = substr($text, $from, $to - $from); $slices[2] = substr($text, $to); -- cgit v1.2.3 From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/common.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 91a068bb0..444e90198 100644 --- a/inc/common.php +++ b/inc/common.php @@ -49,7 +49,7 @@ function ptln($string, $indent = 0) { * * @author Andreas Gohr * - * @param $string string being stripped + * @param string $string being stripped * @return string */ function stripctl($string) { @@ -62,6 +62,7 @@ function stripctl($string) { * @author Andreas Gohr * @link http://en.wikipedia.org/wiki/Cross-site_request_forgery * @link http://christ1an.blogspot.com/2007/04/preventing-csrf-efficiently.html + * * @return string */ function getSecurityToken() { @@ -95,7 +96,7 @@ function checkSecurityToken($token = null) { * @author Andreas Gohr * * @param bool $print if true print the field, otherwise html of the field is returned - * @return void|string html of hidden form field + * @return string html of hidden form field */ function formSecurityToken($print = true) { $ret = '
'."\n"; @@ -336,7 +337,7 @@ function buildAttributes($params, $skipempty = false) { * * @author Andreas Gohr * - * @return array(pageid=>name, ... ) + * @return string[string] with the data: array(pageid=>name, ... ) */ function breadcrumbs() { // we prepare the breadcrumbs early for quick session closing @@ -1110,7 +1111,7 @@ function parsePageTemplate(&$data) { * @param string $range in form "from-to" * @param string $id page id * @param string $rev optional, the revision timestamp - * @return array with three slices + * @return string[] with three slices */ function rawWikiSlices($range, $id, $rev = '') { $text = io_readWikiPage(wikiFN($id, $rev), $id, $rev); @@ -1296,7 +1297,7 @@ function saveOldRevision($id) { * @param int|string $rev Old page revision * @param string $summary What changed * @param boolean $minor Is this a minor edit? - * @param array $replace Additional string substitutions, @KEY@ to be replaced by value + * @param string[] $replace Additional string substitutions, @KEY@ to be replaced by value * @return bool * * @author Andreas Gohr @@ -1376,8 +1377,8 @@ function getGoogleQuery() { /** * Return the human readable size of a file * - * @param int $size A file size - * @param int $dec A number of decimal places + * @param int $size A file size + * @param int $dec A number of decimal places * @return string human readable size * * @author Martin Benjamin @@ -1914,7 +1915,7 @@ function set_doku_pref($pref, $val) { /** * Strips source mapping declarations from given text #601 * - * @param &string $text reference to the CSS or JavaScript code to clean + * @param string &$text reference to the CSS or JavaScript code to clean */ function stripsourcemaps(&$text){ $text = preg_replace('/^(\/\/|\/\*)[@#]\s+sourceMappingURL=.*?(\*\/)?$/im', '\\1\\2', $text); -- cgit v1.2.3 From e3710957c6b7e12293805a15d0624be7c7054092 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 17:05:40 +0200 Subject: more phpdocs and minor check --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 444e90198..7932fc9f0 100644 --- a/inc/common.php +++ b/inc/common.php @@ -337,7 +337,7 @@ function buildAttributes($params, $skipempty = false) { * * @author Andreas Gohr * - * @return string[string] with the data: array(pageid=>name, ... ) + * @return string[] with the data: array(pageid=>name, ... ) */ function breadcrumbs() { // we prepare the breadcrumbs early for quick session closing -- cgit v1.2.3 From 7e8500eea1e53b1de0e0f70400664afa442cd08d Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 2 Oct 2014 14:55:24 +0200 Subject: PHPDocs and some improvements --- inc/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 7932fc9f0..d628ab6b2 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1461,7 +1461,7 @@ function dformat($dt = null, $format = '') { * @author * @link http://www.php.net/manual/en/function.date.php#54072 * - * @param int $int_date: current date in UNIX timestamp + * @param int $int_date current date in UNIX timestamp * @return string */ function date_iso8601($int_date) { -- cgit v1.2.3 From 81781cb6b4211de42700790b0f4968f39feababd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 17 Dec 2014 13:14:29 +0100 Subject: never exit during test runs --- inc/common.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index b5fdd1ea5..2c9359a0c 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1828,6 +1828,8 @@ function send_redirect($url) { } else { header('Location: '.$url); } + + if(defined('DOKU_UNITTEST')) return; // no exits during unit tests exit; } -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- inc/common.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 2c9359a0c..9b330000b 100644 --- a/inc/common.php +++ b/inc/common.php @@ -188,7 +188,7 @@ function pageinfo() { $info['locked'] = checklock($ID); $info['filepath'] = fullpath(wikiFN($ID)); - $info['exists'] = @file_exists($info['filepath']); + $info['exists'] = file_exists($info['filepath']); $info['currentrev'] = @filemtime($info['filepath']); if($REV) { //check if current revision was meant @@ -202,7 +202,7 @@ function pageinfo() { } else { //really use old revision $info['filepath'] = fullpath(wikiFN($ID, $REV)); - $info['exists'] = @file_exists($info['filepath']); + $info['exists'] = file_exists($info['filepath']); } } $info['rev'] = $REV; @@ -256,7 +256,7 @@ function pageinfo() { // draft $draft = getCacheName($info['client'].$ID, '.draft'); - if(@file_exists($draft)) { + if(file_exists($draft)) { if(@filemtime($draft) < @filemtime(wikiFN($ID))) { // remove stale draft @unlink($draft); @@ -352,7 +352,7 @@ function breadcrumbs() { $crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array(); //we only save on show and existing wiki documents $file = wikiFN($ID); - if($ACT != 'show' || !@file_exists($file)) { + if($ACT != 'show' || !file_exists($file)) { $_SESSION[DOKU_COOKIE]['bc'] = $crumbs; return $crumbs; } @@ -853,7 +853,7 @@ function checklock($id) { $lock = wikiLockFN($id); //no lockfile - if(!@file_exists($lock)) return false; + if(!file_exists($lock)) return false; //lockfile expired if((time() - filemtime($lock)) > $conf['locktime']) { @@ -907,7 +907,7 @@ function unlock($id) { global $INPUT; $lock = wikiLockFN($id); - if(@file_exists($lock)) { + if(file_exists($lock)) { @list($ip, $session) = explode("\n", io_readFile($lock)); if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) { @unlink($lock); @@ -1010,13 +1010,13 @@ function pageTemplate($id) { // if the before event did not set a template file, try to find one if(empty($data['tplfile'])) { $path = dirname(wikiFN($id)); - if(@file_exists($path.'/_template.txt')) { + if(file_exists($path.'/_template.txt')) { $data['tplfile'] = $path.'/_template.txt'; } else { // search upper namespaces for templates $len = strlen(rtrim($conf['datadir'], '/')); while(strlen($path) >= $len) { - if(@file_exists($path.'/__template.txt')) { + if(file_exists($path.'/__template.txt')) { $data['tplfile'] = $path.'/__template.txt'; break; } @@ -1197,13 +1197,13 @@ function saveWikiText($id, $text, $summary, $minor = false) { $file = wikiFN($id); $old = @filemtime($file); // from page $wasRemoved = (trim($text) == ''); // check for empty or whitespace only - $wasCreated = !@file_exists($file); + $wasCreated = !file_exists($file); $wasReverted = ($REV == true); $pagelog = new PageChangeLog($id, 1024); $newRev = false; $oldRev = $pagelog->getRevisions(-1, 1); // from changelog $oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]); - if(!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) { + if(!file_exists(wikiFN($id, $old)) && file_exists($file) && $old >= $oldRev) { // add old revision to the attic if missing saveOldRevision($id); // add a changelog entry if this edit came from outside dokuwiki @@ -1285,7 +1285,7 @@ function saveWikiText($id, $text, $summary, $minor = false) { */ function saveOldRevision($id) { $oldf = wikiFN($id); - if(!@file_exists($oldf)) return ''; + if(!file_exists($oldf)) return ''; $date = filemtime($oldf); $newf = wikiFN($id, $date); io_writeWikiPage($newf, rawWiki($id), $id, $date); @@ -1743,7 +1743,7 @@ function license_img($type) { $try[] = 'lib/images/license/'.$type.'/cc.png'; } foreach($try as $src) { - if(@file_exists(DOKU_INC.$src)) return $src; + if(file_exists(DOKU_INC.$src)) return $src; } return ''; } -- cgit v1.2.3 From 326dd43a06ec0806d8771d08a0733d63090e126f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:56:28 +0100 Subject: Remove IE6 workaround for redirects with hashes We no longer support IE6, so hashes in URLs no longer need to be protected when redirecting. --- inc/common.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 9b330000b..5a8b5c900 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1807,17 +1807,6 @@ function send_redirect($url) { // always close the session session_write_close(); - // work around IE bug - // http://www.ianhoar.com/2008/11/16/internet-explorer-6-and-redirected-anchor-links/ - @list($url, $hash) = explode('#', $url); - if($hash) { - if(strpos($url, '?')) { - $url = $url.'&#'.$hash; - } else { - $url = $url.'?&#'.$hash; - } - } - // check if running on IIS < 6 with CGI-PHP if($INPUT->server->has('SERVER_SOFTWARE') && $INPUT->server->has('GATEWAY_INTERFACE') && (strpos($INPUT->server->str('GATEWAY_INTERFACE'), 'CGI') !== false) && -- cgit v1.2.3 From 3a97088971109f1611a03329d12e5296a8c3c515 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 3 May 2015 11:25:06 +0100 Subject: make it possible to remove entries from DOKU_PREFS cookie --- inc/common.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 5a8b5c900..e14bd7af4 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1875,6 +1875,7 @@ function get_doku_pref($pref, $default) { /** * Add a preference to the DokuWiki cookie * (remembering $_COOKIE['DOKU_PREFS'] is urlencoded) + * Remove it by setting $val to false * * @param string $pref preference key * @param string $val preference value @@ -1891,12 +1892,17 @@ function set_doku_pref($pref, $val) { $enc_pref = rawurlencode($pref); for($i = 0; $i < $cnt; $i += 2) { if($parts[$i] == $enc_pref) { - $parts[$i + 1] = rawurlencode($val); + if ($val !== false) { + $parts[$i + 1] = rawurlencode($val); + } else { + unset($parts[$i]); + unset($parts[$i + 1]); + } break; } } $cookieVal = implode('#', $parts); - } else if (!$orig) { + } else if (!$orig && $val !== false) { $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').rawurlencode($pref).'#'.rawurlencode($val); } -- cgit v1.2.3