} else {
$result = fread($fp, $size);
if ($result !== FALSE) {
- // Removing line-feeds
+ // Removing Carriage-Return
$result = str_replace("\r", '', $result);
}
}
// Returns an array
$result = file($path);
if ($result !== FALSE) {
- // Removing line-feeds
+ // Removing Carriage-Return
$result = str_replace("\r", '', $result);
}
}
$postdata = add_author_info($text_without_author);
$is_delete = empty($text_without_author);
- // Create and write diff
+ // Do nothing when it has no changes
$oldpostdata = is_page($page) ? join('', get_source($page)) : '';
+ $oldtext_without_author = remove_author_info($oldpostdata);
+ if ($text_without_author === $oldtext_without_author) {
+ // Do nothing on updating with unchanged content
+ return;
+ }
+ // Create and write diff
$diffdata = do_diff($oldpostdata, $postdata);
file_write(DIFF_DIR, $page, $diffdata);
function add_author_info($wikitext)
{
- global $auth_user, $auth_user_fullname, $auth_type, $ldap_user_account;
+ global $auth_user, $auth_user_fullname;
$author = preg_replace('/"/', '', $auth_user);
- $displayname = preg_replace('/"/', '', $auth_user_fullname);
- $user_prefix = '';
- switch ($auth_type) {
- case AUTH_TYPE_BASIC:
- $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
- break;
- case AUTH_TYPE_EXTERNAL:
- case AUTH_TYPE_EXTERNAL_REMOTE_USER:
- case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
- $user_prefix = AUTH_PROVIDER_USER_PREFIX_EXTERNAL;
- break;
- case AUTH_TYPE_FORM:
- if ($ldap_user_account) {
- $user_prefix = AUTH_PROVIDER_USER_PREFIX_LDAP;
- } else {
- $user_prefix = AUTH_PROVIDER_USER_PREFIX_DEFAULT;
- }
- break;
+ $fullname = $auth_user_fullname;
+ if (!$fullname && $author) {
+ // Fullname is empty, use $author as its fullname
+ $fullname = preg_replace('/^[^:]*:/', '', $author);
}
+ $displayname = preg_replace('/"/', '', $fullname);
+ $user_prefix = get_auth_user_prefix();
$author_text = sprintf('#author("%s","%s","%s")',
get_date_atom(UTIME + LOCALZONE),
($author ? $user_prefix . $author : ''),
htmlsc(basename($filename)));
}
}
+
+/**
+ * Lock-enabled file_get_contents
+ *
+ * Require: PHP5+
+ */
+function pkwk_file_get_contents($filename) {
+ if (! file_exists($filename)) {
+ return false;
+ }
+ $fp = fopen($filename, 'rb');
+ flock($fp, LOCK_SH);
+ $file = file_get_contents($filename);
+ flock($fp, LOCK_UN);
+ return $file;
+}