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