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