xref: /dokuwiki/inc/html.php (revision f11c233fb55043866bc976a324fd2d1ecc72a962)
1<?
2/**
3 * HTML output functions
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
7 */
8
9  include_once("inc/format.php");
10
11/**
12 * Convenience function to quickly build a wikilink
13 *
14 * @author Andreas Gohr <andi@splitbrain.org>
15 */
16function html_wikilink($url,$name='',$search=''){
17  global $conf;
18  $link         = array();
19  $link['url']  = $url;
20  $link['name'] = $name;
21  $link         = format_link_wiki($link);
22
23  if($search){
24    ($conf['userewrite']) ? $link['url'].='?s=' : $link['url'].='&amp;s=';
25    $link['url'] .= urlencode($search);
26  }
27
28  return format_link_build($link);
29}
30
31/**
32 * The loginform
33 *
34 * @author Andreas Gohr <andi@splitbrain.org>
35 */
36function html_login(){
37  global $lang;
38  global $conf;
39  global $ID;
40
41  print parsedLocale('login');
42  ?>
43    <div align="center">
44    <form action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" method="post">
45      <fieldset>
46        <legend><?=$lang['btn_login']?></legend>
47        <input type="hidden" name="id" value="<?=$ID?>" />
48        <input type="hidden" name="do" value="login" />
49        <label>
50          <span><?=$lang['user']?></span>
51          <input type="text" name="u" value="<?=formText($_REQUEST['u'])?>" class="edit" />
52        </label><br />
53        <label>
54          <span><?=$lang['pass']?></span>
55          <input type="password" name="p" class="edit" />
56        </label><br />
57        <input type="submit" value="<?=$lang['btn_login']?>" class="button" />
58        <label for="remember" class="simple">
59          <input type="checkbox" name="r" id="remember" value="1" />
60          <span><?=$lang['remember']?></span>
61        </label>
62      </fieldset>
63    </form>
64  <?
65    if($conf['openregister']){
66      print '<p>';
67      print $lang['reghere'];
68      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
69      print '</p>';
70    }
71  ?>
72    </div>
73  <?
74  if(@file_exists('includes/login.txt')){
75    print io_cacheParse('includes/login.txt');
76  }
77}
78
79/**
80 * shows the edit/source/show button dependent on current mode
81 *
82 * @author Andreas Gohr <andi@splitbrain.org>
83 */
84function html_editbutton(){
85  global $ID;
86  global $REV;
87  global $ACT;
88  global $INFO;
89
90  if($ACT == 'show' || $ACT == 'search'){
91    if($INFO['writable']){
92      if($INFO['exists']){
93        $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
94      }else{
95        $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
96      }
97    }else{
98      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
99    }
100  }else{
101    $r = html_btn('show',$ID,'v',array('do' => 'show'));
102  }
103  return $r;
104}
105
106/**
107 * prints a section editing button
108 *
109 * @author Andreas Gohr <andi@splitbrain.org>
110 */
111function html_secedit_button($section,$p){
112  global $ID;
113  global $lang;
114  $secedit  = '';
115  if($p) $secedit .= "</p>\n";
116  $secedit .= '<div class="secedit">';
117  $secedit .= html_btn('secedit',$ID,'',
118                        array('do'      => 'edit',
119                              'lines'   => "$section"),
120                              'post');
121  $secedit .= '</div>';
122  if($p) $secedit .= "\n<p>";
123  return $secedit;
124}
125
126/**
127 * inserts section edit buttons if wanted or removes the markers
128 *
129 * @author Andreas Gohr <andi@splitbrain.org>
130 */
131function html_secedit($text,$show=true){
132  global $INFO;
133  if($INFO['writable'] && $show){
134    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
135                         "html_secedit_button('\\1',true)",
136                         $text);
137    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
138                         "html_secedit_button('\\1',false)",
139                         $text);
140  }else{
141    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
142  }
143  return $text;
144}
145
146/**
147 * displays the breadcrumbs trace
148 *
149 * @author Andreas Gohr <andi@splitbrain.org>
150 */
151function html_breadcrumbs(){
152  global $lang;
153  global $conf;
154
155  //check if enabled
156  if(!$conf['breadcrumbs']) return;
157
158  $crumbs = breadcrumbs(); //setup crumb trace
159  print '<div class="breadcrumbs">';
160  print $lang['breadcrumb'].':';
161  foreach ($crumbs as $crumb){
162    print ' &raquo; ';
163    print '<a href="'.wl($crumb).'" class="breadcrumbs" onclick="return svchk()" onkeypress="return svchk()" title="'.$crumb.'">'.noNS($crumb).'</a>';
164  }
165  print '</div>';
166}
167
168/**
169 * display the HTML head and metadata
170 *
171 * @author Andreas Gohr <andi@splitbrain.org>
172 */
173function html_head(){
174  global $ID;
175  global $ACT;
176  global $INFO;
177  global $conf;
178  global $lang;
179
180  print '<'.'?xml version="1.0"?'.">\n";
181  print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"';
182  print ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
183  print "\n";
184?>
185  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?=$conf['lang']?>" lang="<?=$conf['lang']?>" dir="ltr">
186  <head>
187    <title><?=$ID?> [<?=$conf['title']?>]</title>
188    <meta http-equiv="Content-Type" content="text/html; charset=<?=$lang['encoding']?>" />
189    <meta name="generator" content="DokuWiki <?=DOKUWIKIVERSION?>" />
190    <link rel="stylesheet" media="screen" type="text/css" href="<?=getBaseURL()?>style.css" />
191    <link rel="stylesheet" media="print" type="text/css" href="<?=getBaseURL()?>print.css" />
192    <link rel="shortcut icon" href="<?=getBaseURL()?>images/favicon.ico" />
193    <link rel="start" href="<?=wl()?>" />
194    <link rel="contents" href="<?=wl($ID,'do=index')?>" title="<?=$lang['index']?>" />
195    <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="<?=getBaseURL()?>feed.php" />
196    <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="<?=getBaseURL()?>feed.php?mode=list&amp;ns=<?=$INFO['namespace']?>" />
197    <link rel="alternate" type="text/html" title="Plain HTML" href="<?=wl($ID,'do=export_html')?>" />
198    <link rel="alternate" type="text/plain" title="Wiki Markup" href="<?=wl($ID, 'do=export_raw')?>" />
199<?
200  if($ACT=='show' || $ACT=='export_html'){
201    if($INFO['exists']){
202      print '    <meta name="robots" content="index,follow" />'."\n";
203      print '    <meta name="date" content="'.date('Y-m-d\TH:i:sO',$INFO['lastmod']).'" />'."\n";
204    }else{
205      print '    <meta name="robots" content="noindex,follow" />'."\n";
206    }
207  }else{
208    print '    <meta name="robots" content="noindex,nofollow" />'."\n";
209  }
210?>
211
212    <script language="JavaScript" type="text/javascript">
213      var alertText   = '<?=$lang['qb_alert']?>';
214      var notSavedYet = '<?=$lang['notsavedyet']?>';
215      var baseURL     = '<?=getBaseURL()?>';
216    </script>
217    <script language="JavaScript" type="text/javascript" src="<?=getBaseURL()?>script.js"></script>
218
219    <!--[if gte IE 5]>
220    <style type="text/css">
221      /* that IE 5+ conditional comment makes this only visible in IE 5+ */
222      img { behavior: url("<?=getBaseURL()?>pngbehavior.htc"); } /* IE bugfix for transparent PNGs */
223    </style>
224    <![endif]-->
225
226    <?@include("includes/meta.html")?>
227  </head>
228<?
229}
230
231/**
232 * Displays a button (using it's own form)
233 *
234 * @author Andreas Gohr <andi@splitbrain.org>
235 */
236function html_btn($name,$id,$akey,$params,$method='get'){
237  global $conf;
238  global $lang;
239
240  $label = $lang['btn_'.$name];
241
242  $ret = '';
243
244  $id = idfilter($id);
245
246  //make nice URLs even for buttons
247  $link = getBaseURL().'/';
248  $link = preg_replace('#//$#','/',$link);
249  if(!$conf['userewrite']){
250    $script = $link.'doku.php';
251    $params['id'] = $id;
252  }else{
253    $script = $link.$id;
254  }
255
256  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'" onsubmit="return svchk()">';
257
258  reset($params);
259  while (list($key, $val) = each($params)) {
260    $ret .= '<input type="hidden" name="'.$key.'" ';
261    $ret .= 'value="'.htmlspecialchars($val).'" />';
262  }
263
264  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
265  if($akey){
266    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
267    $ret .= 'accesskey="'.$akey.'" ';
268  }
269  $ret .= '/>';
270  $ret .= '</form>';
271
272  return $ret;
273}
274
275/**
276 * Check for the given permission or prints an error
277 *
278 * @author Andreas Gohr <andi@splitbrain.org>
279 */
280function html_acl($perm){
281  global $INFO;
282  if($INFO['perm'] >= $perm) return true;
283
284  print parsedLocale('denied');
285  return false;
286}
287
288/**
289 * Displays the overall page header and calls html_head()
290 *
291 * @author Andreas Gohr <andi@splitbrain.org>
292 */
293function html_header(){
294  global $ID;
295  global $REV;
296  global $lang;
297  global $conf;
298  html_head();
299?>
300<body>
301  <div class="all">
302  <?
303    @include("includes/topheader.html");
304    html_msgarea();
305  ?>
306  <div class="stylehead">
307    <div class="header">
308      <div class="pagename">
309        [[<a href="<?=wl($ID,'do=backlink')?>" onclick="return svchk()" onkeypress="return svchk()"><?=$ID?></a>]]
310      </div>
311      <div class="logo">
312        <a href="<?=wl()?>" name="top" accesskey="h" title="[ALT+H]" onclick="return svchk()" onkeypress="return svchk()"><?=$conf['title']?></a>
313      </div>
314    </div>
315    <?@include("includes/header.html")?>
316
317    <div class="bar" id="bar_top">
318      <div class="bar-left" id="bar_topleft">
319        <?=html_editbutton()?>
320        <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
321      </div>
322
323      <div class="bar-right" id="bar_topright">
324        <?=html_btn(recent,'','r',array('do' => 'recent'))?>
325        <form action="<?=wl()?>" accept-charset="<?=$lang['encoding']?>">
326          <input type="hidden" name="do" value="search" />
327          <input type="text" name="id" class="edit" />
328          <input type="submit" value="<?=$lang['btn_search']?>" class="button" />
329        </form>&nbsp;
330      </div>
331    </div>
332
333    <?
334      flush();
335      html_breadcrumbs();
336      @include("includes/pageheader.html");
337    ?>
338  </div>
339  <div class="page">
340  <!-- wikipage start -->
341<?
342}
343
344/**
345 * display document and user info
346 *
347 * Displays some Metadata like who's logged in and the last modified
348 * date - do not confuse this with the HTML meta header.
349 *
350 * @author Andreas Gohr <andi@splitbrain.org>
351 */
352function html_metainfo(){
353  global $conf;
354  global $lang;
355  global $INFO;
356  global $REV;
357
358  $fn = $INFO['filepath'];
359  if(!$conf['fullpath']){
360    if($REV){
361      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
362    }else{
363      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
364    }
365  }
366  $date = date($conf['dformat'],$INFO['lastmod']);
367
368  print '<div class="meta">';
369  if($_SERVER['REMOTE_USER']){
370    print '<div class="user">';
371    print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
372    print '</div>';
373  }
374  print ' &nbsp; ';
375  if($INFO['exists']){
376    print $fn;
377    print ' &middot; ';
378    print $lang['lastmod'];
379    print ': ';
380    print $date;
381    if($INFO['locked']){
382      print ' &middot; ';
383      print $lang['lockedby'];
384      print ': ';
385      print $INFO['locked'];
386    }
387  }
388  print '</div>';
389}
390
391/**
392 * Diplay the overall footer
393 *
394 * @author Andreas Gohr <andi@splitbrain.org>
395 */
396function html_footer(){
397  global $ID;
398  global $REV;
399  global $INFO;
400  global $lang;
401  global $conf;
402?>
403  <!-- wikipage stop -->
404  </div>
405  <div class="clearer">&nbsp;</div>
406  <div class="stylefoot">
407    <?
408      flush();
409      @include("includes/pagefooter.html");
410      html_metainfo();
411    ?>
412    <div class="bar" id="bar_bottom">
413      <div class="bar-left" id="bar_bottomleft">
414        <?=html_editbutton()?>
415        <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
416      </div>
417
418      <div class="bar-right" id="bar_bottomright">
419        <?
420          if($conf['useacl']){
421            if($_SERVER['REMOTE_USER']){
422              print html_btn('logout',$ID,'',array('do' => 'logout',));
423            }else{
424              print html_btn('login',$ID,'',array('do' => 'login'));
425            }
426          }
427        ?>
428        <?=html_btn(index,$ID,'x',array('do' => 'index'))?>
429        <a href="#top"><input type="button" class="button" value="<?=$lang['btn_top']?>" /></a>&nbsp;
430      </div>
431    </div>
432  </div>
433  <?@include("includes/footer.html")?>
434  </div>
435  </body>
436  </html>
437<?
438}
439
440/**
441 * Print the table of contents
442 *
443 * @author Andreas Gohr <andi@splitbrain.org>
444 */
445function html_toc($toc){
446  global $lang;
447  $ret  = '';
448  $ret .= '<div class="toc">';
449  $ret .=   '<div class="tocheader">';
450  $ret .=      $lang['toc'];
451  $ret .=     ' <script type="text/javascript">';
452  $ret .=     'showTocToggle("+","-")';
453  $ret .=     '</script>';
454  $ret .=   '</div>';
455  $ret .=   '<div id="tocinside">';
456  $ret .=   html_buildlist($toc,'toc','html_list_toc');
457  $ret .=   '</div>';
458  $ret .= '</div>';
459  return $ret;
460}
461
462/**
463 * TOC item formatter
464 *
465 * User function for html_buildlist()
466 *
467 * @author Andreas Gohr <andi@splitbrain.org>
468 */
469function html_list_toc($item){
470  $ret  = '';
471  $ret .= '<a href="#'.$item['id'].'" class="toc">';
472  $ret .= $item['name'];
473  $ret .= '</a>';
474  return $ret;
475}
476
477/**
478 * show a wiki page
479 *
480 * @author Andreas Gohr <andi@splitbrain.org>
481 */
482function html_show($text=''){
483  global $ID;
484  global $REV;
485  global $HIGH;
486  //disable section editing for old revisions or in preview
487  if($text || $REV){
488    global $parser;
489    $parser['secedit'] = false;
490  }
491
492  if ($text){
493    //PreviewHeader
494    print parsedLocale('preview');
495    print '<div class="preview">';
496    print html_secedit(parse($text),false);
497    print '</div>';
498  }else{
499    if ($REV) print parsedLocale('showrev');
500    $html = parsedWiki($ID,$REV,true);
501    $html = html_secedit($html);
502    print html_hilight($html,$HIGH);
503  }
504}
505
506/**
507 * Highlights searchqueries in HTML code
508 *
509 * @author Andreas Gohr <andi@splitbrain.org>
510 */
511function html_hilight($html,$query){
512  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
513  foreach ($queries as $q){
514    $q = preg_quote($q,'/');
515    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
516  }
517  return $html;
518}
519
520/**
521 * Run a search and display the result
522 *
523 * @author Andreas Gohr <andi@splitbrain.org>
524 */
525function html_search(){
526  require_once("inc/search.php");
527  global $conf;
528  global $QUERY;
529  global $ID;
530  global $lang;
531
532  print parsedLocale('searchpage');
533  flush();
534
535  //do quick pagesearch
536  $data = array();
537  search($data,$conf['datadir'],'search_pagename',array(query => $QUERY));
538  if(count($data)){
539    sort($data);
540    print '<div class="search_quickresult">';
541    print '<b>'.$lang[quickhits].':</b><br />';
542    foreach($data as $row){
543      print '<div class="search_quickhits">';
544      print html_wikilink(':'.$row['id'],$row['id']);
545      print '</div> ';
546    }
547    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
548    print '<div class="clearer">&nbsp;</div>';
549    print '</div>';
550  }
551  flush();
552
553  //do fulltext search
554  $data = array();
555  search($data,$conf['datadir'],'search_fulltext',array(query => $QUERY));
556  if(count($data)){
557    usort($data,'sort_search_fulltext');
558    foreach($data as $row){
559      print '<div class="search_result">';
560      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
561      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
562      print '<div class="search_snippet">'.$row['snippet'].'</div>';
563      print '</div>';
564    }
565  }else{
566    print '<div align="center">'.$lang['nothingfound'].'</div>';
567  }
568}
569
570/**
571 * Display error on locked pages
572 *
573 * @author Andreas Gohr <andi@splitbrain.org>
574 */
575function html_locked($ip){
576  global $ID;
577  global $conf;
578  global $lang;
579
580  $locktime = filemtime(wikiFN($ID).'.lock');
581  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
582  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
583
584  print parsedLocale('locked');
585  print '<ul>';
586  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
587  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
588  print '</ul>';
589}
590
591/**
592 * list old revisions
593 *
594 * @author Andreas Gohr <andi@splitbrain.org>
595 */
596function html_revisions(){
597  global $ID;
598  global $INFO;
599  global $conf;
600  global $lang;
601  $revisions = getRevisions($ID);
602  $date = @date($conf['dformat'],$INFO['lastmod']);
603
604  print parsedLocale('revisions');
605  print '<ul>';
606  if($INFO['exists']){
607    print '<li>'.$date.' <a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ('.$lang['current'].')</li>';
608  }
609
610  foreach($revisions as $rev){
611    $date = date($conf['dformat'],$rev);
612    print '<li>';
613    print $date.' <a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
614    print '<a href="'.wl($ID,"rev=$rev,do=diff").'">['.$lang['diff'].']</a>';
615    print '</li>';
616  }
617  print '</ul>';
618}
619
620/**
621 * display recent changes
622 *
623 * @author Andreas Gohr <andi@splitbrain.org>
624 */
625function html_recent(){
626  global $conf;
627  $recents = getRecents(0,true);
628
629  print parsedLocale('recent');
630  print '<ul>';
631  foreach(array_keys($recents) as $id){
632    $date = date($conf['dformat'],$recents[$id]['date']);
633    print '<li>';
634    print $date.' '.html_wikilink($id,$id);
635    print ' '.htmlspecialchars($recents[$id]['sum']);
636    print ' <span class="user">(';
637    print $recents[$id]['ip'];
638    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
639    print ')</span>';
640    print '</li>';
641  }
642  print '</ul>';
643}
644
645/**
646 * Display page index
647 *
648 * @author Andreas Gohr <andi@splitbrain.org>
649 */
650function html_index($ns){
651  require_once("inc/search.php");
652  global $conf;
653  global $ID;
654  $dir = $conf['datadir'];
655  $ns  = cleanID($ns);
656  if(empty($ns)){
657    $ns = dirname(str_replace(':','/',$ID));
658    if($ns == '.') $ns ='';
659  }
660  $ns  = str_replace(':','/',$ns);
661
662  print parsedLocale('index');
663
664  $data = array();
665  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
666  print html_buildlist($data,'idx','html_list_index');
667}
668
669/**
670 * Index item formatter
671 *
672 * User function for html_buildlist()
673 *
674 * @author Andreas Gohr <andi@splitbrain.org>
675 */
676function html_list_index($item){
677  $ret = '';
678  $base = ':'.$item['id'];
679  $base = substr($base,strrpos($base,':')+1);
680  if($item['type']=='d'){
681    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
682    $ret .= $base;
683    $ret .= '</a>';
684  }else{
685    $ret .= html_wikilink(':'.$item['id']);
686  }
687  return $ret;
688}
689
690/**
691 * Build an unordered list
692 *
693 * Build an unordered list from the given $data array
694 * Each item in the array has to have a 'level' property
695 * the item itself gets printed by the given $func user
696 * function
697 *
698 * @author Andreas Gohr <andi@splitbrain.org>
699 */
700function html_buildlist($data,$class,$func){
701  $level = 0;
702  $opens = 0;
703  $ret   = '';
704
705  foreach ($data as $item){
706
707    if( $item['level'] > $level ){
708      //open new list
709      $ret .= "\n<ul class=\"$class\">\n";
710    }elseif( $item['level'] < $level ){
711      //close last item
712      $ret .= "</li>\n";
713      for ($i=0; $i<($level - $item['level']); $i++){
714        //close higher lists
715        $ret .= "</ul>\n</li>\n";
716      }
717    }else{
718      //close last item
719      $ret .= "</li>\n";
720    }
721
722    //remember current level
723    $level = $item['level'];
724
725    //print item
726    $ret .= '<li class="level'.$item['level'].'">';
727    $ret .= '<span class="li">';
728    $ret .= $func($item); //user function
729    $ret .= '</span>';
730  }
731
732  //close remaining items and lists
733  for ($i=0; $i < $level; $i++){
734    $ret .= "</li></ul>\n";
735  }
736
737  return $ret;
738}
739
740/**
741 * display backlinks
742 *
743 * @author Andreas Gohr <andi@splitbrain.org>
744 */
745function html_backlinks(){
746  require_once("inc/search.php");
747  global $ID;
748  global $conf;
749
750  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
751    $opts['ns']   = $matches[1];
752    $opts['name'] = $matches[2];
753  }else{
754    $opts['ns']   = '';
755    $opts['name'] = $ID;
756  }
757
758  print parsedLocale('backlinks');
759
760  $data = array();
761  search($data,$conf['datadir'],'search_backlinks',$opts);
762  sort($data);
763
764  print '<ul class="idx">';
765  foreach($data as $row){
766    print '<li>';
767    print html_wikilink(':'.$row['id'],$row['id']);
768    print '</li>';
769  }
770  print '</ul>';
771}
772
773/**
774 * show diff
775 *
776 * @author Andreas Gohr <andi@splitbrain.org>
777 */
778function html_diff($text='',$intro=true){
779  require_once("inc/DifferenceEngine.php");
780  global $ID;
781  global $REV;
782  global $lang;
783  global $conf;
784  if($text){
785    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
786                    split("\n",htmlspecialchars(cleanText($text))));
787    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
788              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
789              $lang['current'];
790    $right = $lang['yours'];
791  }else{
792    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
793                    split("\n",htmlspecialchars(rawWiki($ID,''))));
794    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
795              $ID.' '.date($conf['dformat'],$REV).'</a>';
796    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
797              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
798              $lang['current'];
799  }
800  $tdf = new TableDiffFormatter();
801  if($intro) print parsedLocale('diff');
802  ?>
803    <table class="diff" width="100%">
804      <tr>
805        <td colspan="2" width="50%" class="diff-header">
806          <?=$left?>
807        </td>
808        <td colspan="2" width="50%" class="diff-header">
809          <?=$right?>
810        </td>
811      </tr>
812      <?=$tdf->format($df)?>
813    </table>
814  <?
815}
816
817/**
818 * show warning on conflict detection
819 *
820 * @author Andreas Gohr <andi@splitbrain.org>
821 */
822function html_conflict($text,$summary){
823  global $ID;
824  global $lang;
825
826  print parsedLocale('conflict');
827  ?>
828  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
829  <input type="hidden" name="id" value="<?=$ID?>" />
830  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
831  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
832
833  <div align="center">
834    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
835    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
836  </div>
837  </form>
838  <br /><br /><br /><br />
839  <?
840}
841
842/**
843 * Prints the global message array
844 *
845 * @author Andreas Gohr <andi@splitbrain.org>
846 */
847function html_msgarea(){
848  global $MSG;
849
850  if(!isset($MSG)) return;
851
852  foreach($MSG as $msg){
853    print '<div class="'.$msg['lvl'].'">';
854    print $msg['msg'];
855    print '</div>';
856  }
857}
858
859/**
860 * Prints the registration form
861 *
862 * @author Andreas Gohr <andi@splitbrain.org>
863 */
864function html_register(){
865  global $lang;
866  global $ID;
867
868  print parsedLocale('register');
869?>
870  <div align="center">
871  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
872  <input type="hidden" name="do" value="register" />
873  <input type="hidden" name="save" value="1" />
874  <fieldset>
875    <legend><?=$lang['register']?></legend>
876    <label>
877      <?=$lang['user']?>
878      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
879    </label><br />
880    <label>
881      <?=$lang['fullname']?>
882      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
883    </label><br />
884    <label>
885      <?=$lang['email']?>
886      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
887    </label><br />
888    <input type="submit" class="button" value="<?=$lang['register']?>" />
889  </fieldset>
890  </form>
891  </div>
892<?
893}
894
895/**
896 * This displays the edit form (lots of logic included)
897 *
898 * @author Andreas Gohr <andi@splitbrain.org>
899 */
900function html_edit($text=null,$include='edit'){ //FIXME: include needed?
901  global $ID;
902  global $REV;
903  global $DATE;
904  global $RANGE;
905  global $PRE;
906  global $SUF;
907  global $INFO;
908  global $SUM;
909  global $lang;
910  global $conf;
911
912  //check for create permissions first
913  if(!$INFO['exists'] && !html_acl(AUTH_CREATE)) return;
914
915  //set summary default
916  if(!$SUM){
917    if($REV){
918      $SUM = $lang['restored'];
919    }elseif(!$INFO['exists']){
920      $SUM = $lang['created'];
921    }
922  }
923
924  //no text? Load it!
925  if(!isset($text)){
926    $pr = false; //no preview mode
927    if($RANGE){
928      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
929    }else{
930      $text = rawWiki($ID,$REV);
931    }
932  }else{
933    $pr = true; //preview mode
934  }
935
936  $wr = $INFO['writable'];
937  if($wr){
938    if ($REV) print parsedLocale('editrev');
939    print parsedLocale($include);
940  }else{
941    print parsedLocale('read');
942    $ro='readonly="readonly"';
943  }
944  if(!$DATE) $DATE = $INFO['lastmod'];
945?>
946  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
947  <input type="hidden" name="id"   value="<?=$ID?>" />
948  <input type="hidden" name="rev"  value="<?=$REV?>" />
949  <input type="hidden" name="date" value="<?=$DATE?>" />
950  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
951  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
952  <table style="width:99%">
953    <tr>
954      <td class="toolbar" colspan="3">
955        <?if($wr){?>
956        <script language="JavaScript" type="text/javascript">
957          <?/* sets changed to true when previewed */?>
958          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
959
960          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
961          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
962          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
963          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
964
965          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
966          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
967          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
968          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
969          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
970
971          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
972          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
973
974          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
975          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
976
977          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
978          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
979
980          <?
981          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
982            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
983          }
984          ?>
985        </script>
986        <?}?>
987      </td>
988    </tr>
989    <tr>
990      <td colspan="3">
991        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" tabindex="1"><?="\n".formText($text)?></textarea>
992      </td>
993    </tr>
994    <tr>
995      <td>
996      <?if($wr){?>
997        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
998        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
999        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
1000      <?}?>
1001      </td>
1002      <td>
1003      <?if($wr){?>
1004        <?=$lang['summary']?>:
1005        <input type="text" class="edit" name="summary" size="50" value="<?=formText($SUM)?>" tabindex="2" />
1006      <?}?>
1007      </td>
1008      <td align="right">
1009        <script type="text/javascript">
1010          showSizeCtl();
1011          <?if($wr){?>
1012            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
1013            document.editform.wikitext.focus();
1014          <?}?>
1015        </script>
1016      </td>
1017    </tr>
1018  </table>
1019  </form>
1020<?
1021}
1022
1023/**
1024 * prepares the signature string as configured in the config
1025 *
1026 * @author Andreas Gohr <andi@splitbrain.org>
1027 */
1028function html_signature(){
1029  global $conf;
1030  global $INFO;
1031
1032  $sig = $conf['signature'];
1033  $sig = strftime($sig);
1034  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
1035  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
1036  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
1037  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
1038  return $sig;
1039}
1040
1041/**
1042 * prints some debug info
1043 *
1044 * @author Andreas Gohr <andi@splitbrain.org>
1045 */
1046function html_debug(){
1047  global $conf;
1048
1049  print '<html><body>';
1050
1051  print '<p>When reporting bugs please send all the following ';
1052  print 'output as a mail to andi@splitbrain.org ';
1053  print 'The best way to do this is to save this page in your browser</p>';
1054
1055  print '<b>$_SERVER:</b><pre>';
1056  print_r($_SERVER);
1057  print '</pre>';
1058
1059  print '<b>$conf:</b><pre>';
1060  print_r($conf);
1061  print '</pre>';
1062
1063  print '<b>abs baseURL:</b><pre>';
1064  print getBaseURL(true);
1065  print '</pre>';
1066
1067  print '<b>rel baseURL:</b><pre>';
1068  print dirname($_SERVER['PHP_SELF']).'/';
1069  print '</pre>';
1070
1071  print '<b>PHP Version:</b><pre>';
1072  print phpversion();
1073  print '</pre>';
1074
1075  print '<b>locale:</b><pre>';
1076  print setlocale(LC_ALL,0);
1077  print '</pre>';
1078
1079  print '<b>Environment:</b><pre>';
1080  print_r($_ENV);
1081  print '</pre>';
1082
1083  print '<b>PHP settings:</b><pre>';
1084  $inis = ini_get_all();
1085  print_r($inis);
1086  print '</pre>';
1087
1088  print '</body></html>';
1089}
1090
1091?>
1092