<?php // -*- mode:php -*- require_once "lib.page-edit.php"; require_once "lib.page.php"; if (lwiki_auth_check($emsg) == 1) { lwiki\edit\error($emsg); } $frag_captcha = lwiki_auth_generate(); if (!$edit_session->exists()) { $frag_action = htmlspecialchars(lwiki_link_page($pageid, 'mode=edit')); $frag_title = '新規作成:' . $ht_page_title; } else { if ($edit_session->is_part()) { $frag_action = htmlspecialchars(lwiki_link_page($pageid, 'mode=edit&part=' . urlencode($_GET['part']))); $frag_title = '部分編集:' . $ht_page_title; } else { $frag_action = htmlspecialchars(lwiki_link_page($pageid, 'mode=edit')); $frag_title = '編集:' . $ht_page_title; } } $frag_content = htmlspecialchars($edit_session->content()); $frag_edithash = htmlspecialchars($edit_session->edithash()); $frag_xsrfhash = htmlspecialchars($edit_session->xsrfhash()); $frag_remarks = htmlspecialchars($_POST['remarks']); $frag_partlength = $edit_session->is_part() ? '<input type="hidden" name="partlength" value="' . $edit_session->partlength() . '" />' . PHP_EOL : ''; lwiki\page\begin_document($frag_title, '<meta name="robots" content="none" />' . PHP_EOL); echo '<p class="lwiki-linkbar-main">'; $url_main = htmlspecialchars(lwiki_link_page()); $url_list = htmlspecialchars(lwiki_link_page(null, 'mode=list')); echo '[ <a href="' . $url_main . '">表紙</a>' . ' | <a href="' . $url_list . '">一覧</a> ]';
function comment_add() { global $flock, $comment_id; global $comment_error; if (lwiki_auth_check($comment_error) != 0) { return false; } $name = $_POST['name']; $body = $_POST['body']; $xsrf = $_POST['sigma']; if ($name == '') { comment_echoe('名前が空です。'); return false; } else { if (mb_substr($name, 0, 1) == '#') { comment_echoe('名前が空です。# の前に少なくとも1文字以上入力して下さい。'); return false; } else { if (mb_strlen($name) > 100) { comment_echoe('名前が長すぎです。100文字以下にして下さい。'); return false; } else { if ($body == '') { comment_echoe('コメント内容が空です。'); return false; } else { if (mb_strlen($body) > 5000) { comment_echoe('コメント内容が長すぎです。分割して投稿して下さい。'); return false; } else { if ($xsrf !== _calculate_xsrfhash()) { comment_echoe('フォーム署名が不正です。意図した投稿か確認し再度投稿を試みて下さい。'); return false; } } } } } } global $fdat, $fhtm; if (!$flock->lock($fdat)) { comment_echoe("(comment_add): sorry, failed to lock the file `{$fdat}'."); return false; } $name = htmlspecialchars($name); $ipaddr = $_SERVER["REMOTE_ADDR"]; $date = @lwiki_datetime(); $count = $flock->file_increment("./.lwiki/data/{$comment_id}.count"); $chklast = $ipaddr . '/' . urlencode($name) . '/' . urlencode($body); $flast = "./.lwiki/data/{$comment_id}.last"; if ($chklast == @file_get_contents($flast)) { comment_echoe('二重投稿です'); $flock->unlock($fdat); return false; } $dat = $ipaddr . '/' . $date . '/' . urlencode($name) . '/' . urlencode($body) . '/' . $count . "\n"; if (false === @file_put_contents($fdat, $dat, FILE_APPEND)) { comment_echoe("(comment_add): sorry, failed to append an entry to the file `{$fdat}'."); $flock->unlock($fdat); return false; } // write if (!$flock->file_atomic_append($fhtm, comment_generate_html($ipaddr, $date, $name, $body, $count))) { comment_echoe('(comment_add): sorry, failed to append your comment to the comment.htm file.'); $flock->unlock($fdat); return false; } file_put_contents($flast, $chklast); $flock->unlock($fdat); return true; }
public function execute() { global $flock, $pageid; $ipaddr = $_SERVER["REMOTE_ADDR"]; $date = @lwiki_datetime(); global $edit_session; $content = $edit_session->content(); $edithash = $edit_session->edithash(); $xsrfhash = $edit_session->xsrfhash(); if (lwiki_auth_check($msg) != 0) { error($msg); return false; } $fname_wiki = ".lwiki/data/page.{$pageid}.wiki"; // ロック if (!$flock->lock($fname_wiki)) { error("sorry, failed to lock the file, 'page.{$pageid}.wiki'."); return false; } $original_wiki_source = lwiki_canonicalize_linebreaks(@file_get_contents($fname_wiki)); $param_part = $_GET['part']; if ($param_part && find_section_range($param_part, $original_wiki_source, $i0, $iN)) { // 部分編集 $original_wiki_head = substr($original_wiki_source, 0, $i0); $original_wiki_body = substr($original_wiki_source, $i0, $iN - $i0); $original_wiki_tail = substr($original_wiki_source, $iN); } else { // 全体編集 $original_wiki_head = ''; $original_wiki_body = $original_wiki_source; $original_wiki_tail = ''; } // check 編集の衝突 if ($edithash != _calculate_edithash($original_wiki_body)) { error('編集の衝突が発生しました (別のユーザによる更新が編集中に行われました)。差分を参照して下さい。{' . $i0 . ',' . $iN . '}'); $flock->unlock($fname_wiki); return false; } // XSRF 識別 if ($xsrfhash != _calculate_xsrfhash($edithash)) { error('内部署名が一致しません。この投稿が意図したものか確認し、再度投稿を行って下さい。'); $flock->unlock($fname_wiki); return false; } // check 変更無し if ($content == $original_wiki_body) { error('変更点がありません。'); $flock->unlock($fname_wiki); return false; } //if(mb_substr($content,-1)!=="\n")$content.="\n"; $content = $original_wiki_head . $content . $original_wiki_tail; // 保存実行 if (!@file_put_contents($fname_wiki, $content)) { error('編集データ保存に失敗しました。'); $flock->unlock($fname_wiki); return false; } $flock->unlock($fname_wiki); if (!$this->_page_hist_append($ipaddr, $date, $content, $_POST['remarks'])) { return false; } $conv = \lwiki\convert\create_converter(); $conv->setCustomGenerateEditLink('default'); $content = $conv->convert($content); if (!$flock->file_atomic_save_locked(".lwiki/data/page.{$pageid}.htm", $content)) { error('(page_update): sorry, failed to save html to page.htm.'); return false; } $info = $ipaddr . '/' . $date . PHP_EOL; $info .= urlencode($conv->header_close()) . PHP_EOL; // 頁内目次 $info .= urlencode($conv->tags) . PHP_EOL; // タグ $info .= urlencode($conv->keywords) . PHP_EOL; // 索引 if (!$flock->file_atomic_save_locked(".lwiki/data/page.{$pageid}.info", $info)) { error('(page_update): sorry, failed to update the page information in page.info.'); } return true; }