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