diff options
author | Klap-in <klapinklapin@gmail.com> | 2013-07-14 13:35:06 +0200 |
---|---|---|
committer | Klap-in <klapinklapin@gmail.com> | 2013-07-14 13:35:06 +0200 |
commit | 33c3b3817b00aa9384760813643fac0e33daaaff (patch) | |
tree | 481c880b00a32ba5887834b52a17248bac8bfc7c /inc/common.php | |
parent | 040f0e135c37c5b544f16277ff69205369df5f1f (diff) | |
parent | fbd8067eeeb9f424981aad8b283e17f734c738c3 (diff) | |
download | rpg-33c3b3817b00aa9384760813643fac0e33daaaff.tar.gz rpg-33c3b3817b00aa9384760813643fac0e33daaaff.tar.bz2 |
merge master in branch
Diffstat (limited to 'inc/common.php')
-rw-r--r-- | inc/common.php | 176 |
1 files changed, 125 insertions, 51 deletions
diff --git a/inc/common.php b/inc/common.php index bc49e76b2..1b4d9e8e4 100644 --- a/inc/common.php +++ b/inc/common.php @@ -56,7 +56,7 @@ function stripctl($string) { * @return string */ function getSecurityToken() { - return md5(auth_cookiesalt().session_id().$_SERVER['REMOTE_USER']); + return PassHash::hmac('md5', session_id().$_SERVER['REMOTE_USER'], auth_cookiesalt()); } /** @@ -86,32 +86,20 @@ function formSecurityToken($print = true) { } /** - * Return info about the current document as associative - * array. + * Determine basic information for a request of $id * * @author Andreas Gohr <andi@splitbrain.org> + * @author Chris Smith <chris@jalakai.co.uk> */ -function pageinfo() { - global $ID; - global $REV; - global $RANGE; +function basicinfo($id, $htmlClient=true){ global $USERINFO; - global $lang; - - // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml - // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary - $info['id'] = $ID; - $info['rev'] = $REV; // set info about manager/admin status. $info['isadmin'] = false; $info['ismanager'] = false; if(isset($_SERVER['REMOTE_USER'])) { - $sub = new Subscription(); - $info['userinfo'] = $USERINFO; - $info['perm'] = auth_quickaclcheck($ID); - $info['subscribed'] = $sub->user_subscription(); + $info['perm'] = auth_quickaclcheck($id); $info['client'] = $_SERVER['REMOTE_USER']; if($info['perm'] == AUTH_ADMIN) { @@ -127,12 +115,46 @@ function pageinfo() { } } else { - $info['perm'] = auth_aclcheck($ID, '', null); - $info['subscribed'] = false; + $info['perm'] = auth_aclcheck($id, '', null); $info['client'] = clientIP(true); } - $info['namespace'] = getNS($ID); + $info['namespace'] = getNS($id); + + // mobile detection + if ($htmlClient) { + $info['ismobile'] = clientismobile(); + } + + return $info; + } + +/** + * Return info about the current document as associative + * array. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function pageinfo() { + global $ID; + global $REV; + global $RANGE; + global $lang; + + $info = basicinfo($ID); + + // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml + // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary + $info['id'] = $ID; + $info['rev'] = $REV; + + if(isset($_SERVER['REMOTE_USER'])) {
+ $sub = new Subscription(); + $info['subscribed'] = $sub->user_subscription(); + } else { + $info['subscribed'] = false; + } + $info['locked'] = checklock($ID); $info['filepath'] = fullpath(wikiFN($ID)); $info['exists'] = @file_exists($info['filepath']); @@ -210,8 +232,18 @@ function pageinfo() { } } - // mobile detection - $info['ismobile'] = clientismobile(); + return $info; +} + +/** + * Return information about the current media item as an associative array. + */ +function mediainfo(){ + global $NS; + global $IMG; + + $info = basicinfo("$NS:*"); + $info['image'] = $IMG; return $info; } @@ -311,7 +343,11 @@ function breadcrumbs() { * * This is run on a ID before it is outputted somewhere * currently used to replace the colon with something else - * on Windows systems and to have proper URL encoding + * on Windows (non-IIS) systems and to have proper URL encoding + * + * See discussions at https://github.com/splitbrain/dokuwiki/pull/84 and + * https://github.com/splitbrain/dokuwiki/pull/173 why we use a whitelist of + * unaffected servers instead of blacklisting affected servers here. * * Urlencoding is ommitted when the second parameter is false * @@ -322,7 +358,8 @@ function idfilter($id, $ue = true) { if($conf['useslash'] && $conf['userewrite']) { $id = strtr($id, ':', '/'); } elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && - $conf['userewrite'] + $conf['userewrite'] && + strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') === false ) { $id = strtr($id, ':', ';'); } @@ -430,7 +467,16 @@ function exportlink($id = '', $format = 'raw', $more = '', $abs = false, $sep = */ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) { global $conf; + $isexternalimage = media_isexternal($id); + if(!$isexternalimage) { + $id = cleanID($id); + } + if(is_array($more)) { + // add token for resized images + if($more['w'] || $more['h']){ + $more['tok'] = media_get_token($id,$more['w'],$more['h']); + } // strip defaults for shorter URLs if(isset($more['cache']) && $more['cache'] == 'cache') unset($more['cache']); if(!$more['w']) unset($more['w']); @@ -438,6 +484,14 @@ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) if(isset($more['id']) && $direct) unset($more['id']); $more = buildURLparams($more, $sep); } else { + $matches = array(); + if (preg_match_all('/\b(w|h)=(\d*)\b/',$more,$matches,PREG_SET_ORDER)){ + $resize = array('w'=>0, 'h'=>0); + foreach ($matches as $match){ + $resize[$match[1]] = $match[2]; + } + $more .= $sep.'tok='.media_get_token($id,$resize['w'],$resize['h']); + } $more = str_replace('cache=cache', '', $more); //skip default $more = str_replace(',,', ',', $more); $more = str_replace(',', $sep, $more); @@ -450,10 +504,10 @@ function ml($id = '', $more = '', $direct = true, $sep = '&', $abs = false) } // external URLs are always direct without rewriting - if(preg_match('#^(https?|ftp)://#i', $id)) { + if($isexternalimage) { $xlink .= 'lib/exe/fetch.php'; // add hash: - $xlink .= '?hash='.substr(md5(auth_cookiesalt().$id), 0, 6); + $xlink .= '?hash='.substr(PassHash::hmac('md5', $id, auth_cookiesalt()), 0, 6); if($more) { $xlink .= $sep.$more; $xlink .= $sep.'media='.rawurlencode($id); @@ -535,12 +589,13 @@ function checkwordblock($text = '') { global $TEXT; global $PRE; global $SUF; + global $SUM; global $conf; global $INFO; if(!$conf['usewordblock']) return false; - if(!$text) $text = "$PRE $TEXT $SUF"; + if(!$text) $text = "$PRE $TEXT $SUF $SUM"; // we prepare the text a tiny bit to prevent spammers circumventing URL checks $text = preg_replace('!(\b)(www\.[\w.:?\-;,]+?\.[\w.:?\-;,]+?[\w/\#~:.?+=&%@\!\-.:?\-;,]+?)([.:?\-;,]*[^\w/\#~:.?+=&%@\!\-.:?\-;,])!i', '\1http://\2 \2\3', $text); @@ -772,11 +827,19 @@ function unlock($id) { /** * convert line ending to unix format * + * also makes sure the given text is valid UTF-8 + * * @see formText() for 2crlf conversion * @author Andreas Gohr <andi@splitbrain.org> */ function cleanText($text) { $text = preg_replace("/(\015\012)|(\015)/", "\012", $text); + + // if the text is not valid UTF-8 we simply assume latin1 + // this won't break any worse than it breaks with the wrong encoding + // but might actually fix the problem in many cases + if(!utf8_check($text)) $text = utf8_encode($text); + return $text; } @@ -1170,27 +1233,6 @@ function getGoogleQuery() { } /** - * Try to set correct locale - * - * @deprecated No longer used - * @author Andreas Gohr <andi@splitbrain.org> - */ -function setCorrectLocale() { - global $conf; - global $lang; - - $enc = strtoupper($lang['encoding']); - foreach($lang['locales'] as $loc) { - //try locale - if(@setlocale(LC_ALL, $loc)) return; - //try loceale with encoding - if(@setlocale(LC_ALL, "$loc.$enc")) return; - } - //still here? try to set from environment - @setlocale(LC_ALL, ""); -} - -/** * Return the human readable size of a file * * @param int $size A file size @@ -1546,18 +1588,50 @@ function valid_input_set($param, $valid_values, $array, $exc = '') { /** * Read a preference from the DokuWiki cookie + * (remembering both keys & values are urlencoded) */ function get_doku_pref($pref, $default) { - if(strpos($_COOKIE['DOKU_PREFS'], $pref) !== false) { + $enc_pref = urlencode($pref); + if(strpos($_COOKIE['DOKU_PREFS'], $enc_pref) !== false) { $parts = explode('#', $_COOKIE['DOKU_PREFS']); $cnt = count($parts); for($i = 0; $i < $cnt; $i += 2) { - if($parts[$i] == $pref) { - return $parts[$i + 1]; + if($parts[$i] == $enc_pref) { + return urldecode($parts[$i + 1]); } } } return $default; } +/** + * Add a preference to the DokuWiki cookie + * (remembering $_COOKIE['DOKU_PREFS'] is urlencoded) + */ +function set_doku_pref($pref, $val) { + global $conf; + $orig = get_doku_pref($pref, false); + $cookieVal = ''; + + if($orig && ($orig != $val)) { + $parts = explode('#', $_COOKIE['DOKU_PREFS']); + $cnt = count($parts); + // urlencode $pref for the comparison + $enc_pref = rawurlencode($pref); + for($i = 0; $i < $cnt; $i += 2) { + if($parts[$i] == $enc_pref) { + $parts[$i + 1] = rawurlencode($val); + break; + } + } + $cookieVal = implode('#', $parts); + } else if (!$orig) { + $cookieVal = ($_COOKIE['DOKU_PREFS'] ? $_COOKIE['DOKU_PREFS'].'#' : '').rawurlencode($pref).'#'.rawurlencode($val); + } + + if (!empty($cookieVal)) { + setcookie('DOKU_PREFS', $cookieVal, time()+365*24*3600, DOKU_BASE, '', ($conf['securecookie'] && is_ssl())); + } +} + //Setup VIM: ex: et ts=2 : |