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