Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions helper/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ protected function execute($dir, $src_ns, $src_name, $dst_ns, $dst_name, $extreg
msg('Moving ' . hsc($old_path . '/' . $file) . ' to ' . hsc($new_path . '/' . utf8_encodeFN($dst_name . $match[1])) . ' failed.', -1);
return false;
}

if (pathinfo($file)['extension'] == 'changes') {
$this->edit_changes_file($old_path . '/' . $file, $new_path . '/' . utf8_encodeFN($dst_name . $match[1]));
}
}
}
closedir($dh);
Expand All @@ -153,4 +157,26 @@ protected function execute($dir, $src_ns, $src_name, $dst_ns, $dst_name, $extreg
}
return true;
}

/**
* Edit `.changes` meta file in order to make history of old entries accessible.
*
* if pagename entry is not edited, users can't read or diff old entries that edited before moving.
*
* @param string $old_path Old `.changes` file path.
* @param string $new_path New `.changes` file path.
*/
protected function edit_changes_file($old_path, $new_path) {
global $conf;

$history_content = file_get_contents($new_path);

$old_pagename = str_replace("/", ":", substr($old_path, strlen($conf['metadir']) + 1, -8));
$new_pagename = str_replace("/", ":", substr($new_path, strlen($conf['metadir']) + 1, -8));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is missing an utf8_decodeFN to remove the (potential) encoding of the filename. Also, what speaks against just using $src_ns, $dst_ns, $src_name and $dst_name in the calling method to construct both IDs without the complicated step of first constructing filenames?


$history_content = preg_replace('/(C|E|e|D)\t' . $old_pagename . '\t/', '$1 ' . $new_pagename . ' ', $history_content);

io_saveFile($new_path, $history_content);
}

}