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 if($exists && $first==0){ 470 if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 471 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 472 else 473 $form->addElement(form_makeOpenTag('li')); 474 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 475 $form->addElement(form_makeTag('input', array( 476 'type' => 'checkbox', 477 'name' => 'rev2[]', 478 'value' => 'current'))); 479 480 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 481 $form->addElement($date); 482 $form->addElement(form_makeCloseTag('span')); 483 484 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 485 486 if (!$media_id) $href = wl($id); 487 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); 488 $form->addElement(form_makeOpenTag('a', array( 489 'class' => 'wikilink1', 490 'href' => $href))); 491 $form->addElement($id); 492 $form->addElement(form_makeCloseTag('a')); 493 494 if ($media_id) $form->addElement(form_makeOpenTag('div')); 495 496 if (!$media_id) { 497 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 498 $form->addElement(' – '); 499 $form->addElement(htmlspecialchars($INFO['sum'])); 500 $form->addElement(form_makeCloseTag('span')); 501 } 502 503 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 504 if (!$media_id) $editor = $INFO['editor']; 505 else { 506 $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true); 507 if($revinfo['user']){ 508 $editor = $revinfo['user']; 509 }else{ 510 $editor = $revinfo['ip']; 511 } 512 } 513 $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor)); 514 $form->addElement(form_makeCloseTag('span')); 515 516 $form->addElement('('.$lang['current'].')'); 517 518 if ($media_id) $form->addElement(form_makeCloseTag('div')); 519 520 $form->addElement(form_makeCloseTag('div')); 521 $form->addElement(form_makeCloseTag('li')); 522 } 523 524 foreach($revisions as $rev){ 525 $date = dformat($rev); 526 if (!$media_id) { 527 $info = getRevisionInfo($id,$rev,true); 528 $exists = page_exists($id,$rev); 529 } else { 530 $info = getRevisionInfo($id,$rev,true,true); 531 $exists = @file_exists(mediaFN($id,$rev)); 532 } 533 534 if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 535 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 536 else 537 $form->addElement(form_makeOpenTag('li')); 538 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 539 if($exists){ 540 $form->addElement(form_makeTag('input', array( 541 'type' => 'checkbox', 542 'name' => 'rev2[]', 543 'value' => $rev))); 544 }else{ 545 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 546 } 547 548 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 549 $form->addElement($date); 550 $form->addElement(form_makeCloseTag('span')); 551 552 if($exists){ 553 if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&'); 554 else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); 555 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); 556 $form->addElement(form_makeTag('img', array( 557 'src' => DOKU_BASE.'lib/images/diff.png', 558 'width' => 15, 559 'height' => 11, 560 'title' => $lang['diff'], 561 'alt' => $lang['diff']))); 562 $form->addElement(form_makeCloseTag('a')); 563 if (!$media_id) $href = wl($id,"rev=$rev",false,'&'); 564 else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); 565 $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); 566 $form->addElement($id); 567 $form->addElement(form_makeCloseTag('a')); 568 }else{ 569 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 570 $form->addElement($id); 571 } 572 573 if ($media_id) $form->addElement(form_makeOpenTag('div')); 574 575 if ($info['sum']) { 576 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 577 if (!$media_id) $form->addElement(' – '); 578 $form->addElement(htmlspecialchars($info['sum'])); 579 $form->addElement(form_makeCloseTag('span')); 580 } 581 582 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 583 if($info['user']){ 584 $form->addElement(editorinfo($info['user'])); 585 if(auth_ismanager()){ 586 $form->addElement(' ('.$info['ip'].')'); 587 } 588 }else{ 589 $form->addElement($info['ip']); 590 } 591 $form->addElement(form_makeCloseTag('span')); 592 593 if ($media_id) $form->addElement(form_makeCloseTag('div')); 594 595 $form->addElement(form_makeCloseTag('div')); 596 $form->addElement(form_makeCloseTag('li')); 597 } 598 $form->addElement(form_makeCloseTag('ul')); 599 if (!$media_id) { 600 $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); 601 } else { 602 $form->addHidden('mediado', 'diff'); 603 $form->addElement(form_makeButton('submit', '', $lang['diff2'])); 604 } 605 html_form('revisions', $form); 606 607 print '<div class="pagenav">'; 608 $last = $first + $conf['recent']; 609 if ($first > 0) { 610 $first -= $conf['recent']; 611 if ($first < 0) $first = 0; 612 print '<div class="pagenav-prev">'; 613 if ($media_id) { 614 print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&', false, true)); 615 } else { 616 print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first)); 617 } 618 print '</div>'; 619 } 620 if ($hasNext) { 621 print '<div class="pagenav-next">'; 622 if ($media_id) { 623 print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&', false, true)); 624 } else { 625 print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last)); 626 } 627 print '</div>'; 628 } 629 print '</div>'; 630 631} 632 633/** 634 * display recent changes 635 * 636 * @author Andreas Gohr <andi@splitbrain.org> 637 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 638 * @author Ben Coburn <btcoburn@silicodon.net> 639 * @author Kate Arzamastseva <pshns@ukr.net> 640 */ 641function html_recent($first=0, $show_changes='both'){ 642 global $conf; 643 global $lang; 644 global $ID; 645 /* we need to get one additionally log entry to be able to 646 * decide if this is the last page or is there another one. 647 * This is the cheapest solution to get this information. 648 */ 649 $flags = 0; 650 if ($show_changes == 'mediafiles' && $conf['mediarevisions']) { 651 $flags = RECENTS_MEDIA_CHANGES; 652 } elseif ($show_changes == 'pages') { 653 $flags = 0; 654 } elseif ($conf['mediarevisions']) { 655 $show_changes = 'both'; 656 $flags = RECENTS_MEDIA_PAGES_MIXED; 657 } 658 659 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 660 if(count($recents) == 0 && $first != 0){ 661 $first=0; 662 $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags); 663 } 664 $hasNext = false; 665 if (count($recents)>$conf['recent']) { 666 $hasNext = true; 667 array_pop($recents); // remove extra log entry 668 } 669 670 print p_locale_xhtml('recent'); 671 672 if (getNS($ID) != '') 673 print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>'; 674 675 $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes')); 676 $form->addHidden('sectok', null); 677 $form->addHidden('do', 'recent'); 678 $form->addHidden('id', $ID); 679 680 if ($conf['mediarevisions']) { 681 $form->addElement('<div class="changeType">'); 682 $form->addElement(form_makeListboxField( 683 'show_changes', 684 array( 685 'pages' => $lang['pages_changes'], 686 'mediafiles' => $lang['media_changes'], 687 'both' => $lang['both_changes']), 688 $show_changes, 689 $lang['changes_type'], 690 '','', 691 array('class'=>'quickselect'))); 692 693 $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply'])); 694 $form->addElement('</div>'); 695 } 696 697 $form->addElement(form_makeOpenTag('ul')); 698 699 foreach($recents as $recent){ 700 $date = dformat($recent['date']); 701 if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) 702 $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); 703 else 704 $form->addElement(form_makeOpenTag('li')); 705 706 $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); 707 708 if ($recent['media']) { 709 $form->addElement(media_printicon($recent['id'])); 710 } else { 711 $icon = DOKU_BASE.'lib/images/fileicons/file.png'; 712 $form->addElement('<img src="'.$icon.'" alt="'.$filename.'" class="icon" />'); 713 } 714 715 $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); 716 $form->addElement($date); 717 $form->addElement(form_makeCloseTag('span')); 718 719 if ($recent['media']) { 720 $diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id']))); 721 if ($diff) { 722 $href = media_managerURL(array('tab_details' => 'history', 723 'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 724 } 725 } else { 726 $href = wl($recent['id'],"do=diff", false, '&'); 727 } 728 729 if ($recent['media'] && !$diff) { 730 $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'); 731 } else { 732 $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href))); 733 $form->addElement(form_makeTag('img', array( 734 'src' => DOKU_BASE.'lib/images/diff.png', 735 'width' => 15, 736 'height'=> 11, 737 'title' => $lang['diff'], 738 'alt' => $lang['diff'] 739 ))); 740 $form->addElement(form_makeCloseTag('a')); 741 } 742 743 if ($recent['media']) { 744 $href = media_managerURL(array('tab_details' => 'history', 745 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 746 } else { 747 $href = wl($recent['id'],"do=revisions",false,'&'); 748 } 749 $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href))); 750 $form->addElement(form_makeTag('img', array( 751 'src' => DOKU_BASE.'lib/images/history.png', 752 'width' => 12, 753 'height'=> 14, 754 'title' => $lang['btn_revs'], 755 'alt' => $lang['btn_revs'] 756 ))); 757 $form->addElement(form_makeCloseTag('a')); 758 759 if ($recent['media']) { 760 $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&'); 761 $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2'; 762 $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href))); 763 $form->addElement($recent['id']); 764 $form->addElement(form_makeCloseTag('a')); 765 } else { 766 $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id'])); 767 } 768 $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); 769 $form->addElement(' – '.htmlspecialchars($recent['sum'])); 770 $form->addElement(form_makeCloseTag('span')); 771 772 $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); 773 if($recent['user']){ 774 $form->addElement(editorinfo($recent['user'])); 775 if(auth_ismanager()){ 776 $form->addElement(' ('.$recent['ip'].')'); 777 } 778 }else{ 779 $form->addElement($recent['ip']); 780 } 781 $form->addElement(form_makeCloseTag('span')); 782 783 $form->addElement(form_makeCloseTag('div')); 784 $form->addElement(form_makeCloseTag('li')); 785 } 786 $form->addElement(form_makeCloseTag('ul')); 787 788 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav'))); 789 $last = $first + $conf['recent']; 790 if ($first > 0) { 791 $first -= $conf['recent']; 792 if ($first < 0) $first = 0; 793 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev'))); 794 $form->addElement(form_makeTag('input', array( 795 'type' => 'submit', 796 'name' => 'first['.$first.']', 797 'value' => $lang['btn_newer'], 798 'accesskey' => 'n', 799 'title' => $lang['btn_newer'].' [N]', 800 'class' => 'button show' 801 ))); 802 $form->addElement(form_makeCloseTag('div')); 803 } 804 if ($hasNext) { 805 $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next'))); 806 $form->addElement(form_makeTag('input', array( 807 'type' => 'submit', 808 'name' => 'first['.$last.']', 809 'value' => $lang['btn_older'], 810 'accesskey' => 'p', 811 'title' => $lang['btn_older'].' [P]', 812 'class' => 'button show' 813 ))); 814 $form->addElement(form_makeCloseTag('div')); 815 } 816 $form->addElement(form_makeCloseTag('div')); 817 html_form('recent', $form); 818} 819 820/** 821 * Display page index 822 * 823 * @author Andreas Gohr <andi@splitbrain.org> 824 */ 825function html_index($ns){ 826 global $conf; 827 global $ID; 828 $dir = $conf['datadir']; 829 $ns = cleanID($ns); 830 #fixme use appropriate function 831 if(empty($ns)){ 832 $ns = dirname(str_replace(':','/',$ID)); 833 if($ns == '.') $ns =''; 834 } 835 $ns = utf8_encodeFN(str_replace(':','/',$ns)); 836 837 echo p_locale_xhtml('index'); 838 echo '<div id="index__tree">'; 839 840 $data = array(); 841 search($data,$conf['datadir'],'search_index',array('ns' => $ns)); 842 echo html_buildlist($data,'idx','html_list_index','html_li_index'); 843 844 echo '</div>'; 845} 846 847/** 848 * Index item formatter 849 * 850 * User function for html_buildlist() 851 * 852 * @author Andreas Gohr <andi@splitbrain.org> 853 */ 854function html_list_index($item){ 855 global $ID; 856 $ret = ''; 857 $base = ':'.$item['id']; 858 $base = substr($base,strrpos($base,':')+1); 859 if($item['type']=='d'){ 860 $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>'; 861 $ret .= $base; 862 $ret .= '</strong></a>'; 863 }else{ 864 $ret .= html_wikilink(':'.$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 $conf; 979 global $lang; 980 981 print p_locale_xhtml('backlinks'); 982 983 $data = ft_backlinks($ID); 984 985 if(!empty($data)) { 986 print '<ul class="idx">'; 987 foreach($data as $blink){ 988 print '<li><div class="li">'; 989 print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink); 990 print '</div></li>'; 991 } 992 print '</ul>'; 993 } else { 994 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; 995 } 996} 997 998function html_diff_head($l_rev, $r_rev, $id = null, $media = false) { 999 global $lang; 1000 if ($id === null) { 1001 global $ID; 1002 $id = $ID; 1003 } 1004 $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN'; 1005 $ml_or_wl = $media ? 'ml' : 'wl'; 1006 $l_minor = $r_minor = ''; 1007 1008 if(!$l_rev){ 1009 $l_head = '—'; 1010 }else{ 1011 $l_info = getRevisionInfo($id,$l_rev,true, $media); 1012 if($l_info['user']){ 1013 $l_user = editorinfo($l_info['user']); 1014 if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')'; 1015 } else { 1016 $l_user = $l_info['ip']; 1017 } 1018 $l_user = '<span class="user">'.$l_user.'</span>'; 1019 $l_sum = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : ''; 1020 if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"'; 1021 1022 $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']'; 1023 $l_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'. 1024 $l_head_title.'</a>'. 1025 '<br />'.$l_user.' '.$l_sum; 1026 } 1027 1028 if($r_rev){ 1029 $r_info = getRevisionInfo($id,$r_rev,true, $media); 1030 if($r_info['user']){ 1031 $r_user = editorinfo($r_info['user']); 1032 if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')'; 1033 } else { 1034 $r_user = $r_info['ip']; 1035 } 1036 $r_user = '<span class="user">'.$r_user.'</span>'; 1037 $r_sum = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : ''; 1038 if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1039 1040 $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']'; 1041 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'. 1042 $r_head_title.'</a>'. 1043 '<br />'.$r_user.' '.$r_sum; 1044 }elseif($_rev = @filemtime($media_or_wikiFN($id))){ 1045 $_info = getRevisionInfo($id,$_rev,true, $media); 1046 if($_info['user']){ 1047 $_user = editorinfo($_info['user']); 1048 if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')'; 1049 } else { 1050 $_user = $_info['ip']; 1051 } 1052 $_user = '<span class="user">'.$_user.'</span>'; 1053 $_sum = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : ''; 1054 if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"'; 1055 1056 $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']'; 1057 $r_head = '<a class="wikilink1" href="'.$ml_or_wl($id).'">'. 1058 $r_head_title.'</a> '. 1059 '('.$lang['current'].')'. 1060 '<br />'.$_user.' '.$_sum; 1061 }else{ 1062 $r_head = '— ('.$lang['current'].')'; 1063 } 1064 1065 return array($l_head, $r_head, $l_minor, $r_minor); 1066} 1067 1068/** 1069 * show diff 1070 * 1071 * @author Andreas Gohr <andi@splitbrain.org> 1072 * @param string $text - compare with this text with most current version 1073 * @param bool $intr - display the intro text 1074 */ 1075function html_diff($text='',$intro=true,$type=null){ 1076 global $ID; 1077 global $REV; 1078 global $lang; 1079 global $conf; 1080 global $INPUT; 1081 1082 if(!$type) $type = $INPUT->str('difftype'); 1083 if($type != 'inline') $type = 'sidebyside'; 1084 1085 // we're trying to be clever here, revisions to compare can be either 1086 // given as rev and rev2 parameters, with rev2 being optional. Or in an 1087 // array in rev2. 1088 $rev1 = $REV; 1089 1090 $rev2 = $INPUT->ref('rev2'); 1091 if(is_array($rev2)){ 1092 $rev1 = (int) $rev2[0]; 1093 $rev2 = (int) $rev2[1]; 1094 1095 if(!$rev1){ 1096 $rev1 = $rev2; 1097 unset($rev2); 1098 } 1099 }else{ 1100 $rev2 = $INPUT->int('rev2'); 1101 } 1102 1103 $r_minor = ''; 1104 $l_minor = ''; 1105 1106 if($text){ // compare text to the most current revision 1107 $l_rev = ''; 1108 $l_text = rawWiki($ID,''); 1109 $l_head = '<a class="wikilink1" href="'.wl($ID).'">'. 1110 $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '. 1111 $lang['current']; 1112 1113 $r_rev = ''; 1114 $r_text = cleanText($text); 1115 $r_head = $lang['yours']; 1116 }else{ 1117 if($rev1 && $rev2){ // two specific revisions wanted 1118 // make sure order is correct (older on the left) 1119 if($rev1 < $rev2){ 1120 $l_rev = $rev1; 1121 $r_rev = $rev2; 1122 }else{ 1123 $l_rev = $rev2; 1124 $r_rev = $rev1; 1125 } 1126 }elseif($rev1){ // single revision given, compare to current 1127 $r_rev = ''; 1128 $l_rev = $rev1; 1129 }else{ // no revision was given, compare previous to current 1130 $r_rev = ''; 1131 $revs = getRevisions($ID, 0, 1); 1132 $l_rev = $revs[0]; 1133 $REV = $l_rev; // store revision back in $REV 1134 } 1135 1136 // when both revisions are empty then the page was created just now 1137 if(!$l_rev && !$r_rev){ 1138 $l_text = ''; 1139 }else{ 1140 $l_text = rawWiki($ID,$l_rev); 1141 } 1142 $r_text = rawWiki($ID,$r_rev); 1143 1144 list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev); 1145 } 1146 1147 $df = new Diff(explode("\n",htmlspecialchars($l_text)), 1148 explode("\n",htmlspecialchars($r_text))); 1149 1150 if($type == 'inline'){ 1151 $tdf = new InlineDiffFormatter(); 1152 } else { 1153 $tdf = new TableDiffFormatter(); 1154 } 1155 1156 if($intro) print p_locale_xhtml('diff'); 1157 1158 if (!$text) { 1159 ptln('<div class="diffoptions">'); 1160 1161 $form = new Doku_Form(array('action'=>wl())); 1162 $form->addHidden('id',$ID); 1163 $form->addHidden('rev2[0]',$l_rev); 1164 $form->addHidden('rev2[1]',$r_rev); 1165 $form->addHidden('do','diff'); 1166 $form->addElement(form_makeListboxField( 1167 'difftype', 1168 array( 1169 'sidebyside' => $lang['diff_side'], 1170 'inline' => $lang['diff_inline']), 1171 $type, 1172 $lang['diff_type'], 1173 '','', 1174 array('class'=>'quickselect'))); 1175 $form->addElement(form_makeButton('submit', 'diff','Go')); 1176 $form->printForm(); 1177 1178 $diffurl = wl($ID, array( 1179 'do' => 'diff', 1180 'rev2[0]' => $l_rev, 1181 'rev2[1]' => $r_rev, 1182 'difftype' => $type, 1183 )); 1184 ptln('<p><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a></p>'); 1185 ptln('</div>'); 1186 } 1187 ?> 1188 <div class="table"> 1189 <table class="diff diff_<?php echo $type?>"> 1190 <tr> 1191 <th colspan="2" <?php echo $l_minor?>> 1192 <?php echo $l_head?> 1193 </th> 1194 <th colspan="2" <?php echo $r_minor?>> 1195 <?php echo $r_head?> 1196 </th> 1197 </tr> 1198 <?php echo $tdf->format($df)?> 1199 </table> 1200 </div> 1201 <?php 1202} 1203 1204/** 1205 * show warning on conflict detection 1206 * 1207 * @author Andreas Gohr <andi@splitbrain.org> 1208 */ 1209function html_conflict($text,$summary){ 1210 global $ID; 1211 global $lang; 1212 1213 print p_locale_xhtml('conflict'); 1214 $form = new Doku_Form(array('id' => 'dw__editform')); 1215 $form->addHidden('id', $ID); 1216 $form->addHidden('wikitext', $text); 1217 $form->addHidden('summary', $summary); 1218 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s'))); 1219 $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'])); 1220 html_form('conflict', $form); 1221 print '<br /><br /><br /><br />'.NL; 1222} 1223 1224/** 1225 * Prints the global message array 1226 * 1227 * @author Andreas Gohr <andi@splitbrain.org> 1228 */ 1229function html_msgarea(){ 1230 global $MSG, $MSG_shown; 1231 // store if the global $MSG has already been shown and thus HTML output has been started 1232 $MSG_shown = true; 1233 1234 if(!isset($MSG)) return; 1235 1236 $shown = array(); 1237 foreach($MSG as $msg){ 1238 $hash = md5($msg['msg']); 1239 if(isset($shown[$hash])) continue; // skip double messages 1240 print '<div class="'.$msg['lvl'].'">'; 1241 print $msg['msg']; 1242 print '</div>'; 1243 $shown[$hash] = 1; 1244 } 1245 1246 unset($GLOBALS['MSG']); 1247} 1248 1249/** 1250 * Prints the registration form 1251 * 1252 * @author Andreas Gohr <andi@splitbrain.org> 1253 */ 1254function html_register(){ 1255 global $lang; 1256 global $conf; 1257 global $ID; 1258 global $INPUT; 1259 1260 print p_locale_xhtml('register'); 1261 print '<div class="centeralign">'.NL; 1262 $form = new Doku_Form(array('id' => 'dw__register')); 1263 $form->startFieldset($lang['btn_register']); 1264 $form->addHidden('do', 'register'); 1265 $form->addHidden('save', '1'); 1266 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', array('size'=>'50'))); 1267 if (!$conf['autopasswd']) { 1268 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1269 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1270 } 1271 $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', array('size'=>'50'))); 1272 $form->addElement(form_makeTextField('email', $INPUT->post->str('email'), $lang['email'], '', 'block', array('size'=>'50'))); 1273 $form->addElement(form_makeButton('submit', '', $lang['btn_register'])); 1274 $form->endFieldset(); 1275 html_form('register', $form); 1276 1277 print '</div>'.NL; 1278} 1279 1280/** 1281 * Print the update profile form 1282 * 1283 * @author Christopher Smith <chris@jalakai.co.uk> 1284 * @author Andreas Gohr <andi@splitbrain.org> 1285 */ 1286function html_updateprofile(){ 1287 global $lang; 1288 global $conf; 1289 global $INPUT; 1290 global $ID; 1291 global $INFO; 1292 global $auth; 1293 1294 print p_locale_xhtml('updateprofile'); 1295 1296 $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true); 1297 $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true); 1298 print '<div class="centeralign">'.NL; 1299 $form = new Doku_Form(array('id' => 'dw__register')); 1300 $form->startFieldset($lang['profile']); 1301 $form->addHidden('do', 'profile'); 1302 $form->addHidden('save', '1'); 1303 $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled'))); 1304 $attr = array('size'=>'50'); 1305 if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled'; 1306 $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr)); 1307 $attr = array('size'=>'50'); 1308 if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled'; 1309 $form->addElement(form_makeTextField('email', $email, $lang['email'], '', 'block', $attr)); 1310 $form->addElement(form_makeTag('br')); 1311 if ($auth->canDo('modPass')) { 1312 $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50'))); 1313 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1314 } 1315 if ($conf['profileconfirm']) { 1316 $form->addElement(form_makeTag('br')); 1317 $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50'))); 1318 } 1319 $form->addElement(form_makeButton('submit', '', $lang['btn_save'])); 1320 $form->addElement(form_makeButton('reset', '', $lang['btn_reset'])); 1321 $form->endFieldset(); 1322 html_form('updateprofile', $form); 1323 print '</div>'.NL; 1324} 1325 1326/** 1327 * Preprocess edit form data 1328 * 1329 * @author Andreas Gohr <andi@splitbrain.org> 1330 * 1331 * @triggers HTML_EDITFORM_OUTPUT 1332 */ 1333function html_edit(){ 1334 global $INPUT; 1335 global $ID; 1336 global $REV; 1337 global $DATE; 1338 global $PRE; 1339 global $SUF; 1340 global $INFO; 1341 global $SUM; 1342 global $lang; 1343 global $conf; 1344 global $TEXT; 1345 global $RANGE; 1346 1347 if ($INPUT->has('changecheck')) { 1348 $check = $INPUT->str('changecheck'); 1349 } elseif(!$INFO['exists']){ 1350 // $TEXT has been loaded from page template 1351 $check = md5(''); 1352 } else { 1353 $check = md5($TEXT); 1354 } 1355 $mod = md5($TEXT) !== $check; 1356 1357 $wr = $INFO['writable'] && !$INFO['locked']; 1358 $include = 'edit'; 1359 if($wr){ 1360 if ($REV) $include = 'editrev'; 1361 }else{ 1362 // check pseudo action 'source' 1363 if(!actionOK('source')){ 1364 msg('Command disabled: source',-1); 1365 return; 1366 } 1367 $include = 'read'; 1368 } 1369 1370 global $license; 1371 1372 $form = new Doku_Form(array('id' => 'dw__editform')); 1373 $form->addHidden('id', $ID); 1374 $form->addHidden('rev', $REV); 1375 $form->addHidden('date', $DATE); 1376 $form->addHidden('prefix', $PRE . '.'); 1377 $form->addHidden('suffix', $SUF); 1378 $form->addHidden('changecheck', $check); 1379 1380 $data = array('form' => $form, 1381 'wr' => $wr, 1382 'media_manager' => true, 1383 'target' => ($INPUT->has('target') && $wr && 1384 $RANGE !== '') ? $INPUT->str('target') : 'section', 1385 'intro_locale' => $include); 1386 1387 if ($data['target'] !== 'section') { 1388 // Only emit event if page is writable, section edit data is valid and 1389 // edit target is not section. 1390 trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); 1391 } else { 1392 html_edit_form($data); 1393 } 1394 if (isset($data['intro_locale'])) { 1395 echo p_locale_xhtml($data['intro_locale']); 1396 } 1397 1398 $form->addHidden('target', $data['target']); 1399 $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); 1400 $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); 1401 $form->addElement(form_makeCloseTag('div')); 1402 if ($wr) { 1403 $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons'))); 1404 $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4'))); 1405 $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5'))); 1406 $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6'))); 1407 $form->addElement(form_makeCloseTag('div')); 1408 $form->addElement(form_makeOpenTag('div', array('class'=>'summary'))); 1409 $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2'))); 1410 $elem = html_minoredit(); 1411 if ($elem) $form->addElement($elem); 1412 $form->addElement(form_makeCloseTag('div')); 1413 } 1414 $form->addElement(form_makeCloseTag('div')); 1415 if($wr && $conf['license']){ 1416 $form->addElement(form_makeOpenTag('div', array('class'=>'license'))); 1417 $out = $lang['licenseok']; 1418 $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"'; 1419 if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"'; 1420 $out .= '>'.$license[$conf['license']]['name'].'</a>'; 1421 $form->addElement($out); 1422 $form->addElement(form_makeCloseTag('div')); 1423 } 1424 1425 if ($wr) { 1426 // sets changed to true when previewed 1427 echo '<script type="text/javascript"><!--//--><![CDATA[//><!--'. NL; 1428 echo 'textChanged = ' . ($mod ? 'true' : 'false'); 1429 echo '//--><!]]></script>' . NL; 1430 } ?> 1431 <div class="editBox"> 1432 1433 <div class="toolbar"> 1434 <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div> 1435 <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']?>" 1436 target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div> 1437 </div> 1438 <?php 1439 1440 html_form('edit', $form); 1441 print '</div>'.NL; 1442} 1443 1444/** 1445 * Display the default edit form 1446 * 1447 * Is the default action for HTML_EDIT_FORMSELECTION. 1448 */ 1449function html_edit_form($param) { 1450 global $TEXT; 1451 1452 if ($param['target'] !== 'section') { 1453 msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1); 1454 } 1455 1456 $attr = array('tabindex'=>'1'); 1457 if (!$param['wr']) $attr['readonly'] = 'readonly'; 1458 1459 $param['form']->addElement(form_makeWikiText($TEXT, $attr)); 1460} 1461 1462/** 1463 * Adds a checkbox for minor edits for logged in users 1464 * 1465 * @author Andreas Gohr <andi@splitbrain.org> 1466 */ 1467function html_minoredit(){ 1468 global $conf; 1469 global $lang; 1470 global $INPUT; 1471 // minor edits are for logged in users only 1472 if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){ 1473 return false; 1474 } 1475 1476 $p = array(); 1477 $p['tabindex'] = 3; 1478 if($INPUT->bool('minor')) $p['checked']='checked'; 1479 return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p); 1480} 1481 1482/** 1483 * prints some debug info 1484 * 1485 * @author Andreas Gohr <andi@splitbrain.org> 1486 */ 1487function html_debug(){ 1488 global $conf; 1489 global $lang; 1490 global $auth; 1491 global $INFO; 1492 1493 //remove sensitive data 1494 $cnf = $conf; 1495 debug_guard($cnf); 1496 $nfo = $INFO; 1497 debug_guard($nfo); 1498 $ses = $_SESSION; 1499 debug_guard($ses); 1500 1501 print '<html><body>'; 1502 1503 print '<p>When reporting bugs please send all the following '; 1504 print 'output as a mail to andi@splitbrain.org '; 1505 print 'The best way to do this is to save this page in your browser</p>'; 1506 1507 print '<b>$INFO:</b><pre>'; 1508 print_r($nfo); 1509 print '</pre>'; 1510 1511 print '<b>$_SERVER:</b><pre>'; 1512 print_r($_SERVER); 1513 print '</pre>'; 1514 1515 print '<b>$conf:</b><pre>'; 1516 print_r($cnf); 1517 print '</pre>'; 1518 1519 print '<b>DOKU_BASE:</b><pre>'; 1520 print DOKU_BASE; 1521 print '</pre>'; 1522 1523 print '<b>abs DOKU_BASE:</b><pre>'; 1524 print DOKU_URL; 1525 print '</pre>'; 1526 1527 print '<b>rel DOKU_BASE:</b><pre>'; 1528 print dirname($_SERVER['PHP_SELF']).'/'; 1529 print '</pre>'; 1530 1531 print '<b>PHP Version:</b><pre>'; 1532 print phpversion(); 1533 print '</pre>'; 1534 1535 print '<b>locale:</b><pre>'; 1536 print setlocale(LC_ALL,0); 1537 print '</pre>'; 1538 1539 print '<b>encoding:</b><pre>'; 1540 print $lang['encoding']; 1541 print '</pre>'; 1542 1543 if($auth){ 1544 print '<b>Auth backend capabilities:</b><pre>'; 1545 print_r($auth->cando); 1546 print '</pre>'; 1547 } 1548 1549 print '<b>$_SESSION:</b><pre>'; 1550 print_r($ses); 1551 print '</pre>'; 1552 1553 print '<b>Environment:</b><pre>'; 1554 print_r($_ENV); 1555 print '</pre>'; 1556 1557 print '<b>PHP settings:</b><pre>'; 1558 $inis = ini_get_all(); 1559 print_r($inis); 1560 print '</pre>'; 1561 1562 print '</body></html>'; 1563} 1564 1565/** 1566 * List available Administration Tasks 1567 * 1568 * @author Andreas Gohr <andi@splitbrain.org> 1569 * @author Håkan Sandell <hakan.sandell@home.se> 1570 */ 1571function html_admin(){ 1572 global $ID; 1573 global $INFO; 1574 global $lang; 1575 global $conf; 1576 global $auth; 1577 1578 // build menu of admin functions from the plugins that handle them 1579 $pluginlist = plugin_list('admin'); 1580 $menu = array(); 1581 foreach ($pluginlist as $p) { 1582 if($obj =& plugin_load('admin',$p) === null) continue; 1583 1584 // check permissions 1585 if($obj->forAdminOnly() && !$INFO['isadmin']) continue; 1586 1587 $menu[$p] = array('plugin' => $p, 1588 'prompt' => $obj->getMenuText($conf['lang']), 1589 'sort' => $obj->getMenuSort() 1590 ); 1591 } 1592 1593 // data security check 1594 // @todo: could be checked and only displayed if $conf['savedir'] is under the web root 1595 echo '<a style="border:none; float:right;" 1596 href="http://www.dokuwiki.org/security#web_access_security"> 1597 <img src="data/security.png" alt="Your data directory seems to be protected properly." 1598 onerror="this.parentNode.style.display=\'none\'" /></a>'; 1599 1600 print p_locale_xhtml('admin'); 1601 1602 // Admin Tasks 1603 if($INFO['isadmin']){ 1604 ptln('<ul class="admin_tasks">'); 1605 1606 if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){ 1607 ptln(' <li class="admin_usermanager"><div class="li">'. 1608 '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'. 1609 $menu['usermanager']['prompt'].'</a></div></li>'); 1610 } 1611 unset($menu['usermanager']); 1612 1613 if($menu['acl']){ 1614 ptln(' <li class="admin_acl"><div class="li">'. 1615 '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'. 1616 $menu['acl']['prompt'].'</a></div></li>'); 1617 } 1618 unset($menu['acl']); 1619 1620 if($menu['plugin']){ 1621 ptln(' <li class="admin_plugin"><div class="li">'. 1622 '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'. 1623 $menu['plugin']['prompt'].'</a></div></li>'); 1624 } 1625 unset($menu['plugin']); 1626 1627 if($menu['config']){ 1628 ptln(' <li class="admin_config"><div class="li">'. 1629 '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'. 1630 $menu['config']['prompt'].'</a></div></li>'); 1631 } 1632 unset($menu['config']); 1633 } 1634 ptln('</ul>'); 1635 1636 // Manager Tasks 1637 ptln('<ul class="admin_tasks">'); 1638 1639 if($menu['revert']){ 1640 ptln(' <li class="admin_revert"><div class="li">'. 1641 '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'. 1642 $menu['revert']['prompt'].'</a></div></li>'); 1643 } 1644 unset($menu['revert']); 1645 1646 if($menu['popularity']){ 1647 ptln(' <li class="admin_popularity"><div class="li">'. 1648 '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'. 1649 $menu['popularity']['prompt'].'</a></div></li>'); 1650 } 1651 unset($menu['popularity']); 1652 1653 // print DokuWiki version: 1654 ptln('</ul>'); 1655 echo '<div id="admin__version">'; 1656 echo getVersion(); 1657 echo '</div>'; 1658 1659 // print the rest as sorted list 1660 if(count($menu)){ 1661 usort($menu, 'p_sort_modes'); 1662 // output the menu 1663 ptln('<div class="clearer"></div>'); 1664 print p_locale_xhtml('adminplugins'); 1665 ptln('<ul>'); 1666 foreach ($menu as $item) { 1667 if (!$item['prompt']) continue; 1668 ptln(' <li><div class="li"><a href="'.wl($ID, 'do=admin&page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>'); 1669 } 1670 ptln('</ul>'); 1671 } 1672} 1673 1674/** 1675 * Form to request a new password for an existing account 1676 * 1677 * @author Benoit Chesneau <benoit@bchesneau.info> 1678 * @author Andreas Gohr <gohr@cosmocode.de> 1679 */ 1680function html_resendpwd() { 1681 global $lang; 1682 global $conf; 1683 global $ID; 1684 global $INPUT; 1685 1686 $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth')); 1687 1688 if(!$conf['autopasswd'] && $token){ 1689 print p_locale_xhtml('resetpwd'); 1690 print '<div class="centeralign">'.NL; 1691 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1692 $form->startFieldset($lang['btn_resendpwd']); 1693 $form->addHidden('token', $token); 1694 $form->addHidden('do', 'resendpwd'); 1695 1696 $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50'))); 1697 $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50'))); 1698 1699 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1700 $form->endFieldset(); 1701 html_form('resendpwd', $form); 1702 print '</div>'.NL; 1703 }else{ 1704 print p_locale_xhtml('resendpwd'); 1705 print '<div class="centeralign">'.NL; 1706 $form = new Doku_Form(array('id' => 'dw__resendpwd')); 1707 $form->startFieldset($lang['resendpwd']); 1708 $form->addHidden('do', 'resendpwd'); 1709 $form->addHidden('save', '1'); 1710 $form->addElement(form_makeTag('br')); 1711 $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block')); 1712 $form->addElement(form_makeTag('br')); 1713 $form->addElement(form_makeTag('br')); 1714 $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd'])); 1715 $form->endFieldset(); 1716 html_form('resendpwd', $form); 1717 print '</div>'.NL; 1718 } 1719} 1720 1721/** 1722 * Return the TOC rendered to XHTML 1723 * 1724 * @author Andreas Gohr <andi@splitbrain.org> 1725 */ 1726function html_TOC($toc){ 1727 if(!count($toc)) return ''; 1728 global $lang; 1729 $out = '<!-- TOC START -->'.DOKU_LF; 1730 $out .= '<div id="dw__toc">'.DOKU_LF; 1731 $out .= '<h3 class="toggle">'; 1732 $out .= $lang['toc']; 1733 $out .= '</h3>'.DOKU_LF; 1734 $out .= '<div>'.DOKU_LF; 1735 $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true); 1736 $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF; 1737 $out .= '<!-- TOC END -->'.DOKU_LF; 1738 return $out; 1739} 1740 1741/** 1742 * Callback for html_buildlist 1743 */ 1744function html_list_toc($item){ 1745 if(isset($item['hid'])){ 1746 $link = '#'.$item['hid']; 1747 }else{ 1748 $link = $item['link']; 1749 } 1750 1751 return '<a href="'.$link.'">'.hsc($item['title']).'</a>'; 1752} 1753 1754/** 1755 * Helper function to build TOC items 1756 * 1757 * Returns an array ready to be added to a TOC array 1758 * 1759 * @param string $link - where to link (if $hash set to '#' it's a local anchor) 1760 * @param string $text - what to display in the TOC 1761 * @param int $level - nesting level 1762 * @param string $hash - is prepended to the given $link, set blank if you want full links 1763 */ 1764function html_mktocitem($link, $text, $level, $hash='#'){ 1765 global $conf; 1766 return array( 'link' => $hash.$link, 1767 'title' => $text, 1768 'type' => 'ul', 1769 'level' => $level); 1770} 1771 1772/** 1773 * Output a Doku_Form object. 1774 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT 1775 * 1776 * @author Tom N Harris <tnharris@whoopdedo.org> 1777 */ 1778function html_form($name, &$form) { 1779 // Safety check in case the caller forgets. 1780 $form->endFieldset(); 1781 trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); 1782} 1783 1784/** 1785 * Form print function. 1786 * Just calls printForm() on the data object. 1787 */ 1788function html_form_output($data) { 1789 $data->printForm(); 1790} 1791 1792/** 1793 * Embed a flash object in HTML 1794 * 1795 * This will create the needed HTML to embed a flash movie in a cross browser 1796 * compatble way using valid XHTML 1797 * 1798 * The parameters $params, $flashvars and $atts need to be associative arrays. 1799 * No escaping needs to be done for them. The alternative content *has* to be 1800 * escaped because it is used as is. If no alternative content is given 1801 * $lang['noflash'] is used. 1802 * 1803 * @author Andreas Gohr <andi@splitbrain.org> 1804 * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml 1805 * 1806 * @param string $swf - the SWF movie to embed 1807 * @param int $width - width of the flash movie in pixels 1808 * @param int $height - height of the flash movie in pixels 1809 * @param array $params - additional parameters (<param>) 1810 * @param array $flashvars - parameters to be passed in the flashvar parameter 1811 * @param array $atts - additional attributes for the <object> tag 1812 * @param string $alt - alternative content (is NOT automatically escaped!) 1813 * @returns string - the XHTML markup 1814 */ 1815function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ 1816 global $lang; 1817 1818 $out = ''; 1819 1820 // prepare the object attributes 1821 if(is_null($atts)) $atts = array(); 1822 $atts['width'] = (int) $width; 1823 $atts['height'] = (int) $height; 1824 if(!$atts['width']) $atts['width'] = 425; 1825 if(!$atts['height']) $atts['height'] = 350; 1826 1827 // add object attributes for standard compliant browsers 1828 $std = $atts; 1829 $std['type'] = 'application/x-shockwave-flash'; 1830 $std['data'] = $swf; 1831 1832 // add object attributes for IE 1833 $ie = $atts; 1834 $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 1835 1836 // open object (with conditional comments) 1837 $out .= '<!--[if !IE]> -->'.NL; 1838 $out .= '<object '.buildAttributes($std).'>'.NL; 1839 $out .= '<!-- <![endif]-->'.NL; 1840 $out .= '<!--[if IE]>'.NL; 1841 $out .= '<object '.buildAttributes($ie).'>'.NL; 1842 $out .= ' <param name="movie" value="'.hsc($swf).'" />'.NL; 1843 $out .= '<!--><!-- -->'.NL; 1844 1845 // print params 1846 if(is_array($params)) foreach($params as $key => $val){ 1847 $out .= ' <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL; 1848 } 1849 1850 // add flashvars 1851 if(is_array($flashvars)){ 1852 $out .= ' <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL; 1853 } 1854 1855 // alternative content 1856 if($alt){ 1857 $out .= $alt.NL; 1858 }else{ 1859 $out .= $lang['noflash'].NL; 1860 } 1861 1862 // finish 1863 $out .= '</object>'.NL; 1864 $out .= '<!-- <![endif]-->'.NL; 1865 1866 return $out; 1867} 1868 1869function html_tabs($tabs, $current_tab = null) { 1870 echo '<ul class="tabs">'.NL; 1871 1872 foreach($tabs as $id => $tab) { 1873 html_tab($tab['href'], $tab['caption'], $id === $current_tab); 1874 } 1875 1876 echo '</ul>'.NL; 1877} 1878/** 1879 * Prints a single tab 1880 * 1881 * @author Kate Arzamastseva <pshns@ukr.net> 1882 * @author Adrian Lang <mail@adrianlang.de> 1883 * 1884 * @param string $href - tab href 1885 * @param string $caption - tab caption 1886 * @param boolean $selected - is tab selected 1887 */ 1888 1889function html_tab($href, $caption, $selected=false) { 1890 $tab = '<li>'; 1891 if ($selected) { 1892 $tab .= '<strong>'; 1893 } else { 1894 $tab .= '<a href="' . hsc($href) . '">'; 1895 } 1896 $tab .= hsc($caption) 1897 . '</' . ($selected ? 'strong' : 'a') . '>' 1898 . '</li>'.NL; 1899 echo $tab; 1900} 1901 1902