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