WordPress and PmWiki

Just had a very funny experience. I made a change on the wiki and when I returned to the weblog my posts had disappeared. Every category was empty and even permanent link urls were showing no matching entries. In panic I quickly queried the database – everything was there. I switched to IE and everything worked! I quit Firefox, thinking it must have its knickers in a twist. Still the same. I hacked some code together to dump out the query variables being passed to WordPress:

$wpvarstoreset = array('m','p','posts','w', 'cat',
    'withcomments','s','search','exact', 'sentence','poststart',
    'postend','preview','debug', 'calendar','page','paged',
    'more','tb', 'pb','author','order','orderby', 'year',
    'monthnum', 'day', 'hour', 'minute', 'second', 'name',
    'category_name', 'feed', 'author_name');

for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  $wpvar = $wpvarstoreset[$i];
  echo ( $wpvar . "=" . $$wpvar  . "<br />n");
}

This showed that the author was being set to IanDavis. Aha! I’d just made an edit on the wiki using that name! PmWiki sets a cookie called author and PHP puts cookies into the _POST global array! WordPress was reading this and adding a bogus author parameter to all its page queries. How to fix it though? I could hack WordPress to ignore the author parameter, or I could hack PmWiki to change its cookie name. I chose the latter since, although this is a single author weblog, I might want to use WordPress and PmWiki together on other shared weblogs. I made the following change to scripts/author.php in the PmWiki installation:

if (!isset($Author)) {
  if (isset($_POST['author'])) {
    $Author = htmlspecialchars(stripmagic($_POST['author']),ENT_QUOTES);
    setcookie('wiki-author',$Author,$AuthorCookieExpires,$AuthorCookieDir);
  } else {
    $Author = htmlspecialchars(stripmagic(@$_COOKIE['wiki-author']),ENT_QUOTES);
  }
  $Author = preg_replace('/(^[^[:alpha:]]+)|[^w- ]/','',$Author);
}

Seemed to do the trick!

Update: In the original version of this post I had inadverdently changed the name of the post variable as well as the cookie. I’ve fixed the code above to show the correct version.

About Ian Davis

British entrepreneur and CEO of Kasabi. Primary interests are open data, the semantic web and decentralization.
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

One Response to WordPress and PmWiki

  1. dalton says:

    Holy cow! I just installed PMWiki, and was shocked to see that my wordpress installation appeared empty! Thanks for figuring out the workaround for the Author Cookie…you saved my life.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s