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