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