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