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 9if(!defined('DOKU_INC')) die('meh.'); 10if(!defined('NL')) define('NL',"\n"); 11 12/** 13 * Convenience function to quickly build a wikilink 14 * 15 * @author Andreas Gohr <andi@splitbrain.org> 16 */ 17function html_wikilink($id,$name=null,$search=''){ 18 static $xhtml_renderer = null; 19 if(is_null($xhtml_renderer)){ 20 $xhtml_renderer = p_get_renderer('xhtml'); 21 } 22 23 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 24} 25 26/** 27 * Helps building long attribute lists 28 * 29 * @author Andreas Gohr <andi@splitbrain.org> 30 */ 31function html_attbuild($attributes){ 32 $ret = ''; 33 foreach ( $attributes as $key => $value ) { 34 $ret .= $key.'="'.formText($value).'" '; 35 } 36 return trim($ret); 37} 38 39/** 40 * The loginform 41 * 42 * @author Andreas Gohr <andi@splitbrain.org> 43 */ 44function html_login(){ 45 global $lang; 46 global $conf; 47 global $ID; 48 49 print p_locale_xhtml('login'); 50 print '<div class="centeralign">'.NL; 51 $form = new Doku_Form(array('id' => 'dw__login')); 52 $form->startFieldset($lang['btn_login']); 53 $form->addHidden('id', $ID); 54 $form->addHidden('do', 'login'); 55 $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block')); 56 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 57 if($conf['rememberme']) { 58 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 59 } 60 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 61 $form->endFieldset(); 62 63 if(actionOK('register')){ 64 $form->addElement('<p>' 65 . $lang['reghere'] 66 . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>' 67 . '</p>'); 68 } 69 70 if (actionOK('resendpwd')) { 71 $form->addElement('<p>' 72 . $lang['pwdforget'] 73 . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>' 74 . '</p>'); 75 } 76 77 html_form('login', $form); 78 print '</div>'.NL; 79} 80 81/** 82 * inserts section edit buttons if wanted or removes the markers 83 * 84 * @author Andreas Gohr <andi@splitbrain.org> 85 */ 86function html_secedit($text,$show=true){ 87 global $INFO; 88 89 $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; 90 91 if(!$INFO['writable'] || !$show || $INFO['rev']){ 92 return preg_replace($regexp,'',$text); 93 } 94 95 return preg_replace_callback($regexp, 96 'html_secedit_button', $text); 97} 98 99/** 100 * prepares section edit button data for event triggering 101 * used as a callback in html_secedit 102 * 103 * @triggers HTML_SECEDIT_BUTTON 104 * @author Andreas Gohr <andi@splitbrain.org> 105 */ 106function html_secedit_button($matches){ 107 $data = array('secid' => $matches[1], 108 'target' => strtolower($matches[2]), 109 'range' => $matches[count($matches) - 1]); 110 if (count($matches) === 5) { 111 $data['name'] = $matches[3]; 112 } 113 114 return trigger_event('HTML_SECEDIT_BUTTON', $data, 115 'html_secedit_get_button'); 116} 117 118/** 119 * prints a section editing button 120 * used as default action form HTML_SECEDIT_BUTTON 121 * 122 * @author Adrian Lang <lang@cosmocode.de> 123 */ 124function html_secedit_get_button($data) { 125 global $ID; 126 global $INFO; 127 128 if (!isset($data['name']) || $data['name'] === '') return; 129 130 $name = $data['name']; 131 unset($data['name']); 132 133 $secid = $data['secid']; 134 unset($data['secid']); 135 136 return "<div class='secedit editbutton_" . $data['target'] . 137 " editbutton_" . $secid . "'>" . 138 html_btn('secedit', $ID, '', 139 array_merge(array('do' => 'edit', 140 'rev' => $INFO['lastmod'], 141 'summary' => '['.$name.'] '), $data), 142 'post', $name) . '</div>'; 143} 144 145/** 146 * Just the back to top button (in its own form) 147 * 148 * @author Andreas Gohr <andi@splitbrain.org> 149 */ 150function html_topbtn(){ 151 global $lang; 152 153 $ret = ''; 154 $ret = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>'; 155 156 return $ret; 157} 158 159/** 160 * Displays a button (using its own form) 161 * If tooltip exists, the access key tooltip is replaced. 162 * 163 * @author Andreas Gohr <andi@splitbrain.org> 164 */ 165function html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){ 166 global $conf; 167 global $lang; 168 169 $label = $lang['btn_'.$name]; 170 171 $ret = ''; 172 $tip = ''; 173 174 //filter id (without urlencoding) 175 $id = idfilter($id,false); 176 177 //make nice URLs even for buttons 178 if($conf['userewrite'] == 2){ 179 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 180 }elseif($conf['userewrite']){ 181 $script = DOKU_BASE.$id; 182 }else{ 183 $script = DOKU_BASE.DOKU_SCRIPT; 184 $params['id'] = $id; 185 } 186 187 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 188 189 if(is_array($params)){ 190 reset($params); 191 while (list($key, $val) = each($params)) { 192 $ret .= '<input type="hidden" name="'.$key.'" '; 193 $ret .= 'value="'.htmlspecialchars($val).'" />'; 194 } 195 } 196 197 if ($tooltip!='') { 198 $tip = htmlspecialchars($tooltip); 199 }else{ 200 $tip = htmlspecialchars($label); 201 } 202 203 $ret .= '<input type="submit" value="'.hsc($label).'" class="button" '; 204 if($akey){ 205 $tip .= ' ['.strtoupper($akey).']'; 206 $ret .= 'accesskey="'.$akey.'" '; 207 } 208 $ret .= 'title="'.$tip.'" '; 209 $ret .= '/>'; 210 $ret .= '</div></form>'; 211 212 return $ret; 213} 214 215/** 216 * show a wiki page 217 * 218 * @author Andreas Gohr <andi@splitbrain.org> 219 */ 220function html_show($txt=null){ 221 global $ID; 222 global $REV; 223 global $HIGH; 224 global $INFO; 225 //disable section editing for old revisions or in preview 226 if($txt || $REV){ 227 $secedit = false; 228 }else{ 229 $secedit = true; 230 } 231 232 if (!is_null($txt)){ 233 //PreviewHeader 234 echo '<br id="scroll__here" />'; 235 echo p_locale_xhtml('preview'); 236 echo '<div class="preview">'; 237 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 238 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 239 echo $html; 240 echo '<div class="clearer"></div>'; 241 echo '</div>'; 242 243 }else{ 244 if ($REV) print p_locale_xhtml('showrev'); 245 $html = p_wiki_xhtml($ID,$REV,true); 246 $html = html_secedit($html,$secedit); 247 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 248 $html = html_hilight($html,$HIGH); 249 echo $html; 250 } 251} 252 253/** 254 * ask the user about how to handle an exisiting draft 255 * 256 * @author Andreas Gohr <andi@splitbrain.org> 257 */ 258function html_draft(){ 259 global $INFO; 260 global $ID; 261 global $lang; 262 global $conf; 263 $draft = unserialize(io_readFile($INFO['draft'],false)); 264 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 265 266 print p_locale_xhtml('draft'); 267 $form = new Doku_Form(array('id' => 'dw__editform')); 268 $form->addHidden('id', $ID); 269 $form->addHidden('date', $draft['date']); 270 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 271 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 272 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 273 $form->addElement(form_makeCloseTag('div')); 274 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 275 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 276 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 277 html_form('draft', $form); 278} 279 280/** 281 * Highlights searchqueries in HTML code 282 * 283 * @author Andreas Gohr <andi@splitbrain.org> 284 * @author Harry Fuecks <hfuecks@gmail.com> 285 */ 286function html_hilight($html,$phrases){ 287 $phrases = array_filter((array) $phrases); 288 $regex = join('|',array_map('preg_quote_cb',$phrases)); 289 290 if ($regex === '') return $html; 291 $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 292 return $html; 293} 294 295/** 296 * Callback used by html_hilight() 297 * 298 * @author Harry Fuecks <hfuecks@gmail.com> 299 */ 300function html_hilight_callback($m) { 301 $hlight = unslash($m[0]); 302 if ( !isset($m[2])) { 303 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 304 } 305 return $hlight; 306} 307 308/** 309 * Run a search and display the result 310 * 311 * @author Andreas Gohr <andi@splitbrain.org> 312 */ 313function html_search(){ 314 global $conf; 315 global $QUERY; 316 global $ID; 317 global $lang; 318 319 print p_locale_xhtml('searchpage'); 320 flush(); 321 322 //check if search is restricted to namespace 323 if(preg_match('/@([^@]*)/',$QUERY,$match)) { 324 $id = cleanID($match[1]); 325 } else { 326 $id = cleanID($QUERY); 327 } 328 329 //show progressbar 330 print '<div class="centeralign" id="dw__loading">'.NL; 331 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 332 print 'showLoadBar();'.NL; 333 print '//--><!]]></script>'.NL; 334 print '<br /></div>'.NL; 335 flush(); 336 337 //do quick pagesearch 338 $data = array(); 339 340 if($id) $data = ft_pageLookup($id,true,useHeading('navigation')); 341 if(count($data)){ 342 print '<div class="search_quickresult">'; 343 print '<h3>'.$lang['quickhits'].':</h3>'; 344 print '<ul class="search_quickhits">'; 345 foreach($data as $id => $title){ 346 print '<li> '; 347 if (useHeading('navigation')) { 348 $name = $title; 349 }else{ 350 $ns = getNS($id); 351 if($ns){ 352 $name = shorten(noNS($id), ' ('.$ns.')',30); 353 }else{ 354 $name = $id; 355 } 356 } 357 print html_wikilink(':'.$id,$name); 358 print '</li> '; 359 } 360 print '</ul> '; 361 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 362 print '<div class="clearer"> </div>'; 363 print '</div>'; 364 } 365 flush(); 366 367 //do fulltext search 368 $data = ft_pageSearch($QUERY,$regex); 369 if(count($data)){ 370 $num = 1; 371 foreach($data as $id => $cnt){ 372 print '<div class="search_result">'; 373 print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex); 374 if($cnt !== 0){ 375 print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />'; 376 if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only 377 print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>'; 378 } 379 $num++; 380 } 381 print '</div>'; 382 flush(); 383 } 384 }else{ 385 print '<div class="nothing">'.$lang['nothingfound'].'</div>'; 386 } 387 388 //hide progressbar 389 print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL; 390 print 'hideLoadBar("dw__loading");'.NL; 391 print '//--><!]]></script>'.NL; 392 flush(); 393} 394 395/** 396 * Display error on locked pages 397 * 398 * @author Andreas Gohr <andi@splitbrain.org> 399 */ 400function html_locked(){ 401 global $ID; 402 global $conf; 403 global $lang; 404 global $INFO; 405 406 $locktime = filemtime(wikiLockFN($ID)); 407 $expire = dformat($locktime + $conf['locktime']); 408 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 409 410 print p_locale_xhtml('locked'); 411 print '<ul>'; 412 print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>'; 413 print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>'; 414 print '</ul>'; 415} 416 417/** 418 * list old revisions 419 * 420 * @author Andreas Gohr <andi@splitbrain.org> 421 * @author Ben Coburn <btcoburn@silicodon.net> 422 */ 423function html_revisions($first=0){ 424 global $ID; 425 global $INFO; 426 global $conf; 427 global $lang; 428 /* we need to get one additionally log entry to be able to 429 * decide if this is the last page or is there another one. 430 * see html_recent() 431 */ 432 $revisions = getRevisions($ID, $first, $conf['recent']+1); 433 if(count($revisions)==0 && $first!=0){ 434 $first=0; 435 $revisions = getRevisions($ID, $first, $conf['recent']+1);; 436 } 437 $hasNext = false; 438 if (count($revisions)>$conf['recent']) { 439 $hasNext = true; 440 array_pop($revisions); // remove extra log entry 441 } 442 443 $date = dformat($INFO['lastmod']); 444 445 print p_locale_xhtml('revisions'); 446 447 $form = new Doku_Form(array('id' => 'page__revisions')); 448 $form->addElement(form_makeOpenTag('ul')); 449 if($INFO['exists'] && $first==0){ 450 if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 451 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 452 else 453 $form->addElement(form_makeOpenTag('li')); 454 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 455 $form->addElement(form_makeTag('input', array( 456 'type' => 'checkbox', 457 'name' => 'rev2[]', 458 'value' => 'current'))); 459 460 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 461 $form->addElement($date); 462 $form->addElement(form_makeCloseTag('span')); 463 464 $form->addElement(form_makeTag('img', array( 465 'src' => DOKU_BASE.'lib/images/blank.gif', 466 'width' => '15', 467 'height' => '11', 468 'alt' => ''))); 469 470 $form->addElement(form_makeOpenTag('a', array( 471 'class' => 'wikilink1', 472 'href' => wl($ID)))); 473 $form->addElement($ID); 474 $form->addElement(form_makeCloseTag('a')); 475 476 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 477 $form->addElement(' – '); 478 $form->addElement(htmlspecialchars($INFO['sum'])); 479 $form->addElement(form_makeCloseTag('span')); 480 481 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 482 $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor'])); 483 $form->addElement(form_makeCloseTag('span')); 484 485 $form->addElement('('.$lang['current'].')'); 486 $form->addElement(form_makeCloseTag('div')); 487 $form->addElement(form_makeCloseTag('li')); 488 } 489 490 foreach($revisions as $rev){ 491 $date = dformat($rev); 492 $info = getRevisionInfo($ID,$rev,true); 493 $exists = page_exists($ID,$rev); 494 495 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 496 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 497 else 498 $form->addElement(form_makeOpenTag('li')); 499 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 500 if($exists){ 501 $form->addElement(form_makeTag('input', array( 502 'type' => 'checkbox', 503 'name' => 'rev2[]', 504 'value' => $rev))); 505 }else{ 506 $form->addElement(form_makeTag('img', array( 507 'src' => DOKU_BASE.'lib/images/blank.gif', 508 'width' => 14, 509 'height' => 11, 510 'alt' => ''))); 511 } 512 513 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 514 $form->addElement($date); 515 $form->addElement(form_makeCloseTag('span')); 516 517 if($exists){ 518 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link'))); 519 $form->addElement(form_makeTag('img', array( 520 'src' => DOKU_BASE.'lib/images/diff.png', 521 'width' => 15, 522 'height' => 11, 523 'title' => $lang['diff'], 524 'alt' => $lang['diff']))); 525 $form->addElement(form_makeCloseTag('a')); 526 527 $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1'))); 528 $form->addElement($ID); 529 $form->addElement(form_makeCloseTag('a')); 530 }else{ 531 $form->addElement(form_makeTag('img', array( 532 'src' => DOKU_BASE.'lib/images/blank.gif', 533 'width' => '15', 534 'height' => '11', 535 'alt' => ''))); 536 $form->addElement($ID); 537 } 538 539 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 540 $form->addElement(' – '); 541 $form->addElement(htmlspecialchars($info['sum'])); 542 $form->addElement(form_makeCloseTag('span')); 543 544 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 545 if($info['user']){ 546 $form->addElement(editorinfo($info['user'])); 547 if(auth_ismanager()){ 548 $form->addElement(' ('.$info['ip'].')'); 549 } 550 }else{ 551 $form->addElement($info['ip']); 552 } 553 $form->addElement(form_makeCloseTag('span')); 554 555 $form->addElement(form_makeCloseTag('div')); 556 $form->addElement(form_makeCloseTag('li')); 557 } 558 $form->addElement(form_makeCloseTag('ul')); 559 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 560 html_form('revisions', $form); 561 562 print '<div class="pagenav">'; 563 $last = $first + $conf['recent']; 564 if ($first > 0) { 565 $first -= $conf['recent']; 566 if ($first < 0) $first = 0; 567 print '<div class="pagenav-prev">'; 568 print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first)); 569 print '</div>'; 570 } 571 if ($hasNext) { 572 print '<div class="pagenav-next">'; 573 print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last)); 574 print '</div>'; 575 } 576 print '</div>'; 577 578} 579 580/** 581 * display recent changes 582 * 583 * @author Andreas Gohr <andi@splitbrain.org> 584 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 585 * @author Ben Coburn <btcoburn@silicodon.net> 586 */ 587function html_recent($first=0){ 588 global $conf; 589 global $lang; 590 global $ID; 591 /* we need to get one additionally log entry to be able to 592 * decide if this is the last page or is there another one. 593 * This is the cheapest solution to get this information. 594 */ 595 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 596 if(count($recents) == 0 && $first != 0){ 597 $first=0; 598 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID)); 599 } 600 $hasNext = false; 601 if (count($recents)>$conf['recent']) { 602 $hasNext = true; 603 array_pop($recents); // remove extra log entry 604 } 605 606 print p_locale_xhtml('recent'); 607 608 if (getNS($ID) != '') 609 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 610 611 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET')); 612 $form->addHidden('sectok', null); 613 $form->addHidden('do', 'recent'); 614 $form->addHidden('id', $ID); 615 $form->addElement(form_makeOpenTag('ul')); 616 617 foreach($recents as $recent){ 618 $date = dformat($recent['date']); 619 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 620 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 621 else 622 $form->addElement(form_makeOpenTag('li')); 623 624 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 625 626 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 627 $form->addElement($date); 628 $form->addElement(form_makeCloseTag('span')); 629 630 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&')))); 631 $form->addElement(form_makeTag('img', array( 632 'src' => DOKU_BASE.'lib/images/diff.png', 633 'width' => 15, 634 'height'=> 11, 635 'title' => $lang['diff'], 636 'alt' => $lang['diff'] 637 ))); 638 $form->addElement(form_makeCloseTag('a')); 639 640 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&')))); 641 $form->addElement(form_makeTag('img', array( 642 'src' => DOKU_BASE.'lib/images/history.png', 643 'width' => 12, 644 'height'=> 14, 645 'title' => $lang['btn_revs'], 646 'alt' => $lang['btn_revs'] 647 ))); 648 $form->addElement(form_makeCloseTag('a')); 649 650 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 651 652 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 653 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 654 $form->addElement(form_makeCloseTag('span')); 655 656 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 657 if($recent['user']){ 658 $form->addElement(editorinfo($recent['user'])); 659 if(auth_ismanager()){ 660 $form->addElement(' ('.$recent['ip'].')'); 661 } 662 }else{ 663 $form->addElement($recent['ip']); 664 } 665 $form->addElement(form_makeCloseTag('span')); 666 667 $form->addElement(form_makeCloseTag('div')); 668 $form->addElement(form_makeCloseTag('li')); 669 } 670 $form->addElement(form_makeCloseTag('ul')); 671 672 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 673 $last = $first + $conf['recent']; 674 if ($first > 0) { 675 $first -= $conf['recent']; 676 if ($first < 0) $first = 0; 677 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 678 $form->addElement(form_makeTag('input', array( 679 'type' => 'submit', 680 'name' => 'first['.$first.']', 681 'value' => $lang['btn_newer'], 682 'accesskey' => 'n', 683 'title' => $lang['btn_newer'].' [N]', 684 'class' => 'button' 685 ))); 686 $form->addElement(form_makeCloseTag('div')); 687 } 688 if ($hasNext) { 689 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 690 $form->addElement(form_makeTag('input', array( 691 'type' => 'submit', 692 'name' => 'first['.$last.']', 693 'value' => $lang['btn_older'], 694 'accesskey' => 'p', 695 'title' => $lang['btn_older'].' [P]', 696 'class' => 'button' 697 ))); 698 $form->addElement(form_makeCloseTag('div')); 699 } 700 $form->addElement(form_makeCloseTag('div')); 701 html_form('recent', $form); 702} 703 704/** 705 * Display page index 706 * 707 * @author Andreas Gohr <andi@splitbrain.org> 708 */ 709function html_index($ns){ 710 global $conf; 711 global $ID; 712 $dir = $conf['datadir']; 713 $ns = cleanID($ns); 714 #fixme use appropriate function 715 if(empty($ns)){ 716 $ns = dirname(str_replace(':','/',$ID)); 717 if($ns == '.') $ns =''; 718 } 719 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 720 721 echo p_locale_xhtml('index'); 722 echo '<div id="index__tree">'; 723 724 $data = array(); 725 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 726 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 727 728 echo '</div>'; 729} 730 731/** 732 * Index item formatter 733 * 734 * User function for html_buildlist() 735 * 736 * @author Andreas Gohr <andi@splitbrain.org> 737 */ 738function html_list_index($item){ 739 global $ID; 740 $ret = ''; 741 $base = ':'.$item['id']; 742 $base = substr($base,strrpos($base,':')+1); 743 if($item['type']=='d'){ 744 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 745 $ret .= $base; 746 $ret .= '</strong></a>'; 747 }else{ 748 $ret .= html_wikilink(':'.$item['id']); 749 } 750 return $ret; 751} 752 753/** 754 * Index List item 755 * 756 * This user function is used in html_build_lidt to build the 757 * <li> tags for namespaces when displaying the page index 758 * it gives different classes to opened or closed "folders" 759 * 760 * @author Andreas Gohr <andi@splitbrain.org> 761 */ 762function html_li_index($item){ 763 if($item['type'] == "f"){ 764 return '<li class="level'.$item['level'].'">'; 765 }elseif($item['open']){ 766 return '<li class="open">'; 767 }else{ 768 return '<li class="closed">'; 769 } 770} 771 772/** 773 * Default List item 774 * 775 * @author Andreas Gohr <andi@splitbrain.org> 776 */ 777function html_li_default($item){ 778 return '<li class="level'.$item['level'].'">'; 779} 780 781/** 782 * Build an unordered list 783 * 784 * Build an unordered list from the given $data array 785 * Each item in the array has to have a 'level' property 786 * the item itself gets printed by the given $func user 787 * function. The second and optional function is used to 788 * print the <li> tag. Both user function need to accept 789 * a single item. 790 * 791 * Both user functions can be given as array to point to 792 * a member of an object. 793 * 794 * @author Andreas Gohr <andi@splitbrain.org> 795 */ 796function html_buildlist($data,$class,$func,$lifunc='html_li_default'){ 797 $level = 0; 798 $opens = 0; 799 $ret = ''; 800 801 foreach ($data as $item){ 802 803 if( $item['level'] > $level ){ 804 //open new list 805 for($i=0; $i<($item['level'] - $level); $i++){ 806 if ($i) $ret .= "<li class=\"clear\">\n"; 807 $ret .= "\n<ul class=\"$class\">\n"; 808 } 809 }elseif( $item['level'] < $level ){ 810 //close last item 811 $ret .= "</li>\n"; 812 for ($i=0; $i<($level - $item['level']); $i++){ 813 //close higher lists 814 $ret .= "</ul>\n</li>\n"; 815 } 816 }else{ 817 //close last item 818 $ret .= "</li>\n"; 819 } 820 821 //remember current level 822 $level = $item['level']; 823 824 //print item 825 $ret .= call_user_func($lifunc,$item); 826 $ret .= '<div class="li">'; 827 828 $ret .= call_user_func($func,$item); 829 $ret .= '</div>'; 830 } 831 832 //close remaining items and lists 833 for ($i=0; $i < $level; $i++){ 834 $ret .= "</li></ul>\n"; 835 } 836 837 return $ret; 838} 839 840/** 841 * display backlinks 842 * 843 * @author Andreas Gohr <andi@splitbrain.org> 844 * @author Michael Klier <chi@chimeric.de> 845 */ 846function html_backlinks(){ 847 global $ID; 848 global $conf; 849 global $lang; 850 851 print p_locale_xhtml('backlinks'); 852 853 $data = ft_backlinks($ID); 854 855 if(!empty($data)) { 856 print '<ul class="idx">'; 857 foreach($data as $blink){ 858 print '<li><div class="li">'; 859 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 860 print '</div></li>'; 861 } 862 print '</ul>'; 863 } else { 864 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 865 } 866} 867 868/** 869 * show diff 870 * 871 * @author Andreas Gohr <andi@splitbrain.org> 872 */ 873function html_diff($text='',$intro=true){ 874 global $ID; 875 global $REV; 876 global $lang; 877 global $conf; 878 879 // we're trying to be clever here, revisions to compare can be either 880 // given as rev and rev2 parameters, with rev2 being optional. Or in an 881 // array in rev2. 882 $rev1 = $REV; 883 884 if(is_array($_REQUEST['rev2'])){ 885 $rev1 = (int) $_REQUEST['rev2'][0]; 886 $rev2 = (int) $_REQUEST['rev2'][1]; 887 888 if(!$rev1){ 889 $rev1 = $rev2; 890 unset($rev2); 891 } 892 }else{ 893 $rev2 = (int) $_REQUEST['rev2']; 894 } 895 896 if($text){ // compare text to the most current revision 897 $l_rev = ''; 898 $l_text = rawWiki($ID,''); 899 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 900 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 901 $lang['current']; 902 903 $r_rev = ''; 904 $r_text = cleanText($text); 905 $r_head = $lang['yours']; 906 }else{ 907 if($rev1 && $rev2){ // two specific revisions wanted 908 // make sure order is correct (older on the left) 909 if($rev1 < $rev2){ 910 $l_rev = $rev1; 911 $r_rev = $rev2; 912 }else{ 913 $l_rev = $rev2; 914 $r_rev = $rev1; 915 } 916 }elseif($rev1){ // single revision given, compare to current 917 $r_rev = ''; 918 $l_rev = $rev1; 919 }else{ // no revision was given, compare previous to current 920 $r_rev = ''; 921 $revs = getRevisions($ID, 0, 1); 922 $l_rev = $revs[0]; 923 $REV = $l_rev; // store revision back in $REV 924 } 925 926 // when both revisions are empty then the page was created just now 927 if(!$l_rev && !$r_rev){ 928 $l_text = ''; 929 }else{ 930 $l_text = rawWiki($ID,$l_rev); 931 } 932 $r_text = rawWiki($ID,$r_rev); 933 934 if(!$l_rev){ 935 $l_head = '—'; 936 }else{ 937 $l_info = getRevisionInfo($ID,$l_rev,true); 938 if($l_info['user']){ 939 $l_user = editorinfo($l_info['user']); 940 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 941 } else { 942 $l_user = $l_info['ip']; 943 } 944 $l_user = '<span class="user">'.$l_user.'</span>'; 945 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 946 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 947 948 $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'. 949 $ID.' ['.dformat($l_rev).']</a>'. 950 '<br />'.$l_user.' '.$l_sum; 951 } 952 953 if($r_rev){ 954 $r_info = getRevisionInfo($ID,$r_rev,true); 955 if($r_info['user']){ 956 $r_user = editorinfo($r_info['user']); 957 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 958 } else { 959 $r_user = $r_info['ip']; 960 } 961 $r_user = '<span class="user">'.$r_user.'</span>'; 962 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 963 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 964 965 $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'. 966 $ID.' ['.dformat($r_rev).']</a>'. 967 '<br />'.$r_user.' '.$r_sum; 968 }elseif($_rev = @filemtime(wikiFN($ID))){ 969 $_info = getRevisionInfo($ID,$_rev,true); 970 if($_info['user']){ 971 $_user = editorinfo($_info['user']); 972 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')'; 973 } else { 974 $_user = $_info['ip']; 975 } 976 $_user = '<span class="user">'.$_user.'</span>'; 977 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : ''; 978 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 979 980 $r_head = '<a class="wikilink1" href="'.wl($ID).'">'. 981 $ID.' ['.dformat($_rev).']</a> '. 982 '('.$lang['current'].')'. 983 '<br />'.$_user.' '.$_sum; 984 }else{ 985 $r_head = '— ('.$lang['current'].')'; 986 } 987 } 988 989 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 990 explode("\n",htmlspecialchars($r_text))); 991 992 $tdf = new TableDiffFormatter(); 993 if($intro) print p_locale_xhtml('diff'); 994 995 if (!$text) { 996 $diffurl = wl($ID, array('do'=>'diff', 'rev2[0]'=>$l_rev, 'rev2[1]'=>$r_rev)); 997 ptln('<p class="difflink">'); 998 ptln(' <a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>'); 999 ptln('</p>'); 1000 } 1001 ?> 1002 <table class="diff"> 1003 <tr> 1004 <th colspan="2" <?php echo $l_minor?>> 1005 <?php echo $l_head?> 1006 </th> 1007 <th colspan="2" <?php echo $r_minor?>> 1008 <?php echo $r_head?> 1009 </th> 1010 </tr> 1011 <?php echo $tdf->format($df)?> 1012 </table> 1013 <?php 1014} 1015 1016/** 1017 * show warning on conflict detection 1018 * 1019 * @author Andreas Gohr <andi@splitbrain.org> 1020 */ 1021function html_conflict($text,$summary){ 1022 global $ID; 1023 global $lang; 1024 1025 print p_locale_xhtml('conflict'); 1026 $form = new Doku_Form(array('id' => 'dw__editform')); 1027 $form->addHidden('id', $ID); 1028 $form->addHidden('wikitext', $text); 1029 $form->addHidden('summary', $summary); 1030 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1031 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1032 html_form('conflict', $form); 1033 print '<br /><br /><br /><br />'.NL; 1034} 1035 1036/** 1037 * Prints the global message array 1038 * 1039 * @author Andreas Gohr <andi@splitbrain.org> 1040 */ 1041function html_msgarea(){ 1042 global $MSG; 1043 if(!isset($MSG)) return; 1044 1045 $shown = array(); 1046 foreach($MSG as $msg){ 1047 $hash = md5($msg['msg']); 1048 if(isset($shown[$hash])) continue; // skip double messages 1049 print '<div class="'.$msg['lvl'].'">'; 1050 print $msg['msg']; 1051 print '</div>'; 1052 $shown[$hash] = 1; 1053 } 1054} 1055 1056/** 1057 * Prints the registration form 1058 * 1059 * @author Andreas Gohr <andi@splitbrain.org> 1060 */ 1061function html_register(){ 1062 global $lang; 1063 global $conf; 1064 global $ID; 1065 1066 print p_locale_xhtml('register'); 1067 print '<div class="centeralign">'.NL; 1068 $form = new Doku_Form(array('id' => 'dw__register')); 1069 $form->startFieldset($lang['register']); 1070 $form->addHidden('do', 'register'); 1071 $form->addHidden('save', '1'); 1072 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50'))); 1073 if (!$conf['autopasswd']) { 1074 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1075 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1076 } 1077 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50'))); 1078 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50'))); 1079 $form->addElement(form_makeButton('submit', '', $lang['register'])); 1080 $form->endFieldset(); 1081 html_form('register', $form); 1082 1083 print '</div>'.NL; 1084} 1085 1086/** 1087 * Print the update profile form 1088 * 1089 * @author Christopher Smith <chris@jalakai.co.uk> 1090 * @author Andreas Gohr <andi@splitbrain.org> 1091 */ 1092function html_updateprofile(){ 1093 global $lang; 1094 global $conf; 1095 global $ID; 1096 global $INFO; 1097 global $auth; 1098 1099 print p_locale_xhtml('updateprofile'); 1100 1101 if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name']; 1102 if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail']; 1103 print '<div class="centeralign">'.NL; 1104 $form = new Doku_Form(array('id' => 'dw__register')); 1105 $form->startFieldset($lang['profile']); 1106 $form->addHidden('do', 'profile'); 1107 $form->addHidden('save', '1'); 1108 $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1109 $attr = array('size'=>'50'); 1110 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1111 $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr)); 1112 $attr = array('size'=>'50'); 1113 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1114 $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr)); 1115 $form->addElement(form_makeTag('br')); 1116 if ($auth->canDo('modPass')) { 1117 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1118 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1119 } 1120 if ($conf['profileconfirm']) { 1121 $form->addElement(form_makeTag('br')); 1122 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1123 } 1124 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1125 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1126 $form->endFieldset(); 1127 html_form('updateprofile', $form); 1128 print '</div>'.NL; 1129} 1130 1131/** 1132 * Preprocess edit form data 1133 * 1134 * @author Andreas Gohr <andi@splitbrain.org> 1135 * 1136 * @triggers HTML_EDITFORM_OUTPUT 1137 */ 1138function html_edit(){ 1139 global $ID; 1140 global $REV; 1141 global $DATE; 1142 global $PRE; 1143 global $SUF; 1144 global $INFO; 1145 global $SUM; 1146 global $lang; 1147 global $conf; 1148 global $TEXT; 1149 global $RANGE; 1150 1151 if (isset($_REQUEST['changecheck'])) { 1152 $check = $_REQUEST['changecheck']; 1153 } elseif(!$INFO['exists']){ 1154 // $TEXT has been loaded from page template 1155 $check = md5(''); 1156 } else { 1157 $check = md5($TEXT); 1158 } 1159 $mod = md5($TEXT) !== $check; 1160 1161 $wr = $INFO['writable'] && !$INFO['locked']; 1162 $include = 'edit'; 1163 if($wr){ 1164 if ($REV) $include = 'editrev'; 1165 }else{ 1166 // check pseudo action 'source' 1167 if(!actionOK('source')){ 1168 msg('Command disabled: source',-1); 1169 return; 1170 } 1171 $include = 'read'; 1172 } 1173 1174 global $license; 1175 1176 $form = new Doku_Form(array('id' => 'dw__editform')); 1177 $form->addHidden('id', $ID); 1178 $form->addHidden('rev', $REV); 1179 $form->addHidden('date', $DATE); 1180 $form->addHidden('prefix', $PRE); 1181 $form->addHidden('suffix', $SUF); 1182 $form->addHidden('changecheck', $check); 1183 1184 $data = array('form' => $form, 1185 'wr' => $wr, 1186 'media_manager' => true, 1187 'target' => (isset($_REQUEST['target']) && $wr && 1188 $RANGE !== '') ? $_REQUEST['target'] : 'section', 1189 'intro_locale' => $include); 1190 1191 if ($data['target'] !== 'section') { 1192 // Only emit event if page is writable, section edit data is valid and 1193 // edit target is not section. 1194 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1195 } else { 1196 html_edit_form($data); 1197 } 1198 if (isset($data['intro_locale'])) { 1199 echo p_locale_xhtml($data['intro_locale']); 1200 } 1201 1202 $form->addHidden('target', $data['target']); 1203 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar'))); 1204 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1205 $form->addElement(form_makeCloseTag('div')); 1206 if ($wr) { 1207 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1208 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1209 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1210 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1211 $form->addElement(form_makeCloseTag('div')); 1212 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1213 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1214 $elem = html_minoredit(); 1215 if ($elem) $form->addElement($elem); 1216 $form->addElement(form_makeCloseTag('div')); 1217 } 1218 $form->addElement(form_makeCloseTag('div')); 1219 if($wr && $conf['license']){ 1220 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1221 $out = $lang['licenseok']; 1222 $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1223 if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"'; 1224 $out .= '> '.$license[$conf['license']]['name'].'</a>'; 1225 $form->addElement($out); 1226 $form->addElement(form_makeCloseTag('div')); 1227 } 1228 1229 if ($wr) { 1230 // sets changed to true when previewed 1231 echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL; 1232 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1233 echo '//--><!]]></script>' . NL; 1234 } ?> 1235 <div style="width:99%;"> 1236 1237 <div class="toolbar"> 1238 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1239 <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1240 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1241 1242 </div> 1243 <?php 1244 1245 html_form('edit', $form); 1246 print '</div>'.NL; 1247} 1248 1249/** 1250 * Display the default edit form 1251 * 1252 * Is the default action for HTML_EDIT_FORMSELECTION. 1253 */ 1254function html_edit_form($param) { 1255 global $TEXT; 1256 1257 if ($param['target'] !== 'section') { 1258 msg('No editor for edit target ' . $param['target'] . ' found.', -1); 1259 } 1260 1261 $attr = array('tabindex'=>'1'); 1262 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1263 1264 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1265} 1266 1267/** 1268 * Adds a checkbox for minor edits for logged in users 1269 * 1270 * @author Andreas Gohr <andi@splitbrain.org> 1271 */ 1272function html_minoredit(){ 1273 global $conf; 1274 global $lang; 1275 // minor edits are for logged in users only 1276 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1277 return false; 1278 } 1279 1280 $p = array(); 1281 $p['tabindex'] = 3; 1282 if(!empty($_REQUEST['minor'])) $p['checked']='checked'; 1283 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1284} 1285 1286/** 1287 * prints some debug info 1288 * 1289 * @author Andreas Gohr <andi@splitbrain.org> 1290 */ 1291function html_debug(){ 1292 global $conf; 1293 global $lang; 1294 global $auth; 1295 global $INFO; 1296 1297 //remove sensitive data 1298 $cnf = $conf; 1299 debug_guard($cnf); 1300 $nfo = $INFO; 1301 debug_guard($nfo); 1302 $ses = $_SESSION; 1303 debug_guard($ses); 1304 1305 print '<html><body>'; 1306 1307 print '<p>When reporting bugs please send all the following '; 1308 print 'output as a mail to andi@splitbrain.org '; 1309 print 'The best way to do this is to save this page in your browser</p>'; 1310 1311 print '<b>$INFO:</b><pre>'; 1312 print_r($nfo); 1313 print '</pre>'; 1314 1315 print '<b>$_SERVER:</b><pre>'; 1316 print_r($_SERVER); 1317 print '</pre>'; 1318 1319 print '<b>$conf:</b><pre>'; 1320 print_r($cnf); 1321 print '</pre>'; 1322 1323 print '<b>DOKU_BASE:</b><pre>'; 1324 print DOKU_BASE; 1325 print '</pre>'; 1326 1327 print '<b>abs DOKU_BASE:</b><pre>'; 1328 print DOKU_URL; 1329 print '</pre>'; 1330 1331 print '<b>rel DOKU_BASE:</b><pre>'; 1332 print dirname($_SERVER['PHP_SELF']).'/'; 1333 print '</pre>'; 1334 1335 print '<b>PHP Version:</b><pre>'; 1336 print phpversion(); 1337 print '</pre>'; 1338 1339 print '<b>locale:</b><pre>'; 1340 print setlocale(LC_ALL,0); 1341 print '</pre>'; 1342 1343 print '<b>encoding:</b><pre>'; 1344 print $lang['encoding']; 1345 print '</pre>'; 1346 1347 if($auth){ 1348 print '<b>Auth backend capabilities:</b><pre>'; 1349 print_r($auth->cando); 1350 print '</pre>'; 1351 } 1352 1353 print '<b>$_SESSION:</b><pre>'; 1354 print_r($ses); 1355 print '</pre>'; 1356 1357 print '<b>Environment:</b><pre>'; 1358 print_r($_ENV); 1359 print '</pre>'; 1360 1361 print '<b>PHP settings:</b><pre>'; 1362 $inis = ini_get_all(); 1363 print_r($inis); 1364 print '</pre>'; 1365 1366 print '</body></html>'; 1367} 1368 1369/** 1370 * List available Administration Tasks 1371 * 1372 * @author Andreas Gohr <andi@splitbrain.org> 1373 * @author Håkan Sandell <hakan.sandell@home.se> 1374 */ 1375function html_admin(){ 1376 global $ID; 1377 global $INFO; 1378 global $lang; 1379 global $conf; 1380 global $auth; 1381 1382 // build menu of admin functions from the plugins that handle them 1383 $pluginlist = plugin_list('admin'); 1384 $menu = array(); 1385 foreach ($pluginlist as $p) { 1386 if($obj =& plugin_load('admin',$p) === null) continue; 1387 1388 // check permissions 1389 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1390 1391 $menu[$p] = array('plugin' => $p, 1392 'prompt' => $obj->getMenuText($conf['lang']), 1393 'sort' => $obj->getMenuSort() 1394 ); 1395 } 1396 1397 // data security check 1398 echo '<a style="background: transparent url(data/security.png) left top no-repeat; 1399 display: block; width:380px; height:73px; border:none; float:right" 1400 target="_blank" 1401 href="http://www.dokuwiki.org/security#web_access_security"></a>'; 1402 1403 print p_locale_xhtml('admin'); 1404 1405 // Admin Tasks 1406 if($INFO['isadmin']){ 1407 ptln('<ul class="admin_tasks">'); 1408 1409 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1410 ptln(' <li class="admin_usermanager"><div class="li">'. 1411 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1412 $menu['usermanager']['prompt'].'</a></div></li>'); 1413 } 1414 unset($menu['usermanager']); 1415 1416 if($menu['acl']){ 1417 ptln(' <li class="admin_acl"><div class="li">'. 1418 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1419 $menu['acl']['prompt'].'</a></div></li>'); 1420 } 1421 unset($menu['acl']); 1422 1423 if($menu['plugin']){ 1424 ptln(' <li class="admin_plugin"><div class="li">'. 1425 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'. 1426 $menu['plugin']['prompt'].'</a></div></li>'); 1427 } 1428 unset($menu['plugin']); 1429 1430 if($menu['config']){ 1431 ptln(' <li class="admin_config"><div class="li">'. 1432 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1433 $menu['config']['prompt'].'</a></div></li>'); 1434 } 1435 unset($menu['config']); 1436 } 1437 ptln('</ul>'); 1438 1439 // Manager Tasks 1440 ptln('<ul class="admin_tasks">'); 1441 1442 if($menu['revert']){ 1443 ptln(' <li class="admin_revert"><div class="li">'. 1444 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1445 $menu['revert']['prompt'].'</a></div></li>'); 1446 } 1447 unset($menu['revert']); 1448 1449 if($menu['popularity']){ 1450 ptln(' <li class="admin_popularity"><div class="li">'. 1451 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1452 $menu['popularity']['prompt'].'</a></div></li>'); 1453 } 1454 unset($menu['popularity']); 1455 1456 // print DokuWiki version: 1457 ptln('</ul>'); 1458 echo '<div id="admin__version">'; 1459 echo getVersion(); 1460 echo '</div>'; 1461 1462 // print the rest as sorted list 1463 if(count($menu)){ 1464 usort($menu, 'p_sort_modes'); 1465 // output the menu 1466 ptln('<div class="clearer"></div>'); 1467 print p_locale_xhtml('adminplugins'); 1468 ptln('<ul>'); 1469 foreach ($menu as $item) { 1470 if (!$item['prompt']) continue; 1471 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1472 } 1473 ptln('</ul>'); 1474 } 1475} 1476 1477/** 1478 * Form to request a new password for an existing account 1479 * 1480 * @author Benoit Chesneau <benoit@bchesneau.info> 1481 */ 1482function html_resendpwd() { 1483 global $lang; 1484 global $conf; 1485 global $ID; 1486 1487 print p_locale_xhtml('resendpwd'); 1488 print '<div class="centeralign">'.NL; 1489 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1490 $form->startFieldset($lang['resendpwd']); 1491 $form->addHidden('do', 'resendpwd'); 1492 $form->addHidden('save', '1'); 1493 $form->addElement(form_makeTag('br')); 1494 $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block')); 1495 $form->addElement(form_makeTag('br')); 1496 $form->addElement(form_makeTag('br')); 1497 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1498 $form->endFieldset(); 1499 html_form('resendpwd', $form); 1500 print '</div>'.NL; 1501} 1502 1503/** 1504 * Return the TOC rendered to XHTML 1505 * 1506 * @author Andreas Gohr <andi@splitbrain.org> 1507 */ 1508function html_TOC($toc){ 1509 if(!count($toc)) return ''; 1510 global $lang; 1511 $out = '<!-- TOC START -->'.DOKU_LF; 1512 $out .= '<div class="toc">'.DOKU_LF; 1513 $out .= '<div class="tocheader toctoggle" id="toc__header">'; 1514 $out .= $lang['toc']; 1515 $out .= '</div>'.DOKU_LF; 1516 $out .= '<div id="toc__inside">'.DOKU_LF; 1517 $out .= html_buildlist($toc,'toc','html_list_toc'); 1518 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1519 $out .= '<!-- TOC END -->'.DOKU_LF; 1520 return $out; 1521} 1522 1523/** 1524 * Callback for html_buildlist 1525 */ 1526function html_list_toc($item){ 1527 if(isset($item['hid'])){ 1528 $link = '#'.$item['hid']; 1529 }else{ 1530 $link = $item['link']; 1531 } 1532 1533 return '<span class="li"><a href="'.$link.'" class="toc">'. 1534 hsc($item['title']).'</a></span>'; 1535} 1536 1537/** 1538 * Helper function to build TOC items 1539 * 1540 * Returns an array ready to be added to a TOC array 1541 * 1542 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1543 * @param string $text - what to display in the TOC 1544 * @param int $level - nesting level 1545 * @param string $hash - is prepended to the given $link, set blank if you want full links 1546 */ 1547function html_mktocitem($link, $text, $level, $hash='#'){ 1548 global $conf; 1549 return array( 'link' => $hash.$link, 1550 'title' => $text, 1551 'type' => 'ul', 1552 'level' => $level); 1553} 1554 1555/** 1556 * Output a Doku_Form object. 1557 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1558 * 1559 * @author Tom N Harris <tnharris@whoopdedo.org> 1560 */ 1561function html_form($name, &$form) { 1562 // Safety check in case the caller forgets. 1563 $form->endFieldset(); 1564 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1565} 1566 1567/** 1568 * Form print function. 1569 * Just calls printForm() on the data object. 1570 */ 1571function html_form_output($data) { 1572 $data->printForm(); 1573} 1574 1575/** 1576 * Embed a flash object in HTML 1577 * 1578 * This will create the needed HTML to embed a flash movie in a cross browser 1579 * compatble way using valid XHTML 1580 * 1581 * The parameters $params, $flashvars and $atts need to be associative arrays. 1582 * No escaping needs to be done for them. The alternative content *has* to be 1583 * escaped because it is used as is. If no alternative content is given 1584 * $lang['noflash'] is used. 1585 * 1586 * @author Andreas Gohr <andi@splitbrain.org> 1587 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1588 * 1589 * @param string $swf - the SWF movie to embed 1590 * @param int $width - width of the flash movie in pixels 1591 * @param int $height - height of the flash movie in pixels 1592 * @param array $params - additional parameters (<param>) 1593 * @param array $flashvars - parameters to be passed in the flashvar parameter 1594 * @param array $atts - additional attributes for the <object> tag 1595 * @param string $alt - alternative content (is NOT automatically escaped!) 1596 * @returns string - the XHTML markup 1597 */ 1598function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1599 global $lang; 1600 1601 $out = ''; 1602 1603 // prepare the object attributes 1604 if(is_null($atts)) $atts = array(); 1605 $atts['width'] = (int) $width; 1606 $atts['height'] = (int) $height; 1607 if(!$atts['width']) $atts['width'] = 425; 1608 if(!$atts['height']) $atts['height'] = 350; 1609 1610 // add object attributes for standard compliant browsers 1611 $std = $atts; 1612 $std['type'] = 'application/x-shockwave-flash'; 1613 $std['data'] = $swf; 1614 1615 // add object attributes for IE 1616 $ie = $atts; 1617 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1618 1619 // open object (with conditional comments) 1620 $out .= '<!--[if !IE]> -->'.NL; 1621 $out .= '<object '.buildAttributes($std).'>'.NL; 1622 $out .= '<!-- <![endif]-->'.NL; 1623 $out .= '<!--[if IE]>'.NL; 1624 $out .= '<object '.buildAttributes($ie).'>'.NL; 1625 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1626 $out .= '<!--><!-- -->'.NL; 1627 1628 // print params 1629 if(is_array($params)) foreach($params as $key => $val){ 1630 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1631 } 1632 1633 // add flashvars 1634 if(is_array($flashvars)){ 1635 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1636 } 1637 1638 // alternative content 1639 if($alt){ 1640 $out .= $alt.NL; 1641 }else{ 1642 $out .= $lang['noflash'].NL; 1643 } 1644 1645 // finish 1646 $out .= '</object>'.NL; 1647 $out .= '<!-- <![endif]-->'.NL; 1648 1649 return $out; 1650} 1651 1652