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