some code cleanup and php docs

This commit is contained in:
Andreas Gohr 2012-06-25 19:03:02 +02:00
parent fbb9105e03
commit 3272d79733
3 changed files with 432 additions and 408 deletions

View File

@ -503,7 +503,7 @@ function auth_quickaclcheck($id) {
*
* @param string $id page ID (needs to be resolved and cleaned)
* @param string $user Username
* @param array $groups Array of groups the user is in
* @param array|null $groups Array of groups the user is in
* @return int permission level
*/
function auth_aclcheck($id, $user, $groups) {

View File

@ -80,12 +80,9 @@ function checkSecurityToken($token=null){
*/
function formSecurityToken($print = true) {
$ret = '<div class="no"><input type="hidden" name="sectok" value="'.getSecurityToken().'" /></div>'."\n";
if($print){
echo $ret;
}else{
if($print) echo $ret;
return $ret;
}
}
/**
* Return info about the current document as associative
@ -257,7 +254,6 @@ function buildAttributes($params,$skipempty=false){
return $url;
}
/**
* This builds the breadcrumb trail and returns it as array
*
@ -323,7 +319,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']
) {
$id = strtr($id, ':', ';');
}
if($ue) {
@ -421,11 +418,12 @@ function exportlink($id='',$format='raw',$more='',$abs=false,$sep='&amp;'){
* The $more parameter should always be given as array, the function then
* will strip default parameters to produce even cleaner URLs
*
* @param string $id - the media file id or URL
* @param mixed $more - string or array with additional parameters
* @param boolean $direct - link to detail page if false
* @param string $sep - URL parameter separator
* @param boolean $abs - Create an absolute URL
* @param string $id the media file id or URL
* @param mixed $more string or array with additional parameters
* @param bool $direct link to detail page if false
* @param string $sep URL parameter separator
* @param bool $abs Create an absolute URL
* @return string
*/
function ml($id = '', $more = '', $direct = true, $sep = '&amp;', $abs = false) {
global $conf;
@ -495,8 +493,6 @@ function ml($id='',$more='',$direct=true,$sep='&amp;',$abs=false){
return $xlink;
}
/**
* Just builds a link to a script
*
@ -592,8 +588,9 @@ function checkwordblock($text=''){
* a routable public address, prefering the ones suplied in the X
* headers
*
* @param boolean $single If set only a single IP is returned
* @author Andreas Gohr <andi@splitbrain.org>
* @param boolean $single If set only a single IP is returned
* @return string
*/
function clientIP($single = false) {
$ip = array();
@ -674,14 +671,14 @@ function clientismobile(){
return false;
}
/**
* Convert one or more comma separated IPs to hostnames
*
* If $conf['dnslookups'] is disabled it simply returns the input string
*
* @author Glen Harris <astfgl@iamnota.org>
* @returns a comma separated list of hostnames
* @param string $ips comma separated list of IP addresses
* @return string a comma separated list of hostnames
*/
function gethostsbyaddrs($ips) {
global $conf;
@ -753,6 +750,7 @@ function lock($id){
* Unlock a page if it was locked by the user
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $id page id to unlock
* @return bool true if a lock was removed
*/
function unlock($id) {
@ -835,7 +833,6 @@ 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));
$tpl = '';
if(@file_exists($path.'/_template.txt')) {
$data['tplfile'] = $path.'/_template.txt';
} else {
@ -868,6 +865,12 @@ function pageTemplate($id){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function parsePageTemplate(&$data) {
/**
* @var string $id the id of the page to be created
* @var string $tpl the text used as template
* @var string $tplfile the file above text was/should be loaded from
* @var bool $doreplace should wildcard replacements be done on the text?
*/
extract($data);
global $USERINFO;
@ -877,7 +880,8 @@ function parsePageTemplate(&$data) {
$file = noNS($id);
$page = strtr($file, $conf['sepchar'], ' ');
$tpl = str_replace(array(
$tpl = str_replace(
array(
'@ID@',
'@NS@',
'@FILE@',
@ -906,7 +910,8 @@ function parsePageTemplate(&$data) {
$USERINFO['name'],
$USERINFO['mail'],
$conf['dformat'],
), $tpl);
), $tpl
);
// we need the callback to work around strftime's char limit
$tpl = preg_replace_callback('/%./', create_function('$m', 'return strftime($m[0]);'), $tpl);
@ -951,11 +956,13 @@ function rawWikiSlices($range,$id,$rev=''){
function con($pre, $text, $suf, $pretty = false) {
if($pretty) {
if($pre !== '' && substr($pre, -1) !== "\n" &&
substr($text, 0, 1) !== "\n") {
substr($text, 0, 1) !== "\n"
) {
$pre .= "\n";
}
if($suf !== '' && substr($text, -1) !== "\n" &&
substr($suf, 0, 1) !== "\n") {
substr($suf, 0, 1) !== "\n"
) {
$text .= "\n";
}
}
@ -1038,10 +1045,13 @@ function saveWikiText($id,$text,$summary,$minor=false){
if($wasReverted) {
$type = DOKU_CHANGE_TYPE_REVERT;
$extra = $REV;
}
else if ($wasCreated) { $type = DOKU_CHANGE_TYPE_CREATE; }
else if ($wasRemoved) { $type = DOKU_CHANGE_TYPE_DELETE; }
else if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; } //minor edits only for logged in users
} else if($wasCreated) {
$type = DOKU_CHANGE_TYPE_CREATE;
} else if($wasRemoved) {
$type = DOKU_CHANGE_TYPE_DELETE;
} else if($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) {
$type = DOKU_CHANGE_TYPE_MINOR_EDIT;
} //minor edits only for logged in users
addLogEntry($newRev, $id, $type, $summary, $extra);
// send notify mails
@ -1082,11 +1092,12 @@ function saveOldRevision($id){
*
* @param string $id The changed page
* @param string $who Who to notify (admin|subscribers|register)
* @param int $rev Old page revision
* @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
*
* @return bool
* @author Andreas Gohr <andi@splitbrain.org>
*/
function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) {
@ -1097,27 +1108,29 @@ function notify($id,$who,$rev='',$summary='',$minor=false,$replace=array()){
// decide if there is something to do, eg. whom to mail
if($who == 'admin') {
if(empty($conf['notify'])) return; //notify enabled?
if(empty($conf['notify'])) return false; //notify enabled?
$text = rawLocale('mailtext');
$to = $conf['notify'];
$bcc = '';
} elseif($who == 'subscribers') {
if(!$conf['subscribers']) return; //subscribers enabled?
if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return; //skip minors
if(!$conf['subscribers']) return false; //subscribers enabled?
if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return false; //skip minors
$data = array('id' => $id, 'addresslist' => '', 'self' => false);
trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data,
'subscription_addresslist');
trigger_event(
'COMMON_NOTIFY_ADDRESSLIST', $data,
'subscription_addresslist'
);
$bcc = $data['addresslist'];
if(empty($bcc)) return;
if(empty($bcc)) return false;
$to = '';
$text = rawLocale('subscr_single');
} elseif($who == 'register') {
if(empty($conf['registernotify'])) return;
if(empty($conf['registernotify'])) return false;
$text = rawLocale('registermail');
$to = $conf['registernotify'];
$bcc = '';
} else {
return; //just to be safe
return false; //just to be safe
}
// prepare replacements (keys not set in hrep will be taken from trep)
@ -1304,6 +1317,7 @@ function dformat($dt=null,$format=''){
* @author <ungu at terong dot com>
* @link http://www.php.net/manual/en/function.date.php#54072
* @param int $int_date: current date in UNIX timestamp
* @return string
*/
function date_iso8601($int_date) {
$date_mod = date('Y-m-d\TH:i:s', $int_date);
@ -1398,6 +1412,7 @@ function preg_quote_cb($string){
* @param int $max maximum chars you want for the whole string
* @param int $min minimum number of chars to have left for middle shortening
* @param string $char the shortening character to use
* @return string
*/
function shorten($keep, $short, $max, $min = 9, $char = '…') {
$max = $max - utf8_strlen($keep);
@ -1451,6 +1466,7 @@ function editorinfo($username){
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $type - type of image 'badge' or 'button'
* @return string
*/
function license_img($type) {
global $license;
@ -1476,10 +1492,13 @@ function license_img($type){
* If the memory_get_usage() function is not available the
* function just assumes $bytes of already allocated memory
*
* @param int $mem Size of memory you want to allocate in bytes
* @param int $used already allocated memory (see above)
* @author Filip Oscadal <webmaster@illusionsoftworks.cz>
* @author Andreas Gohr <andi@splitbrain.org>
*
* @param int $mem Size of memory you want to allocate in bytes
* @param int $bytes
* @internal param int $used already allocated memory (see above)
* @return bool
*/
function is_mem_available($mem, $bytes = 1048576) {
$limit = trim(ini_get('memory_limit'));
@ -1537,7 +1556,8 @@ function send_redirect($url){
if(isset($_SERVER['SERVER_SOFTWARE']) && isset($_SERVER['GATEWAY_INTERFACE']) &&
(strpos($_SERVER['GATEWAY_INTERFACE'], 'CGI') !== false) &&
(preg_match('|^Microsoft-IIS/(\d)\.\d$|', trim($_SERVER['SERVER_SOFTWARE']), $matches)) &&
$matches[1] < 6 ){
$matches[1] < 6
) {
header('Refresh: 0;url='.$url);
} else {
header('Location: '.$url);
@ -1559,6 +1579,8 @@ function send_redirect($url){
* or $_GET)
* @param string $exc The text of the raised exception
*
* @throws Exception
* @return mixed
* @author Adrian Lang <lang@cosmocode.de>
*/
function valid_input_set($param, $valid_values, $array, $exc = '') {

View File

@ -3,7 +3,9 @@
* Initialize some defaults needed for DokuWiki
*/
// start timing Dokuwiki execution
/**
* timing Dokuwiki execution
*/
function delta_time($start=0) {
return microtime(true)-((float)$start);
}