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