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