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