00862: allow deletion from other $WikiLibDirs besides $WikiDir

Summary: allow deletion from other $WikiLibDirs besides $WikiDir
Created: 2007-01-11 09:01
Status: Open
Category: CoreCandidate
Priority: 4
Version: 2.2

Description: Currently the PostPage() function only deletes pages that are in $WikiDir (wiki.d) even if other writable page-storage objects are present in $WikiLibDirs. This means that recipes that provide additional page-storage options, such as DataQuery, have to provide a replacement for the entire PostPage() function in the $EditFunctions array. By adding six lines (adapted from WritePage()) to the existing function, the way would be paved for other data-storage options:

 function PostPage($pagename, &$page, &$new) {
  global $DiffKeepDays, $DiffFunction, $DeleteKeyPattern, $EnablePost,
    $Now, $Author, $WikiLibDirs, $WikiDir, $IsPagePosted;
  $IsPagePosted = false;
  if ($EnablePost) {
    $new["author:$Now"] = @$Author;
    $new["host:$Now"] = $_SERVER['REMOTE_ADDR'];
    $diffclass = preg_replace('/\\W/','',@$_POST['diffclass']);
    if ($page["time"]>0 && function_exists(@$DiffFunction))
      $new["diff:$Now:{$page['time']}:$diffclass"] =
    $keepgmt = $Now-$DiffKeepDays * 86400;
    $keys = array_keys($new);
    foreach($keys as $k)
      if (preg_match("/^\\w+:(\\d+)/",$k,$match) && $match[1]<$keepgmt)
    if (preg_match("/$DeleteKeyPattern/",$new['text'])) {

      //this is the changed bit, scavenged from WritePage()
      for($i=0; $i<count($WikiLibDirs); $i++) {
        $wd = &$WikiLibDirs[$i];
        if ($wd->iswrite && $wd->exists($pagename)) break;
      if ($i >= count($WikiLibDirs)) $wd = &$WikiDir;
      //end of modification

    } else WritePage($pagename,$new);
    $IsPagePosted = true;