From: Geoffrey T. D. <da...@us...> - 2001-08-18 05:09:12
|
Update of /cvsroot/phpwiki/phpwiki/lib In directory usw-pr-cvs1:/tmp/cvs-serv19382/lib Modified Files: Tag: release-1_2-branch db_filesystem.php Log Message: Fix SF bug #227748. When using the flat-file back end, page names with slashes in them didn't work. We fix this by urlencoding '%' '/' '\\' and ':' when they occur in page names. WARNING: If any pages currently in your flat-file database contain any of those characters in their titles, this change will make them invisible to PhpWiki. You should back them up before upgrading, and restore them after upgrading. Index: db_filesystem.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/db_filesystem.php,v retrieving revision 1.4.2.3 retrieving revision 1.4.2.4 diff -C2 -r1.4.2.3 -r1.4.2.4 *** db_filesystem.php 2001/08/18 02:38:34 1.4.2.3 --- db_filesystem.php 2001/08/18 05:09:09 1.4.2.4 *************** *** 42,49 **** } ! // Return hash of page + attributes or default function RetrievePage($dbi, $pagename, $pagestore) { ! $filename = $dbi[$pagestore] . "/" . $pagename; if ($fd = @fopen($filename, "rb")) { $locked = flock($fd, 1); # Read lock --- 42,61 ---- } ! // Sort of urlencode() the pagename. ! // We only encode a limited set of characters to minimize breakage ! // of existing databases. The encoded names can be decoded with ! // urldecode. ! function EncodePagename($pagename) { ! $bad_chars = '%/\\:'; // '%' must be first! ! for ($i = 0; $i < strlen($bad_chars); $i++) { ! $pagename = str_replace($bad_chars[$i], ! rawurlencode($bad_chars[$i]), $pagename); ! } ! return $pagename; ! } ! // Return hash of page + attributes or default function RetrievePage($dbi, $pagename, $pagestore) { ! $filename = $dbi[$pagestore] . "/" . EncodePagename($pagename); if ($fd = @fopen($filename, "rb")) { $locked = flock($fd, 1); # Read lock *************** *** 55,59 **** $pagehash = unserialize($data); if (!is_array($pagehash)) ! ExitWiki(sprintf("'%s': corrupt file", htmlspecialchars($filename))); } --- 67,71 ---- $pagehash = unserialize($data); if (!is_array($pagehash)) ! ExitWiki(sprintf(gettext("'%s': corrupt file"), htmlspecialchars($filename))); } *************** *** 82,86 **** } ! $filename = $dbi . "/" . $pagename; if($fd = fopen($filename, 'a+b')) { $locked = flock($fd,2); #Exclusive blocking lock --- 94,98 ---- } ! $filename = $dbi . "/" . EncodePagename($pagename); if($fd = fopen($filename, 'a+b')) { $locked = flock($fd,2); #Exclusive blocking lock *************** *** 116,125 **** function IsWikiPage($dbi, $pagename) { ! return file_exists($dbi['wiki'] . "/" . $pagename); } function IsInArchive($dbi, $pagename) { ! return file_exists($dbi['archive'] . "/" . $pagename); } --- 128,137 ---- function IsWikiPage($dbi, $pagename) { ! return file_exists($dbi['wiki'] . "/" . EncodePagename($pagename)); } function IsInArchive($dbi, $pagename) { ! return file_exists($dbi['archive'] . "/" . EncodePagename($pagename)); } *************** *** 200,203 **** --- 212,219 ---- while (list($key, $page) = each($pos['data'])) { $pagedata = RetrievePage($dbi, $page, $WikiPageStore); + if (!is_array($pagedata)) { + printf(gettext("%s: bad data<br>\n"), htmlspecialchars($page)); + continue; + } while (list($i, $line) = each($pagedata['content'])) { *************** *** 285,290 **** $d = opendir($dbi); while($entry = readdir($d)) { ! if ($entry != '.' && $entry != '..') ! $namelist[] = $entry; } --- 301,313 ---- $d = opendir($dbi); while($entry = readdir($d)) { ! if ($entry == '.' || $entry == '..') ! continue; ! $pagename = rawurldecode($entry); ! if ($entry != EncodePagename($pagename)) { ! printf(gettext("%s: Bad filename in database<br>\n"), ! htmlspecialchars("$dbi/$entry")); ! continue; ! } ! $namelist[] = $pagename; } |