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