1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Esther Brunner <wikidesign@gmail.com> 5 */ 6 7// must be run within Dokuwiki 8if (!defined('DOKU_INC')) die(); 9 10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'action.php'); 12 13if (!defined('NL')) define('NL',"\n"); 14 15class action_plugin_discussion extends DokuWiki_Action_Plugin{ 16 17 /** 18 * Return some info 19 */ 20 function getInfo(){ 21 return array( 22 'author' => 'Esther Brunner', 23 'email' => 'wikidesign@gmail.com', 24 'date' => '2006-11-15', 25 'name' => 'Discussion Plugin', 26 'desc' => 'Enables discussion features', 27 'url' => 'http://wiki:splitbrain.org/plugin:discussion', 28 ); 29 } 30 31 /** 32 * Register the eventhandlers 33 */ 34 function register(&$contr){ 35 $contr->register_hook( 36 'ACTION_ACT_PREPROCESS', 37 'BEFORE', 38 $this, 39 'handle_act_preprocess', 40 array() 41 ); 42 $contr->register_hook( 43 'TPL_ACT_RENDER', 44 'AFTER', 45 $this, 46 'comments', 47 array() 48 ); 49 } 50 51 /** 52 * Main function; dispatches the comment actions 53 */ 54 function comments(&$event, $param){ 55 if ($event->data != 'show') return; // nothing to do for us 56 57 $cid = $_REQUEST['cid']; 58 59 switch ($_REQUEST['comment']){ 60 61 case 'add': 62 $comment = array( 63 'user' => $_REQUEST['user'], 64 'name' => $_REQUEST['name'], 65 'mail' => $_REQUEST['mail'], 66 'url' => $_REQUEST['url'], 67 'address' => $_REQUEST['address'], 68 'date' => $_REQUEST['date'], 69 'raw' => cleanText($_REQUEST['text']) 70 ); 71 $repl = $_REQUEST['reply']; 72 $this->_add($comment, $repl); 73 break; 74 75 case 'edit': 76 $this->_show(NULL, $cid); 77 break; 78 79 case 'save': 80 $raw = cleanText($_REQUEST['text']); 81 $this->_save($cid, $raw); 82 break; 83 84 case 'delete': 85 $this->_save($cid, ''); 86 87 case 'toogle': 88 $this->_save($cid, '', true); 89 break; 90 91 default: // 'show' => $this->_show(), 'reply' => $this->_show($cid) 92 $this->_show($cid); 93 } 94 } 95 96 /** 97 * Shows all comments of the current page 98 */ 99 function _show($reply = NULL, $edit = NULL){ 100 global $ID; 101 102 // get discussion meta file name 103 $file = metaFN($ID, '.comments'); 104 105 if (!file_exists($file)) return true; // no comments at all 106 107 $data = unserialize(io_readFile($file, false)); 108 109 if ($data['status'] == 0) return true; // comments are off 110 111 // section title 112 $title = $this->getLang('discussion'); 113 $secid = cleanID($title); 114 echo '<h2><a name="'.$secid.'" id="'.$secid.'">'.$title.'</a></h2>'; 115 echo '<div class="level2">'; 116 117 // now display the comments 118 if (isset($data['comments'])){ 119 foreach ($data['comments'] as $key => $value){ 120 if ($key == $edit) $this->_form($value['raw'], 'save', $edit); // edit form 121 else $this->_print($key, $data, '', $reply); 122 } 123 } 124 125 // comment form 126 if (($data['status'] == 1) && !$reply && !$edit) $this->_form(''); 127 128 echo '</div>'; 129 130 return true; 131 } 132 133 /** 134 * Adds a new comment and then displays all comments 135 */ 136 function _add($comment, $parent){ 137 global $ID; 138 global $TEXT; 139 140 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 141 $TEXT = $comment['raw']; 142 143 // spamcheck against the DokuWiki blacklist 144 if (checkwordblock()){ 145 msg($this->getLang('wordblock'), -1); 146 $this->_show(); 147 return false; 148 } 149 150 $TEXT = $otxt; // restore global $TEXT 151 152 // get discussion meta file name 153 $file = metaFN($ID, '.comments'); 154 155 $data = array(); 156 $data = unserialize(io_readFile($file, false)); 157 158 if ($data['status'] != 1) return false; // comments off or closed 159 if ((!$this->getConf('allowguests')) 160 && ($comment['user'] != $_SERVER['REMOTE_USER'])) 161 return false; // guest comments not allowed 162 163 if ($comment['date']) $date = strtotime($comment['date']); 164 else $date = time(); 165 if ($date == -1) $date = time(); 166 $cid = md5($comment['user'].$date); // create a unique id 167 168 if (!is_array($data['comments'][$parent])) $parent = NULL; // invalid parent comment 169 170 // render the comment 171 $xhtml = $this->_render($comment['raw']); 172 173 // fill in the new comment 174 $data['comments'][$cid] = array( 175 'user' => htmlspecialchars($comment['user']), 176 'name' => htmlspecialchars($comment['name']), 177 'mail' => htmlspecialchars($comment['mail']), 178 'date' => $date, 179 'show' => true, 180 'raw' => trim($comment['raw']), 181 'xhtml' => $xhtml, 182 'parent' => $parent, 183 'replies' => array() 184 ); 185 if ($comment['url']) 186 $data['comments'][$cid]['url'] = htmlspecialchars($comment['url']); 187 if ($comment['address']) 188 $data['comments'][$cid]['address'] = htmlspecialchars($comment['address']); 189 190 // update parent comment 191 if ($parent) $data['comments'][$parent]['replies'][] = $cid; 192 193 // update the number of comments 194 $data['number']++; 195 196 // save the comment metadata file 197 io_saveFile($file, serialize($data)); 198 $this->_addLogEntry($date, $ID, 'cc', '', $cid); 199 200 // notify subscribers of the page 201 $this->_notify($data['comments'][$cid]); 202 203 $this->_show(); 204 return true; 205 } 206 207 /** 208 * Saves the comment with the given ID and then displays all comments 209 */ 210 function _save($cid, $raw, $toogle = false){ 211 global $ID; 212 global $TEXT; 213 global $INFO; 214 215 $otxt = $TEXT; // set $TEXT to comment text for wordblock check 216 $TEXT = $raw; 217 218 // spamcheck against the DokuWiki blacklist 219 if (checkwordblock()){ 220 msg($this->getLang('wordblock'), -1); 221 $this->_show(); 222 return false; 223 } 224 225 $TEXT = $otxt; // restore global $TEXT 226 227 // get discussion meta file name 228 $file = metaFN($ID, '.comments'); 229 230 $data = array(); 231 $data = unserialize(io_readFile($file, false)); 232 233 // someone else was trying to edit our comment -> abort 234 if (($data['comments'][$cid]['user'] != $_SERVER['REMOTE_USER']) 235 && ($INFO['perm'] != AUTH_ADMIN)) return false; 236 237 $date = time(); 238 239 if ($toogle){ // toogle visibility 240 $now = $data['comments'][$cid]['show']; 241 $data['comments'][$cid]['show'] = !$now; 242 $data['number'] = $this->_count($data); 243 244 $type = ($data['comments'][$cid]['show'] ? 'sc' : 'hc'); 245 246 } elseif (!$raw){ // remove the comment 247 unset($data['comments'][$cid]); 248 $data['number'] = $this->_count($data); 249 250 $type = 'dc'; 251 252 } else { // save changed comment 253 $xhtml = $this->_render($raw); 254 255 // now change the comment's content 256 $data['comments'][$cid]['edited'] = $date; 257 $data['comments'][$cid]['raw'] = trim($raw); 258 $data['comments'][$cid]['xhtml'] = $xhtml; 259 260 $type = 'ec'; 261 } 262 263 // save the comment metadata file 264 io_saveFile($file, serialize($data)); 265 $this->_addLogEntry($date, $ID, $type, '', $cid); 266 267 $this->_show(); 268 return true; 269 } 270 271 /** 272 * Prints an individual comment 273 */ 274 function _print($cid, &$data, $parent = '', $reply = '', $visible = true){ 275 global $conf; 276 global $lang; 277 global $ID; 278 global $INFO; 279 280 $comment = $data['comments'][$cid]; 281 282 if (!is_array($comment)) return false; // corrupt datatype 283 284 if ($comment['parent'] != $parent) return true; // reply to an other comment 285 286 if (!$comment['show']){ // comment hidden 287 if ($INFO['perm'] == AUTH_ADMIN) echo '<div class="comment_hidden">'.NL; 288 else return true; 289 } 290 291 // comment head with date and user data 292 echo '<div class="comment_head">'.NL; 293 echo '<a name="comment__'.$cid.'" id="comment__'.$cid.'">'.NL; 294 295 // show gravatar image 296 if ($this->getConf('usegravatar')){ 297 $default = DOKU_URL.'lib/plugins/discussion/images/default.gif'; 298 $size = $this->getConf('gravatar_size'); 299 if ($comment['mail']) $src = ml('http://www.gravatar.com/avatar.php?'. 300 'gravatar_id='.md5($comment['mail']). 301 '&default='.urlencode($default). 302 '&size='.$size. 303 '&rating='.$this->getConf('gravatar_rating')); 304 else $src = $default; 305 $title = ($comment['name'] ? $comment['name'] : obfuscate($comment['mail'])); 306 echo '<img src="'.$src.'" class="medialeft" title="'.$title.'"'. 307 ' alt="'.$title.'" width="'.$size.'" height="'.$size.'" />'.NL; 308 $style = ' style="margin-left: '.($size + 14).'px;"'; 309 } else { 310 $style = ' style="margin-left: 20px;"'; 311 } 312 313 echo '</a>'.NL; 314 if ($this->getConf('linkemail') && $comment['mail']){ 315 echo $this->email($comment['email'], $comment['name']); 316 } elseif ($comment['url']){ 317 echo $this->external_link($comment['url'], $comment['name'], 'urlextern'); 318 } else { 319 echo $comment['name']; 320 } 321 if ($comment['address']) echo ', '.htmlentities($comment['address']); 322 echo ', '.date($conf['dformat'], $comment['date']); 323 if ($comment['edited']) echo ' ('.date($conf['dformat'], $comment['edited']).')'; 324 echo ':'.NL; 325 echo '</div>'.NL; // class="comment_head" 326 327 // main comment content 328 echo '<div class="comment_body"'.($this->getConf('usegravatar') ? $style : '').'>'.NL; 329 echo $comment['xhtml'].NL; 330 echo '</div>'.NL; // class="comment_body" 331 332 333 if ($visible){ 334 // show hide/show toogle button? 335 echo '<div class="comment_buttons">'.NL; 336 if ($INFO['perm'] == AUTH_ADMIN){ 337 if (!$comment['show']) $label = $this->getLang('btn_show'); 338 else $label = $this->getLang('btn_hide'); 339 340 $this->_button($cid, $label, 'toogle'); 341 } 342 343 // show reply button? 344 if (($data['status'] == 1) && !$reply && $comment['show'] 345 && ($this->getConf('allowguests') || $_SERVER['REMOTE_USER'])) 346 $this->_button($cid, $this->getLang('btn_reply'), 'reply', true); 347 348 // show edit and delete button? 349 if ((($comment['user'] == $_SERVER['REMOTE_USER']) && ($comment['user'] != '')) 350 || ($INFO['perm'] == AUTH_ADMIN)) 351 $this->_button($cid, $lang['btn_secedit'], 'edit', true); 352 if ($INFO['perm'] == AUTH_ADMIN) 353 $this->_button($cid, $lang['btn_delete'], 'delete'); 354 echo '</div>'.NL; // class="comment_buttons" 355 } 356 357 // replies to this comment entry? 358 if (count($comment['replies'])){ 359 echo '<div class="comment_replies"'.$style.'>'.NL; 360 $visible = ($comment['show'] && $visible); 361 foreach ($comment['replies'] as $rid){ 362 $this->_print($rid, $data, $cid, $reply, $visible); 363 } 364 echo '</div>'.NL; // class="comment_replies" 365 } 366 367 if (!$comment['show']) echo '</div>'.NL; // class="comment_hidden" 368 369 // reply form 370 if ($reply == $cid){ 371 echo '<div class="comment_replies">'.NL; 372 $this->_form('', 'add', $cid); 373 echo '</div>'.NL; // class="comment_replies" 374 } 375 } 376 377 /** 378 * Outputs the comment form 379 */ 380 function _form($raw = '', $act = 'add', $cid = NULL){ 381 global $lang; 382 global $conf; 383 global $ID; 384 global $INFO; 385 386 // not for unregistered users when guest comments aren't allowed 387 if (!$_SERVER['REMOTE_USER'] && !$this->getConf('allowguests')) return false; 388 389 ?> 390 <div class="comment_form"> 391 <form id="discussion__comment_form" method="post" action="<?php echo script() ?>" accept-charset="<?php echo $lang['encoding'] ?>" onsubmit="return validate(this);"> 392 <div class="no"> 393 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 394 <input type="hidden" name="do" value="show" /> 395 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 396 <?php 397 398 // for adding a comment 399 if ($act == 'add'){ 400 ?> 401 <input type="hidden" name="reply" value="<?php echo $cid ?>" /> 402 <?php 403 // for registered user 404 if ($conf['useacl'] && $_SERVER['REMOTE_USER']){ 405 ?> 406 <input type="hidden" name="user" value="<?php echo $_SERVER['REMOTE_USER'] ?>" /> 407 <input type="hidden" name="name" value="<?php echo $INFO['userinfo']['name'] ?>" /> 408 <input type="hidden" name="mail" value="<?php echo $INFO['userinfo']['mail'] ?>" /> 409 <?php 410 // for guest: show name and e-mail entry fields 411 } else { 412 ?> 413 <input type="hidden" name="user" value="<?php echo clientIP() ?>" /> 414 <div class="comment_name"> 415 <label class="block" for="discussion__comment_name"> 416 <span><?php echo $lang['fullname'] ?>:</span> 417 <input type="text" class="edit" name="name" id="discussion__comment_name" size="50" tabindex="1" /> 418 </label> 419 </div> 420 <div class="comment_mail"> 421 <label class="block" for="discussion__comment_mail"> 422 <span><?php echo $lang['email'] ?>:</span> 423 <input type="text" class="edit" name="mail" id="discussion__comment_mail" size="50" tabindex="2" /> 424 </label> 425 </div> 426 <?php 427 } 428 429 // allow entering an URL 430 if ($this->getConf('urlfield')){ 431 ?> 432 <div class="comment_url"> 433 <label class="block" for="discussion__comment_url"> 434 <span><?php echo $this->getLang('url') ?>:</span> 435 <input type="text" class="edit" name="url" id="discussion__comment_url" size="50" tabindex="3" /> 436 </label> 437 </div> 438 <?php 439 } 440 441 // allow entering an address 442 if ($this->getConf('addressfield')){ 443 ?> 444 <div class="comment_address"> 445 <label class="block" for="discussion__comment_address"> 446 <span><?php echo $this->getLang('address') ?>:</span> 447 <input type="text" class="edit" name="address" id="discussion__comment_address" size="50" tabindex="4" /> 448 </label> 449 </div> 450 <?php 451 } 452 453 // allow setting the comment date 454 if ($this->getConf('datefield') && ($INFO['perm'] == AUTH_ADMIN)){ 455 ?> 456 <div class="comment_date"> 457 <label class="block" for="discussion__comment_date"> 458 <span><?php echo $this->getLang('date') ?>:</span> 459 <input type="text" class="edit" name="date" id="discussion__comment_date" size="50" /> 460 </label> 461 </div> 462 <?php 463 } 464 465 // for saving a comment 466 } else { 467 ?> 468 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 469 <?php 470 } 471 ?> 472 <div class="comment_text"> 473 <textarea class="edit" name="text" cols="80" rows="10" id="discussion__comment_text" tabindex="5"><?php echo $raw ?></textarea> 474 </div> 475 <input class="button" type="submit" name="submit" value="<?php echo $lang['btn_save'] ?>" tabindex="6" /> 476 </div> 477 </form> 478 </div> 479 <?php 480 if ($this->getConf('usecocomment')) echo $this->_coComment(); 481 } 482 483 /** 484 * Adds a javascript to interact with coComments 485 */ 486 function _coComment(){ 487 global $ID; 488 global $conf; 489 global $INFO; 490 491 $user = $_SERVER['REMOTE_USER']; 492 493 ?> 494 <script type="text/javascript"><!--//--><![CDATA[//><!-- 495 var blogTool = "DokuWiki"; 496 var blogURL = "<?php echo DOKU_URL ?>"; 497 var blogTitle = "<?php echo $conf['title'] ?>"; 498 var postURL = "<?php echo wl($ID, '', true) ?>"; 499 var postTitle = "<?php echo tpl_pagetitle($ID, true) ?>"; 500 <?php 501 if ($user){ 502 ?> 503 var commentAuthor = "<?php echo $INFO['userinfo']['name'] ?>"; 504 <?php 505 } else { 506 ?> 507 var commentAuthorFieldName = "name"; 508 <?php 509 } 510 ?> 511 var commentAuthorLoggedIn = <?php echo ($user ? 'true' : 'false') ?>; 512 var commentFormID = "discussion__comment_form"; 513 var commentTextFieldName = "text"; 514 var commentButtonName = "submit"; 515 var cocomment_force = false; 516 //--><!]]></script> 517 <script type="text/javascript" src="http://www.cocomment.com/js/cocomment.js"> 518 </script> 519 <?php 520 } 521 522 /** 523 * General button function 524 */ 525 function _button($cid, $label, $act, $jump = false){ 526 global $ID; 527 $anchor = ($jump ? '#discussion__comment_form' : '' ); 528 529 ?> 530 <form class="button" method="post" action="<?php echo script().$anchor ?>"> 531 <div class="no"> 532 <input type="hidden" name="id" value="<?php echo $ID ?>" /> 533 <input type="hidden" name="do" value="show" /> 534 <input type="hidden" name="comment" value="<?php echo $act ?>" /> 535 <input type="hidden" name="cid" value="<?php echo $cid ?>" /> 536 <input type="submit" value="<?php echo $label ?>" class="button" title="<?php echo $label ?>" /> 537 </div> 538 </form> 539 <?php 540 return true; 541 } 542 543 /** 544 * Adds an entry to the comments changelog 545 * 546 * @author Esther Brunner <wikidesign@gmail.com> 547 * @author Ben Coburn <btcoburn@silicodon.net> 548 */ 549 function _addLogEntry($date, $id, $type = 'cc', $summary = '', $extra = ''){ 550 global $conf; 551 552 $changelog = $conf['metadir'].'/_comments.changes'; 553 554 if(!$date) $date = time(); //use current time if none supplied 555 $remote = $_SERVER['REMOTE_ADDR']; 556 $user = $_SERVER['REMOTE_USER']; 557 558 $strip = array("\t", "\n"); 559 $logline = array( 560 'date' => $date, 561 'ip' => $remote, 562 'type' => str_replace($strip, '', $type), 563 'id' => $id, 564 'user' => $user, 565 'sum' => str_replace($strip, '', $summary), 566 'extra' => str_replace($strip, '', $extra) 567 ); 568 569 // add changelog line 570 $logline = implode("\t", $logline)."\n"; 571 io_saveFile($changelog, $logline, true); //global changelog cache 572 $this->_trimRecentCommentsLog($changelog); 573 } 574 575 /** 576 * Trims the recent comments cache to the last $conf['changes_days'] recent 577 * changes or $conf['recent'] items, which ever is larger. 578 * The trimming is only done once a day. 579 * 580 * @author Ben Coburn <btcoburn@silicodon.net> 581 */ 582 function _trimRecentCommentsLog($changelog){ 583 global $conf; 584 585 if (@file_exists($changelog) && 586 (filectime($changelog) + 86400) < time() && 587 !@file_exists($changelog.'_tmp')){ 588 589 io_lock($changelog); 590 $lines = file($changelog); 591 if (count($lines)<$conf['recent']) { 592 // nothing to trim 593 io_unlock($changelog); 594 return true; 595 } 596 597 io_saveFile($changelog.'_tmp', ''); // presave tmp as 2nd lock 598 $trim_time = time() - $conf['recent_days']*86400; 599 $out_lines = array(); 600 601 for ($i=0; $i<count($lines); $i++) { 602 $log = parseChangelogLine($lines[$i]); 603 if ($log === false) continue; // discard junk 604 if ($log['date'] < $trim_time) { 605 $old_lines[$log['date'].".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions) 606 } else { 607 $out_lines[$log['date'].".$i"] = $lines[$i]; // definitely keep these lines 608 } 609 } 610 611 // sort the final result, it shouldn't be necessary, 612 // however the extra robustness in making the changelog cache self-correcting is worth it 613 ksort($out_lines); 614 $extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum 615 if ($extra > 0) { 616 ksort($old_lines); 617 $out_lines = array_merge(array_slice($old_lines,-$extra),$out_lines); 618 } 619 620 // save trimmed changelog 621 io_saveFile($changelog.'_tmp', implode('', $out_lines)); 622 @unlink($changelog); 623 if (!rename($changelog.'_tmp', $changelog)) { 624 // rename failed so try another way... 625 io_unlock($changelog); 626 io_saveFile($changelog, implode('', $out_lines)); 627 @unlink($changelog.'_tmp'); 628 } else { 629 io_unlock($changelog); 630 } 631 return true; 632 } 633 } 634 635 /** 636 * Sends a notify mail on new comment 637 * 638 * @param array $comment data array of the new comment 639 * 640 * @author Andreas Gohr <andi@splitbrain.org> 641 * @author Esther Brunner <wikidesign@gmail.com> 642 */ 643 function _notify($comment){ 644 global $conf; 645 global $ID; 646 647 if (!$conf['subscribers']) return; //subscribers enabled? 648 $bcc = subscriber_addresslist($ID); 649 if (empty($bcc)) return; 650 $to = ''; 651 $text = io_readFile($this->localFN('subscribermail')); 652 653 $text = str_replace('@PAGE@', $ID, $text); 654 $text = str_replace('@TITLE@', $conf['title'], $text); 655 $text = str_replace('@DATE@', date($conf['dformat'], $comment['date']), $text); 656 $text = str_replace('@NAME@', $comment['name'], $text); 657 $text = str_replace('@TEXT@', $comment['raw'], $text); 658 $text = str_replace('@UNSUBSCRIBE@', wl($ID, 'do=unsubscribe', true, '&'), $text); 659 $text = str_replace('@DOKUWIKIURL@', DOKU_URL, $text); 660 661 $subject = '['.$conf['title'].'] '.$this->getLang('mail_newcomment'); 662 663 mail_send($to, $subject, $text, $conf['mailfrom'], '', $bcc); 664 } 665 666 /** 667 * Counts the number of visible comments 668 */ 669 function _count($data){ 670 $number = 0; 671 foreach ($data['comments'] as $cid => $comment){ 672 if ($comment['parent']) continue; 673 if (!$comment['show']) continue; 674 $number++; 675 $rids = $comment['replies']; 676 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 677 } 678 return $number; 679 } 680 681 function _countReplies(&$data, $rids){ 682 $number = 0; 683 foreach ($rids as $rid){ 684 if (!$data['comments'][$rid]['show']) continue; 685 $number++; 686 $rids = $data['comments'][$rid]['replies']; 687 if (count($rids)) $number = $number + $this->_countReplies($data, $rids); 688 } 689 return $number; 690 } 691 692 /** 693 * Renders the comment text 694 */ 695 function _render($raw){ 696 if ($this->getConf('wikisyntaxok')){ 697 $xhtml = $this->render($raw); 698 } else { // wiki syntax not allowed -> just encode special chars 699 $xhtml = htmlspecialchars(trim($raw)); 700 } 701 return $xhtml; 702 } 703 704 /** 705 * Checks if 'newthread' was given as action, if so we 706 * do handle the event our self and no further checking takes place 707 */ 708 function handle_act_preprocess(&$event, $param){ 709 if ($event->data != 'newthread') return; // nothing to do for us 710 711 global $ACT; 712 global $ID; 713 714 // we can handle it -> prevent others 715 $event->stopPropagation(); 716 $event->preventDefault(); 717 718 $ns = $_REQUEST['ns']; 719 $title = str_replace(':', '', $_REQUEST['title']); 720 $id = ($ns ? $ns.':' : '').cleanID($title); 721 722 // check if we are allowed to create this file 723 if (auth_quickaclcheck($id) >= AUTH_CREATE){ 724 $back = $ID; 725 $ID = $id; 726 $file = wikiFN($ID); 727 728 //check if locked by anyone - if not lock for my self 729 if (checklock($ID)){ 730 $ACT = 'locked'; 731 } else { 732 lock($ID); 733 } 734 735 // prepare the new thread file with default stuff 736 if (!@file_exists($file)){ 737 global $TEXT; 738 global $INFO; 739 global $conf; 740 741 $TEXT = pageTemplate(array($ns.':'.$title)); 742 if (!$TEXT) $TEXT = "<- [[:$back]]\n\n====== $title ======\n\n". 743 "{{gravatar>".$INFO['userinfo']['mail']." }} ". 744 "//".$INFO['userinfo']['name'].", ". 745 date($conf['dformat']).": //\n\n\n\n". 746 "~~DISCUSSION~~\n"; 747 $ACT = 'preview'; 748 } else { 749 $ACT = 'edit'; 750 } 751 } else { 752 $ACT = 'show'; 753 } 754 } 755 756} 757 758//Setup VIM: ex: et ts=4 enc=utf-8 : 759