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