#2 EditCopy bug in phpwiki 1.1.6b (with MySQL)

Arno Hollosi

The MySQL schema uses (pagename,version) for primary key into the 'archive' table. The effect of this is that when "replace"ing an archive paged, the page is added rather than actually replaced. (The archive table contains all versions of a given page which were ever archived.)

RetrievePage() in wiki_mysql.php3 doesn't take into account that there may be more than one entry for a give pagename --- therefore, as it currently stands it just picks a random version rather than the most recently archived version.

There are (at least) two possible fixes:

  1. Fix the MySQL schema so that only one backup of each page is kept. (This is probably the best alternative, since there is no way to get at any but the most recent archived copy anyway.)

  2. Fix RetrievePage() so that it picks the most recent version of a page. This is what I did. Here's the patch:

--- bugfix.3/wiki_mysql.php3 Tue, 27 Jun 2000 11:00:54 -0700 dairiki (phpwiki/18_wiki_mysql 1.1 664)
+++ bugfix.4/wiki_mysql.php3 Wed, 28 Jun 2000 14:44:28 -0700 dairiki (phpwiki/18_wiki_mysql 664)
@@ -69,7 +69,7 @@
// Return hash of page + attributes or default
function RetrievePage($dbi, $pagename) {
$pagename = addslashes($pagename);
- if ($res = mysql_query("select * from $dbi[table] where pagename='$pagename'", $dbi['dbc'])) {
+ if ($res = mysql_query("select * from $dbi[table] where pagename='$pagename' order by version desc limit 1", $dbi['dbc'])) {
if ($dbhash = mysql_fetch_array($res)) {
return MakePageHash($dbhash);


  • I've never assigned a bug before, so I hope you are not offended. :-)

  • Arno Hollosi
    Arno Hollosi

    I opt for the first variant: fixing the mySQL schema.
    Having more than one version in the archive right now
    makes no sense. Later versions of phpwiki may allow
    a complete history of edits. Until then there's no need
    for it.