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
Assigned:
Priority: 4
Version: 2.2
OS:

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;
  SDV($DiffKeepDays,3650);
  SDV($DeleteKeyPattern,"^\\s*delete\\s*$");
  $IsPagePosted = false;
  if ($EnablePost) {
    $new["author"]=@$Author;
    $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"] =
        $DiffFunction($new['text'],@$page['text']);
    $keepgmt = $Now-$DiffKeepDays * 86400;
    $keys = array_keys($new);
    foreach($keys as $k)
      if (preg_match("/^\\w+:(\\d+)/",$k,$match) && $match[1]<$keepgmt)
        unset($new[$k]);
    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;
      $wd->delete($pagename);
      //end of modification

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