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