User:Ahecht/Scripts/pageswap

's pageswap is a script that allows a user to swap the histories of two pages (with reasonable restrictions), sometimes known as a history swap, sometimes called a round-robin move. This script is a modified version of User:Andy M. Wang/pageswap, designed for easier usage in answering requested moves. The script requires the user to have  and   rights. The script will add a "Swap" tab to the top of the page near the "new section" button, as well as a "Swap" link within "The page cannot be moved" error messages.

To use this script: Copy the line below, then  [ click here] , paste the line, and hit.
 * Report any issues to me, Ahecht.
 * Report any issues to me, Ahecht.

Features
This script contains all the features of Andy's script, plus the following:
 * Run from Special:MovePage. Pages can be swapped directly from the "name already exists" error message at Special:MovePage, using the previously entered page name and reason.
 * Create redlinked talk pages. When two pages swapped and one doesn't have a talk page, the script will prompt to create the missing talk page as a redirect.
 * Fix self-redirects. When a redirect is swapped with its target, the script will update the redirect to the new title.
 * Open Special:Contributions. After swapping, the script prompts to open the contributions page, to make checking for needed post-move cleanup easier.
 * Progress indication. Uses Bubble notifications to indicate swap progress.

Usage

 * 1) Go to the page to be swapped (i.e. page A as described at WP:PMVR). At the top of the page, there should be an additional option to "Swap" (right below "Move" or "Purge", it may be hidden under the "More" menu). Click "Swap".
 * 2) *You can also swap pages directly from Special:MovePage where the target page already exists. Once you've attempted to move a page and gotten the red "The page could not be moved" error box, either choose "Swap" from the top of the page as described above, or click on the swap link in the error message. This also works when clicking the "move" link on a requested move.
 * 3) Enter the full page name complete with namespace prefix. (Click cancel to step out.) Proceed through the forms as appropriate. (Press "OK" for "Yes", "Cancel" for "No".)
 * 4) *To cancel out of the swap routine, currently you will need to step through the sequence of menus, but just be sure to click cancel at the last screen that asks if you want to proceed.
 * 5) (Manually perform step 4 of the round-robin move if necessary, including correcting any moved redirects, and creating new redlinked talk pages. The tool will prompt you to open your contributions to assist with this.)
 * 6) (Manually perform any necessary post-move cleanup.)

Options
Editors can specify a default move reason via moveReasonDefault in their common.js above the line that loads pageswap. This is helpful for those who use pageswap who frequently perform similar actions with the same move summary (For example, var moveReasonDefault = "Requested at WP:RMTR"; ). If the swap is initiated from Special:MovePage with a pre-filled reason, that reason will be used as the default.

Editors can disable prompting for post-move cleanup by adding pagemoveDoPostMoveCleanup = false; in their common.js above the line that loads pageswap. Currently, the only post-move cleanup options that are implemented are to create red-linked talk pages and fix subject and talk pages (but not subpages) that redirect to themselves. Editors will still have to correct other issues listed in themselves.

Description
Because the round-robin move involves three distinct moves, in which each move step might fail for legitimate reasons, (target of a subpage is create-protected, a talk page is move-protected, or a target namespaces does not have subpages enabled, the target doesn't actually exist, etc) much of the script involves various checks to try to ensure that the three moves can happen unimpeded to the best of its ability. The script will detect the existence of talk pages and subpages and prompt the user, and will prompt to create red-linked talk pages. The script will not move subpages if the number of subpages of a namespace exceeds 100 pages. (In this case, attempt to perform the move manually, moving batches of 100 at a time.)

Editors can specify a default move reason (see "Options" section above). If the swap is initiated from Special:MovePage with a pre-filled reason, that reason will be used as the default.

If the move is complicated (i.e. subpages and talk subpages exist for source and destination), there will be a number of screens alerting you of the configuration to help you make the best decision about whether subpages should be moved. Occasionally, a (sub)page may be move-protected or immovable.

The prefix for the intermediate title (C) used for page B (as described at WP:PMVR) is hard-coded as  per convention.

Page swapping is enabled for most namespaces that can handle them. The ability to swap a page in a subject space with one in a talk space is currently disabled. Users who are unable to  or   have the swap functionality disabled.

Future changes
Have any suggestions for the scripts? Please leave a message on my talk page.

To do

 * Redo workflow to use a single form (via mw:OOUI) instead of pop-up boxes.

Out of scope

 * Checking template/file namespace for incoming links to original title
 * Correcting redirects unrelated to the source page
 * Correcting or retargeting any redirects on subpages
 * Other post-move cleanup (editnotices, lede/dab/hatnote corrections) These actions should be performed post-move manually.
 * Create newly red-linked subject / subpages as redirects

Script
The live script is at .js. Latest version published 14:03, 26 April 2022‎‎‎ (UTC).

Version history

 * 1.0, 17 December 2018‎: Direct copy from User:Andy M. Wang/pageswap.js v1.6.1.2018.0920.
 * 1.1, 19 December 2018: Work from Special:MovePage and modify error message on that page to include swap link, use reason from move page as default.
 * 1.2, 21 December 2018: Add option for post-move cleanup, implement creating red-linked talk page as part of cleanup.
 * 1.3, 11 February 2019: Redo workflow to avoid redundant messages. Prompt to open Special:Contributions for post-move cleanup.
 * 1.3.1, 23 February 2019: Make post-move cleanup default.
 * 1.3.2, 11 March 2019: Check if move page has proper parameters, use old page title as default new page title.
 * 1.3.3, 16 December 2020: Read page names and reasons from form fields in addition to URL so it works from any move page, not just ones linked from WP:RM/TR.
 * 1.3.4, 9 January 2021: Fix reading destination from form field if destination is not in article namespace.
 * 1.4, 12 January 2021: Correct self redirects resulting from swapping a redirect page and its target.
 * 1.5, 24 May 2021: Use mw:Bubble notifications to provide status updates, and instead of pop-ups for error messages.
 * 1.5.1, 26 April 2022: Update to no longer rely on the  class on Special:MovePage per phab:T300314.
 * 1.5.2, 25 October 2022: Warn about subpages that may need updating.