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