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