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 9use dokuwiki\ChangeLog\MediaChangeLog; 10use dokuwiki\ChangeLog\PageChangeLog; 11use dokuwiki\Extension\AuthPlugin; 12 13if (!defined('SEC_EDIT_PATTERN')) { 14 define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#'); 15} 16 17 18/** 19 * Convenience function to quickly build a wikilink 20 * 21 * @author Andreas Gohr <andi@splitbrain.org> 22 * @param string $id id of the target page 23 * @param string $name the name of the link, i.e. the text that is displayed 24 * @param string|array $search search string(s) that shall be highlighted in the target page 25 * @return string the HTML code of the link 26 */ 27function html_wikilink($id,$name=null,$search=''){ 28 /** @var Doku_Renderer_xhtml $xhtml_renderer */ 29 static $xhtml_renderer = null; 30 if(is_null($xhtml_renderer)){ 31 $xhtml_renderer = p_get_renderer('xhtml'); 32 } 33 34 return $xhtml_renderer->internallink($id,$name,$search,true,'navigation'); 35} 36 37/** 38 * The loginform 39 * 40 * @author Andreas Gohr <andi@splitbrain.org> 41 * 42 * @param bool $svg Whether to show svg icons in the register and resendpwd links or not 43 */ 44function html_login($svg = false){ 45 global $lang; 46 global $conf; 47 global $ID; 48 global $INPUT; 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( 57 'u', 58 ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), 59 $lang['user'], 60 'focus__this', 61 'block') 62 ); 63 $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block')); 64 if($conf['rememberme']) { 65 $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple')); 66 } 67 $form->addElement(form_makeButton('submit', '', $lang['btn_login'])); 68 $form->endFieldset(); 69 70 if(actionOK('register')){ 71 $registerLink = (new \dokuwiki\Menu\Item\Register())->asHtmlLink('', $svg); 72 $form->addElement('<p>'.$lang['reghere'].': '. $registerLink .'</p>'); 73 } 74 75 if (actionOK('resendpwd')) { 76 $resendPwLink = (new \dokuwiki\Menu\Item\Resendpwd())->asHtmlLink('', $svg); 77 $form->addElement('<p>'.$lang['pwdforget'].': '. $resendPwLink .'</p>'); 78 } 79 80 html_form('login', $form); 81 print '</div>'.NL; 82} 83 84 85/** 86 * Denied page content 87 * 88 * @return string html 89 */ 90function html_denied() { 91 print p_locale_xhtml('denied'); 92 93 if(empty($_SERVER['REMOTE_USER']) && actionOK('login')){ 94 html_login(); 95 } 96} 97 98/** 99 * inserts section edit buttons if wanted or removes the markers 100 * 101 * @author Andreas Gohr <andi@splitbrain.org> 102 * 103 * @param string $text 104 * @param bool $show show section edit buttons? 105 * @return string 106 */ 107function html_secedit($text,$show=true){ 108 global $INFO; 109 110 if(!$INFO['writable'] || !$show || $INFO['rev']){ 111 return preg_replace(SEC_EDIT_PATTERN,'',$text); 112 } 113 114 return preg_replace_callback(SEC_EDIT_PATTERN, 115 'html_secedit_button', $text); 116} 117 118/** 119 * prepares section edit button data for event triggering 120 * used as a callback in html_secedit 121 * 122 * @author Andreas Gohr <andi@splitbrain.org> 123 * 124 * @param array $matches matches with regexp 125 * @return string 126 * @triggers HTML_SECEDIT_BUTTON 127 */ 128function html_secedit_button($matches){ 129 $json = htmlspecialchars_decode($matches[1], ENT_QUOTES); 130 $data = json_decode($json, true); 131 if ($data == NULL) { 132 return; 133 } 134 $data ['target'] = strtolower($data['target']); 135 $data ['hid'] = strtolower($data['hid']); 136 137 return trigger_event('HTML_SECEDIT_BUTTON', $data, 138 'html_secedit_get_button'); 139} 140 141/** 142 * prints a section editing button 143 * used as default action form HTML_SECEDIT_BUTTON 144 * 145 * @author Adrian Lang <lang@cosmocode.de> 146 * 147 * @param array $data name, section id and target 148 * @return string html 149 */ 150function html_secedit_get_button($data) { 151 global $ID; 152 global $INFO; 153 154 if (!isset($data['name']) || $data['name'] === '') return ''; 155 156 $name = $data['name']; 157 unset($data['name']); 158 159 $secid = $data['secid']; 160 unset($data['secid']); 161 162 return "<div class='secedit editbutton_" . $data['target'] . 163 " editbutton_" . $secid . "'>" . 164 html_btn('secedit', $ID, '', 165 array_merge(array('do' => 'edit', 166 'rev' => $INFO['lastmod'], 167 'summary' => '['.$name.'] '), $data), 168 'post', $name) . '</div>'; 169} 170 171/** 172 * Just the back to top button (in its own form) 173 * 174 * @author Andreas Gohr <andi@splitbrain.org> 175 * 176 * @return string html 177 */ 178function html_topbtn(){ 179 global $lang; 180 181 $ret = '<a class="nolink" href="#dokuwiki__top">' . 182 '<button class="button" onclick="window.scrollTo(0, 0)" title="' . $lang['btn_top'] . '">' . 183 $lang['btn_top'] . 184 '</button></a>'; 185 186 return $ret; 187} 188 189/** 190 * Displays a button (using its own form) 191 * If tooltip exists, the access key tooltip is replaced. 192 * 193 * @author Andreas Gohr <andi@splitbrain.org> 194 * 195 * @param string $name 196 * @param string $id 197 * @param string $akey access key 198 * @param string[] $params key-value pairs added as hidden inputs 199 * @param string $method 200 * @param string $tooltip 201 * @param bool|string $label label text, false: lookup btn_$name in localization 202 * @param string $svg (optional) svg code, inserted into the button 203 * @return string 204 */ 205function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false, $svg=null){ 206 global $conf; 207 global $lang; 208 209 if (!$label) 210 $label = $lang['btn_'.$name]; 211 212 $ret = ''; 213 214 //filter id (without urlencoding) 215 $id = idfilter($id,false); 216 217 //make nice URLs even for buttons 218 if($conf['userewrite'] == 2){ 219 $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id; 220 }elseif($conf['userewrite']){ 221 $script = DOKU_BASE.$id; 222 }else{ 223 $script = DOKU_BASE.DOKU_SCRIPT; 224 $params['id'] = $id; 225 } 226 227 $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">'; 228 229 if(is_array($params)){ 230 foreach($params as $key => $val) { 231 $ret .= '<input type="hidden" name="'.$key.'" '; 232 $ret .= 'value="'.hsc($val).'" />'; 233 } 234 } 235 236 if ($tooltip!='') { 237 $tip = hsc($tooltip); 238 }else{ 239 $tip = hsc($label); 240 } 241 242 $ret .= '<button type="submit" '; 243 if($akey){ 244 $tip .= ' ['.strtoupper($akey).']'; 245 $ret .= 'accesskey="'.$akey.'" '; 246 } 247 $ret .= 'title="'.$tip.'">'; 248 if ($svg) { 249 $ret .= '<span>' . hsc($label) . '</span>'; 250 $ret .= inlineSVG($svg); 251 } else { 252 $ret .= hsc($label); 253 } 254 $ret .= '</button>'; 255 $ret .= '</div></form>'; 256 257 return $ret; 258} 259/** 260 * show a revision warning 261 * 262 * @author Szymon Olewniczak <dokuwiki@imz.re> 263 */ 264function html_showrev() { 265 print p_locale_xhtml('showrev'); 266} 267 268/** 269 * Show a wiki page 270 * 271 * @author Andreas Gohr <andi@splitbrain.org> 272 * 273 * @param null|string $txt wiki text or null for showing $ID 274 */ 275function html_show($txt=null){ 276 global $ID; 277 global $REV; 278 global $HIGH; 279 global $INFO; 280 global $DATE_AT; 281 //disable section editing for old revisions or in preview 282 if($txt || $REV){ 283 $secedit = false; 284 }else{ 285 $secedit = true; 286 } 287 288 if (!is_null($txt)){ 289 //PreviewHeader 290 echo '<br id="scroll__here" />'; 291 echo p_locale_xhtml('preview'); 292 echo '<div class="preview"><div class="pad">'; 293 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 294 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 295 echo $html; 296 echo '<div class="clearer"></div>'; 297 echo '</div></div>'; 298 299 }else{ 300 if ($REV||$DATE_AT){ 301 $data = array('rev' => &$REV, 'date_at' => &$DATE_AT); 302 trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev'); 303 } 304 $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT); 305 $html = html_secedit($html,$secedit); 306 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 307 $html = html_hilight($html,$HIGH); 308 echo $html; 309 } 310} 311 312/** 313 * ask the user about how to handle an exisiting draft 314 * 315 * @author Andreas Gohr <andi@splitbrain.org> 316 */ 317function html_draft(){ 318 global $INFO; 319 global $ID; 320 global $lang; 321 $draft = new \dokuwiki\Draft($ID, $INFO['client']); 322 $text = $draft->getDraftText(); 323 324 print p_locale_xhtml('draft'); 325 html_diff($text, false); 326 $form = new Doku_Form(array('id' => 'dw__editform')); 327 $form->addHidden('id', $ID); 328 $form->addHidden('date', $draft->getDraftDate()); 329 $form->addHidden('wikitext', $text); 330 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 331 $form->addElement($draft->getDraftMessage()); 332 $form->addElement(form_makeCloseTag('div')); 333 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 334 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 335 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 336 html_form('draft', $form); 337} 338 339/** 340 * Highlights searchqueries in HTML code 341 * 342 * @author Andreas Gohr <andi@splitbrain.org> 343 * @author Harry Fuecks <hfuecks@gmail.com> 344 * 345 * @param string $html 346 * @param array|string $phrases 347 * @return string html 348 */ 349function html_hilight($html,$phrases){ 350 $phrases = (array) $phrases; 351 $phrases = array_map('preg_quote_cb', $phrases); 352 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 353 $phrases = array_filter($phrases); 354 $regex = join('|',$phrases); 355 356 if ($regex === '') return $html; 357 if (!utf8_check($regex)) return $html; 358 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 359 return $html; 360} 361 362/** 363 * Callback used by html_hilight() 364 * 365 * @author Harry Fuecks <hfuecks@gmail.com> 366 * 367 * @param array $m matches 368 * @return string html 369 */ 370function html_hilight_callback($m) { 371 $hlight = unslash($m[0]); 372 if ( !isset($m[2])) { 373 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 374 } 375 return $hlight; 376} 377 378/** 379 * Display error on locked pages 380 * 381 * @author Andreas Gohr <andi@splitbrain.org> 382 */ 383function html_locked(){ 384 global $ID; 385 global $conf; 386 global $lang; 387 global $INFO; 388 389 $locktime = filemtime(wikiLockFN($ID)); 390 $expire = dformat($locktime + $conf['locktime']); 391 $min = round(($conf['locktime'] - (time() - $locktime) )/60); 392 393 print p_locale_xhtml('locked'); 394 print '<ul>'; 395 print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>'; 396 print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>'; 397 print '</ul>'; 398} 399 400/** 401 * list old revisions 402 * 403 * @author Andreas Gohr <andi@splitbrain.org> 404 * @author Ben Coburn <btcoburn@silicodon.net> 405 * @author Kate Arzamastseva <pshns@ukr.net> 406 * 407 * @param int $first skip the first n changelog lines 408 * @param bool|string $media_id id of media, or false for current page 409 */ 410function html_revisions($first=0, $media_id = false){ 411 global $ID; 412 global $INFO; 413 global $conf; 414 global $lang; 415 $id = $ID; 416 if ($media_id) { 417 $id = $media_id; 418 $changelog = new MediaChangeLog($id); 419 } else { 420 $changelog = new PageChangeLog($id); 421 } 422 423 /* we need to get one additional log entry to be able to 424 * decide if this is the last page or is there another one. 425 * see html_recent() 426 */ 427 428 $revisions = $changelog->getRevisions($first, $conf['recent']+1); 429 430 if(count($revisions)==0 && $first!=0){ 431 $first=0; 432 $revisions = $changelog->getRevisions($first, $conf['recent']+1); 433 } 434 $hasNext = false; 435 if (count($revisions)>$conf['recent']) { 436 $hasNext = true; 437 array_pop($revisions); // remove extra log entry 438 } 439 440 if (!$media_id) print p_locale_xhtml('revisions'); 441 442 $params = array('id' => 'page__revisions', 'class' => 'changes'); 443 if($media_id) { 444 $params['action'] = media_managerURL(array('image' => $media_id), '&'); 445 } 446 447 if(!$media_id) { 448 $exists = $INFO['exists']; 449 $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; 450 if(!$display_name) { 451 $display_name = $id; 452 } 453 } else { 454 $exists = file_exists(mediaFN($id)); 455 $display_name = $id; 456 } 457 458 $form = new Doku_Form($params); 459 $form->addElement(form_makeOpenTag('ul')); 460 461 if($exists && $first == 0) { 462 $minor = false; 463 if($media_id) { 464 $date = dformat(@filemtime(mediaFN($id))); 465 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 466 467 $changelog->setChunkSize(1024); 468 $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id)))); 469 470 $summary = $revinfo['sum']; 471 if($revinfo['user']) { 472 $editor = $revinfo['user']; 473 } else { 474 $editor = $revinfo['ip']; 475 } 476 $sizechange = $revinfo['sizechange']; 477 } else { 478 $date = dformat($INFO['lastmod']); 479 if(isset($INFO['meta']) && isset($INFO['meta']['last_change'])) { 480 if($INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 481 $minor = true; 482 } 483 if(isset($INFO['meta']['last_change']['sizechange'])) { 484 $sizechange = $INFO['meta']['last_change']['sizechange']; 485 } else { 486 $sizechange = null; 487 } 488 } 489 $pagelog = new PageChangeLog($ID); 490 $latestrev = $pagelog->getRevisions(-1, 1); 491 $latestrev = array_pop($latestrev); 492 $href = wl($id,"rev=$latestrev",false,'&'); 493 $summary = $INFO['sum']; 494 $editor = $INFO['editor']; 495 } 496 497 $form->addElement(form_makeOpenTag('li', array('class' => ($minor ? 'minor' : '')))); 498 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 499 $form->addElement(form_makeTag('input', array( 500 'type' => 'checkbox', 501 'name' => 'rev2[]', 502 'value' => 'current'))); 503 504 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 505 $form->addElement($date); 506 $form->addElement(form_makeCloseTag('span')); 507 508 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 509 510 $form->addElement(form_makeOpenTag('a', array( 511 'class' => 'wikilink1', 512 'href' => $href))); 513 $form->addElement($display_name); 514 $form->addElement(form_makeCloseTag('a')); 515 516 if ($media_id) $form->addElement(form_makeOpenTag('div')); 517 518 if($summary) { 519 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 520 if(!$media_id) $form->addElement(' – '); 521 $form->addElement('<bdi>' . hsc($summary) . '</bdi>'); 522 $form->addElement(form_makeCloseTag('span')); 523 } 524 525 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 526 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):'<bdi>'.editorinfo($editor).'</bdi>'); 527 $form->addElement(form_makeCloseTag('span')); 528 529 html_sizechange($sizechange, $form); 530 531 $form->addElement('('.$lang['current'].')'); 532 533 if ($media_id) $form->addElement(form_makeCloseTag('div')); 534 535 $form->addElement(form_makeCloseTag('div')); 536 $form->addElement(form_makeCloseTag('li')); 537 } 538 539 foreach($revisions as $rev) { 540 $date = dformat($rev); 541 $info = $changelog->getRevisionInfo($rev); 542 if($media_id) { 543 $exists = file_exists(mediaFN($id, $rev)); 544 } else { 545 $exists = page_exists($id, $rev); 546 } 547 548 $class = ''; 549 if($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 550 $class = 'minor'; 551 } 552 $form->addElement(form_makeOpenTag('li', array('class' => $class))); 553 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 554 if($exists){ 555 $form->addElement(form_makeTag('input', array( 556 'type' => 'checkbox', 557 'name' => 'rev2[]', 558 'value' => $rev))); 559 }else{ 560 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 561 } 562 563 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 564 $form->addElement($date); 565 $form->addElement(form_makeCloseTag('span')); 566 567 if($exists){ 568 if (!$media_id) { 569 $href = wl($id,"rev=$rev,do=diff", false, '&'); 570 } else { 571 $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 572 } 573 $form->addElement(form_makeOpenTag('a', array( 574 'class' => 'diff_link', 575 'href' => $href))); 576 $form->addElement(form_makeTag('img', array( 577 'src' => DOKU_BASE.'lib/images/diff.png', 578 'width' => 15, 579 'height' => 11, 580 'title' => $lang['diff'], 581 'alt' => $lang['diff']))); 582 $form->addElement(form_makeCloseTag('a')); 583 584 if (!$media_id) { 585 $href = wl($id,"rev=$rev",false,'&'); 586 } else { 587 $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 588 } 589 $form->addElement(form_makeOpenTag('a', array( 590 'class' => 'wikilink1', 591 'href' => $href))); 592 $form->addElement($display_name); 593 $form->addElement(form_makeCloseTag('a')); 594 }else{ 595 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 596 $form->addElement($display_name); 597 } 598 599 if ($media_id) $form->addElement(form_makeOpenTag('div')); 600 601 if ($info['sum']) { 602 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 603 if(!$media_id) $form->addElement(' – '); 604 $form->addElement('<bdi>'.hsc($info['sum']).'</bdi>'); 605 $form->addElement(form_makeCloseTag('span')); 606 } 607 608 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 609 if($info['user']){ 610 $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>'); 611 if(auth_ismanager()){ 612 $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>'); 613 } 614 }else{ 615 $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>'); 616 } 617 $form->addElement(form_makeCloseTag('span')); 618 619 html_sizechange($info['sizechange'], $form); 620 621 if ($media_id) $form->addElement(form_makeCloseTag('div')); 622 623 $form->addElement(form_makeCloseTag('div')); 624 $form->addElement(form_makeCloseTag('li')); 625 } 626 $form->addElement(form_makeCloseTag('ul')); 627 if (!$media_id) { 628 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 629 } else { 630 $form->addHidden('mediado', 'diff'); 631 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 632 } 633 html_form('revisions', $form); 634 635 print '<div class="pagenav">'; 636 $last = $first + $conf['recent']; 637 if ($first > 0) { 638 $first -= $conf['recent']; 639 if ($first < 0) $first = 0; 640 print '<div class="pagenav-prev">'; 641 if ($media_id) { 642 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&', false, true)); 643 } else { 644 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 645 } 646 print '</div>'; 647 } 648 if ($hasNext) { 649 print '<div class="pagenav-next">'; 650 if ($media_id) { 651 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&', false, true)); 652 } else { 653 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 654 } 655 print '</div>'; 656 } 657 print '</div>'; 658 659} 660 661/** 662 * display recent changes 663 * 664 * @author Andreas Gohr <andi@splitbrain.org> 665 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 666 * @author Ben Coburn <btcoburn@silicodon.net> 667 * @author Kate Arzamastseva <pshns@ukr.net> 668 * 669 * @param int $first 670 * @param string $show_changes 671 */ 672function html_recent($first = 0, $show_changes = 'both') { 673 global $conf; 674 global $lang; 675 global $ID; 676 /* we need to get one additionally log entry to be able to 677 * decide if this is the last page or is there another one. 678 * This is the cheapest solution to get this information. 679 */ 680 $flags = 0; 681 if($show_changes == 'mediafiles' && $conf['mediarevisions']) { 682 $flags = RECENTS_MEDIA_CHANGES; 683 } elseif($show_changes == 'pages') { 684 $flags = 0; 685 } elseif($conf['mediarevisions']) { 686 $show_changes = 'both'; 687 $flags = RECENTS_MEDIA_PAGES_MIXED; 688 } 689 690 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); 691 if(count($recents) == 0 && $first != 0) { 692 $first = 0; 693 $recents = getRecents($first, $conf['recent'] + 1, getNS($ID), $flags); 694 } 695 $hasNext = false; 696 if(count($recents) > $conf['recent']) { 697 $hasNext = true; 698 array_pop($recents); // remove extra log entry 699 } 700 701 print p_locale_xhtml('recent'); 702 703 if(getNS($ID) != '') { 704 print '<div class="level1"><p>' . 705 sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . 706 '</p></div>'; 707 } 708 709 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); 710 $form->addHidden('sectok', null); 711 $form->addHidden('do', 'recent'); 712 $form->addHidden('id', $ID); 713 714 if($conf['mediarevisions']) { 715 $form->addElement('<div class="changeType">'); 716 $form->addElement(form_makeListboxField( 717 'show_changes', 718 array( 719 'pages' => $lang['pages_changes'], 720 'mediafiles' => $lang['media_changes'], 721 'both' => $lang['both_changes'] 722 ), 723 $show_changes, 724 $lang['changes_type'], 725 '', '', 726 array('class' => 'quickselect'))); 727 728 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); 729 $form->addElement('</div>'); 730 } 731 732 $form->addElement(form_makeOpenTag('ul')); 733 734 foreach($recents as $recent) { 735 $date = dformat($recent['date']); 736 737 $class = ''; 738 if($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { 739 $class = 'minor'; 740 } 741 $form->addElement(form_makeOpenTag('li', array('class' => $class))); 742 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 743 744 if(!empty($recent['media'])) { 745 $form->addElement(media_printicon($recent['id'])); 746 } else { 747 $icon = DOKU_BASE . 'lib/images/fileicons/file.png'; 748 $form->addElement('<img src="' . $icon . '" alt="' . $recent['id'] . '" class="icon" />'); 749 } 750 751 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 752 $form->addElement($date); 753 $form->addElement(form_makeCloseTag('span')); 754 755 $diff = false; 756 $href = ''; 757 758 if(!empty($recent['media'])) { 759 $changelog = new MediaChangeLog($recent['id']); 760 $revs = $changelog->getRevisions(0, 1); 761 $diff = (count($revs) && file_exists(mediaFN($recent['id']))); 762 if($diff) { 763 $href = media_managerURL(array( 764 'tab_details' => 'history', 765 'mediado' => 'diff', 766 'image' => $recent['id'], 767 'ns' => getNS($recent['id']) 768 ), '&'); 769 } 770 } else { 771 $href = wl($recent['id'], "do=diff", false, '&'); 772 } 773 774 if(!empty($recent['media']) && !$diff) { 775 $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); 776 } else { 777 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); 778 $form->addElement(form_makeTag('img', array( 779 'src' => DOKU_BASE . 'lib/images/diff.png', 780 'width' => 15, 781 'height' => 11, 782 'title' => $lang['diff'], 783 'alt' => $lang['diff'] 784 ))); 785 $form->addElement(form_makeCloseTag('a')); 786 } 787 788 if(!empty($recent['media'])) { 789 $href = media_managerURL( 790 array( 791 'tab_details' => 'history', 792 'image' => $recent['id'], 793 'ns' => getNS($recent['id']) 794 ), 795 '&' 796 ); 797 } else { 798 $href = wl($recent['id'], "do=revisions", false, '&'); 799 } 800 $form->addElement(form_makeOpenTag('a', array( 801 'class' => 'revisions_link', 802 'href' => $href))); 803 $form->addElement(form_makeTag('img', array( 804 'src' => DOKU_BASE . 'lib/images/history.png', 805 'width' => 12, 806 'height' => 14, 807 'title' => $lang['btn_revs'], 808 'alt' => $lang['btn_revs'] 809 ))); 810 $form->addElement(form_makeCloseTag('a')); 811 812 if(!empty($recent['media'])) { 813 $href = media_managerURL( 814 array( 815 'tab_details' => 'view', 816 'image' => $recent['id'], 817 'ns' => getNS($recent['id']) 818 ), 819 '&' 820 ); 821 $class = file_exists(mediaFN($recent['id'])) ? 'wikilink1' : 'wikilink2'; 822 $form->addElement(form_makeOpenTag('a', array( 823 'class' => $class, 824 'href' => $href))); 825 $form->addElement($recent['id']); 826 $form->addElement(form_makeCloseTag('a')); 827 } else { 828 $form->addElement(html_wikilink(':' . $recent['id'], useHeading('navigation') ? null : $recent['id'])); 829 } 830 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 831 $form->addElement(' – ' . hsc($recent['sum'])); 832 $form->addElement(form_makeCloseTag('span')); 833 834 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 835 if($recent['user']) { 836 $form->addElement('<bdi>' . editorinfo($recent['user']) . '</bdi>'); 837 if(auth_ismanager()) { 838 $form->addElement(' <bdo dir="ltr">(' . $recent['ip'] . ')</bdo>'); 839 } 840 } else { 841 $form->addElement('<bdo dir="ltr">' . $recent['ip'] . '</bdo>'); 842 } 843 $form->addElement(form_makeCloseTag('span')); 844 845 html_sizechange($recent['sizechange'], $form); 846 847 $form->addElement(form_makeCloseTag('div')); 848 $form->addElement(form_makeCloseTag('li')); 849 } 850 $form->addElement(form_makeCloseTag('ul')); 851 852 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 853 $last = $first + $conf['recent']; 854 if($first > 0) { 855 $first -= $conf['recent']; 856 if($first < 0) $first = 0; 857 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 858 $form->addElement(form_makeOpenTag('button', array( 859 'type' => 'submit', 860 'name' => 'first[' . $first . ']', 861 'accesskey' => 'n', 862 'title' => $lang['btn_newer'] . ' [N]', 863 'class' => 'button show' 864 ))); 865 $form->addElement($lang['btn_newer']); 866 $form->addElement(form_makeCloseTag('button')); 867 $form->addElement(form_makeCloseTag('div')); 868 } 869 if($hasNext) { 870 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 871 $form->addElement(form_makeOpenTag('button', array( 872 'type' => 'submit', 873 'name' => 'first[' . $last . ']', 874 'accesskey' => 'p', 875 'title' => $lang['btn_older'] . ' [P]', 876 'class' => 'button show' 877 ))); 878 $form->addElement($lang['btn_older']); 879 $form->addElement(form_makeCloseTag('button')); 880 $form->addElement(form_makeCloseTag('div')); 881 } 882 $form->addElement(form_makeCloseTag('div')); 883 html_form('recent', $form); 884} 885 886/** 887 * Display page index 888 * 889 * @author Andreas Gohr <andi@splitbrain.org> 890 * 891 * @param string $ns 892 */ 893function html_index($ns){ 894 global $conf; 895 global $ID; 896 $ns = cleanID($ns); 897 if(empty($ns)){ 898 $ns = getNS($ID); 899 if($ns === false) $ns =''; 900 } 901 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 902 903 echo p_locale_xhtml('index'); 904 echo '<div id="index__tree" class="index__tree">'; 905 906 $data = array(); 907 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 908 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 909 910 echo '</div>'; 911} 912 913/** 914 * Index item formatter 915 * 916 * User function for html_buildlist() 917 * 918 * @author Andreas Gohr <andi@splitbrain.org> 919 * 920 * @param array $item 921 * @return string 922 */ 923function html_list_index($item){ 924 global $ID, $conf; 925 926 // prevent searchbots needlessly following links 927 $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? 'rel="nofollow"' : ''; 928 929 $ret = ''; 930 $base = ':'.$item['id']; 931 $base = substr($base,strrpos($base,':')+1); 932 if($item['type']=='d'){ 933 // FS#2766, no need for search bots to follow namespace links in the index 934 $link = wl($ID, 'idx=' . rawurlencode($item['id'])); 935 $ret .= '<a href="' . $link . '" title="' . $item['id'] . '" class="idx_dir" ' . $nofollow . '><strong>'; 936 $ret .= $base; 937 $ret .= '</strong></a>'; 938 }else{ 939 // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605 940 $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id'])); 941 } 942 return $ret; 943} 944 945/** 946 * Index List item 947 * 948 * This user function is used in html_buildlist to build the 949 * <li> tags for namespaces when displaying the page index 950 * it gives different classes to opened or closed "folders" 951 * 952 * @author Andreas Gohr <andi@splitbrain.org> 953 * 954 * @param array $item 955 * @return string html 956 */ 957function html_li_index($item){ 958 global $INFO; 959 global $ACT; 960 961 $class = ''; 962 $id = ''; 963 964 if($item['type'] == "f"){ 965 // scroll to the current item 966 if($item['id'] == $INFO['id'] && $ACT == 'index') { 967 $id = ' id="scroll__here"'; 968 $class = ' bounce'; 969 } 970 return '<li class="level'.$item['level'].$class.'" '.$id.'>'; 971 }elseif($item['open']){ 972 return '<li class="open">'; 973 }else{ 974 return '<li class="closed">'; 975 } 976} 977 978/** 979 * Default List item 980 * 981 * @author Andreas Gohr <andi@splitbrain.org> 982 * 983 * @param array $item 984 * @return string html 985 */ 986function html_li_default($item){ 987 return '<li class="level'.$item['level'].'">'; 988} 989 990/** 991 * Build an unordered list 992 * 993 * Build an unordered list from the given $data array 994 * Each item in the array has to have a 'level' property 995 * the item itself gets printed by the given $func user 996 * function. The second and optional function is used to 997 * print the <li> tag. Both user function need to accept 998 * a single item. 999 * 1000 * Both user functions can be given as array to point to 1001 * a member of an object. 1002 * 1003 * @author Andreas Gohr <andi@splitbrain.org> 1004 * 1005 * @param array $data array with item arrays 1006 * @param string $class class of ul wrapper 1007 * @param callable $func callback to print an list item 1008 * @param callable $lifunc callback to the opening li tag 1009 * @param bool $forcewrapper Trigger building a wrapper ul if the first level is 1010 * 0 (we have a root object) or 1 (just the root content) 1011 * @return string html of an unordered list 1012 */ 1013function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){ 1014 if (count($data) === 0) { 1015 return ''; 1016 } 1017 1018 $firstElement = reset($data); 1019 $start_level = $firstElement['level']; 1020 $level = $start_level; 1021 $ret = ''; 1022 $open = 0; 1023 1024 foreach ($data as $item){ 1025 1026 if( $item['level'] > $level ){ 1027 //open new list 1028 for($i=0; $i<($item['level'] - $level); $i++){ 1029 if ($i) $ret .= "<li class=\"clear\">"; 1030 $ret .= "\n<ul class=\"$class\">\n"; 1031 $open++; 1032 } 1033 $level = $item['level']; 1034 1035 }elseif( $item['level'] < $level ){ 1036 //close last item 1037 $ret .= "</li>\n"; 1038 while( $level > $item['level'] && $open > 0 ){ 1039 //close higher lists 1040 $ret .= "</ul>\n</li>\n"; 1041 $level--; 1042 $open--; 1043 } 1044 } elseif ($ret !== '') { 1045 //close previous item 1046 $ret .= "</li>\n"; 1047 } 1048 1049 //print item 1050 $ret .= call_user_func($lifunc,$item); 1051 $ret .= '<div class="li">'; 1052 1053 $ret .= call_user_func($func,$item); 1054 $ret .= '</div>'; 1055 } 1056 1057 //close remaining items and lists 1058 $ret .= "</li>\n"; 1059 while($open-- > 0) { 1060 $ret .= "</ul></li>\n"; 1061 } 1062 1063 if ($forcewrapper || $start_level < 2) { 1064 // Trigger building a wrapper ul if the first level is 1065 // 0 (we have a root object) or 1 (just the root content) 1066 $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n"; 1067 } 1068 1069 return $ret; 1070} 1071 1072/** 1073 * display backlinks 1074 * 1075 * @author Andreas Gohr <andi@splitbrain.org> 1076 * @author Michael Klier <chi@chimeric.de> 1077 */ 1078function html_backlinks(){ 1079 global $ID; 1080 global $lang; 1081 1082 print p_locale_xhtml('backlinks'); 1083 1084 $data = ft_backlinks($ID); 1085 1086 if(!empty($data)) { 1087 print '<ul class="idx">'; 1088 foreach($data as $blink){ 1089 print '<li><div class="li">'; 1090 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 1091 print '</div></li>'; 1092 } 1093 print '</ul>'; 1094 } else { 1095 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 1096 } 1097} 1098 1099/** 1100 * Get header of diff HTML 1101 * 1102 * @param string $l_rev Left revisions 1103 * @param string $r_rev Right revision 1104 * @param string $id Page id, if null $ID is used 1105 * @param bool $media If it is for media files 1106 * @param bool $inline Return the header on a single line 1107 * @return string[] HTML snippets for diff header 1108 */ 1109function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) { 1110 global $lang; 1111 if ($id === null) { 1112 global $ID; 1113 $id = $ID; 1114 } 1115 $head_separator = $inline ? ' ' : '<br />'; 1116 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1117 $ml_or_wl = $media ? 'ml' : 'wl'; 1118 $l_minor = $r_minor = ''; 1119 1120 if($media) { 1121 $changelog = new MediaChangeLog($id); 1122 } else { 1123 $changelog = new PageChangeLog($id); 1124 } 1125 if(!$l_rev){ 1126 $l_head = '—'; 1127 }else{ 1128 $l_info = $changelog->getRevisionInfo($l_rev); 1129 if($l_info['user']){ 1130 $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>'; 1131 if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>'; 1132 } else { 1133 $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>'; 1134 } 1135 $l_user = '<span class="user">'.$l_user.'</span>'; 1136 $l_sum = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : ''; 1137 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1138 1139 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1140 $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1141 $l_head_title.'</a></bdi>'. 1142 $head_separator.$l_user.' '.$l_sum; 1143 } 1144 1145 if($r_rev){ 1146 $r_info = $changelog->getRevisionInfo($r_rev); 1147 if($r_info['user']){ 1148 $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>'; 1149 if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>'; 1150 } else { 1151 $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>'; 1152 } 1153 $r_user = '<span class="user">'.$r_user.'</span>'; 1154 $r_sum = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : ''; 1155 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1156 1157 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1158 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1159 $r_head_title.'</a></bdi>'. 1160 $head_separator.$r_user.' '.$r_sum; 1161 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1162 $_info = $changelog->getRevisionInfo($_rev); 1163 if($_info['user']){ 1164 $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>'; 1165 if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>'; 1166 } else { 1167 $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>'; 1168 } 1169 $_user = '<span class="user">'.$_user.'</span>'; 1170 $_sum = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : ''; 1171 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1172 1173 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1174 $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1175 $r_head_title.'</a></bdi> '. 1176 '('.$lang['current'].')'. 1177 $head_separator.$_user.' '.$_sum; 1178 }else{ 1179 $r_head = '— ('.$lang['current'].')'; 1180 } 1181 1182 return array($l_head, $r_head, $l_minor, $r_minor); 1183} 1184 1185/** 1186 * Show diff 1187 * between current page version and provided $text 1188 * or between the revisions provided via GET or POST 1189 * 1190 * @author Andreas Gohr <andi@splitbrain.org> 1191 * @param string $text when non-empty: compare with this text with most current version 1192 * @param bool $intro display the intro text 1193 * @param string $type type of the diff (inline or sidebyside) 1194 */ 1195function html_diff($text = '', $intro = true, $type = null) { 1196 global $ID; 1197 global $REV; 1198 global $lang; 1199 global $INPUT; 1200 global $INFO; 1201 $pagelog = new PageChangeLog($ID); 1202 1203 /* 1204 * Determine diff type 1205 */ 1206 if(!$type) { 1207 $type = $INPUT->str('difftype'); 1208 if(empty($type)) { 1209 $type = get_doku_pref('difftype', $type); 1210 if(empty($type) && $INFO['ismobile']) { 1211 $type = 'inline'; 1212 } 1213 } 1214 } 1215 if($type != 'inline') $type = 'sidebyside'; 1216 1217 /* 1218 * Determine requested revision(s) 1219 */ 1220 // we're trying to be clever here, revisions to compare can be either 1221 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1222 // array in rev2. 1223 $rev1 = $REV; 1224 1225 $rev2 = $INPUT->ref('rev2'); 1226 if(is_array($rev2)) { 1227 $rev1 = (int) $rev2[0]; 1228 $rev2 = (int) $rev2[1]; 1229 1230 if(!$rev1) { 1231 $rev1 = $rev2; 1232 unset($rev2); 1233 } 1234 } else { 1235 $rev2 = $INPUT->int('rev2'); 1236 } 1237 1238 /* 1239 * Determine left and right revision, its texts and the header 1240 */ 1241 $r_minor = ''; 1242 $l_minor = ''; 1243 1244 if($text) { // compare text to the most current revision 1245 $l_rev = ''; 1246 $l_text = rawWiki($ID, ''); 1247 $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . 1248 $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . 1249 $lang['current']; 1250 1251 $r_rev = ''; 1252 $r_text = cleanText($text); 1253 $r_head = $lang['yours']; 1254 } else { 1255 if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted 1256 // make sure order is correct (older on the left) 1257 if($rev1 < $rev2) { 1258 $l_rev = $rev1; 1259 $r_rev = $rev2; 1260 } else { 1261 $l_rev = $rev2; 1262 $r_rev = $rev1; 1263 } 1264 } elseif($rev1) { // single revision given, compare to current 1265 $r_rev = ''; 1266 $l_rev = $rev1; 1267 } else { // no revision was given, compare previous to current 1268 $r_rev = ''; 1269 $revs = $pagelog->getRevisions(0, 1); 1270 $l_rev = $revs[0]; 1271 $REV = $l_rev; // store revision back in $REV 1272 } 1273 1274 // when both revisions are empty then the page was created just now 1275 if(!$l_rev && !$r_rev) { 1276 $l_text = ''; 1277 } else { 1278 $l_text = rawWiki($ID, $l_rev); 1279 } 1280 $r_text = rawWiki($ID, $r_rev); 1281 1282 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); 1283 } 1284 1285 /* 1286 * Build navigation 1287 */ 1288 $l_nav = ''; 1289 $r_nav = ''; 1290 if(!$text) { 1291 list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev); 1292 } 1293 /* 1294 * Create diff object and the formatter 1295 */ 1296 $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); 1297 1298 if($type == 'inline') { 1299 $diffformatter = new InlineDiffFormatter(); 1300 } else { 1301 $diffformatter = new TableDiffFormatter(); 1302 } 1303 /* 1304 * Display intro 1305 */ 1306 if($intro) print p_locale_xhtml('diff'); 1307 1308 /* 1309 * Display type and exact reference 1310 */ 1311 if(!$text) { 1312 ptln('<div class="diffoptions group">'); 1313 1314 1315 $form = new Doku_Form(array('action' => wl())); 1316 $form->addHidden('id', $ID); 1317 $form->addHidden('rev2[0]', $l_rev); 1318 $form->addHidden('rev2[1]', $r_rev); 1319 $form->addHidden('do', 'diff'); 1320 $form->addElement( 1321 form_makeListboxField( 1322 'difftype', 1323 array( 1324 'sidebyside' => $lang['diff_side'], 1325 'inline' => $lang['diff_inline'] 1326 ), 1327 $type, 1328 $lang['diff_type'], 1329 '', '', 1330 array('class' => 'quickselect') 1331 ) 1332 ); 1333 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1334 $form->printForm(); 1335 1336 ptln('<p>'); 1337 // link to exactly this view FS#2835 1338 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); 1339 ptln('</p>'); 1340 1341 ptln('</div>'); // .diffoptions 1342 } 1343 1344 /* 1345 * Display diff view table 1346 */ 1347 ?> 1348 <div class="table"> 1349 <table class="diff diff_<?php echo $type ?>"> 1350 1351 <?php 1352 //navigation and header 1353 if($type == 'inline') { 1354 if(!$text) { ?> 1355 <tr> 1356 <td class="diff-lineheader">-</td> 1357 <td class="diffnav"><?php echo $l_nav ?></td> 1358 </tr> 1359 <tr> 1360 <th class="diff-lineheader">-</th> 1361 <th <?php echo $l_minor ?>> 1362 <?php echo $l_head ?> 1363 </th> 1364 </tr> 1365 <?php } ?> 1366 <tr> 1367 <td class="diff-lineheader">+</td> 1368 <td class="diffnav"><?php echo $r_nav ?></td> 1369 </tr> 1370 <tr> 1371 <th class="diff-lineheader">+</th> 1372 <th <?php echo $r_minor ?>> 1373 <?php echo $r_head ?> 1374 </th> 1375 </tr> 1376 <?php } else { 1377 if(!$text) { ?> 1378 <tr> 1379 <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> 1380 <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> 1381 </tr> 1382 <?php } ?> 1383 <tr> 1384 <th colspan="2" <?php echo $l_minor ?>> 1385 <?php echo $l_head ?> 1386 </th> 1387 <th colspan="2" <?php echo $r_minor ?>> 1388 <?php echo $r_head ?> 1389 </th> 1390 </tr> 1391 <?php } 1392 1393 //diff view 1394 echo html_insert_softbreaks($diffformatter->format($diff)); ?> 1395 1396 </table> 1397 </div> 1398<?php 1399} 1400 1401/** 1402 * Create html for revision navigation 1403 * 1404 * @param PageChangeLog $pagelog changelog object of current page 1405 * @param string $type inline vs sidebyside 1406 * @param int $l_rev left revision timestamp 1407 * @param int $r_rev right revision timestamp 1408 * @return string[] html of left and right navigation elements 1409 */ 1410function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) { 1411 global $INFO, $ID; 1412 1413 // last timestamp is not in changelog, retrieve timestamp from metadata 1414 // note: when page is removed, the metadata timestamp is zero 1415 if(!$r_rev) { 1416 if(isset($INFO['meta']['last_change']['date'])) { 1417 $r_rev = $INFO['meta']['last_change']['date']; 1418 } else { 1419 $r_rev = 0; 1420 } 1421 } 1422 1423 //retrieve revisions with additional info 1424 list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev); 1425 $l_revisions = array(); 1426 if(!$l_rev) { 1427 $l_revisions[0] = array(0, "", false); //no left revision given, add dummy 1428 } 1429 foreach($l_revs as $rev) { 1430 $info = $pagelog->getRevisionInfo($rev); 1431 $l_revisions[$rev] = array( 1432 $rev, 1433 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1434 $r_rev ? $rev >= $r_rev : false //disable? 1435 ); 1436 } 1437 $r_revisions = array(); 1438 if(!$r_rev) { 1439 $r_revisions[0] = array(0, "", false); //no right revision given, add dummy 1440 } 1441 foreach($r_revs as $rev) { 1442 $info = $pagelog->getRevisionInfo($rev); 1443 $r_revisions[$rev] = array( 1444 $rev, 1445 dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'], 1446 $rev <= $l_rev //disable? 1447 ); 1448 } 1449 1450 //determine previous/next revisions 1451 $l_index = array_search($l_rev, $l_revs); 1452 $l_prev = $l_revs[$l_index + 1]; 1453 $l_next = $l_revs[$l_index - 1]; 1454 if($r_rev) { 1455 $r_index = array_search($r_rev, $r_revs); 1456 $r_prev = $r_revs[$r_index + 1]; 1457 $r_next = $r_revs[$r_index - 1]; 1458 } else { 1459 //removed page 1460 if($l_next) { 1461 $r_prev = $r_revs[0]; 1462 } else { 1463 $r_prev = null; 1464 } 1465 $r_next = null; 1466 } 1467 1468 /* 1469 * Left side: 1470 */ 1471 $l_nav = ''; 1472 //move back 1473 if($l_prev) { 1474 $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev); 1475 $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev); 1476 } 1477 //dropdown 1478 $form = new Doku_Form(array('action' => wl())); 1479 $form->addHidden('id', $ID); 1480 $form->addHidden('difftype', $type); 1481 $form->addHidden('rev2[1]', $r_rev); 1482 $form->addHidden('do', 'diff'); 1483 $form->addElement( 1484 form_makeListboxField( 1485 'rev2[0]', 1486 $l_revisions, 1487 $l_rev, 1488 '', '', '', 1489 array('class' => 'quickselect') 1490 ) 1491 ); 1492 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1493 $l_nav .= $form->getForm(); 1494 //move forward 1495 if($l_next && ($l_next < $r_rev || !$r_rev)) { 1496 $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev); 1497 } 1498 1499 /* 1500 * Right side: 1501 */ 1502 $r_nav = ''; 1503 //move back 1504 if($l_rev < $r_prev) { 1505 $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev); 1506 } 1507 //dropdown 1508 $form = new Doku_Form(array('action' => wl())); 1509 $form->addHidden('id', $ID); 1510 $form->addHidden('rev2[0]', $l_rev); 1511 $form->addHidden('difftype', $type); 1512 $form->addHidden('do', 'diff'); 1513 $form->addElement( 1514 form_makeListboxField( 1515 'rev2[1]', 1516 $r_revisions, 1517 $r_rev, 1518 '', '', '', 1519 array('class' => 'quickselect') 1520 ) 1521 ); 1522 $form->addElement(form_makeButton('submit', 'diff', 'Go')); 1523 $r_nav .= $form->getForm(); 1524 //move forward 1525 if($r_next) { 1526 if($pagelog->isCurrentRevision($r_next)) { 1527 $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page 1528 } else { 1529 $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next); 1530 } 1531 $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next); 1532 } 1533 return array($l_nav, $r_nav); 1534} 1535 1536/** 1537 * Create html link to a diff defined by two revisions 1538 * 1539 * @param string $difftype display type 1540 * @param string $linktype 1541 * @param int $lrev oldest revision 1542 * @param int $rrev newest revision or null for diff with current revision 1543 * @return string html of link to a diff 1544 */ 1545function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) { 1546 global $ID, $lang; 1547 if(!$rrev) { 1548 $urlparam = array( 1549 'do' => 'diff', 1550 'rev' => $lrev, 1551 'difftype' => $difftype, 1552 ); 1553 } else { 1554 $urlparam = array( 1555 'do' => 'diff', 1556 'rev2[0]' => $lrev, 1557 'rev2[1]' => $rrev, 1558 'difftype' => $difftype, 1559 ); 1560 } 1561 return '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' . 1562 '<span>' . $lang[$linktype] . '</span>' . 1563 '</a>' . "\n"; 1564} 1565 1566/** 1567 * Insert soft breaks in diff html 1568 * 1569 * @param string $diffhtml 1570 * @return string 1571 */ 1572function html_insert_softbreaks($diffhtml) { 1573 // search the diff html string for both: 1574 // - html tags, so these can be ignored 1575 // - long strings of characters without breaking characters 1576 return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml); 1577} 1578 1579/** 1580 * callback which adds softbreaks 1581 * 1582 * @param array $match array with first the complete match 1583 * @return string the replacement 1584 */ 1585function html_softbreak_callback($match){ 1586 // if match is an html tag, return it intact 1587 if ($match[0]{0} == '<') return $match[0]; 1588 1589 // its a long string without a breaking character, 1590 // make certain characters into breaking characters by inserting a 1591 // word break opportunity (<wbr> tag) in front of them. 1592 $regex = <<< REGEX 1593(?(?= # start a conditional expression with a positive look ahead ... 1594&\#?\\w{1,6};) # ... for html entities - we don't want to split them (ok to catch some invalid combinations) 1595&\#?\\w{1,6}; # yes pattern - a quicker match for the html entity, since we know we have one 1596| 1597[?/,&\#;:] # no pattern - any other group of 'special' characters to insert a breaking character after 1598)+ # end conditional expression 1599REGEX; 1600 1601 return preg_replace('<'.$regex.'>xu','\0<wbr>',$match[0]); 1602} 1603 1604/** 1605 * show warning on conflict detection 1606 * 1607 * @author Andreas Gohr <andi@splitbrain.org> 1608 * 1609 * @param string $text 1610 * @param string $summary 1611 */ 1612function html_conflict($text,$summary){ 1613 global $ID; 1614 global $lang; 1615 1616 print p_locale_xhtml('conflict'); 1617 $form = new Doku_Form(array('id' => 'dw__editform')); 1618 $form->addHidden('id', $ID); 1619 $form->addHidden('wikitext', $text); 1620 $form->addHidden('summary', $summary); 1621 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1622 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1623 html_form('conflict', $form); 1624 print '<br /><br /><br /><br />'.NL; 1625} 1626 1627/** 1628 * Prints the global message array 1629 * 1630 * @author Andreas Gohr <andi@splitbrain.org> 1631 */ 1632function html_msgarea(){ 1633 global $MSG, $MSG_shown; 1634 /** @var array $MSG */ 1635 // store if the global $MSG has already been shown and thus HTML output has been started 1636 $MSG_shown = true; 1637 1638 if(!isset($MSG)) return; 1639 1640 $shown = array(); 1641 foreach($MSG as $msg){ 1642 $hash = md5($msg['msg']); 1643 if(isset($shown[$hash])) continue; // skip double messages 1644 if(info_msg_allowed($msg)){ 1645 print '<div class="'.$msg['lvl'].'">'; 1646 print $msg['msg']; 1647 print '</div>'; 1648 } 1649 $shown[$hash] = 1; 1650 } 1651 1652 unset($GLOBALS['MSG']); 1653} 1654 1655/** 1656 * Prints the registration form 1657 * 1658 * @author Andreas Gohr <andi@splitbrain.org> 1659 */ 1660function html_register(){ 1661 global $lang; 1662 global $conf; 1663 global $INPUT; 1664 1665 $base_attrs = array('size'=>50,'required'=>'required'); 1666 $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit'); 1667 1668 print p_locale_xhtml('register'); 1669 print '<div class="centeralign">'.NL; 1670 $form = new Doku_Form(array('id' => 'dw__register')); 1671 $form->startFieldset($lang['btn_register']); 1672 $form->addHidden('do', 'register'); 1673 $form->addHidden('save', '1'); 1674 $form->addElement( 1675 form_makeTextField( 1676 'login', 1677 $INPUT->post->str('login'), 1678 $lang['user'], 1679 '', 1680 'block', 1681 $base_attrs 1682 ) 1683 ); 1684 if (!$conf['autopasswd']) { 1685 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs)); 1686 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs)); 1687 } 1688 $form->addElement( 1689 form_makeTextField( 1690 'fullname', 1691 $INPUT->post->str('fullname'), 1692 $lang['fullname'], 1693 '', 1694 'block', 1695 $base_attrs 1696 ) 1697 ); 1698 $form->addElement( 1699 form_makeField( 1700 'email', 1701 'email', 1702 $INPUT->post->str('email'), 1703 $lang['email'], 1704 '', 1705 'block', 1706 $email_attrs 1707 ) 1708 ); 1709 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1710 $form->endFieldset(); 1711 html_form('register', $form); 1712 1713 print '</div>'.NL; 1714} 1715 1716/** 1717 * Print the update profile form 1718 * 1719 * @author Christopher Smith <chris@jalakai.co.uk> 1720 * @author Andreas Gohr <andi@splitbrain.org> 1721 */ 1722function html_updateprofile(){ 1723 global $lang; 1724 global $conf; 1725 global $INPUT; 1726 global $INFO; 1727 /** @var AuthPlugin $auth */ 1728 global $auth; 1729 1730 print p_locale_xhtml('updateprofile'); 1731 print '<div class="centeralign">'.NL; 1732 1733 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1734 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1735 $form = new Doku_Form(array('id' => 'dw__register')); 1736 $form->startFieldset($lang['profile']); 1737 $form->addHidden('do', 'profile'); 1738 $form->addHidden('save', '1'); 1739 $form->addElement( 1740 form_makeTextField( 1741 'login', 1742 $_SERVER['REMOTE_USER'], 1743 $lang['user'], 1744 '', 1745 'block', 1746 array('size' => '50', 'disabled' => 'disabled') 1747 ) 1748 ); 1749 $attr = array('size'=>'50'); 1750 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1751 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1752 $attr = array('size'=>'50', 'class'=>'edit'); 1753 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1754 $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr)); 1755 $form->addElement(form_makeTag('br')); 1756 if ($auth->canDo('modPass')) { 1757 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1758 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1759 } 1760 if ($conf['profileconfirm']) { 1761 $form->addElement(form_makeTag('br')); 1762 $form->addElement( 1763 form_makePasswordField( 1764 'oldpass', 1765 $lang['oldpass'], 1766 '', 1767 'block', 1768 array('size' => '50', 'required' => 'required') 1769 ) 1770 ); 1771 } 1772 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1773 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1774 1775 $form->endFieldset(); 1776 html_form('updateprofile', $form); 1777 1778 if ($auth->canDo('delUser') && actionOK('profile_delete')) { 1779 $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete')); 1780 $form_profiledelete->startFieldset($lang['profdeleteuser']); 1781 $form_profiledelete->addHidden('do', 'profile_delete'); 1782 $form_profiledelete->addHidden('delete', '1'); 1783 $form_profiledelete->addElement( 1784 form_makeCheckboxField( 1785 'confirm_delete', 1786 '1', 1787 $lang['profconfdelete'], 1788 'dw__confirmdelete', 1789 '', 1790 array('required' => 'required') 1791 ) 1792 ); 1793 if ($conf['profileconfirm']) { 1794 $form_profiledelete->addElement(form_makeTag('br')); 1795 $form_profiledelete->addElement( 1796 form_makePasswordField( 1797 'oldpass', 1798 $lang['oldpass'], 1799 '', 1800 'block', 1801 array('size' => '50', 'required' => 'required') 1802 ) 1803 ); 1804 } 1805 $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser'])); 1806 $form_profiledelete->endFieldset(); 1807 1808 html_form('profiledelete', $form_profiledelete); 1809 } 1810 1811 print '</div>'.NL; 1812} 1813 1814/** 1815 * Preprocess edit form data 1816 * 1817 * @author Andreas Gohr <andi@splitbrain.org> 1818 * 1819 * @triggers HTML_EDITFORM_OUTPUT 1820 */ 1821function html_edit(){ 1822 global $INPUT; 1823 global $ID; 1824 global $REV; 1825 global $DATE; 1826 global $PRE; 1827 global $SUF; 1828 global $INFO; 1829 global $SUM; 1830 global $lang; 1831 global $conf; 1832 global $TEXT; 1833 1834 if ($INPUT->has('changecheck')) { 1835 $check = $INPUT->str('changecheck'); 1836 } elseif(!$INFO['exists']){ 1837 // $TEXT has been loaded from page template 1838 $check = md5(''); 1839 } else { 1840 $check = md5($TEXT); 1841 } 1842 $mod = md5($TEXT) !== $check; 1843 1844 $wr = $INFO['writable'] && !$INFO['locked']; 1845 $include = 'edit'; 1846 if($wr){ 1847 if ($REV) $include = 'editrev'; 1848 }else{ 1849 // check pseudo action 'source' 1850 if(!actionOK('source')){ 1851 msg('Command disabled: source',-1); 1852 return; 1853 } 1854 $include = 'read'; 1855 } 1856 1857 global $license; 1858 1859 $form = new Doku_Form(array('id' => 'dw__editform')); 1860 $form->addHidden('id', $ID); 1861 $form->addHidden('rev', $REV); 1862 $form->addHidden('date', $DATE); 1863 $form->addHidden('prefix', $PRE . '.'); 1864 $form->addHidden('suffix', $SUF); 1865 $form->addHidden('changecheck', $check); 1866 1867 $data = array('form' => $form, 1868 'wr' => $wr, 1869 'media_manager' => true, 1870 'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section', 1871 'intro_locale' => $include); 1872 1873 if ($data['target'] !== 'section') { 1874 // Only emit event if page is writable, section edit data is valid and 1875 // edit target is not section. 1876 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1877 } else { 1878 html_edit_form($data); 1879 } 1880 if (isset($data['intro_locale'])) { 1881 echo p_locale_xhtml($data['intro_locale']); 1882 } 1883 1884 $form->addHidden('target', $data['target']); 1885 if ($INPUT->has('hid')) { 1886 $form->addHidden('hid', $INPUT->str('hid')); 1887 } 1888 if ($INPUT->has('codeblockOffset')) { 1889 $form->addHidden('codeblockOffset', $INPUT->str('codeblockOffset')); 1890 } 1891 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1892 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1893 $form->addElement(form_makeCloseTag('div')); 1894 if ($wr) { 1895 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1896 $form->addElement( 1897 form_makeButton( 1898 'submit', 1899 'save', 1900 $lang['btn_save'], 1901 array('id' => 'edbtn__save', 'accesskey' => 's', 'tabindex' => '4') 1902 ) 1903 ); 1904 $form->addElement( 1905 form_makeButton( 1906 'submit', 1907 'preview', 1908 $lang['btn_preview'], 1909 array('id' => 'edbtn__preview', 'accesskey' => 'p', 'tabindex' => '5') 1910 ) 1911 ); 1912 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1913 $form->addElement(form_makeCloseTag('div')); 1914 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1915 $form->addElement( 1916 form_makeTextField( 1917 'summary', 1918 $SUM, 1919 $lang['summary'], 1920 'edit__summary', 1921 'nowrap', 1922 array('size' => '50', 'tabindex' => '2') 1923 ) 1924 ); 1925 $elem = html_minoredit(); 1926 if ($elem) $form->addElement($elem); 1927 $form->addElement(form_makeCloseTag('div')); 1928 } 1929 $form->addElement(form_makeCloseTag('div')); 1930 if($wr && $conf['license']){ 1931 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1932 $out = $lang['licenseok']; 1933 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1934 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1935 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1936 $form->addElement($out); 1937 $form->addElement(form_makeCloseTag('div')); 1938 } 1939 1940 if ($wr) { 1941 // sets changed to true when previewed 1942 echo '<script type="text/javascript">/*<![CDATA[*/'. NL; 1943 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1944 echo '/*!]]>*/</script>' . NL; 1945 } ?> 1946 <div class="editBox" role="application"> 1947 1948 <div class="toolbar group"> 1949 <div id="tool__bar" class="tool__bar"><?php 1950 if ($wr && $data['media_manager']){ 1951 ?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>" 1952 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php 1953 }?> 1954 </div> 1955 </div> 1956 <div id="draft__status" class="draft__status"> 1957 <?php 1958 $draft = new \dokuwiki\Draft($ID, $INFO['client']); 1959 if ($draft->isDraftAvailable()) { 1960 echo $draft->getDraftMessage(); 1961 } 1962 ?> 1963 </div> 1964 <?php 1965 1966 html_form('edit', $form); 1967 print '</div>'.NL; 1968} 1969 1970/** 1971 * Display the default edit form 1972 * 1973 * Is the default action for HTML_EDIT_FORMSELECTION. 1974 * 1975 * @param mixed[] $param 1976 */ 1977function html_edit_form($param) { 1978 global $TEXT; 1979 1980 if ($param['target'] !== 'section') { 1981 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1982 } 1983 1984 $attr = array('tabindex'=>'1'); 1985 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1986 1987 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1988} 1989 1990/** 1991 * Adds a checkbox for minor edits for logged in users 1992 * 1993 * @author Andreas Gohr <andi@splitbrain.org> 1994 * 1995 * @return array|bool 1996 */ 1997function html_minoredit(){ 1998 global $conf; 1999 global $lang; 2000 global $INPUT; 2001 // minor edits are for logged in users only 2002 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 2003 return false; 2004 } 2005 2006 $p = array(); 2007 $p['tabindex'] = 3; 2008 if($INPUT->bool('minor')) $p['checked']='checked'; 2009 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 2010} 2011 2012/** 2013 * prints some debug info 2014 * 2015 * @author Andreas Gohr <andi@splitbrain.org> 2016 */ 2017function html_debug(){ 2018 global $conf; 2019 global $lang; 2020 /** @var AuthPlugin $auth */ 2021 global $auth; 2022 global $INFO; 2023 2024 //remove sensitive data 2025 $cnf = $conf; 2026 debug_guard($cnf); 2027 $nfo = $INFO; 2028 debug_guard($nfo); 2029 $ses = $_SESSION; 2030 debug_guard($ses); 2031 2032 print '<html><body>'; 2033 2034 print '<p>When reporting bugs please send all the following '; 2035 print 'output as a mail to andi@splitbrain.org '; 2036 print 'The best way to do this is to save this page in your browser</p>'; 2037 2038 print '<b>$INFO:</b><pre>'; 2039 print_r($nfo); 2040 print '</pre>'; 2041 2042 print '<b>$_SERVER:</b><pre>'; 2043 print_r($_SERVER); 2044 print '</pre>'; 2045 2046 print '<b>$conf:</b><pre>'; 2047 print_r($cnf); 2048 print '</pre>'; 2049 2050 print '<b>DOKU_BASE:</b><pre>'; 2051 print DOKU_BASE; 2052 print '</pre>'; 2053 2054 print '<b>abs DOKU_BASE:</b><pre>'; 2055 print DOKU_URL; 2056 print '</pre>'; 2057 2058 print '<b>rel DOKU_BASE:</b><pre>'; 2059 print dirname($_SERVER['PHP_SELF']).'/'; 2060 print '</pre>'; 2061 2062 print '<b>PHP Version:</b><pre>'; 2063 print phpversion(); 2064 print '</pre>'; 2065 2066 print '<b>locale:</b><pre>'; 2067 print setlocale(LC_ALL,0); 2068 print '</pre>'; 2069 2070 print '<b>encoding:</b><pre>'; 2071 print $lang['encoding']; 2072 print '</pre>'; 2073 2074 if($auth){ 2075 print '<b>Auth backend capabilities:</b><pre>'; 2076 foreach ($auth->getCapabilities() as $cando){ 2077 print ' '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL; 2078 } 2079 print '</pre>'; 2080 } 2081 2082 print '<b>$_SESSION:</b><pre>'; 2083 print_r($ses); 2084 print '</pre>'; 2085 2086 print '<b>Environment:</b><pre>'; 2087 print_r($_ENV); 2088 print '</pre>'; 2089 2090 print '<b>PHP settings:</b><pre>'; 2091 $inis = ini_get_all(); 2092 print_r($inis); 2093 print '</pre>'; 2094 2095 if (function_exists('apache_get_version')) { 2096 $apache = array(); 2097 $apache['version'] = apache_get_version(); 2098 2099 if (function_exists('apache_get_modules')) { 2100 $apache['modules'] = apache_get_modules(); 2101 } 2102 print '<b>Apache</b><pre>'; 2103 print_r($apache); 2104 print '</pre>'; 2105 } 2106 2107 print '</body></html>'; 2108} 2109 2110/** 2111 * Form to request a new password for an existing account 2112 * 2113 * @author Benoit Chesneau <benoit@bchesneau.info> 2114 * @author Andreas Gohr <gohr@cosmocode.de> 2115 */ 2116function html_resendpwd() { 2117 global $lang; 2118 global $conf; 2119 global $INPUT; 2120 2121 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 2122 2123 if(!$conf['autopasswd'] && $token){ 2124 print p_locale_xhtml('resetpwd'); 2125 print '<div class="centeralign">'.NL; 2126 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2127 $form->startFieldset($lang['btn_resendpwd']); 2128 $form->addHidden('token', $token); 2129 $form->addHidden('do', 'resendpwd'); 2130 2131 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 2132 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 2133 2134 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2135 $form->endFieldset(); 2136 html_form('resendpwd', $form); 2137 print '</div>'.NL; 2138 }else{ 2139 print p_locale_xhtml('resendpwd'); 2140 print '<div class="centeralign">'.NL; 2141 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2142 $form->startFieldset($lang['resendpwd']); 2143 $form->addHidden('do', 'resendpwd'); 2144 $form->addHidden('save', '1'); 2145 $form->addElement(form_makeTag('br')); 2146 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 2147 $form->addElement(form_makeTag('br')); 2148 $form->addElement(form_makeTag('br')); 2149 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2150 $form->endFieldset(); 2151 html_form('resendpwd', $form); 2152 print '</div>'.NL; 2153 } 2154} 2155 2156/** 2157 * Return the TOC rendered to XHTML 2158 * 2159 * @author Andreas Gohr <andi@splitbrain.org> 2160 * 2161 * @param array $toc 2162 * @return string html 2163 */ 2164function html_TOC($toc){ 2165 if(!count($toc)) return ''; 2166 global $lang; 2167 $out = '<!-- TOC START -->'.DOKU_LF; 2168 $out .= '<div id="dw__toc" class="dw__toc">'.DOKU_LF; 2169 $out .= '<h3 class="toggle">'; 2170 $out .= $lang['toc']; 2171 $out .= '</h3>'.DOKU_LF; 2172 $out .= '<div>'.DOKU_LF; 2173 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 2174 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 2175 $out .= '<!-- TOC END -->'.DOKU_LF; 2176 return $out; 2177} 2178 2179/** 2180 * Callback for html_buildlist 2181 * 2182 * @param array $item 2183 * @return string html 2184 */ 2185function html_list_toc($item){ 2186 if(isset($item['hid'])){ 2187 $link = '#'.$item['hid']; 2188 }else{ 2189 $link = $item['link']; 2190 } 2191 2192 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 2193} 2194 2195/** 2196 * Helper function to build TOC items 2197 * 2198 * Returns an array ready to be added to a TOC array 2199 * 2200 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 2201 * @param string $text - what to display in the TOC 2202 * @param int $level - nesting level 2203 * @param string $hash - is prepended to the given $link, set blank if you want full links 2204 * @return array the toc item 2205 */ 2206function html_mktocitem($link, $text, $level, $hash='#'){ 2207 return array( 'link' => $hash.$link, 2208 'title' => $text, 2209 'type' => 'ul', 2210 'level' => $level); 2211} 2212 2213/** 2214 * Output a Doku_Form object. 2215 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 2216 * 2217 * @author Tom N Harris <tnharris@whoopdedo.org> 2218 * 2219 * @param string $name The name of the form 2220 * @param Doku_Form $form The form 2221 */ 2222function html_form($name, &$form) { 2223 // Safety check in case the caller forgets. 2224 $form->endFieldset(); 2225 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 2226} 2227 2228/** 2229 * Form print function. 2230 * Just calls printForm() on the data object. 2231 * 2232 * @param Doku_Form $data The form 2233 */ 2234function html_form_output($data) { 2235 $data->printForm(); 2236} 2237 2238/** 2239 * Embed a flash object in HTML 2240 * 2241 * This will create the needed HTML to embed a flash movie in a cross browser 2242 * compatble way using valid XHTML 2243 * 2244 * The parameters $params, $flashvars and $atts need to be associative arrays. 2245 * No escaping needs to be done for them. The alternative content *has* to be 2246 * escaped because it is used as is. If no alternative content is given 2247 * $lang['noflash'] is used. 2248 * 2249 * @author Andreas Gohr <andi@splitbrain.org> 2250 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 2251 * 2252 * @param string $swf - the SWF movie to embed 2253 * @param int $width - width of the flash movie in pixels 2254 * @param int $height - height of the flash movie in pixels 2255 * @param array $params - additional parameters (<param>) 2256 * @param array $flashvars - parameters to be passed in the flashvar parameter 2257 * @param array $atts - additional attributes for the <object> tag 2258 * @param string $alt - alternative content (is NOT automatically escaped!) 2259 * @return string - the XHTML markup 2260 */ 2261function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 2262 global $lang; 2263 2264 $out = ''; 2265 2266 // prepare the object attributes 2267 if(is_null($atts)) $atts = array(); 2268 $atts['width'] = (int) $width; 2269 $atts['height'] = (int) $height; 2270 if(!$atts['width']) $atts['width'] = 425; 2271 if(!$atts['height']) $atts['height'] = 350; 2272 2273 // add object attributes for standard compliant browsers 2274 $std = $atts; 2275 $std['type'] = 'application/x-shockwave-flash'; 2276 $std['data'] = $swf; 2277 2278 // add object attributes for IE 2279 $ie = $atts; 2280 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 2281 2282 // open object (with conditional comments) 2283 $out .= '<!--[if !IE]> -->'.NL; 2284 $out .= '<object '.buildAttributes($std).'>'.NL; 2285 $out .= '<!-- <![endif]-->'.NL; 2286 $out .= '<!--[if IE]>'.NL; 2287 $out .= '<object '.buildAttributes($ie).'>'.NL; 2288 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 2289 $out .= '<!--><!-- -->'.NL; 2290 2291 // print params 2292 if(is_array($params)) foreach($params as $key => $val){ 2293 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 2294 } 2295 2296 // add flashvars 2297 if(is_array($flashvars)){ 2298 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 2299 } 2300 2301 // alternative content 2302 if($alt){ 2303 $out .= $alt.NL; 2304 }else{ 2305 $out .= $lang['noflash'].NL; 2306 } 2307 2308 // finish 2309 $out .= '</object>'.NL; 2310 $out .= '<!-- <![endif]-->'.NL; 2311 2312 return $out; 2313} 2314 2315/** 2316 * Prints HTML code for the given tab structure 2317 * 2318 * @param array $tabs tab structure 2319 * @param string $current_tab the current tab id 2320 */ 2321function html_tabs($tabs, $current_tab = null) { 2322 echo '<ul class="tabs">'.NL; 2323 2324 foreach($tabs as $id => $tab) { 2325 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 2326 } 2327 2328 echo '</ul>'.NL; 2329} 2330 2331/** 2332 * Prints a single tab 2333 * 2334 * @author Kate Arzamastseva <pshns@ukr.net> 2335 * @author Adrian Lang <mail@adrianlang.de> 2336 * 2337 * @param string $href - tab href 2338 * @param string $caption - tab caption 2339 * @param boolean $selected - is tab selected 2340 */ 2341 2342function html_tab($href, $caption, $selected=false) { 2343 $tab = '<li>'; 2344 if ($selected) { 2345 $tab .= '<strong>'; 2346 } else { 2347 $tab .= '<a href="' . hsc($href) . '">'; 2348 } 2349 $tab .= hsc($caption) 2350 . '</' . ($selected ? 'strong' : 'a') . '>' 2351 . '</li>'.NL; 2352 echo $tab; 2353} 2354 2355/** 2356 * Display size change 2357 * 2358 * @param int $sizechange - size of change in Bytes 2359 * @param Doku_Form $form - form to add elements to 2360 */ 2361 2362function html_sizechange($sizechange, Doku_Form $form) { 2363 if(isset($sizechange)) { 2364 $class = 'sizechange'; 2365 $value = filesize_h(abs($sizechange)); 2366 if($sizechange > 0) { 2367 $class .= ' positive'; 2368 $value = '+' . $value; 2369 } elseif($sizechange < 0) { 2370 $class .= ' negative'; 2371 $value = '-' . $value; 2372 } else { 2373 $value = '±' . $value; 2374 } 2375 $form->addElement(form_makeOpenTag('span', array('class' => $class))); 2376 $form->addElement($value); 2377 $form->addElement(form_makeCloseTag('span')); 2378 } 2379} 2380