draft.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2006 Patrick R. Michaud (pmichaud@pobox.com)
  3. This file is part of PmWiki; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version. See pmwiki.php for full details.
  7. */
  8. array_unshift($EditFunctions, 'EditDraft');
  9. SDV($DraftSuffix, '-Draft');
  10. if ($DraftSuffix) $SearchPatterns['normal'][] = "!$DraftSuffix\$!";
  11. if ($action == 'edit')
  12. SDVA($InputTags['e_savedraftbutton'], array(
  13. ':html' => "<input type='submit' \$InputFormArgs />",
  14. 'name' => 'postdraft', 'value' => ' '.XL('Save as draft').' ',
  15. 'accesskey' => XL('ak_savedraft')));
  16. function EditDraft(&$pagename, &$page, &$new) {
  17. global $WikiDir, $DraftSuffix, $DeleteKeyPattern;
  18. SDV($DeleteKeyPattern, "^\\s*delete\\s*$");
  19. $basename = preg_replace("/$DraftSuffix\$/", '', $pagename);
  20. $draftname = $basename . $DraftSuffix;
  21. if ($_POST['postdraft'])
  22. { $pagename = $draftname; return; }
  23. if ($_POST['post'] && !preg_match("/$DeleteKeyPattern/", $new['text'])) {
  24. $pagename = $basename;
  25. $page = ReadPage($basename);
  26. $WikiDir->delete($draftname);
  27. return;
  28. }
  29. if (PageExists($draftname) && $pagename != $draftname)
  30. { Redirect($draftname, '$PageUrl?action=edit'); exit(); }
  31. }