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 reset($params); 212 while (list($key, $val) = each($params)) { 213 $ret .= '<input type="hidden" name="'.$key.'" '; 214 $ret .= 'value="'.htmlspecialchars($val).'" />'; 215 } 216 } 217 218 if ($tooltip!='') { 219 $tip = htmlspecialchars($tooltip); 220 }else{ 221 $tip = htmlspecialchars($label); 222 } 223 224 $ret .= '<button type="submit" '; 225 if($akey){ 226 $tip .= ' ['.strtoupper($akey).']'; 227 $ret .= 'accesskey="'.$akey.'" '; 228 } 229 $ret .= 'title="'.$tip.'">'; 230 $ret .= hsc($label); 231 $ret .= '</button>'; 232 $ret .= '</div></form>'; 233 234 return $ret; 235} 236/** 237 * show a revision warning 238 * 239 * @author Szymon Olewniczak <dokuwiki@imz.re> 240 */ 241function html_showrev() { 242 print p_locale_xhtml('showrev'); 243} 244 245/** 246 * Show a wiki page 247 * 248 * @author Andreas Gohr <andi@splitbrain.org> 249 * 250 * @param null|string $txt wiki text or null for showing $ID 251 */ 252function html_show($txt=null){ 253 global $ID; 254 global $REV; 255 global $HIGH; 256 global $INFO; 257 global $DATE_AT; 258 //disable section editing for old revisions or in preview 259 if($txt || $REV){ 260 $secedit = false; 261 }else{ 262 $secedit = true; 263 } 264 265 if (!is_null($txt)){ 266 //PreviewHeader 267 echo '<br id="scroll__here" />'; 268 echo p_locale_xhtml('preview'); 269 echo '<div class="preview"><div class="pad">'; 270 $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit); 271 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 272 echo $html; 273 echo '<div class="clearer"></div>'; 274 echo '</div></div>'; 275 276 }else{ 277 if ($REV||$DATE_AT){ 278 $data = array('rev' => &$REV, 'date_at' => &$DATE_AT); 279 trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev'); 280 } 281 $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT); 282 $html = html_secedit($html,$secedit); 283 if($INFO['prependTOC']) $html = tpl_toc(true).$html; 284 $html = html_hilight($html,$HIGH); 285 echo $html; 286 } 287} 288 289/** 290 * ask the user about how to handle an exisiting draft 291 * 292 * @author Andreas Gohr <andi@splitbrain.org> 293 */ 294function html_draft(){ 295 global $INFO; 296 global $ID; 297 global $lang; 298 $draft = unserialize(io_readFile($INFO['draft'],false)); 299 $text = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true)); 300 301 print p_locale_xhtml('draft'); 302 $form = new Doku_Form(array('id' => 'dw__editform')); 303 $form->addHidden('id', $ID); 304 $form->addHidden('date', $draft['date']); 305 $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly'))); 306 $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status'))); 307 $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft']))); 308 $form->addElement(form_makeCloseTag('div')); 309 $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1'))); 310 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2'))); 311 $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3'))); 312 html_form('draft', $form); 313} 314 315/** 316 * Highlights searchqueries in HTML code 317 * 318 * @author Andreas Gohr <andi@splitbrain.org> 319 * @author Harry Fuecks <hfuecks@gmail.com> 320 * 321 * @param string $html 322 * @param array|string $phrases 323 * @return string html 324 */ 325function html_hilight($html,$phrases){ 326 $phrases = (array) $phrases; 327 $phrases = array_map('preg_quote_cb', $phrases); 328 $phrases = array_map('ft_snippet_re_preprocess', $phrases); 329 $phrases = array_filter($phrases); 330 $regex = join('|',$phrases); 331 332 if ($regex === '') return $html; 333 if (!utf8_check($regex)) return $html; 334 $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html); 335 return $html; 336} 337 338/** 339 * Callback used by html_hilight() 340 * 341 * @author Harry Fuecks <hfuecks@gmail.com> 342 * 343 * @param array $m matches 344 * @return string html 345 */ 346function html_hilight_callback($m) { 347 $hlight = unslash($m[0]); 348 if ( !isset($m[2])) { 349 $hlight = '<span class="search_hit">'.$hlight.'</span>'; 350 } 351 return $hlight; 352} 353 354/** 355 * Run a search and display the result 356 * 357 * @author Andreas Gohr <andi@splitbrain.org> 358 */ 359function html_search(){ 360 global $QUERY, $ID; 361 global $lang; 362 363 $intro = p_locale_xhtml('searchpage'); 364 // allow use of placeholder in search intro 365 $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : ''; 366 $intro = str_replace( 367 array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'), 368 array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo), 369 $intro 370 ); 371 echo $intro; 372 flush(); 373 374 //show progressbar 375 print '<div id="dw__loading">'.NL; 376 print '<script type="text/javascript">/*<![CDATA[*/'.NL; 377 print 'showLoadBar();'.NL; 378 print '/*!]]>*/</script>'.NL; 379 print '</div>'.NL; 380 flush(); 381 382 //do quick pagesearch 383 $data = ft_pageLookup($QUERY,true,useHeading('navigation')); 384 if(count($data)){ 385 print '<div class="search_quickresult">'; 386 print '<h3>'.$lang['quickhits'].':</h3>'; 387 print '<ul class="search_quickhits">'; 388 foreach($data as $id => $title){ 389 print '<li> '; 390 if (useHeading('navigation')) { 391 $name = $title; 392 }else{ 393 $ns = getNS($id); 394 if($ns){ 395 $name = shorten(noNS($id), ' ('.$ns.')',30); 396 }else{ 397 $name = $id; 398 } 399 } 400 print html_wikilink(':'.$id,$name); 401 print '</li> '; 402 } 403 print '</ul> '; 404 //clear float (see http://www.complexspiral.com/publications/containing-floats/) 405 print '<div class="clearer"></div>'; 406 print '</div>'; 407 } 408 flush(); 409 410 //do fulltext search 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 = array_pop($pagelog->getRevisions(-1, 1)); 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 * List available Administration Tasks 2055 * 2056 * @author Andreas Gohr <andi@splitbrain.org> 2057 * @author Håkan Sandell <hakan.sandell@home.se> 2058 */ 2059function html_admin(){ 2060 global $ID; 2061 global $INFO; 2062 global $conf; 2063 /** @var DokuWiki_Auth_Plugin $auth */ 2064 global $auth; 2065 2066 // build menu of admin functions from the plugins that handle them 2067 $pluginlist = plugin_list('admin'); 2068 $menu = array(); 2069 foreach ($pluginlist as $p) { 2070 /** @var DokuWiki_Admin_Plugin $obj */ 2071 if(($obj = plugin_load('admin',$p)) === null) continue; 2072 2073 // check permissions 2074 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 2075 2076 $menu[$p] = array('plugin' => $p, 2077 'prompt' => $obj->getMenuText($conf['lang']), 2078 'sort' => $obj->getMenuSort() 2079 ); 2080 } 2081 2082 // data security check 2083 // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL 2084 // it verifies either: 2085 // 'savedir' has been moved elsewhere, or 2086 // has protection to prevent the webserver serving files from it 2087 if (substr($conf['savedir'],0,2) == './'){ 2088 echo '<a style="border:none; float:right;" 2089 href="http://www.dokuwiki.org/security#web_access_security"> 2090 <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly." 2091 onerror="this.parentNode.style.display=\'none\'" /></a>'; 2092 } 2093 2094 print p_locale_xhtml('admin'); 2095 2096 // Admin Tasks 2097 if($INFO['isadmin']){ 2098 ptln('<ul class="admin_tasks">'); 2099 2100 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 2101 ptln(' <li class="admin_usermanager"><div class="li">'. 2102 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 2103 $menu['usermanager']['prompt'].'</a></div></li>'); 2104 } 2105 unset($menu['usermanager']); 2106 2107 if($menu['acl']){ 2108 ptln(' <li class="admin_acl"><div class="li">'. 2109 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 2110 $menu['acl']['prompt'].'</a></div></li>'); 2111 } 2112 unset($menu['acl']); 2113 2114 if($menu['extension']){ 2115 ptln(' <li class="admin_plugin"><div class="li">'. 2116 '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'. 2117 $menu['extension']['prompt'].'</a></div></li>'); 2118 } 2119 unset($menu['extension']); 2120 2121 if($menu['config']){ 2122 ptln(' <li class="admin_config"><div class="li">'. 2123 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 2124 $menu['config']['prompt'].'</a></div></li>'); 2125 } 2126 unset($menu['config']); 2127 2128 if($menu['styling']){ 2129 ptln(' <li class="admin_styling"><div class="li">'. 2130 '<a href="'.wl($ID, array('do' => 'admin','page' => 'styling')).'">'. 2131 $menu['styling']['prompt'].'</a></div></li>'); 2132 } 2133 unset($menu['styling']); 2134 } 2135 ptln('</ul>'); 2136 2137 // Manager Tasks 2138 ptln('<ul class="admin_tasks">'); 2139 2140 if($menu['revert']){ 2141 ptln(' <li class="admin_revert"><div class="li">'. 2142 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 2143 $menu['revert']['prompt'].'</a></div></li>'); 2144 } 2145 unset($menu['revert']); 2146 2147 if($menu['popularity']){ 2148 ptln(' <li class="admin_popularity"><div class="li">'. 2149 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 2150 $menu['popularity']['prompt'].'</a></div></li>'); 2151 } 2152 unset($menu['popularity']); 2153 2154 // print DokuWiki version: 2155 ptln('</ul>'); 2156 echo '<div id="admin__version">'; 2157 echo getVersion(); 2158 echo '</div>'; 2159 2160 // print the rest as sorted list 2161 if(count($menu)){ 2162 // sort by name, then sort 2163 usort( 2164 $menu, 2165 function ($a, $b) { 2166 $strcmp = strcasecmp($a['prompt'], $b['prompt']); 2167 if($strcmp != 0) return $strcmp; 2168 if($a['sort'] == $b['sort']) return 0; 2169 return ($a['sort'] < $b['sort']) ? -1 : 1; 2170 } 2171 ); 2172 2173 // output the menu 2174 ptln('<div class="clearer"></div>'); 2175 print p_locale_xhtml('adminplugins'); 2176 ptln('<ul>'); 2177 foreach ($menu as $item) { 2178 if (!$item['prompt']) continue; 2179 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 2180 } 2181 ptln('</ul>'); 2182 } 2183} 2184 2185/** 2186 * Form to request a new password for an existing account 2187 * 2188 * @author Benoit Chesneau <benoit@bchesneau.info> 2189 * @author Andreas Gohr <gohr@cosmocode.de> 2190 */ 2191function html_resendpwd() { 2192 global $lang; 2193 global $conf; 2194 global $INPUT; 2195 2196 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 2197 2198 if(!$conf['autopasswd'] && $token){ 2199 print p_locale_xhtml('resetpwd'); 2200 print '<div class="centeralign">'.NL; 2201 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2202 $form->startFieldset($lang['btn_resendpwd']); 2203 $form->addHidden('token', $token); 2204 $form->addHidden('do', 'resendpwd'); 2205 2206 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 2207 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 2208 2209 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2210 $form->endFieldset(); 2211 html_form('resendpwd', $form); 2212 print '</div>'.NL; 2213 }else{ 2214 print p_locale_xhtml('resendpwd'); 2215 print '<div class="centeralign">'.NL; 2216 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 2217 $form->startFieldset($lang['resendpwd']); 2218 $form->addHidden('do', 'resendpwd'); 2219 $form->addHidden('save', '1'); 2220 $form->addElement(form_makeTag('br')); 2221 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 2222 $form->addElement(form_makeTag('br')); 2223 $form->addElement(form_makeTag('br')); 2224 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 2225 $form->endFieldset(); 2226 html_form('resendpwd', $form); 2227 print '</div>'.NL; 2228 } 2229} 2230 2231/** 2232 * Return the TOC rendered to XHTML 2233 * 2234 * @author Andreas Gohr <andi@splitbrain.org> 2235 * 2236 * @param array $toc 2237 * @return string html 2238 */ 2239function html_TOC($toc){ 2240 if(!count($toc)) return ''; 2241 global $lang; 2242 $out = '<!-- TOC START -->'.DOKU_LF; 2243 $out .= '<div id="dw__toc">'.DOKU_LF; 2244 $out .= '<h3 class="toggle">'; 2245 $out .= $lang['toc']; 2246 $out .= '</h3>'.DOKU_LF; 2247 $out .= '<div>'.DOKU_LF; 2248 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 2249 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 2250 $out .= '<!-- TOC END -->'.DOKU_LF; 2251 return $out; 2252} 2253 2254/** 2255 * Callback for html_buildlist 2256 * 2257 * @param array $item 2258 * @return string html 2259 */ 2260function html_list_toc($item){ 2261 if(isset($item['hid'])){ 2262 $link = '#'.$item['hid']; 2263 }else{ 2264 $link = $item['link']; 2265 } 2266 2267 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 2268} 2269 2270/** 2271 * Helper function to build TOC items 2272 * 2273 * Returns an array ready to be added to a TOC array 2274 * 2275 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 2276 * @param string $text - what to display in the TOC 2277 * @param int $level - nesting level 2278 * @param string $hash - is prepended to the given $link, set blank if you want full links 2279 * @return array the toc item 2280 */ 2281function html_mktocitem($link, $text, $level, $hash='#'){ 2282 return array( 'link' => $hash.$link, 2283 'title' => $text, 2284 'type' => 'ul', 2285 'level' => $level); 2286} 2287 2288/** 2289 * Output a Doku_Form object. 2290 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 2291 * 2292 * @author Tom N Harris <tnharris@whoopdedo.org> 2293 * 2294 * @param string $name The name of the form 2295 * @param Doku_Form $form The form 2296 */ 2297function html_form($name, &$form) { 2298 // Safety check in case the caller forgets. 2299 $form->endFieldset(); 2300 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 2301} 2302 2303/** 2304 * Form print function. 2305 * Just calls printForm() on the data object. 2306 * 2307 * @param Doku_Form $data The form 2308 */ 2309function html_form_output($data) { 2310 $data->printForm(); 2311} 2312 2313/** 2314 * Embed a flash object in HTML 2315 * 2316 * This will create the needed HTML to embed a flash movie in a cross browser 2317 * compatble way using valid XHTML 2318 * 2319 * The parameters $params, $flashvars and $atts need to be associative arrays. 2320 * No escaping needs to be done for them. The alternative content *has* to be 2321 * escaped because it is used as is. If no alternative content is given 2322 * $lang['noflash'] is used. 2323 * 2324 * @author Andreas Gohr <andi@splitbrain.org> 2325 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 2326 * 2327 * @param string $swf - the SWF movie to embed 2328 * @param int $width - width of the flash movie in pixels 2329 * @param int $height - height of the flash movie in pixels 2330 * @param array $params - additional parameters (<param>) 2331 * @param array $flashvars - parameters to be passed in the flashvar parameter 2332 * @param array $atts - additional attributes for the <object> tag 2333 * @param string $alt - alternative content (is NOT automatically escaped!) 2334 * @return string - the XHTML markup 2335 */ 2336function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 2337 global $lang; 2338 2339 $out = ''; 2340 2341 // prepare the object attributes 2342 if(is_null($atts)) $atts = array(); 2343 $atts['width'] = (int) $width; 2344 $atts['height'] = (int) $height; 2345 if(!$atts['width']) $atts['width'] = 425; 2346 if(!$atts['height']) $atts['height'] = 350; 2347 2348 // add object attributes for standard compliant browsers 2349 $std = $atts; 2350 $std['type'] = 'application/x-shockwave-flash'; 2351 $std['data'] = $swf; 2352 2353 // add object attributes for IE 2354 $ie = $atts; 2355 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 2356 2357 // open object (with conditional comments) 2358 $out .= '<!--[if !IE]> -->'.NL; 2359 $out .= '<object '.buildAttributes($std).'>'.NL; 2360 $out .= '<!-- <![endif]-->'.NL; 2361 $out .= '<!--[if IE]>'.NL; 2362 $out .= '<object '.buildAttributes($ie).'>'.NL; 2363 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 2364 $out .= '<!--><!-- -->'.NL; 2365 2366 // print params 2367 if(is_array($params)) foreach($params as $key => $val){ 2368 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 2369 } 2370 2371 // add flashvars 2372 if(is_array($flashvars)){ 2373 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 2374 } 2375 2376 // alternative content 2377 if($alt){ 2378 $out .= $alt.NL; 2379 }else{ 2380 $out .= $lang['noflash'].NL; 2381 } 2382 2383 // finish 2384 $out .= '</object>'.NL; 2385 $out .= '<!-- <![endif]-->'.NL; 2386 2387 return $out; 2388} 2389 2390/** 2391 * Prints HTML code for the given tab structure 2392 * 2393 * @param array $tabs tab structure 2394 * @param string $current_tab the current tab id 2395 */ 2396function html_tabs($tabs, $current_tab = null) { 2397 echo '<ul class="tabs">'.NL; 2398 2399 foreach($tabs as $id => $tab) { 2400 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 2401 } 2402 2403 echo '</ul>'.NL; 2404} 2405 2406/** 2407 * Prints a single tab 2408 * 2409 * @author Kate Arzamastseva <pshns@ukr.net> 2410 * @author Adrian Lang <mail@adrianlang.de> 2411 * 2412 * @param string $href - tab href 2413 * @param string $caption - tab caption 2414 * @param boolean $selected - is tab selected 2415 */ 2416 2417function html_tab($href, $caption, $selected=false) { 2418 $tab = '<li>'; 2419 if ($selected) { 2420 $tab .= '<strong>'; 2421 } else { 2422 $tab .= '<a href="' . hsc($href) . '">'; 2423 } 2424 $tab .= hsc($caption) 2425 . '</' . ($selected ? 'strong' : 'a') . '>' 2426 . '</li>'.NL; 2427 echo $tab; 2428} 2429 2430/** 2431 * Display size change 2432 * 2433 * @param int $sizechange - size of change in Bytes 2434 * @param Doku_Form $form - form to add elements to 2435 */ 2436 2437function html_sizechange($sizechange, Doku_Form $form) { 2438 if(isset($sizechange)) { 2439 $class = 'sizechange'; 2440 $value = filesize_h(abs($sizechange)); 2441 if($sizechange > 0) { 2442 $class .= ' positive'; 2443 $value = '+' . $value; 2444 } elseif($sizechange < 0) { 2445 $class .= ' negative'; 2446 $value = '-' . $value; 2447 } else { 2448 $value = '±' . $value; 2449 } 2450 $form->addElement(form_makeOpenTag('span', array('class' => $class))); 2451 $form->addElement($value); 2452 $form->addElement(form_makeCloseTag('span')); 2453 } 2454} 2455