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