xref: /dokuwiki/inc/html.php (revision 15fae1076f4439c7cd1302494a48e24f707a3020)
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 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    html_msgarea();
304    @include("includes/topheader.html")
305  ?>
306  <div class="header">
307    <div class="pagename">
308      [[<a href="<?=wl($ID,'do=backlink')?>" onclick="return svchk()" onkeypress="return svchk()"><?=$ID?></a>]]
309    </div>
310    <div class="logo">
311      <a href="<?=wl()?>" name="top" accesskey="h" title="[ALT+H]" onclick="return svchk()" onkeypress="return svchk()"><?=$conf['title']?></a>
312    </div>
313  </div>
314  <?@include("includes/header.html")?>
315
316  <div class="bar" id="bar_top">
317    <div class="bar-left" id="bar_topleft">
318      <?=html_editbutton()?>
319      <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
320    </div>
321
322    <div class="bar-right" id="bar_topright">
323      <?=html_btn(recent,'','r',array('do' => 'recent'))?>
324      <form action="<?=wl()?>" accept-charset="<?=$lang['encoding']?>">
325      <input type="hidden" name="do" value="search" />
326      <input type="text" name="id" class="edit" />
327			<input type="submit" value="<?=$lang['btn_search']?>" class="button" />
328      </form>&nbsp;
329    </div>
330  </div>
331
332  <?
333    flush();
334    html_breadcrumbs();
335    @include("includes/pageheader.html");
336  ?>
337  <div class="page">
338  <!-- wikipage start -->
339<?
340}
341
342/**
343 * display document and user info
344 *
345 * Displays some Metadata like who's logged in and the last modified
346 * date - do not confuse this with the HTML meta header.
347 *
348 * @author Andreas Gohr <andi@splitbrain.org>
349 */
350function html_metainfo(){
351  global $conf;
352  global $lang;
353  global $INFO;
354  global $REV;
355
356  $fn = $INFO['filepath'];
357  if(!$conf['fullpath']){
358    if($REV){
359      $fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
360    }else{
361      $fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
362    }
363  }
364  $date = date($conf['dformat'],$INFO['lastmod']);
365
366  print '<div class="meta">';
367  if($_SERVER['REMOTE_USER']){
368    print '<div class="user">';
369    print $lang['loggedinas'].': '.$_SERVER['REMOTE_USER'];
370    print '</div>';
371  }
372  print ' &nbsp; ';
373  if($INFO['exists']){
374    print $fn;
375    print ' &middot; ';
376    print $lang['lastmod'];
377    print ': ';
378    print $date;
379    if($INFO['locked']){
380      print ' &middot; ';
381      print $lang['lockedby'];
382      print ': ';
383      print $INFO['locked'];
384    }
385  }
386  print '</div>';
387}
388
389/**
390 * Diplay the overall footer
391 *
392 * @author Andreas Gohr <andi@splitbrain.org>
393 */
394function html_footer(){
395  global $ID;
396  global $REV;
397  global $INFO;
398  global $lang;
399  global $conf;
400?>
401  <!-- wikipage stop -->
402  </div>
403  <div class="clearer">&nbsp;</div>
404  <?
405    flush();
406    @include("includes/pagefooter.html");
407    html_metainfo();
408  ?>
409  <div class="bar" id="bar_bottom">
410    <div class="bar-left" id="bar_bottomleft">
411      <?=html_editbutton()?>
412      <?=html_btn(revs,$ID,'r',array('do' => 'revisions'))?>
413    </div>
414
415    <div class="bar-right" id="bar_bottomright">
416      <?
417        if($conf['useacl']){
418          if($_SERVER['REMOTE_USER']){
419            print html_btn('logout',$ID,'',array('do' => 'logout',));
420          }else{
421            print html_btn('login',$ID,'',array('do' => 'login'));
422          }
423        }
424      ?>
425      <?=html_btn(index,$ID,'x',array('do' => 'index'))?>
426      <a href="#top"><input type="button" class="button" value="<?=$lang['btn_top']?>" /></a>&nbsp;
427    </div>
428  </div>
429  <?@include("includes/footer.html")?>
430  </div>
431  </body>
432  </html>
433<?
434}
435
436/**
437 * Print the table of contents
438 *
439 * @author Andreas Gohr <andi@splitbrain.org>
440 */
441function html_toc($toc){
442  global $lang;
443  $ret  = '';
444  $ret .= '<div class="toc">';
445  $ret .=   '<div class="tocheader">';
446  $ret .=      $lang['toc'];
447  $ret .=     ' <script type="text/javascript">';
448  $ret .=     'showTocToggle("+","-")';
449  $ret .=     '</script>';
450  $ret .=   '</div>';
451  $ret .=   '<div id="tocinside">';
452  $ret .=   html_buildlist($toc,'toc','html_list_toc');
453  $ret .=   '</div>';
454  $ret .= '</div>';
455  return $ret;
456}
457
458/**
459 * TOC item formatter
460 *
461 * User function for html_buildlist()
462 *
463 * @author Andreas Gohr <andi@splitbrain.org>
464 */
465function html_list_toc($item){
466  $ret  = '';
467  $ret .= '<a href="#'.$item['id'].'" class="toc">';
468  $ret .= $item['name'];
469  $ret .= '</a>';
470  return $ret;
471}
472
473/**
474 * show a wiki page
475 *
476 * @author Andreas Gohr <andi@splitbrain.org>
477 */
478function html_show($text=''){
479  global $ID;
480  global $REV;
481  global $HIGH;
482  //disable section editing for old revisions or in preview
483  if($text || $REV){
484    global $parser;
485    $parser['secedit'] = false;
486  }
487
488  if ($text){
489    //PreviewHeader
490    print parsedLocale('preview');
491    print '<div class="preview">';
492    print html_secedit(parse($text),false);
493    print '</div>';
494  }else{
495    if ($REV) print parsedLocale('showrev');
496    $html = parsedWiki($ID,$REV,true);
497    $html = html_secedit($html);
498    print html_hilight($html,$HIGH);
499  }
500}
501
502/**
503 * Highlights searchqueries in HTML code
504 *
505 * @author Andreas Gohr <andi@splitbrain.org>
506 */
507function html_hilight($html,$query){
508  $queries = preg_split ("/\s/",$query,-1,PREG_SPLIT_NO_EMPTY);
509  foreach ($queries as $q){
510    $q = preg_quote($q,'/');
511    $html = preg_replace("/((<[^>]*)|$q)/ie", '"\2"=="\1"? "\1":"<span class=\"search_hit\">\1</span>"', $html);
512  }
513  return $html;
514}
515
516/**
517 * Run a search and display the result
518 *
519 * @author Andreas Gohr <andi@splitbrain.org>
520 */
521function html_search(){
522  require_once("inc/search.php");
523  global $conf;
524  global $QUERY;
525  global $ID;
526  global $lang;
527
528  print parsedLocale('searchpage');
529  flush();
530
531  //do quick pagesearch
532  $data = array();
533  search($data,$conf['datadir'],'search_pagename',array(query => $QUERY));
534  if(count($data)){
535    sort($data);
536    print '<div class="search_quickresult">';
537    print '<b>'.$lang[quickhits].':</b><br />';
538    foreach($data as $row){
539      print '<div class="search_quickhits">';
540      print html_wikilink(':'.$row['id'],$row['id']);
541      print '</div> ';
542    }
543    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
544    print '<div class="clearer">&nbsp;</div>';
545    print '</div>';
546  }
547  flush();
548
549  //do fulltext search
550  $data = array();
551  search($data,$conf['datadir'],'search_fulltext',array(query => $QUERY));
552  if(count($data)){
553    usort($data,'sort_search_fulltext');
554    foreach($data as $row){
555      print '<div class="search_result">';
556      print html_wikilink(':'.$row['id'],$row['id'],$QUERY);
557      print ': <span class="search_cnt">'.$row['count'].' '.$lang['hits'].'</span><br />';
558      print '<div class="search_snippet">'.$row['snippet'].'</div>';
559      print '</div>';
560    }
561  }else{
562    print '<div align="center">'.$lang['nothingfound'].'</div>';
563  }
564}
565
566/**
567 * Display error on locked pages
568 *
569 * @author Andreas Gohr <andi@splitbrain.org>
570 */
571function html_locked($ip){
572  global $ID;
573  global $conf;
574  global $lang;
575
576  $locktime = filemtime(wikiFN($ID).'.lock');
577  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
578  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
579
580  print parsedLocale('locked');
581  print '<ul>';
582  print '<li><b>'.$lang['lockedby'].':</b> '.$ip.'</li>';
583  print '<li><b>'.$lang['lockexpire'].':</b> '.$expire.' ('.$min.' min)</li>';
584  print '</ul>';
585}
586
587/**
588 * list old revisions
589 *
590 * @author Andreas Gohr <andi@splitbrain.org>
591 */
592function html_revisions(){
593  global $ID;
594  global $INFO;
595  global $conf;
596  global $lang;
597  $revisions = getRevisions($ID);
598  $date = @date($conf['dformat'],$INFO['lastmod']);
599
600  print parsedLocale('revisions');
601  print '<ul>';
602  if($INFO['exists']){
603    print '<li>'.$date.' <a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ('.$lang['current'].')</li>';
604  }
605
606  foreach($revisions as $rev){
607    $date = date($conf['dformat'],$rev);
608    print '<li>';
609    print $date.' <a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
610    print '<a href="'.wl($ID,"rev=$rev,do=diff").'">['.$lang['diff'].']</a>';
611    print '</li>';
612  }
613  print '</ul>';
614}
615
616/**
617 * display recent changes
618 *
619 * @author Andreas Gohr <andi@splitbrain.org>
620 */
621function html_recent(){
622  global $conf;
623  $recents = getRecents(0,true);
624
625  print parsedLocale('recent');
626  print '<ul>';
627  foreach(array_keys($recents) as $id){
628    $date = date($conf['dformat'],$recents[$id]['date']);
629    print '<li>';
630    print $date.' '.html_wikilink($id,$id);
631    print ' '.htmlspecialchars($recents[$id]['sum']);
632    print ' <span class="user">(';
633    print $recents[$id]['ip'];
634    if($recents[$id]['user']) print ' '.$recents[$id]['user'];
635    print ')</span>';
636    print '</li>';
637  }
638  print '</ul>';
639}
640
641/**
642 * Display page index
643 *
644 * @author Andreas Gohr <andi@splitbrain.org>
645 */
646function html_index($ns){
647  require_once("inc/search.php");
648  global $conf;
649  global $ID;
650  $dir = $conf['datadir'];
651  $ns  = cleanID($ns);
652  if(empty($ns)){
653    $ns = dirname(str_replace(':','/',$ID));
654    if($ns == '.') $ns ='';
655  }
656  $ns  = str_replace(':','/',$ns);
657
658  print parsedLocale('index');
659
660  $data = array();
661  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
662  print html_buildlist($data,'idx','html_list_index');
663}
664
665/**
666 * Index item formatter
667 *
668 * User function for html_buildlist()
669 *
670 * @author Andreas Gohr <andi@splitbrain.org>
671 */
672function html_list_index($item){
673  $ret = '';
674  $base = ':'.$item['id'];
675  $base = substr($base,strrpos($base,':')+1);
676  if($item['type']=='d'){
677    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
678    $ret .= $base;
679    $ret .= '</a>';
680  }else{
681    $ret .= html_wikilink(':'.$item['id']);
682  }
683  return $ret;
684}
685
686/**
687 * Build an unordered list
688 *
689 * Build an unordered list from the given $data array
690 * Each item in the array has to have a 'level' property
691 * the item itself gets printed by the given $func user
692 * function
693 *
694 * @author Andreas Gohr <andi@splitbrain.org>
695 */
696function html_buildlist($data,$class,$func){
697  $level = 0;
698  $opens = 0;
699  $ret   = '';
700
701  foreach ($data as $item){
702
703    if( $item['level'] > $level ){
704      //open new list
705      $ret .= "\n<ul class=\"$class\">\n";
706    }elseif( $item['level'] < $level ){
707      //close last item
708      $ret .= "</li>\n";
709      for ($i=0; $i<($level - $item['level']); $i++){
710        //close higher lists
711        $ret .= "</ul>\n</li>\n";
712      }
713    }else{
714      //close last item
715      $ret .= "</li>\n";
716    }
717
718    //remember current level
719    $level = $item['level'];
720
721    //print item
722    $ret .= '<li class="level'.$item['level'].'">';
723    $ret .= '<span class="li">';
724    $ret .= $func($item); //user function
725    $ret .= '</span>';
726  }
727
728  //close remaining items and lists
729  for ($i=0; $i < $level; $i++){
730    $ret .= "</li></ul>\n";
731  }
732
733  return $ret;
734}
735
736/**
737 * display backlinks
738 *
739 * @author Andreas Gohr <andi@splitbrain.org>
740 */
741function html_backlinks(){
742  require_once("inc/search.php");
743  global $ID;
744  global $conf;
745
746  if(preg_match('#^(.*):(.*)$#',$ID,$matches)){
747    $opts['ns']   = $matches[1];
748    $opts['name'] = $matches[2];
749  }else{
750    $opts['ns']   = '';
751    $opts['name'] = $ID;
752  }
753
754  print parsedLocale('backlinks');
755
756  $data = array();
757  search($data,$conf['datadir'],'search_backlinks',$opts);
758  sort($data);
759
760  print '<ul class="idx">';
761  foreach($data as $row){
762    print '<li>';
763    print html_wikilink(':'.$row['id'],$row['id']);
764    print '</li>';
765  }
766  print '</ul>';
767}
768
769/**
770 * show diff
771 *
772 * @author Andreas Gohr <andi@splitbrain.org>
773 */
774function html_diff($text='',$intro=true){
775  require_once("inc/DifferenceEngine.php");
776  global $ID;
777  global $REV;
778  global $lang;
779  global $conf;
780  if($text){
781    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
782                    split("\n",htmlspecialchars(cleanText($text))));
783    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
784              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
785              $lang['current'];
786    $right = $lang['yours'];
787  }else{
788    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$REV))),
789                    split("\n",htmlspecialchars(rawWiki($ID,''))));
790    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$REV").'">'.
791              $ID.' '.date($conf['dformat'],$REV).'</a>';
792    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
793              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
794              $lang['current'];
795  }
796  $tdf = new TableDiffFormatter();
797  if($intro) print parsedLocale('diff');
798  ?>
799    <table class="diff" width="100%">
800      <tr>
801        <td colspan="2" width="50%" class="diff-header">
802          <?=$left?>
803        </td>
804        <td colspan="2" width="50%" class="diff-header">
805          <?=$right?>
806        </td>
807      </tr>
808      <?=$tdf->format($df)?>
809    </table>
810  <?
811}
812
813/**
814 * show warning on conflict detection
815 *
816 * @author Andreas Gohr <andi@splitbrain.org>
817 */
818function html_conflict($text,$summary){
819  global $ID;
820  global $lang;
821
822  print parsedLocale('conflict');
823  ?>
824  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>">
825  <input type="hidden" name="id" value="<?=$ID?>" />
826  <input type="hidden" name="wikitext" value="<?=formText($text)?>" />
827  <input type="hidden" name="summary" value="<?=formText($summary)?>" />
828
829  <div align="center">
830    <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
831    <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" />
832  </div>
833  </form>
834  <br /><br /><br /><br />
835  <?
836}
837
838/**
839 * Prints the global message array
840 *
841 * @author Andreas Gohr <andi@splitbrain.org>
842 */
843function html_msgarea(){
844  global $MSG;
845
846  if(!isset($MSG)) return;
847
848  foreach($MSG as $msg){
849    print '<div class="'.$msg['lvl'].'">';
850    print $msg['msg'];
851    print '</div>';
852  }
853}
854
855/**
856 * Prints the registration form
857 *
858 * @author Andreas Gohr <andi@splitbrain.org>
859 */
860function html_register(){
861  global $lang;
862  global $ID;
863
864  print parsedLocale('register');
865?>
866  <div align="center">
867  <form name="register" method="post" action="<?=wl($ID)?>" accept-charset="<?=$lang['encoding']?>">
868  <input type="hidden" name="do" value="register" />
869  <input type="hidden" name="save" value="1" />
870  <fieldset>
871    <legend><?=$lang['register']?></legend>
872    <label>
873      <?=$lang['user']?>
874      <input type="text" name="login" class="edit" size="50" value="<?=formText($_POST['login'])?>" />
875    </label><br />
876    <label>
877      <?=$lang['fullname']?>
878      <input type="text" name="fullname" class="edit" size="50" value="<?=formText($_POST['fullname'])?>" />
879    </label><br />
880    <label>
881      <?=$lang['email']?>
882      <input type="text" name="email" class="edit" size="50" value="<?=formText($_POST['email'])?>" />
883    </label><br />
884    <input type="submit" class="button" value="<?=$lang['register']?>" />
885  </fieldset>
886  </form>
887  </div>
888<?
889}
890
891/**
892 * This displays the edit form (lots of logic included)
893 *
894 * @author Andreas Gohr <andi@splitbrain.org>
895 */
896function html_edit($text=null,$include='edit'){ //FIXME: include needed?
897  global $ID;
898  global $REV;
899  global $DATE;
900  global $RANGE;
901  global $PRE;
902  global $SUF;
903  global $INFO;
904  global $SUM;
905  global $lang;
906  global $conf;
907
908  //check for create permissions first
909  if(!$INFO['exists'] && !html_acl(AUTH_CREATE)) return;
910
911  //set summary default
912  if(!$SUM){
913    if($REV){
914      $SUM = $lang['restored'];
915    }elseif(!$INFO['exists']){
916      $SUM = $lang['created'];
917    }
918  }
919
920  //no text? Load it!
921  if(!isset($text)){
922    $pr = false; //no preview mode
923    if($RANGE){
924      list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
925    }else{
926      $text = rawWiki($ID,$REV);
927    }
928  }else{
929    $pr = true; //preview mode
930  }
931
932  $wr = $INFO['writable'];
933  if($wr){
934    if ($REV) print parsedLocale('editrev');
935    print parsedLocale($include);
936  }else{
937    print parsedLocale('read');
938    $ro='readonly="readonly"';
939  }
940  if(!$DATE) $DATE = $INFO['lastmod'];
941?>
942  <form name="editform" method="post" action="<?=script()?>" accept-charset="<?=$lang['encoding']?>" onsubmit="return svchk()">
943  <input type="hidden" name="id"   value="<?=$ID?>" />
944  <input type="hidden" name="rev"  value="<?=$REV?>" />
945  <input type="hidden" name="date" value="<?=$DATE?>" />
946  <input type="hidden" name="prefix" value="<?=formText($PRE)?>" />
947  <input type="hidden" name="suffix" value="<?=formText($SUF)?>" />
948  <table style="width:99%">
949    <tr>
950      <td class="toolbar" colspan="3">
951        <?if($wr){?>
952        <script language="JavaScript" type="text/javascript">
953          <?/* sets changed to true when previewed */?>
954          textChanged = <? ($pr) ? print 'true' : print 'false' ?>;
955
956          formatButton('images/bold.png','<?=$lang['qb_bold']?>','**','**','<?=$lang['qb_bold']?>','b');
957          formatButton('images/italic.png','<?=$lang['qb_italic']?>',"\/\/","\/\/",'<?=$lang['qb_italic']?>','i');
958          formatButton('images/underline.png','<?=$lang['qb_underl']?>','__','__','<?=$lang['qb_underl']?>','u');
959          formatButton('images/code.png','<?=$lang['qb_code']?>','\'\'','\'\'','<?=$lang['qb_code']?>','c');
960
961          formatButton('images/fonth1.png','<?=$lang['qb_h1']?>','====== ',' ======\n','<?=$lang['qb_h1']?>','1');
962          formatButton('images/fonth2.png','<?=$lang['qb_h2']?>','===== ',' =====\n','<?=$lang['qb_h2']?>','2');
963          formatButton('images/fonth3.png','<?=$lang['qb_h3']?>','==== ',' ====\n','<?=$lang['qb_h3']?>','3');
964          formatButton('images/fonth4.png','<?=$lang['qb_h4']?>','=== ',' ===\n','<?=$lang['qb_h4']?>','4');
965          formatButton('images/fonth5.png','<?=$lang['qb_h5']?>','== ',' ==\n','<?=$lang['qb_h5']?>','5');
966
967          formatButton('images/link.png','<?=$lang['qb_link']?>','[[',']]','<?=$lang['qb_link']?>','l');
968          formatButton('images/extlink.png','<?=$lang['qb_extlink']?>','[[',']]','http://www.example.com|<?=$lang['qb_extlink']?>');
969
970          formatButton('images/list.png','<?=$lang['qb_ol']?>','  - ','\n','<?=$lang['qb_ol']?>');
971          formatButton('images/list_ul.png','<?=$lang['qb_ul']?>','  * ','\n','<?=$lang['qb_ul']?>');
972
973          insertButton('images/rule.png','<?=$lang['qb_hr']?>','----\n');
974          mediaButton('images/image.png','<?=$lang['qb_media']?>','m','<?=$INFO['namespace']?>');
975
976					<?
977          if($conf['useacl'] && $_SERVER['REMOTE_USER']){
978            echo "insertButton('images/sig.png','".$lang['qb_sig']."','".html_signature()."','y');";
979          }
980          ?>
981        </script>
982        <?}?>
983      </td>
984    </tr>
985    <tr>
986      <td colspan="3">
987        <textarea name="wikitext" id="wikitext" <?=$ro?> cols="80" rows="10" class="edit" onchange="textChanged = true;" tabindex="1"><?="\n".formText($text)?></textarea>
988      </td>
989    </tr>
990    <tr>
991      <td>
992      <?if($wr){?>
993        <input class="button" type="submit" name="do" value="<?=$lang['btn_save']?>" accesskey="s" title="[ALT+S]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="3" />
994        <input class="button" type="submit" name="do" value="<?=$lang['btn_preview']?>" accesskey="p" title="[ALT+P]" onclick="textChanged=false" onkeypress="textChanged=false" tabindex="4" />
995        <input class="button" type="submit" name="do" value="<?=$lang['btn_cancel']?>" tabindex="5" />
996      <?}?>
997      </td>
998      <td>
999      <?if($wr){?>
1000        <?=$lang['summary']?>:
1001        <input type="text" class="edit" name="summary" size="50" value="<?=formText($SUM)?>" tabindex="2" />
1002      <?}?>
1003      </td>
1004      <td align="right">
1005        <script type="text/javascript">
1006          showSizeCtl();
1007          <?if($wr){?>
1008            init_locktimer(<?=$conf['locktime']-60?>,'<?=$lang['willexpire']?>');
1009					  document.editform.wikitext.focus();
1010          <?}?>
1011        </script>
1012      </td>
1013    </tr>
1014  </table>
1015  </form>
1016<?
1017}
1018
1019/**
1020 * prepares the signature string as configured in the config
1021 *
1022 * @author Andreas Gohr <andi@splitbrain.org>
1023 */
1024function html_signature(){
1025  global $conf;
1026  global $INFO;
1027
1028  $sig = $conf['signature'];
1029  $sig = strftime($sig);
1030  $sig = str_replace('@USER@',$_SERVER['REMOTE_USER'],$sig);
1031  $sig = str_replace('@NAME@',$INFO['userinfo']['name'],$sig);
1032  $sig = str_replace('@MAIL@',$INFO['userinfo']['mail'],$sig);
1033  $sig = str_replace('@DATE@',date($conf['dformat']),$sig);
1034  return $sig;
1035}
1036
1037/**
1038 * prints some debug info
1039 *
1040 * @author Andreas Gohr <andi@splitbrain.org>
1041 */
1042function html_debug(){
1043  global $conf;
1044
1045  print '<html><body>';
1046
1047  print '<p>When reporting bugs please send all the following ';
1048  print 'output as a mail to andi@splitbrain.org ';
1049  print 'The best way to do this is to save this page in your browser</p>';
1050
1051  print '<b>$_SERVER:</b><pre>';
1052  print_r($_SERVER);
1053  print '</pre>';
1054
1055  print '<b>$conf:</b><pre>';
1056  print_r($conf);
1057  print '</pre>';
1058
1059  print '<b>abs baseURL:</b><pre>';
1060  print getBaseURL(true);
1061  print '</pre>';
1062
1063  print '<b>rel baseURL:</b><pre>';
1064  print dirname($_SERVER['PHP_SELF']).'/';
1065  print '</pre>';
1066
1067  print '<b>PHP Version:</b><pre>';
1068  print phpversion();
1069  print '</pre>';
1070
1071  print '<b>locale:</b><pre>';
1072  print setlocale(LC_ALL,0);
1073  print '</pre>';
1074
1075  print '<b>Environment:</b><pre>';
1076  print_r($_ENV);
1077  print '</pre>';
1078
1079  print '<b>PHP settings:</b><pre>';
1080  $inis = ini_get_all();
1081  print_r($inis);
1082  print '</pre>';
1083
1084  print '</body></html>';
1085}
1086
1087?>
1088