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