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