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.