User:Jeffq/Transwiki automation

This process is designed to automate the initial transfer and logging of articles from one wiki project to another, based on the principles outlined in Transwiki. Besides enforcing guidelines that are frequently ignored in practice, it adds three features practically never provided under the current transwiki process:
 * 1) Accurate edit history timestamps.
 * 2) Project-specific editor links (e.g., clicking on an editor in a transwiki page history will take you to that editor's user page for the originating project).
 * 3) The discussion page of the originating article, complete with reformatted links.

NOTE: Articles are copied into the Transwiki: namespace instead of directly into the main article space for two major reasons, based on Transwiki policy:
 * 1) An article may exist already on the destination project.
 * 2) The destination project should decide the ultimate fate of any incoming articles. They may not agree with the originating project's decision to move the article, or they may want to make significant changes before adding it to their article space.

The specific actions taken by this process are:
 * 1) Create a copy of the original article in the Transwiki: namespace of the destination project.
 * 2) Copy and format the edit history of the original article into the discussion page of the new article, including UTC timestamps and project-specific user links.
 * 3) Copy and format the discussion page of the original article into the discussion page of the new article, including UTC timestamps and project-specific user links.
 * 4) Log the transwiki copy in both projects, including UTC timestamps and project

Assumptions

 * Transwiki logs are found at PROJECT:Transwiki (standard practice).
 * Each transwiki log has a section for recording outgoing transwikis. (The heading is not assumed, but is required input.)
 * Each transwiki log has a section for recording incoming transwikis. (The heading is not assumed, but is required input.)
 * NOTE: A policy change for all projects to standardize on incoming/outgoing nomenclature, or at least register their headings or section numbers, would greatly simplify even this automated process for Transwiki editors.
 * Transwiki log order (within a section) has the most recent entries appended to the end of the section (common practice; standard?).
 * User will initiate process on the originating project.
 * The following log entry format is acceptable to all participating projects:
 * ORIG:Old article name &rarr; DEST:Transwiki:New article name — User:Local username or IP timestamp
 * NOTE: The project prefixes will be adjusted so that the links direct to what is expected, per Principle of least astonishment.

Information needed

 * Originating project
 * Article name
 * Origin username or IP (may be calculated)
 * User password (unnecessary if IP or if user already logged in)
 * Timezone offset (unnecessary if IP)
 * Heading of Transwiki log's outgoing section (default=Outgoing)


 * Destination project
 * New article name (default=Article name)
 * Destination username or IP (default: same as originating project)
 * User password (unnecessary if IP)
 * Timezone offset (unnecessary if IP)
 * Heading of Transwiki log's incoming section (default=Incoming)

Steps

 * 1) Set up process.
 * 2) If username provide and not logged in, log in user. Fail if login fails.
 * 3) Open session on destination project. Fail if can't login or if session unavailable.
 * 4) Calculate project prefixes for link conversions: origin&rarr;destination (NEW:) and destination&rarr;origin (OLD:).
 * Example: en:Wikiquote&rarr;Wikisource: "wikisource:"; Wikisource&rarr;en:Wikiquote: "q:en:".
 * 1) Save user's current timezone offset on each project (if necessary) and set each to offset=0 (UTC).
 * 2) Copy article.
 * 3) Fetch ORIG:Article name.
 * 4) Create DEST:Transwiki:New article name.
 * 5) Copy history.
 * 6) Fetch &action=history&offset=0&limit=50000 of ORIG:Article name.
 * 7) In the history text, append " (UTC)" to all timestamps, and add project-specific links to all usernames/IPs.
 * 8) Edit &action=edit&section=new for DEST:Transwiki talk:New article name.
 * 9) Paste formatted history with &Subject/headline=Transwikied article edit history and save.
 * 10) Copy original discussion page.
 * 11) Fetch ORIG:Talk:Article name.
 * 12) In the discussion page text, add project-specific links to all usernames and IPs. BONUS: Convert all links to project-specific links.
 * 13) Edit &action=edit&section=new for DEST:Transwiki talk:New article name.
 * 14) Paste formatted discussion page with &Subject/headline=Transwikied article discussion page and save.
 * 15) Log transwiki on origin and destination projects.
 * 16) Create basic log entry in format:
 * Article name &rarr; Transwiki:New article name
 * 1) For origin log entry, add destination prefix (NEW:) to 2nd log field and append "— User:Origin username or IP timestamp".
 * 2) Edit ORIG:Transwiki and append origin log entry to it.
 * 3) For destination log entry, add destination prefix (OLD:) to 1st log field and append "— User:Destination username or IP timestamp".
 * 4) Edit DEST:Transwiki and append origin log entry to it.
 * 5) OPTIONAL: Submit transwikied article for speedy deletion on originating project.
 * 6) Wikiquote: Add    tag to ORIG:Article name.
 * 7) Clean up process.
 * 8) Restore user timezone preferences on each project.