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