* * Move and copy wiki pages * * Developed and tested using PmWiki 2.2.x * * To use, add the following to a configuration file: if (($action=='copy') || ($action=='move') || ($action=='rename')) include_once("$FarmD/cookbook/movepage.php"); * For more information, please see the online documentation at * http://www.pmwiki.org/wiki/Cookbook/MovePage * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Script maintained by Petko Yotov www.pmwiki.org/petko */ $RecipeInfo['MovePage']['Version'] = '20171206'; SDVA($HandleActions, array( 'copy' => 'HandleMovePage', 'move' => 'HandleMovePage', 'rename' => 'HandleMovePage' )); SDVA($HandleAuth, [ 'copy' => 'edit', 'move' => 'edit', 'rename' => 'edit' ]); SDVA($ActionTitleFmt, array( 'copy' => '| $[Copy/move]', 'move' => '| $[Copy/move]', 'rename' => '| $[Copy/move]' )); SDV($MovePageDefaultAction, 'move'); SDV($MovePageSetDefaultActionFromPageAction, false); function MovePage($pagename, &$tgtname, &$page, $auth) { global $action, $FmtPV, $ChangeSummary, $Now, $MovePageFmt, $Charset; if ($Charset != 'UTF-8' && preg_match('/[\\x80-\\xbf]/', $tgtname)) $tgtname = utf8_decode($tgtname); $tgtname = MakePageName($pagename, $tgtname); if (empty($tgtname)) return 'invalid target'; $FmtPV['$MoveTargetName'] = "'$tgtname'"; if (PageExists($tgtname)) return "target page ($tgtname) exists"; $tgt = RetrieveAuthPage($tgtname, $auth, FALSE); if (!$tgt) return "cannot read target location ($tgtname); insufficient authority?"; if (!empty($_REQUEST['copy'])) $mp_action = 'copy'; else if (!empty($_REQUEST['move'])) $mp_action = 'move'; else if (!empty($_REQUEST['rename'])) $mp_action = 'rename'; else $mp_action = $action; $new = $page; $new['csum'] = $ChangeSummary = FmtPageName($MovePageFmt["$mp_action-csum"], $pagename); if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary; if (!UpdatePage($tgtname, $page, $new)) return "error writing page ($tgtname)"; if ($mp_action == 'move') { $new = $page; $new['text'] = FmtPageName($MovePageFmt['old-text'], $pagename); $new['csum'] = $ChangeSummary = FmtPageName($MovePageFmt['old-csum'], $pagename); if ($ChangeSummary) $new["csum:$Now"] = $ChangeSummary; if (!UpdatePage($pagename, $page, $new)) return "target ($tgtname) written ok, error writing to source page ($pagename)"; } else if ($mp_action == 'rename') { global $WikiDir, $LastModFile; $page = RetrieveAuthPage($pagename, $auth, false, READPAGE_CURRENT); if (!$page) return "?cannot delete $pagename"; $WikiDir->delete($pagename); } return FALSE; } function HandleMovePage($pagename, $auth='edit') { global $PageStartFmt, $PageEndFmt, $ActionTitleFmt, $action, $FmtPV, $Now, $ChangeSummary, $MessagesFmt, $MovePageFmt, $MovePageDefaultAction, $MovePageSetDefaultActionFromPageAction; if (isset($_REQUEST['cancel'])) Redirect($pagename); Lock(2); if (!PageExists($pagename)) Abort("MovePage: source page ($pagename) doesn't exist"); $page = RetrieveAuthPage($pagename, $auth, TRUE); if (!$page) Abort("MovePage: cannot read source ($pagename)"); ## Determine what is the default action (which will happen if the user hits Enter in ## the text field). $default_action = $MovePageSetDefaultActionFromPageAction ? $action : $MovePageDefaultAction; ## This is to apply a 'default_action' class to the button corresponding to the ## default action (for distinctive styling if desired). $copy_default_action_class = ($default_action == 'copy') ? "class='default_action'" : ""; $move_default_action_class = ($default_action == 'move') ? "class='default_action'" : ""; $rename_default_action_class = ($default_action == 'rename') ? "class='default_action'" : ""; SDVA($MovePageFmt, array( 'copy-csum' => 'Page copied to {$MoveTargetName} from {$FullName}', 'move-csum' => 'Page moved to {$MoveTargetName} from {$FullName}', 'rename-csum' => 'Page renamed to {$MoveTargetName} from {$FullName}', 'old-csum' => 'Page moved to {$MoveTargetName}', 'old-text' => '(:redirect {$MoveTargetName}:)', 'form' => array( "

$[Copy/move/rename] {\$FullName} $[to:]

", 'markup:(:messages:)', "
" ), 'print' => array( &$PageStartFmt, &$MovePageFmt['form'], &$PageEndFmt ) )); $FmtPV['$MoveTargetName'] = "'$pagename'"; if (empty($_POST['to'])) { Lock(0); PrintFmt($pagename, $MovePageFmt['print']); return; } $tgtname = $_POST['to']; $status = MovePage($pagename, $tgtname, $page, $auth); Lock(0); if ($status) { $MessagesFmt[] = "
MovePage: $status
"; PrintFmt($pagename, $MovePageFmt['print']); } else Redirect($tgtname); }