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