xref: /dokuwiki/inc/html.php (revision 96331712eb165972845b097644336ca87a81dfcd)
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 class="centeralign">
54    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
55      <fieldset>
56        <legend><?php echo $lang['btn_login']?></legend>
57        <input type="hidden" name="id" value="<?php echo $ID?>" />
58        <input type="hidden" name="do" value="login" />
59        <label class="block">
60          <span><?php echo $lang['user']?></span>
61          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" />
62        </label><br />
63        <label class="block">
64          <span><?php echo $lang['pass']?></span>
65          <input type="password" name="p" class="edit" />
66        </label><br />
67        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
68        <label for="remember" class="simple">
69          <input type="checkbox" name="r" id="remember" value="1" />
70          <span><?php echo $lang['remember']?></span>
71        </label>
72      </fieldset>
73    </form>
74  <?php
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    if (auth_canDo('modifyUser')) {
83      print '<p>';
84      print $lang['pwdforget'];
85      print ': <a href="'.wl($ID,'do=resendpwd').'" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
86      print '</p>';
87    }
88  ?>
89    </div>
90  <?php
91/*
92 FIXME provide new hook
93  if(@file_exists('includes/login.txt')){
94    print io_cacheParse('includes/login.txt');
95  }
96*/
97}
98
99/**
100 * shows the edit/source/show button dependent on current mode
101 *
102 * @author Andreas Gohr <andi@splitbrain.org>
103 */
104function html_editbutton(){
105  global $ID;
106  global $REV;
107  global $ACT;
108  global $INFO;
109
110  if($ACT == 'show' || $ACT == 'search'){
111    if($INFO['writable']){
112      if($INFO['exists']){
113        $r = html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
114      }else{
115        $r = html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
116      }
117    }else{
118      $r = html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
119    }
120  }else{
121    $r = html_btn('show',$ID,'v',array('do' => 'show'));
122  }
123  return $r;
124}
125
126/**
127 * prints a section editing button
128 *
129 * @author Andreas Gohr <andi@splitbrain.org>
130 */
131function html_secedit_button($section,$p){
132  global $ID;
133  global $lang;
134  $secedit  = '';
135#  if($p) $secedit .= "</p>\n";
136  $secedit .= '<div class="secedit">';
137  $secedit .= html_btn('secedit',$ID,'',
138                        array('do'      => 'edit',
139                              'lines'   => "$section"),
140                              'post');
141  $secedit .= '</div>';
142#  if($p) $secedit .= "\n<p>";
143  return $secedit;
144}
145
146/**
147 * inserts section edit buttons if wanted or removes the markers
148 *
149 * @author Andreas Gohr <andi@splitbrain.org>
150 */
151function html_secedit($text,$show=true){
152  global $INFO;
153  if($INFO['writable'] && $show && !$INFO['rev']){
154    $text = preg_replace('#<!-- SECTION \[(\d+-\d+)\] -->#e',
155                         "html_secedit_button('\\1',true)",
156                         $text);
157    $text = preg_replace('#<!-- SECTION \[(\d+-)\] -->#e',
158                         "html_secedit_button('\\1',false)",
159                         $text);
160  }else{
161    $text = preg_replace('#<!-- SECTION \[(\d*-\d*)\] -->#e','',$text);
162  }
163  return $text;
164}
165
166/**
167 * Just the back to top button (in its own form)
168 *
169 * @author Andreas Gohr <andi@splitbrain.org>
170 */
171function html_topbtn(){
172  global $lang;
173
174  $ret  = '';
175  $ret  = '<a href="#top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" /></a>';
176
177  return $ret;
178}
179
180/**
181 * Just the back to media window button in its own form
182 *
183 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
184 */
185function html_backtomedia_button($params,$akey=''){
186  global $conf;
187  global $lang;
188
189  $ret = '<form class="button" method="get" action="'.DOKU_BASE.'lib/exe/media.php"><div class="no">';
190
191  reset($params);
192  while (list($key, $val) = each($params)) {
193    $ret .= '<input type="hidden" name="'.$key.'" ';
194    $ret .= 'value="'.htmlspecialchars($val).'" />';
195  }
196
197  $ret .= '<input type="submit" value="'.htmlspecialchars($lang['btn_backtomedia']).'" class="button" ';
198  if($akey){
199    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
200    $ret .= 'accesskey="'.$akey.'" ';
201  }
202  $ret .= '/>';
203  $ret .= '</div></form>';
204
205  return $ret;
206}
207
208/**
209 * Displays a button (using its own form)
210 *
211 * @author Andreas Gohr <andi@splitbrain.org>
212 */
213function html_btn($name,$id,$akey,$params,$method='get'){
214  global $conf;
215  global $lang;
216
217  $label = $lang['btn_'.$name];
218
219  $ret = '';
220
221  //filter id (without urlencoding)
222  $id = idfilter($id,false);
223
224  //make nice URLs even for buttons
225  if($conf['userewrite'] == 2){
226    $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
227  }elseif($conf['userewrite']){
228    $script = DOKU_BASE.$id;
229  }else{
230    $script = DOKU_BASE.DOKU_SCRIPT;
231    $params['id'] = $id;
232  }
233
234  $ret .= '<form class="button" method="'.$method.'" action="'.$script.'"><div class="no">';
235
236  reset($params);
237  while (list($key, $val) = each($params)) {
238    $ret .= '<input type="hidden" name="'.$key.'" ';
239    $ret .= 'value="'.htmlspecialchars($val).'" />';
240  }
241
242  $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
243  if($akey){
244    $ret .= 'title="ALT+'.strtoupper($akey).'" ';
245    $ret .= 'accesskey="'.$akey.'" ';
246  }
247  $ret .= '/>';
248  $ret .= '</div></form>';
249
250  return $ret;
251}
252
253/**
254 * show a wiki page
255 *
256 * @author Andreas Gohr <andi@splitbrain.org>
257 */
258function html_show($txt=''){
259  global $ID;
260  global $REV;
261  global $HIGH;
262  //disable section editing for old revisions or in preview
263  if($txt || $REV){
264    $secedit = false;
265  }else{
266    $secedit = true;
267  }
268
269  if ($txt){
270    //PreviewHeader
271    print p_locale_xhtml('preview');
272    print '<div class="preview">';
273    print html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
274    print '</div>';
275
276  }else{
277    if ($REV) print p_locale_xhtml('showrev');
278    $html = p_wiki_xhtml($ID,$REV,true);
279    $html = html_secedit($html,$secedit);
280    print html_hilight($html,$HIGH);
281  }
282}
283
284/**
285 * Highlights searchqueries in HTML code
286 *
287 * @author Andreas Gohr <andi@splitbrain.org>
288 * @author Harry Fuecks <hfuecks@gmail.com>
289 */
290function html_hilight($html,$query){
291  //split at common delimiters
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_callback("/((<[^>]*)|$q)/i",'html_hilight_callback',$html);
296  }
297  return $html;
298}
299
300/**
301 * Callback used by html_hilight()
302 *
303 * @author Harry Fuecks <hfuecks@gmail.com>
304 */
305function html_hilight_callback($m) {
306  $hlight = unslash($m[0]);
307  if ( !isset($m[2])) {
308    $hlight = '<span class="search_hit">'.$hlight.'</span>';
309  }
310  return $hlight;
311}
312
313/**
314 * Run a search and display the result
315 *
316 * @author Andreas Gohr <andi@splitbrain.org>
317 */
318function html_search(){
319  require_once(DOKU_INC.'inc/search.php');
320  require_once(DOKU_INC.'inc/fulltext.php');
321  global $conf;
322  global $QUERY;
323  global $ID;
324  global $lang;
325
326  print p_locale_xhtml('searchpage');
327  flush();
328
329  //show progressbar
330  print '<div class="centeralign">';
331  print '<script type="text/javascript" charset="utf-8">';
332  print 'showLoadBar();';
333  print '</script>';
334  print '<br /></div>';
335
336  //do quick pagesearch
337  $data = array();
338  $data = ft_pageLookup(cleanID($QUERY));
339  if(count($data)){
340    sort($data);
341    print '<div class="search_quickresult">';
342    print '<strong>'.$lang[quickhits].':</strong><br />';
343    foreach($data as $id){
344      print '<div class="search_quickhits">';
345      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id);
346      print '</div> ';
347    }
348    //clear float (see http://www.complexspiral.com/publications/containing-floats/)
349    print '<div class="clearer">&nbsp;</div>';
350    print '</div>';
351  }
352  flush();
353
354  //do fulltext search
355  $data = ft_pageSearch($QUERY,$poswords);
356  if(count($data)){
357    $num = 1;
358    foreach($data as $id => $cnt){
359      print '<div class="search_result">';
360      print html_wikilink(':'.$id,$conf['useheading']?NULL:$id,$poswords);
361      print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
362      if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
363        print '<div class="search_snippet">'.ft_snippet($id,$poswords).'</div>';
364      }
365      print '</div>';
366      flush();
367      $num++;
368    }
369  }else{
370    print '<div class="nothing">'.$lang['nothingfound'].'</div>';
371  }
372
373  //hide progressbar
374  print '<script type="text/javascript" charset="utf-8">';
375  print 'hideLoadBar();';
376  print '</script>';
377}
378
379/**
380 * Display error on locked pages
381 *
382 * @author Andreas Gohr <andi@splitbrain.org>
383 */
384function html_locked(){
385  global $ID;
386  global $conf;
387  global $lang;
388  global $INFO;
389
390  $locktime = filemtime(wikiFN($ID).'.lock');
391  $expire = @date($conf['dformat'], $locktime + $conf['locktime'] );
392  $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
393
394  print p_locale_xhtml('locked');
395  print '<ul>';
396  print '<li><strong>'.$lang['lockedby'].':</strong> '.$INFO['locked'].'</li>';
397  print '<li><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</li>';
398  print '</ul>';
399}
400
401/**
402 * list old revisions
403 *
404 * @author Andreas Gohr <andi@splitbrain.org>
405 */
406function html_revisions(){
407  global $ID;
408  global $INFO;
409  global $conf;
410  global $lang;
411  $revisions = getRevisions($ID);
412  $date = @date($conf['dformat'],$INFO['lastmod']);
413
414  print p_locale_xhtml('revisions');
415  print '<ul>';
416  if($INFO['exists']){
417    print ($INFO['minor']) ? '<li class="minor">' : '<li>';
418
419    print $date;
420
421    print ' <img src="'.DOKU_BASE.'lib/images/blank.gif" border="0" width="15" height="11" alt="" /> ';
422
423    print '<a class="wikilink1" href="'.wl($ID).'">'.$ID.'</a> ';
424
425    print $INFO['sum'];
426    print ' <span class="user">';
427    print $INFO['editor'];
428    print '</span> ';
429
430    print '('.$lang['current'].')';
431    print '</li>';
432  }
433
434  foreach($revisions as $rev){
435    $date = date($conf['dformat'],$rev);
436    $info = getRevisionInfo($ID,$rev);
437
438    print ($info['minor']) ? '<li class="minor">' : '<li>';
439    print $date;
440
441    print ' <a href="'.wl($ID,"rev=$rev,do=diff").'">';
442    $p = array();
443    $p['src']    = DOKU_BASE.'lib/images/diff.png';
444    $p['border'] = 0;
445    $p['width']  = 15;
446    $p['height'] = 11;
447    $p['title']  = $lang['diff'];
448    $p['alt']    = $lang['diff'];
449    $att = buildAttributes($p);
450    print "<img $att />";
451    print '</a> ';
452
453    print '<a class="wikilink1" href="'.wl($ID,"rev=$rev").'">'.$ID.'</a> ';
454
455    print htmlspecialchars($info['sum']);
456    print ' <span class="user">';
457    if($info['user']){
458      print $info['user'];
459    }else{
460      print $info['ip'];
461    }
462    print '</span>';
463
464    print '</li>';
465  }
466  print '</ul>';
467}
468
469/**
470 * display recent changes
471 *
472 * @author Andreas Gohr <andi@splitbrain.org>
473 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
474 */
475function html_recent($first=0){
476  global $conf;
477  global $lang;
478  global $ID;
479  /* we need to get one additionally log entry to be able to
480   * decide if this is the last page or is there another one.
481   * This is the cheapest solution to get this information.
482   */
483  $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
484  if(count($recents) == 0 && $first != 0){
485    $first=0;
486    $recents = getRecents(0,$conf['recent'] + 1,getNS($ID));
487  }
488  $cnt = count($recents) <= $conf['recent'] ? count($recents) : $conf['recent'];
489
490  print p_locale_xhtml('recent');
491  print '<ul>';
492
493  foreach($recents as $recent){
494    $date = date($conf['dformat'],$recent['date']);
495    print ($recent['minor']) ? '<li class="minor">' : '<li>';
496
497    print $date.' ';
498
499    print '<a href="'.wl($recent['id'],"do=diff").'">';
500    $p = array();
501    $p['src']    = DOKU_BASE.'lib/images/diff.png';
502    $p['border'] = 0;
503    $p['width']  = 15;
504    $p['height'] = 11;
505    $p['title']  = $lang['diff'];
506    $p['alt']    = $lang['diff'];
507    $att = buildAttributes($p);
508    print "<img $att />";
509    print '</a> ';
510
511    print '<a href="'.wl($recent['id'],"do=revisions").'">';
512    $p = array();
513    $p['src']    = DOKU_BASE.'lib/images/history.png';
514    $p['border'] = 0;
515    $p['width']  = 12;
516    $p['height'] = 14;
517    $p['title']  = $lang['btn_revs'];
518    $p['alt']    = $lang['btn_revs'];
519    $att = buildAttributes($p);
520    print "<img $att />";
521    print '</a> ';
522
523    print html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
524    print ' '.htmlspecialchars($recent['sum']);
525
526    print ' <span class="user">';
527    if($recent['user']){
528      print $recent['user'];
529    }else{
530      print $recent['ip'];
531    }
532    print '</span>';
533
534    print '</li>';
535  }
536  print '</ul>';
537
538  print '<div class="pagenav">';
539  $last = $first + $conf['recent'];
540  if ($first > 0) {
541    $first -= $conf['recent'];
542    if ($first < 0) $first = 0;
543    print '<div class="pagenav-prev">';
544    print html_btn('newer','',"p",array('do' => 'recent', 'first' => $first));
545    print '</div>';
546  }
547  if ($conf['recent'] < count($recents)) {
548    print '<div class="pagenav-next">';
549    print html_btn('older','',"n",array('do' => 'recent', 'first' => $last));
550    print '</div>';
551  }
552  print '</div>';
553}
554
555/**
556 * Display page index
557 *
558 * @author Andreas Gohr <andi@splitbrain.org>
559 */
560function html_index($ns){
561  require_once(DOKU_INC.'inc/search.php');
562  global $conf;
563  global $ID;
564  $dir = $conf['datadir'];
565  $ns  = cleanID($ns);
566  #fixme use appropriate function
567  if(empty($ns)){
568    $ns = dirname(str_replace(':','/',$ID));
569    if($ns == '.') $ns ='';
570  }
571  $ns  = utf8_encodeFN(str_replace(':','/',$ns));
572
573  print p_locale_xhtml('index');
574
575  $data = array();
576  search($data,$conf['datadir'],'search_index',array('ns' => $ns));
577  print html_buildlist($data,'idx','html_list_index','html_li_index');
578}
579
580/**
581 * Index item formatter
582 *
583 * User function for html_buildlist()
584 *
585 * @author Andreas Gohr <andi@splitbrain.org>
586 */
587function html_list_index($item){
588  $ret = '';
589  $base = ':'.$item['id'];
590  $base = substr($base,strrpos($base,':')+1);
591  if($item['type']=='d'){
592    $ret .= '<a href="'.wl($ID,'idx='.$item['id']).'" class="idx_dir">';
593    $ret .= $base;
594    $ret .= '</a>';
595  }else{
596    $ret .= html_wikilink(':'.$item['id']);
597  }
598  return $ret;
599}
600
601/**
602 * Index List item
603 *
604 * This user function is used in html_build_lidt to build the
605 * <li> tags for namespaces when displaying the page index
606 * it gives different classes to opened or closed "folders"
607 *
608 * @author Andreas Gohr <andi@splitbrain.org>
609 */
610function html_li_index($item){
611  if($item['type'] == "f"){
612    return '<li class="level'.$item['level'].'">';
613  }elseif($item['open']){
614    return '<li class="open">';
615  }else{
616    return '<li class="closed">';
617  }
618}
619
620/**
621 * Default List item
622 *
623 * @author Andreas Gohr <andi@splitbrain.org>
624 */
625function html_li_default($item){
626  return '<li class="level'.$item['level'].'">';
627}
628
629/**
630 * Build an unordered list
631 *
632 * Build an unordered list from the given $data array
633 * Each item in the array has to have a 'level' property
634 * the item itself gets printed by the given $func user
635 * function. The second and optional function is used to
636 * print the <li> tag. Both user function need to accept
637 * a single item.
638 *
639 * @author Andreas Gohr <andi@splitbrain.org>
640 */
641function html_buildlist($data,$class,$func,$lifunc='html_li_default'){
642  $level = 0;
643  $opens = 0;
644  $ret   = '';
645
646  foreach ($data as $item){
647
648    if( $item['level'] > $level ){
649      //open new list
650      for($i=0; $i<($item['level'] - $level); $i++){
651        if ($i) $ret .= "<li class=\"clear\">\n";
652        $ret .= "\n<ul class=\"$class\">\n";
653      }
654    }elseif( $item['level'] < $level ){
655      //close last item
656      $ret .= "</li>\n";
657      for ($i=0; $i<($level - $item['level']); $i++){
658        //close higher lists
659        $ret .= "</ul>\n</li>\n";
660      }
661    }else{
662      //close last item
663      $ret .= "</li>\n";
664    }
665
666    //remember current level
667    $level = $item['level'];
668
669    //print item
670    $ret .= $lifunc($item); //user function
671    $ret .= '<span class="li">';
672    $ret .= $func($item); //user function
673    $ret .= '</span>';
674  }
675
676  //close remaining items and lists
677  for ($i=0; $i < $level; $i++){
678    $ret .= "</li></ul>\n";
679  }
680
681  return $ret;
682}
683
684/**
685 * display backlinks
686 *
687 * @author Andreas Gohr <andi@splitbrain.org>
688 */
689function html_backlinks(){
690  require_once(DOKU_INC.'inc/fulltext.php');
691  global $ID;
692  global $conf;
693
694  print p_locale_xhtml('backlinks');
695
696  $data = ft_backlinks($ID);
697
698  print '<ul class="idx">';
699  foreach($data as $blink){
700    print '<li>';
701    print html_wikilink(':'.$blink,$conf['useheading']?NULL:$blink);
702    print '</li>';
703  }
704  print '</ul>';
705}
706
707/**
708 * show diff
709 *
710 * @author Andreas Gohr <andi@splitbrain.org>
711 */
712function html_diff($text='',$intro=true){
713  require_once(DOKU_INC.'inc/DifferenceEngine.php');
714  global $ID;
715  global $REV;
716  global $lang;
717  global $conf;
718  if($text){
719    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,''))),
720                    split("\n",htmlspecialchars(cleanText($text))));
721    $left  = '<a class="wikilink1" href="'.wl($ID).'">'.
722              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a>'.
723              $lang['current'];
724    $right = $lang['yours'];
725  }else{
726    if($REV){
727      $r = $REV;
728    }else{
729      //use last revision if none given
730      $revs = getRevisions($ID);
731      $r = $revs[0];
732    }
733
734    $df  = new Diff(split("\n",htmlspecialchars(rawWiki($ID,$r))),
735                    split("\n",htmlspecialchars(rawWiki($ID,''))));
736    $left  = '<a class="wikilink1" href="'.wl($ID,"rev=$r").'">'.
737              $ID.' '.date($conf['dformat'],$r).'</a>';
738    $right = '<a class="wikilink1" href="'.wl($ID).'">'.
739              $ID.' '.date($conf['dformat'],@filemtime(wikiFN($ID))).'</a> '.
740              $lang['current'];
741  }
742  $tdf = new TableDiffFormatter();
743  if($intro) print p_locale_xhtml('diff');
744  ?>
745    <table class="diff" width="100%">
746      <tr>
747        <td colspan="2" width="50%" class="diff-header">
748          <?php echo $left?>
749        </td>
750        <td colspan="2" width="50%" class="diff-header">
751          <?php echo $right?>
752        </td>
753      </tr>
754      <?php echo $tdf->format($df)?>
755    </table>
756  <?php
757}
758
759/**
760 * show warning on conflict detection
761 *
762 * @author Andreas Gohr <andi@splitbrain.org>
763 */
764function html_conflict($text,$summary){
765  global $ID;
766  global $lang;
767
768  print p_locale_xhtml('conflict');
769  ?>
770  <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
771  <div class="centeralign">
772    <input type="hidden" name="id" value="<?php echo $ID?>" />
773    <input type="hidden" name="wikitext" value="<?php echo formText($text)?>" />
774    <input type="hidden" name="summary" value="<?php echo formText($summary)?>" />
775
776    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" />
777    <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" />
778  </div>
779  </form>
780  <br /><br /><br /><br />
781  <?php
782}
783
784/**
785 * Prints the global message array
786 *
787 * @author Andreas Gohr <andi@splitbrain.org>
788 */
789function html_msgarea(){
790  global $MSG;
791
792  if(!isset($MSG)) return;
793
794  foreach($MSG as $msg){
795    print '<div class="'.$msg['lvl'].'">';
796    print $msg['msg'];
797    print '</div>';
798  }
799}
800
801/**
802 * Prints the registration form
803 *
804 * @author Andreas Gohr <andi@splitbrain.org>
805 */
806function html_register(){
807  global $lang;
808  global $conf;
809  global $ID;
810
811  print p_locale_xhtml('register');
812?>
813  <div class="centeralign">
814  <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
815  <fieldset>
816    <input type="hidden" name="do" value="register" />
817    <input type="hidden" name="save" value="1" />
818
819    <legend><?php echo $lang['register']?></legend>
820    <label class="block">
821      <?php echo $lang['user']?>
822      <input type="text" name="login" class="edit" size="50" value="<?php echo formText($_POST['login'])?>" />
823    </label><br />
824
825    <?php
826      if (!$conf['autopasswd']) {
827    ?>
828      <label class="block">
829        <?php echo $lang['pass']?>
830        <input type="password" name="pass" class="edit" size="50" />
831      </label><br />
832      <label class="block">
833        <?php echo $lang['passchk']?>
834        <input type="password" name="passchk" class="edit" size="50" />
835      </label><br />
836    <?php
837      }
838    ?>
839
840    <label class="block">
841      <?php echo $lang['fullname']?>
842      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
843    </label><br />
844    <label class="block">
845      <?php echo $lang['email']?>
846      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
847    </label><br />
848    <input type="submit" class="button" value="<?php echo $lang['register']?>" />
849  </fieldset>
850  </form>
851  </div>
852<?php
853}
854
855/**
856 * Print the update profile form
857 *
858 * @author Christopher Smith <chris@jalakai.co.uk>
859 * @author Andreas Gohr <andi@splitbrain.org>
860 */
861function html_updateprofile(){
862  global $lang;
863  global $conf;
864  global $ID;
865  global $INFO;
866
867  print p_locale_xhtml('updateprofile');
868
869  if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
870  if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
871?>
872  <div class="centeralign">
873  <form name="register" method="post" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>">
874  <fieldset style="width: 80%;">
875    <input type="hidden" name="do" value="profile" />
876    <input type="hidden" name="save" value="1" />
877
878    <legend><?php echo $lang['profile']?></legend>
879    <label class="block">
880      <?php echo $lang['user']?>
881      <input type="text" name="fullname" disabled="disabled" class="edit" size="50" value="<?php echo formText($_SERVER['REMOTE_USER'])?>" />
882    </label><br />
883    <label class="block">
884      <?php echo $lang['fullname']?>
885      <input type="text" name="fullname" class="edit" size="50" value="<?php echo formText($_POST['fullname'])?>" />
886    </label><br />
887    <label class="block">
888      <?php echo $lang['email']?>
889      <input type="text" name="email" class="edit" size="50" value="<?php echo formText($_POST['email'])?>" />
890    </label><br /><br />
891    <label class="block">
892      <?php echo $lang['newpass']?>
893      <input type="password" name="newpass" class="edit" size="50" />
894    </label><br />
895    <label class="block">
896      <?php echo $lang['passchk']?>
897      <input type="password" name="passchk" class="edit" size="50" />
898    </label><br />
899
900    <?php if ($conf['profileconfirm']) { ?>
901      <br />
902      <label class="block">
903      <?php echo $lang['oldpass']?>
904      <input type="password" name="oldpass" class="edit" size="50" />
905    </label><br />
906    <?php } ?>
907
908    <input type="submit" class="button" value="<?php echo $lang['btn_save']?>" />
909    <input type="reset" class="button" value="<?php echo $lang['btn_reset']?>" />
910  </fieldset>
911  </form>
912  </div>
913<?php
914}
915
916/**
917 * This displays the edit form (lots of logic included)
918 *
919 * @fixme  this is a huge lump of code and should be modularized
920 * @author Andreas Gohr <andi@splitbrain.org>
921 */
922function html_edit($text=null,$include='edit'){ //FIXME: include needed?
923  global $ID;
924  global $REV;
925  global $DATE;
926  global $RANGE;
927  global $PRE;
928  global $SUF;
929  global $INFO;
930  global $SUM;
931  global $lang;
932  global $conf;
933
934  //set summary default
935  if(!$SUM){
936    if($REV){
937      $SUM = $lang['restored'];
938    }elseif(!$INFO['exists']){
939      $SUM = $lang['created'];
940    }
941  }
942
943  //no text? Load it!
944  if(!isset($text)){
945    $pr = false; //no preview mode
946    if($INFO['exists']){
947      if($RANGE){
948        list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
949      }else{
950        $text = rawWiki($ID,$REV);
951      }
952    }else{
953      //try to load a pagetemplate
954      $text = pageTemplate($ID);
955    }
956  }else{
957    $pr = true; //preview mode
958  }
959
960  $wr = $INFO['writable'];
961  if($wr){
962    if ($REV) print p_locale_xhtml('editrev');
963    print p_locale_xhtml($include);
964  }else{
965    print p_locale_xhtml('read');
966    $ro='readonly="readonly"';
967  }
968  if(!$DATE) $DATE = $INFO['lastmod'];
969
970
971?>
972  <form name="editform" method="post" action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>">
973  <table style="width:99%">
974    <tr>
975      <td class="toolbar" colspan="2">
976        <div id="toolbar"></div>
977        <input type="hidden" name="id"   value="<?php echo $ID?>" />
978        <input type="hidden" name="rev"  value="<?php echo $REV?>" />
979        <input type="hidden" name="date" value="<?php echo $DATE?>" />
980        <input type="hidden" name="prefix" value="<?php echo formText($PRE)?>" />
981        <input type="hidden" name="suffix" value="<?php echo formText($SUF)?>" />
982
983        <?php if($wr){?>
984        <script type="text/javascript" charset="utf-8">
985          <?php /* sets changed to true when previewed */?>
986          textChanged = <?php ($pr) ? print 'true' : print 'false' ?>;
987        </script>
988        <span id="spell_action"></span>
989        <?php } ?>
990      </td>
991      <td>
992        <div id="spell_suggest"></div>
993      </td>
994    </tr>
995    <tr>
996      <td colspan="3">
997        <div id="spell_result"></div>
998        <textarea name="wikitext" id="wikitext" <?php echo $ro?> cols="80" rows="10" class="edit" tabindex="1"><?php echo "\n".formText($text)?></textarea>
999      </td>
1000    </tr>
1001    <tr id="wikieditbar">
1002      <td>
1003      <?php if($wr){?>
1004        <input class="button" id="edbtn_save" type="submit" name="do" value="<?php echo $lang['btn_save']?>" accesskey="s" title="[ALT+S]" tabindex="4" />
1005        <input class="button" id="edbtn_preview" type="submit" name="do" value="<?php echo $lang['btn_preview']?>" accesskey="p" title="[ALT+P]" tabindex="5" />
1006        <input class="button" type="submit" name="do" value="<?php echo $lang['btn_cancel']?>" tabindex="5" />
1007      <?php } ?>
1008      </td>
1009      <td>
1010      <?php if($wr){ ?>
1011        <?php echo $lang['summary']?>:
1012        <input type="text" class="edit" name="summary" id="summary" size="50" value="<?php echo formText($SUM)?>" tabindex="2" />
1013        <?php html_minoredit()?>
1014      <?php }?>
1015      </td>
1016      <td class="rightalign">
1017        <div id="sizectl"></div>
1018      </td>
1019    </tr>
1020  </table>
1021  </form>
1022<?php
1023}
1024
1025/**
1026 * Adds a checkbox for minor edits for logged in users
1027 *
1028 * @author Andrea Gohr <andi@splitbrain.org>
1029 */
1030function html_minoredit(){
1031  global $conf;
1032  global $lang;
1033  // minor edits are for logged in users only
1034  if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1035    return;
1036  }
1037
1038  $p = array();
1039  $p['name']     = 'minor';
1040  $p['type']     = 'checkbox';
1041  $p['id']       = 'minoredit';
1042  $p['tabindex'] = 3;
1043  $p['value']    = '1';
1044  if($_REQUEST['minor']) $p['checked']='checked';
1045  $att = buildAttributes($p);
1046
1047  print "<input $att />";
1048  print '<label for="minoredit">';
1049  print $lang['minoredit'];
1050  print '</label>';
1051}
1052
1053/**
1054 * prints some debug info
1055 *
1056 * @author Andreas Gohr <andi@splitbrain.org>
1057 */
1058function html_debug(){
1059  global $conf;
1060  global $lang;
1061  //remove sensitive data
1062  $cnf = $conf;
1063  $cnf['auth']='***';
1064  $cnf['notify']='***';
1065  $cnf['ftp']='***';
1066
1067  print '<html><body>';
1068
1069  print '<p>When reporting bugs please send all the following ';
1070  print 'output as a mail to andi@splitbrain.org ';
1071  print 'The best way to do this is to save this page in your browser</p>';
1072
1073  print '<b>$_SERVER:</b><pre>';
1074  print_r($_SERVER);
1075  print '</pre>';
1076
1077  print '<b>$conf:</b><pre>';
1078  print_r($cnf);
1079  print '</pre>';
1080
1081  print '<b>DOKU_BASE:</b><pre>';
1082  print DOKU_BASE;
1083  print '</pre>';
1084
1085  print '<b>abs DOKU_BASE:</b><pre>';
1086  print DOKU_URL;
1087  print '</pre>';
1088
1089  print '<b>rel DOKU_BASE:</b><pre>';
1090  print dirname($_SERVER['PHP_SELF']).'/';
1091  print '</pre>';
1092
1093  print '<b>PHP Version:</b><pre>';
1094  print phpversion();
1095  print '</pre>';
1096
1097  print '<b>locale:</b><pre>';
1098  print setlocale(LC_ALL,0);
1099  print '</pre>';
1100
1101  print '<b>encoding:</b><pre>';
1102  print $lang['encoding'];
1103  print '</pre>';
1104
1105  print '<b>Environment:</b><pre>';
1106  print_r($_ENV);
1107  print '</pre>';
1108
1109  print '<b>PHP settings:</b><pre>';
1110  $inis = ini_get_all();
1111  print_r($inis);
1112  print '</pre>';
1113
1114  print '</body></html>';
1115}
1116
1117function html_admin(){
1118  global $ID;
1119  global $lang;
1120  global $conf;
1121
1122  print p_locale_xhtml('admin');
1123
1124  // build menu of admin functions from the plugins that handle them
1125  $pluginlist = plugin_list('admin');
1126  $menu = array();
1127  foreach ($pluginlist as $p) {
1128    if($obj =& plugin_load('admin',$p) === NULL) continue;
1129    $menu[] = array('plugin' => $p,
1130                    'prompt' => $obj->getMenuText($conf['lang']),
1131                    'sort' => $obj->getMenuSort()
1132                   );
1133  }
1134
1135  usort($menu, p_sort_modes);
1136
1137  // output the menu
1138  ptln('<ul>');
1139
1140  foreach ($menu as $item) {
1141    if (!$item['prompt']) continue;
1142    ptln('  <li><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></li>');
1143  }
1144
1145  // add in non-plugin functions
1146  if (!$conf['openregister']){
1147    ptln('<li><a href="'.wl($ID,'do=register').'">'.$lang['admin_register'].'</a></li>');
1148  }
1149
1150  ptln('</ul>');
1151}
1152
1153/**
1154 * Form to request a new password for an existing account
1155 *
1156 * @author Benoit Chesneau <benoit@bchesneau.info>
1157 */
1158function html_resendpwd() {
1159  global $lang;
1160  global $conf;
1161  global $ID;
1162
1163  print p_locale_xhtml('resendpwd');
1164?>
1165  <div class="centeralign">
1166  <form name="resendpwd" action="<?php echo wl($ID)?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
1167    <fieldset>
1168      <br />
1169      <legend><?php echo $lang['resendpwd']?></legend>
1170      <input type="hidden" name="do" value="resendpwd" />
1171      <input type="hidden" name="save" value="1" />
1172      <label class="block">
1173        <span><?php echo $lang['user']?></span>
1174        <input type="text" name="login" value="<?php echo formText($_POST['login'])?>" class="edit" /><br /><br />
1175      </label><br />
1176      <input type="submit" value="<?php echo $lang['btn_resendpwd']?>" class="button" />
1177    </fieldset>
1178  </form>
1179  </div>
1180<?php
1181}
1182
1183//Setup VIM: ex: et ts=2 enc=utf-8 :
1184