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