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