MovePage

Summary: Move and copy wiki pages
Version: 20240109
Prerequisites: PmWiki 2.3.30
Status: production
Maintainer: Petko (original author: Eemeli Aro)
Discussion: MovePage-Talk
Download: movepage.phpΔ

Description

MovePage provides a simple form and simple actions to copy, move, or rename a page within a wiki. Copy duplicates the page, Rename changes the name and creates a redirect to the new page at the old page, and move simply changes the name.

If per page upload directories is enabled the folders for uploads attached to the page can also be copied or renamed at the same time.

To use, once installed, add ?action=copy or ?action=move or ?action=rename to a page's location (or use a PageActions link, if you've defined one) to get a simple form, fill in the target name and press a button ("Copy" or "Move" or '"Rename"). MovePage will verify that the target page doesn't already exist, and that you have the required permissions, then moves or copies or renames the page including all of its history, as well as adding a note in the page history & recent changes that the copy/move/rename has been made.

Installation

If you upgrade, please do read the release notes below.

  • Download movepage.phpΔ to your cookbook directory
  • Add the following to your config file:
    if ($action=='copy' || $action=='move' || $action=='rename') 
      include_once("$FarmD/cookbook/movepage.php");
  • Optionally, add something like the following to your Site.PageActions page:
    (:if auth edit:)
    * %item rel=nofollow class=move% [[{*$FullName}?action=move | $[Copy/move] ]]
    (:ifend:)
    

Configuration

MovePage is configured via an array $MovePageFmt, which contains the following entries. These are all interpreted in the context of the source page, hence the use of a new page variable {$MoveTargetName}.

$MovePageFmt['copy-csum']
default 'Page copied to {$MoveTargetName} from {$FullName}'
The change summary to leave on a copied target page.
$MovePageFmt['move-csum']
default 'Page moved to {$MoveTargetName} from {$FullName}'
The change summary to leave on a moved target page.
$MovePageFmt['rename-csum']
default 'Page renamed to {$MoveTargetName} from {$FullName}'
The change summary to leave on a renamed target page.
$MovePageFmt['old-csum']
default 'Page moved to {$MoveTargetName}'
The change summary to leave on a moved source page, if it is not deleted.
$MovePageFmt['old-text']
default '(:redirect {$MoveTargetName}:)'
The text to leave on a moved source page. Use $MovePageFmt['old-text'] = 'delete'; to delete the source page when moving.
$MovePageFmt['form']
The form used to copy or move a page. See the source for the default value or below for an equivalent in wiki markup.

Custom copy/move form

To modify the form used, you'll need to define your own form as a wiki page, such as Site.MoveForm and then set the following in a config file:

$MovePageFmt['form'] = 'wiki:Site.MoveForm';

Here's how to re-implement the default form using wiki markup:

>>id=wikimove<<
!! %block wikiaction% $[Copy/move/rename] [[{*$FullName}]] $[to:]
(:messages:)
(:input form method=post action={*$PageUrl} :)
(:input default request=1:)(:input default to {*$FullName}:)
(:input hidden n {*$FullName}:)(:input pmtoken:)
'''$[New page name]:'''\\
(:input text to placeholder="$[New page name]":)

(:input radio action copy "$[Copy]: $[Make a copy of the page with a new name, without modifying the original]":)\\
(:input radio action move "$[Move]: $[Move the page to the new name, leaving a redirect to the new page at the old name]\":)\\
(:input radio action rename "$[Rename]: $[Move the page to the new name, leaving nothing at the old name]":)

(:if enabled EnableMovePageUploads:)
(:input checkbox includeuploads 1 "$[Also include the page upload directory]":)

(:ifend:)
(:if enabled EnablePostAuthorRequired:)
'''$[Author]:'''\\
(:input e_author:)

(:ifend:)
(:input submit go "$[Go]":) (:input submit cancel "$[Cancel]":) 
(:input end:)
>><<
Old markup, before version 20240109
>>wikimove<<
!! %block wikiaction% $[Copy/move] {*$FullName} $[to:]
(:messages:)
(:input form "{*$PageUrl}?action=move" post:)
(:input hidden action move:)
(:input hidden n {*$FullName}:)
(:input text to {*$MoveTargetName}:)
(:input submit copy $[Copy]:)
(:input submit move $[Move]:)
(:input submit rename $[Rename]:)
(:input submit cancel $[Cancel]:)
(:input end:)
>><<

Notes

If you want, you can use MovePage's actions from another recipe or form by POSTing to a location such as {$PageUrl}?action=copy or {$PageUrl}?action=move with a POST parameters to=New.Name and pmtoken= with the value from pmtoken(). to as a GET parameter is explicitly not handled, as that might result more easily in accidental use, in that case the page form is displayed with the target page pre-filled with that value.

RenamePage has done pretty much this since 2005, but it's broken enough things on my sites for me to have disabled it. I also couldn't be bothered to look through its code to figure out all that it does.

Release notes

  • 20240109Δ : major rewrite (by Petko):
    • Requires PmWiki 2.3.30 or more recent if $EnablePostAuthorRequired is set.
    • The PmToken security functions are now enabled for this recipe.
    • Redesigned the $MovePageFmt['form'] element to use PmWiki markup. Suggested markup above to use in a wiki page has changed.
    • Replaced 3 action buttons with radio buttons.
    • More prominent labels.
    • Removed $MovePageDefaultAction, $MovePageSetDefaultActionFromPageAction. The radio button corresponding to the selected ?action will be selected.
    • Added a checkbox and functions to also copy/move the attached files (requested by Simon). This only works when there are per-page upload directories see $UploadPrefixFmt, and the whole directory with all files is copied or moved, regardless of whether the existing files are linked from the page, or from other pages. The checkbox only appears when the per-page upload directory exists.
    • When $EnablePostAuthorRequired is set, an "Author:" input box will appear (requested by Simon).
    • When a page is moved with a redirect, the old page also includes a Summary page text variable that appears in pagelists.
    • In case of errors, the form will reappear with the error message, and will remember previously selected options.
    • Added bold styles for selected labels.
  • 20180225Δ: This version allows to pre-fill the new page name field if there is a "&to=Group.Page" string in the "?action=move" URL.
  • 20171206Δ: add default_action class, $MovePageDefaultAction, $MovePageSetDefaultActionFromPageAction, see Talk page (Said Achmiz)
  • 20171121: Revert back to using array() construct, for compatibility with PHP 5.3 and earlier. Make title tooltips translatable. Fix bug with international page names when UTF-8 is enabled. Remove unneeded updating of $LastModFile, already done in WritePage. Remove unneeded auth prompt when renaming. Move warnings/messages above form, not after it. Add hidden form element with the action for the POST array (on some installations the GET element may be lost). (Petko)
  • 2017-11-20Δ: added 'rename' action to move without leaving a redirect (Said Achmiz)
  • 2009-08-17Δ: first release (Eemeli Aro)

See also

Contributors

Comments


This space is for User-contributed commentary and notes. Please include your name and a date (eg 2007-05-19) along with your comment. Please leave new comments at the top of this section.

It seems this line is not necessary, since most Page Manipulation routine is handles UTF-8 encoded path w/o problem. I can't rename a page into a 'Chinese file name' unless I comment out this line.

   if (preg_match('/[\\x80-\\xbf]/', $tgtname)) $tgtname = utf8_decode($tgtname);

This was fixed in 20171121. --Petko November 21, 2017, at 02:07 AM

I have some problems with Pagelists and Conditions

I installed the Cookbook Cookbook.MovePage. As soon a page ist moved from the Group e.g. "Shows" to "Showsarchive" it still exists in the group "Shows". Therefore I want to give out all the "Shows.*" pages in a pagelists but not showing the pages that are already in the group "Showsarchive.*".

It should be a conditions something like this:

(:pagelist group="Shows" fmt="#simple" if="!group Showsarchive.*" :)

But i have not clue and invested already hours in finding out. Maybe you can help me? That would save my day! Jean Baptiste On May 24, 2010 - at 13:28 PM

I just found out, Yeah:

(:pagelist group="Shows" fmt="#simple" if="!exists Showsarchive.{=$Name}" :)

Jean Baptiste On May 26, 2010 - at 1:13 AM

Are you sure you're moving these pages instead of copying them? Moving should remove the page from the original group; if that's not happening then there's a bug. However, if you're copying pages then your solution is a good one. —Eemeli Aro
My experience was that "move" changes the original to redirect to the new page - but the original still exists. If it didn't do that, links to the original would be broken - so for some installations that might not be a bug. However, if you need to be able to test whether the original is redirecting, perhaps the recipe can be modified to include on the original page a page text variable such as "moved: newname" - then moved pages can be tested by a conditional. - RandyB May 26, 2010, at 12:56 PM

Jazzvox on Dec 07, 2011 - at 11:55 CET

Use CleanUp in addition, or delete moved pages manually. It's the way it should be.

User notes +8: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.