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