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