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