lib/file.phpのfile_write()、page_write()に追記オプション追加paraedit

  • ページ: Develop/Modification1
  • 投稿者: ぃぉぃぉ
  • 優先順位: 普通
  • 状態: 完了
  • カテゴリー: 本体新機能
  • 投稿日: 2009-05-14 (木) 13:04:02
  • バージョン:

メッセージparaedit

page_write()paraedit

// Put a data(wiki text) into a physical file(diff, backup, text)
-function page_write($page, $postdata, $notimestamp = FALSE)
+function page_write($page, $postdata, $notimestamp = FALSE, $add = FALSE)
{
	require_once(LIB_DIR . 'backup.php');
	require_once(LIB_DIR . 'diff.php');
	global $autoalias, $aliaspage;
 
	if (PKWK_READONLY) return; // Do nothing
 
	$postdata = make_str_rules($postdata);
 
	// Create and write diff
	$oldpostdata = is_page($page) ? get_source($page, TRUE, TRUE) : '';
	$diffdata    = do_diff($oldpostdata, $postdata);
	file_write(DIFF_DIR, $page, $diffdata);
	unset($oldpostdata, $diffdata);
 
	// Create backup
	make_backup($page, $postdata == ''); // Is $postdata null?
 
	// Create wiki text
-	file_write(DATA_DIR, $page, $postdata, $notimestamp);
+	file_write(DATA_DIR, $page, $postdata, $notimestamp, '.txt', $add);
 
	links_update($page);
 
	// Update autoalias.dat (AutoAliasName)
	if ($autoalias && $page === $aliaspage) {
		$aliases = get_autoaliases();
		if (empty($aliases)) {
			// Remove
			@unlink(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
		} else {
			// Create or Update
			autolink_pattern_write(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE,
				get_autolink_pattern(array_keys($aliases), $autoalias));
		}
	}
}

file_write()paraedit

// Output to a file
-function file_write($dir, $page, $str, $notimestamp = FALSE, $postfix = '.txt')
+function file_write($dir, $page, $str, $notimestamp = FALSE, $postfix = '.txt', $add = FALSE)
{
	global $_msg_invalidiwn, $notify, $notify_diff_only, $notify_subject;
	global $whatsdeleted, $maxshow_deleted;
    global $editable_flag;
 
	if (PKWK_READONLY) return; // Do nothing
    if (!$editable_flag && !check_editable($page, FALSE, FALSE)) {
        die('file_write(): page ' . $page . ' not editable');
    }
    unset($editable_flag);
 
	if ($dir != DATA_DIR && $dir != DIFF_DIR && $dir != UPLOAD_DIR) die('file_write(): Invalid directory');
 
	$page = strip_bracket($page);
	$file = $dir . encode($page) . $postfix;
	$file_exists = file_exists($file);
 
	// ----
	// Delete?
 
	if ($dir == DATA_DIR && $str === '') {
		// Page deletion
		if (! $file_exists) return; // Ignore null posting for DATA_DIR
 
		// Update RecentDeleted (Add the $page)
		add_recent($page, $whatsdeleted, '', $maxshow_deleted);
 
		// Remove the page
		unlink($file);
 
		// Update RecentDeleted, and remove the page from RecentChanges
		lastmodified_add($whatsdeleted, $page);
 
		// Clear is_page() cache
		is_page($page, TRUE);
 
		return;
 
	} else if ($dir == DIFF_DIR && $str === " \n") {
		return; // Ignore null posting for DIFF_DIR
	}
 
	// ----
	// File replacement (Edit)
 
	if (! is_pagename($page))
		die_message(str_replace('$1', htmlspecialchars($page),
		            str_replace('$2', 'WikiName', $_msg_invalidiwn)));
 
	if($dir !== UPLOAD_DIR) {
		$str = rtrim(preg_replace('/' . "\r" . '/', '', $str)) . "\n";
	}
	$timestamp = ($file_exists && $notimestamp) ? filemtime($file) : FALSE;
 
	$fp = fopen($file, 'a') or die('fopen() failed: ' .
		htmlspecialchars(basename($dir) . '/' . encode($page) . '.txt') .
		'<br />' . "\n" .
		'Maybe permission is not writable or filename is too long');
	set_file_buffer($fp, 0);
	flock($fp, LOCK_EX);
+	if(!$add) {
		ftruncate($fp, 0);
		rewind($fp);
+	}
	fputs($fp, $str);
	flock($fp, LOCK_UN);
	fclose($fp);
 
	if ($timestamp) pkwk_touch_file($file, $timestamp);
 
	// Optional actions
	if ($dir == DATA_DIR) {
		// Update RecentChanges (Add or renew the $page)
		if ($timestamp === FALSE) lastmodified_add($page);
 
		// Command execution per update
		if (defined('PKWK_UPDATE_EXEC') && PKWK_UPDATE_EXEC)
			system(PKWK_UPDATE_EXEC . ' > /dev/null &');
 
	} else if ($dir == DIFF_DIR && $notify) {
		if ($notify_diff_only) $str = preg_replace('/^[^-+].*\n/m', '', $str);
		$summary = array();
		$summary['ACTION'] = 'Page update';
		$summary['PAGE']   = & $page;
		$summary['URI']    = get_script_uri() . '?' . rawurlencode($page);
		$summary['USER_AGENT']  = TRUE;
		$summary['REMOTE_ADDR'] = TRUE;
		pkwk_mail_notify($notify_subject, $str, $summary) or
			die('pkwk_mail_notify(): Failed');
	}
 
	is_page($page, TRUE); // Clear is_page() cache
}



トップ 編集凍結差分バックアップ添付複製名前変更リロード 新規一覧 単語検索 最終更新  ヘルプ  最終更新のRSS
Last-modified: 2009-05-19 (火) 02:41:38 (3835d)