1<?php 2/** 3 * Common DokuWiki functions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 10 require_once(DOKU_CONF.'dokuwiki.php'); 11 require_once(DOKU_INC.'inc/io.php'); 12 require_once(DOKU_INC.'inc/utf8.php'); 13 require_once(DOKU_INC.'inc/mail.php'); 14 require_once(DOKU_INC.'inc/parserutils.php'); 15 16/** 17 * Return info about the current document as associative 18 * array. 19 * 20 * @author Andreas Gohr <andi@splitbrain.org> 21 */ 22function pageinfo(){ 23 global $ID; 24 global $REV; 25 global $USERINFO; 26 global $conf; 27 28 if($_SERVER['REMOTE_USER']){ 29 $info['user'] = $_SERVER['REMOTE_USER']; 30 $info['userinfo'] = $USERINFO; 31 $info['perm'] = auth_quickaclcheck($ID); 32 }else{ 33 $info['user'] = ''; 34 $info['perm'] = auth_aclcheck($ID,'',null); 35 } 36 37 $info['namespace'] = getNS($ID); 38 $info['locked'] = checklock($ID); 39 $info['filepath'] = realpath(wikiFN($ID,$REV)); 40 $info['exists'] = @file_exists($info['filepath']); 41 if($REV && !$info['exists']){ 42 //check if current revision was meant 43 $cur = wikiFN($ID); 44 if(@file_exists($cur) && (@filemtime($cur) == $REV)){ 45 $info['filepath'] = realpath($cur); 46 $info['exists'] = true; 47 $REV = ''; 48 } 49 } 50 $info['rev'] = $REV; 51 if($info['exists']){ 52 $info['writable'] = (is_writable($info['filepath']) && 53 ($info['perm'] >= AUTH_EDIT)); 54 }else{ 55 $info['writable'] = ($info['perm'] >= AUTH_CREATE); 56 } 57 $info['editable'] = ($info['writable'] && empty($info['lock'])); 58 $info['lastmod'] = @filemtime($info['filepath']); 59 60 //who's the editor 61 if($REV){ 62 $revinfo = getRevisionInfo($ID,$REV); 63 }else{ 64 $revinfo = getRevisionInfo($ID,$info['lastmod']); 65 } 66 $info['ip'] = $revinfo['ip']; 67 $info['user'] = $revinfo['user']; 68 $info['sum'] = $revinfo['sum']; 69 $info['editor'] = $revinfo['ip']; 70 if($revinfo['user']){ 71 $info['editor'] = $revinfo['user']; 72 }else{ 73 $info['editor'] = $revinfo['ip']; 74 } 75 76 return $info; 77} 78 79/** 80 * Build an string of URL parameters 81 * 82 * @author Andreas Gohr 83 */ 84function buildURLparams($params){ 85 $url = ''; 86 $amp = false; 87 foreach($params as $key => $val){ 88 if($amp) $url .= '&'; 89 90 $url .= $key.'='; 91 $url .= urlencode($val); 92 $amp = true; 93 } 94 return $url; 95} 96 97/** 98 * Build an string of html tag attributes 99 * 100 * @author Andreas Gohr 101 */ 102function buildAttributes($params){ 103 $url = ''; 104 foreach($params as $key => $val){ 105 $url .= $key.'="'; 106 $url .= htmlspecialchars ($val); 107 $url .= '" '; 108 } 109 return $url; 110} 111 112 113/** 114 * print a message 115 * 116 * If HTTP headers were not sent yet the message is added 117 * to the global message array else it's printed directly 118 * using html_msgarea() 119 * 120 * 121 * Levels can be: 122 * 123 * -1 error 124 * 0 info 125 * 1 success 126 * 127 * @author Andreas Gohr <andi@splitbrain.org> 128 * @see html_msgarea 129 */ 130function msg($message,$lvl=0){ 131 global $MSG; 132 $errors[-1] = 'error'; 133 $errors[0] = 'info'; 134 $errors[1] = 'success'; 135 136 if(!headers_sent()){ 137 if(!isset($MSG)) $MSG = array(); 138 $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message); 139 }else{ 140 $MSG = array(); 141 $MSG[]=array('lvl' => $errors[$lvl], 'msg' => $message); 142 if(function_exists('html_msgarea')){ 143 html_msgarea(); 144 }else{ 145 print "ERROR($lvl) $message"; 146 } 147 } 148} 149 150/** 151 * This builds the breadcrumb trail and returns it as array 152 * 153 * @author Andreas Gohr <andi@splitbrain.org> 154 */ 155function breadcrumbs(){ 156 // we prepare the breadcrumbs early for quick session closing 157 static $crumbs = null; 158 if($crumbs != null) return $crumbs; 159 160 global $ID; 161 global $ACT; 162 global $conf; 163 $crumbs = $_SESSION[$conf['title']]['bc']; 164 165 //first visit? 166 if (!is_array($crumbs)){ 167 $crumbs = array(); 168 } 169 //we only save on show and existing wiki documents 170 $file = wikiFN($ID); 171 if($ACT != 'show' || !@file_exists($file)){ 172 $_SESSION[$conf['title']]['bc'] = $crumbs; 173 return $crumbs; 174 } 175 176 // page names 177 $name = noNS($ID); 178 if ($conf['useheading']) { 179 // get page title 180 $title = p_get_first_heading($ID); 181 if ($title) { 182 $name = $title; 183 } 184 } 185 186 //remove ID from array 187 if (isset($crumbs[$ID])) { 188 unset($crumbs[$ID]); 189 } 190 191 //add to array 192 $crumbs[$ID] = $name; 193 //reduce size 194 while(count($crumbs) > $conf['breadcrumbs']){ 195 array_shift($crumbs); 196 } 197 //save to session 198 $_SESSION[$conf['title']]['bc'] = $crumbs; 199 return $crumbs; 200} 201 202/** 203 * Filter for page IDs 204 * 205 * This is run on a ID before it is outputted somewhere 206 * currently used to replace the colon with something else 207 * on Windows systems and to have proper URL encoding 208 * 209 * Urlencoding is ommitted when the second parameter is false 210 * 211 * @author Andreas Gohr <andi@splitbrain.org> 212 */ 213function idfilter($id,$ue=true){ 214 global $conf; 215 if ($conf['useslash'] && $conf['userewrite']){ 216 $id = strtr($id,':','/'); 217 }elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && 218 $conf['userewrite']) { 219 $id = strtr($id,':',';'); 220 } 221 if($ue){ 222 $id = urlencode($id); 223 $id = str_replace('%3A',':',$id); //keep as colon 224 $id = str_replace('%2F','/',$id); //keep as slash 225 } 226 return $id; 227} 228 229/** 230 * This builds a link to a wikipage 231 * 232 * It handles URL rewriting and adds additional parameter if 233 * given in $more 234 * 235 * @author Andreas Gohr <andi@splitbrain.org> 236 */ 237function wl($id='',$more='',$abs=false){ 238 global $conf; 239 $more = str_replace(',','&',$more); 240 241 $id = idfilter($id); 242 if($abs){ 243 $xlink = DOKU_URL; 244 }else{ 245 $xlink = DOKU_BASE; 246 } 247 248 if($conf['userewrite'] == 2){ 249 $xlink .= DOKU_SCRIPT.'/'.$id; 250 if($more) $xlink .= '?'.$more; 251 }elseif($conf['userewrite']){ 252 $xlink .= $id; 253 if($more) $xlink .= '?'.$more; 254 }else{ 255 $xlink .= DOKU_SCRIPT.'?id='.$id; 256 if($more) $xlink .= '&'.$more; 257 } 258 259 return $xlink; 260} 261 262/** 263 * Just builds a link to a script 264 * 265 * @todo maybe obsolete 266 * @author Andreas Gohr <andi@splitbrain.org> 267 */ 268function script($script='doku.php'){ 269# $link = getBaseURL(); 270# $link .= $script; 271# return $link; 272 return DOKU_BASE.DOKU_SCRIPT; 273} 274 275/** 276 * Spamcheck against wordlist 277 * 278 * Checks the wikitext against a list of blocked expressions 279 * returns true if the text contains any bad words 280 * 281 * @author Andreas Gohr <andi@splitbrain.org> 282 */ 283function checkwordblock(){ 284 global $TEXT; 285 global $conf; 286 287 if(!$conf['usewordblock']) return false; 288 289 $blockfile = file(DOKU_CONF.'wordblock.conf'); 290 //how many lines to read at once (to work around some PCRE limits) 291 if(version_compare(phpversion(),'4.3.0','<')){ 292 //old versions of PCRE define a maximum of parenthesises even if no 293 //backreferences are used - the maximum is 99 294 //this is very bad performancewise and may even be too high still 295 $chunksize = 40; 296 }else{ 297 //read file in chunks of 600 - this should work around the 298 //MAX_PATTERN_SIZE in modern PCRE 299 $chunksize = 600; 300 } 301 while($blocks = array_splice($blockfile,0,$chunksize)){ 302 $re = array(); 303 #build regexp from blocks 304 foreach($blocks as $block){ 305 $block = preg_replace('/#.*$/','',$block); 306 $block = trim($block); 307 if(empty($block)) continue; 308 $re[] = $block; 309 } 310 if(preg_match('#('.join('|',$re).')#si',$TEXT)) return true; 311 } 312 return false; 313} 314 315/** 316 * Return the IP of the client 317 * 318 * Honours X-Forwarded-For Proxy Headers 319 * 320 * @author Andreas Gohr <andi@splitbrain.org> 321 */ 322function clientIP(){ 323 $my = $_SERVER['REMOTE_ADDR']; 324 if($_SERVER['HTTP_X_FORWARDED_FOR']){ 325 $my .= ' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')'; 326 } 327 return $my; 328} 329 330/** 331 * Checks if a given page is currently locked. 332 * 333 * removes stale lockfiles 334 * 335 * @author Andreas Gohr <andi@splitbrain.org> 336 */ 337function checklock($id){ 338 global $conf; 339 $lock = wikiFN($id).'.lock'; 340 341 //no lockfile 342 if(!@file_exists($lock)) return false; 343 344 //lockfile expired 345 if((time() - filemtime($lock)) > $conf['locktime']){ 346 unlink($lock); 347 return false; 348 } 349 350 //my own lock 351 $ip = io_readFile($lock); 352 if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){ 353 return false; 354 } 355 356 return $ip; 357} 358 359/** 360 * Lock a page for editing 361 * 362 * @author Andreas Gohr <andi@splitbrain.org> 363 */ 364function lock($id){ 365 $lock = wikiFN($id).'.lock'; 366 if($_SERVER['REMOTE_USER']){ 367 io_saveFile($lock,$_SERVER['REMOTE_USER']); 368 }else{ 369 io_saveFile($lock,clientIP()); 370 } 371} 372 373/** 374 * Unlock a page if it was locked by the user 375 * 376 * @author Andreas Gohr <andi@splitbrain.org> 377 * @return bool true if a lock was removed 378 */ 379function unlock($id){ 380 $lock = wikiFN($id).'.lock'; 381 if(@file_exists($lock)){ 382 $ip = io_readFile($lock); 383 if( ($ip == clientIP()) || ($ip == $_SERVER['REMOTE_USER']) ){ 384 @unlink($lock); 385 return true; 386 } 387 } 388 return false; 389} 390 391/** 392 * convert line ending to unix format 393 * 394 * @see formText() for 2crlf conversion 395 * @author Andreas Gohr <andi@splitbrain.org> 396 */ 397function cleanText($text){ 398 $text = preg_replace("/(\015\012)|(\015)/","\012",$text); 399 return $text; 400} 401 402/** 403 * Prepares text for print in Webforms by encoding special chars. 404 * It also converts line endings to Windows format which is 405 * pseudo standard for webforms. 406 * 407 * @see cleanText() for 2unix conversion 408 * @author Andreas Gohr <andi@splitbrain.org> 409 */ 410function formText($text){ 411 $text = preg_replace("/\012/","\015\012",$text); 412 return htmlspecialchars($text); 413} 414 415/** 416 * Returns the specified local text in raw format 417 * 418 * @author Andreas Gohr <andi@splitbrain.org> 419 */ 420function rawLocale($id){ 421 return io_readFile(localeFN($id)); 422} 423 424/** 425 * Returns the raw WikiText 426 * 427 * @author Andreas Gohr <andi@splitbrain.org> 428 */ 429function rawWiki($id,$rev=''){ 430 return io_readFile(wikiFN($id,$rev)); 431} 432 433/** 434 * Returns the pagetemplate contents for the ID's namespace 435 * 436 * @author Andreas Gohr <andi@splitbrain.org> 437 */ 438function pageTemplate($id){ 439 return io_readFile(dirname(wikiFN($id)).'/_template.txt'); 440} 441 442 443/** 444 * Returns the raw Wiki Text in three slices. 445 * 446 * The range parameter needs to have the form "from-to" 447 * and gives the range of the section in bytes - no 448 * UTF-8 awareness is needed. 449 * The returned order is prefix, section and suffix. 450 * 451 * @author Andreas Gohr <andi@splitbrain.org> 452 */ 453function rawWikiSlices($range,$id,$rev=''){ 454 list($from,$to) = split('-',$range,2); 455 $text = io_readFile(wikiFN($id,$rev)); 456 if(!$from) $from = 0; 457 if(!$to) $to = strlen($text)+1; 458 459 $slices[0] = substr($text,0,$from-1); 460 $slices[1] = substr($text,$from-1,$to-$from); 461 $slices[2] = substr($text,$to); 462 463 return $slices; 464} 465 466/** 467 * Joins wiki text slices 468 * 469 * function to join the text slices with correct lineendings again. 470 * When the pretty parameter is set to true it adds additional empty 471 * lines between sections if needed (used on saving). 472 * 473 * @author Andreas Gohr <andi@splitbrain.org> 474 */ 475function con($pre,$text,$suf,$pretty=false){ 476 477 if($pretty){ 478 if($pre && substr($pre,-1) != "\n") $pre .= "\n"; 479 if($suf && substr($text,-1) != "\n") $text .= "\n"; 480 } 481 482 if($pre) $pre .= "\n"; 483 if($suf) $text .= "\n"; 484 return $pre.$text.$suf; 485} 486 487/** 488 * print debug messages 489 * 490 * little function to print the content of a var 491 * 492 * @author Andreas Gohr <andi@splitbrain.org> 493 */ 494function dbg($msg,$hidden=false){ 495 (!$hidden) ? print '<pre class="dbg">' : print "<!--\n"; 496 print_r($msg); 497 (!$hidden) ? print '</pre>' : print "\n-->"; 498} 499 500/** 501 * Add's an entry to the changelog 502 * 503 * @author Andreas Gohr <andi@splitbrain.org> 504 */ 505function addLogEntry($date,$id,$summary=""){ 506 global $conf; 507 $id = cleanID($id);//FIXME not needed anymore? 508 509 if(!@is_writable($conf['changelog'])){ 510 msg($conf['changelog'].' is not writable!',-1); 511 return; 512 } 513 514 if(!$date) $date = time(); //use current time if none supplied 515 $remote = $_SERVER['REMOTE_ADDR']; 516 $user = $_SERVER['REMOTE_USER']; 517 518 $logline = join("\t",array($date,$remote,$id,$user,$summary))."\n"; 519 520 //FIXME: use adjusted io_saveFile instead 521 $fh = fopen($conf['changelog'],'a'); 522 if($fh){ 523 fwrite($fh,$logline); 524 fclose($fh); 525 } 526} 527 528/** 529 * returns an array of recently changed files using the 530 * changelog 531 * first : first entry in array returned 532 * num : return 'num' entries 533 * 534 * @author Andreas Gohr <andi@splitbrain.org> 535 */ 536function getRecents($first,$num,$incdel=false){ 537 global $conf; 538 $recent = array(); 539 $names = array(); 540 541 if(!$num) 542 return $recent; 543 544 if(!@is_readable($conf['changelog'])){ 545 msg($conf['changelog'].' is not readable',-1); 546 return $recent; 547 } 548 549 $loglines = file($conf['changelog']); 550 rsort($loglines); //reverse sort on timestamp 551 552 foreach ($loglines as $line){ 553 $line = rtrim($line); //remove newline 554 if(empty($line)) continue; //skip empty lines 555 $info = split("\t",$line); //split into parts 556 //add id if not in yet and file still exists and is allowed to read 557 if(!$names[$info[2]] && 558 (@file_exists(wikiFN($info[2])) || $incdel) && 559 (auth_quickaclcheck($info[2]) >= AUTH_READ) 560 ){ 561 $names[$info[2]] = 1; 562 if(--$first >= 0) continue; /* skip "first" entries */ 563 564 $recent[$info[2]]['date'] = $info[0]; 565 $recent[$info[2]]['ip'] = $info[1]; 566 $recent[$info[2]]['user'] = $info[3]; 567 $recent[$info[2]]['sum'] = $info[4]; 568 $recent[$info[2]]['del'] = !@file_exists(wikiFN($info[2])); 569 } 570 if(count($recent) >= $num){ 571 break; //finish if enough items found 572 } 573 } 574 return $recent; 575} 576 577/** 578 * gets additonal informations for a certain pagerevison 579 * from the changelog 580 * 581 * @author Andreas Gohr <andi@splitbrain.org> 582 */ 583function getRevisionInfo($id,$rev){ 584 global $conf; 585 586 if(!$rev) return(null); 587 588 $info = array(); 589 if(!@is_readable($conf['changelog'])){ 590 msg($conf['changelog'].' is not readable',-1); 591 return $recent; 592 } 593 $loglines = file($conf['changelog']); 594 $loglines = preg_grep("/$rev\t\d+\.\d+\.\d+\.\d+\t$id\t/",$loglines); 595 $loglines = array_reverse($loglines); //reverse sort on timestamp (shouldn't be needed) 596 $line = split("\t",$loglines[0]); 597 $info['date'] = $line[0]; 598 $info['ip'] = $line[1]; 599 $info['user'] = $line[3]; 600 $info['sum'] = $line[4]; 601 return $info; 602} 603 604/** 605 * Saves a wikitext by calling io_saveFile 606 * 607 * @author Andreas Gohr <andi@splitbrain.org> 608 */ 609function saveWikiText($id,$text,$summary){ 610 global $conf; 611 global $lang; 612 umask($conf['umask']); 613 // ignore if no changes were made 614 if($text == rawWiki($id,'')){ 615 return; 616 } 617 618 $file = wikiFN($id); 619 $old = saveOldRevision($id); 620 621 if (empty($text)){ 622 // remove empty files 623 @unlink($file); 624 $del = true; 625 //autoset summary on deletion 626 if(empty($summary)) $summary = $lang['deleted']; 627 //remove empty namespaces 628 io_sweepNS($id); 629 }else{ 630 // save file (datadir is created in io_saveFile) 631 io_saveFile($file,$text); 632 $del = false; 633 } 634 635 addLogEntry(@filemtime($file),$id,$summary); 636 notify($id,$old,$summary); 637 638 //purge cache on add by updating the purgefile 639 if($conf['purgeonadd'] && (!$old || $del)){ 640 io_saveFile($conf['cachedir'].'/purgefile',time()); 641 } 642} 643 644/** 645 * moves the current version to the attic and returns its 646 * revision date 647 * 648 * @author Andreas Gohr <andi@splitbrain.org> 649 */ 650function saveOldRevision($id){ 651 global $conf; 652 umask($conf['umask']); 653 $oldf = wikiFN($id); 654 if(!@file_exists($oldf)) return ''; 655 $date = filemtime($oldf); 656 $newf = wikiFN($id,$date); 657 if(substr($newf,-3)=='.gz'){ 658 io_saveFile($newf,rawWiki($id)); 659 }else{ 660 io_makeFileDir($newf); 661 copy($oldf, $newf); 662 } 663 return $date; 664} 665 666/** 667 * Sends a notify mail to the wikiadmin when a page was 668 * changed 669 * 670 * @author Andreas Gohr <andi@splitbrain.org> 671 */ 672function notify($id,$rev="",$summary=""){ 673 global $lang; 674 global $conf; 675 $hdrs =''; 676 if(empty($conf['notify'])) return; //notify enabled? 677 678 $text = rawLocale('mailtext'); 679 $text = str_replace('@DATE@',date($conf['dformat']),$text); 680 $text = str_replace('@BROWSER@',$_SERVER['HTTP_USER_AGENT'],$text); 681 $text = str_replace('@IPADDRESS@',$_SERVER['REMOTE_ADDR'],$text); 682 $text = str_replace('@HOSTNAME@',gethostbyaddr($_SERVER['REMOTE_ADDR']),$text); 683 $text = str_replace('@NEWPAGE@',wl($id,'',true),$text); 684 $text = str_replace('@DOKUWIKIURL@',DOKU_URL,$text); 685 $text = str_replace('@SUMMARY@',$summary,$text); 686 $text = str_replace('@USER@',$_SERVER['REMOTE_USER'],$text); 687 688 if($rev){ 689 $subject = $lang['mail_changed'].' '.$id; 690 $text = str_replace('@OLDPAGE@',wl($id,"rev=$rev",true),$text); 691 require_once("inc/DifferenceEngine.php"); 692 $df = new Diff(split("\n",rawWiki($id,$rev)), 693 split("\n",rawWiki($id))); 694 $dformat = new UnifiedDiffFormatter(); 695 $diff = $dformat->format($df); 696 }else{ 697 $subject=$lang['mail_newpage'].' '.$id; 698 $text = str_replace('@OLDPAGE@','none',$text); 699 $diff = rawWiki($id); 700 } 701 $text = str_replace('@DIFF@',$diff,$text); 702 $subject = '['.$conf['title'].'] '.$subject; 703 704 mail_send($conf['notify'],$subject,$text,$conf['mailfrom']); 705} 706 707/** 708 * Return a list of available page revisons 709 * 710 * @author Andreas Gohr <andi@splitbrain.org> 711 */ 712function getRevisions($id){ 713 $revd = dirname(wikiFN($id,'foo')); 714 $revs = array(); 715 $clid = cleanID($id); 716 if(strrpos($clid,':')) $clid = substr($clid,strrpos($clid,':')+1); //remove path 717 $clid = utf8_encodeFN($clid); 718 719 if (is_dir($revd) && $dh = opendir($revd)) { 720 while (($file = readdir($dh)) !== false) { 721 if (is_dir($revd.'/'.$file)) continue; 722 if (preg_match('/^'.$clid.'\.(\d+)\.txt(\.gz)?$/',$file,$match)){ 723 $revs[]=$match[1]; 724 } 725 } 726 closedir($dh); 727 } 728 rsort($revs); 729 return $revs; 730} 731 732/** 733 * extracts the query from a google referer 734 * 735 * @todo should be more generic and support yahoo et al 736 * @author Andreas Gohr <andi@splitbrain.org> 737 */ 738function getGoogleQuery(){ 739 $url = parse_url($_SERVER['HTTP_REFERER']); 740 if(!$url) return ''; 741 742 if(!preg_match("#google\.#i",$url['host'])) return ''; 743 $query = array(); 744 parse_str($url['query'],$query); 745 746 return $query['q']; 747} 748 749/** 750 * Try to set correct locale 751 * 752 * @deprecated No longer used 753 * @author Andreas Gohr <andi@splitbrain.org> 754 */ 755function setCorrectLocale(){ 756 global $conf; 757 global $lang; 758 759 $enc = strtoupper($lang['encoding']); 760 foreach ($lang['locales'] as $loc){ 761 //try locale 762 if(@setlocale(LC_ALL,$loc)) return; 763 //try loceale with encoding 764 if(@setlocale(LC_ALL,"$loc.$enc")) return; 765 } 766 //still here? try to set from environment 767 @setlocale(LC_ALL,""); 768} 769 770/** 771 * Return the human readable size of a file 772 * 773 * @param int $size A file size 774 * @param int $dec A number of decimal places 775 * @author Martin Benjamin <b.martin@cybernet.ch> 776 * @author Aidan Lister <aidan@php.net> 777 * @version 1.0.0 778 */ 779function filesize_h($size, $dec = 1){ 780 $sizes = array('B', 'KB', 'MB', 'GB'); 781 $count = count($sizes); 782 $i = 0; 783 784 while ($size >= 1024 && ($i < $count - 1)) { 785 $size /= 1024; 786 $i++; 787 } 788 789 return round($size, $dec) . ' ' . $sizes[$i]; 790} 791 792/** 793 * Return DokuWikis version 794 * 795 * @author Andreas Gohr <andi@splitbrain.org> 796 */ 797function getVersion(){ 798 //import version string 799 if(@file_exists('VERSION')){ 800 //official release 801 return 'Release '.trim(io_readfile('VERSION')); 802 }elseif(is_dir('_darcs')){ 803 //darcs checkout 804 $inv = file('_darcs/inventory'); 805 $inv = preg_grep('#andi@splitbrain\.org\*\*\d{14}#',$inv); 806 $cur = array_pop($inv); 807 preg_match('#\*\*(\d{4})(\d{2})(\d{2})#',$cur,$matches); 808 return 'Darcs '.$matches[1].'-'.$matches[2].'-'.$matches[3]; 809 }else{ 810 return 'snapshot?'; 811 } 812} 813 814/** 815 * Run a few sanity checks 816 * 817 * @author Andreas Gohr <andi@splitbrain.org> 818 */ 819function check(){ 820 global $conf; 821 global $INFO; 822 823 msg('DokuWiki version: '.getVersion(),1); 824 825 if(version_compare(phpversion(),'4.3.0','<')){ 826 msg('Your PHP version is too old ('.phpversion().' vs. 4.3.+ recommended)',-1); 827 }elseif(version_compare(phpversion(),'4.3.10','<')){ 828 msg('Consider upgrading PHP to 4.3.10 or higher for security reasons (your version: '.phpversion().')',0); 829 }else{ 830 msg('PHP version '.phpversion(),1); 831 } 832 833 if(is_writable($conf['changelog'])){ 834 msg('Changelog is writable',1); 835 }else{ 836 msg('Changelog is not writable',-1); 837 } 838 839 if(is_writable($conf['datadir'])){ 840 msg('Datadir is writable',1); 841 }else{ 842 msg('Datadir is not writable',-1); 843 } 844 845 if(is_writable($conf['olddir'])){ 846 msg('Attic is writable',1); 847 }else{ 848 msg('Attic is not writable',-1); 849 } 850 851 if(is_writable($conf['mediadir'])){ 852 msg('Mediadir is writable',1); 853 }else{ 854 msg('Mediadir is not writable',-1); 855 } 856 857 if(is_writable($conf['cachedir'])){ 858 msg('Cachedir is writable',1); 859 }else{ 860 msg('Cachedir is not writable',-1); 861 } 862 863 if(is_writable(DOKU_CONF.'users.auth.php')){ 864 msg('conf/users.auth.php is writable',1); 865 }else{ 866 msg('conf/users.auth.php is not writable',0); 867 } 868 869 if(function_exists('mb_strpos')){ 870 if(defined('UTF8_NOMBSTRING')){ 871 msg('mb_string extension is available but will not be used',0); 872 }else{ 873 msg('mb_string extension is available and will be used',1); 874 } 875 }else{ 876 msg('mb_string extension not available - PHP only replacements will be used',0); 877 } 878 879 msg('Your current permission for this page is '.$INFO['perm'],0); 880 881 if(is_writable($INFO['filepath'])){ 882 msg('The current page is writable by the webserver',0); 883 }else{ 884 msg('The current page is not writable by the webserver',0); 885 } 886 887 if($INFO['writable']){ 888 msg('The current page is writable by you',0); 889 }else{ 890 msg('The current page is not writable you',0); 891 } 892} 893 894 895//Setup VIM: ex: et ts=2 enc=utf-8 : 896