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