## Context
When the temporary account feature is enabled, and an anonymous user attempts to save an edit, [[ https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1008530/5/includes/editpage/EditPage.php#b2464 | we create a temporary account for the user ]] and log the user in to this account.
The current order of operations in `EditPage.php#internalAttemptSave` is:
- `onEditPage__attemptSave`
- `onEditFilter`
- edit conflict checks
- Constructing a Content object
- `EditConstraintRunner()` has run:
- EditFilterMergedContentHookConstraint
- UnicodeConstraint
- SimpleAntiSpamConstraint
- SpamRegexConstraint
- ImageRedirectConstraint
- UserBlockConstraint
- ContentModelChangeConstraint
- ReadOnlyConstraint
- UserRateLimitConstraint
- PageSizeConstraint
- ChangeTagsConstraint
- AccidentalRecreationConstraint
- EditRightConstraint
- DefaultTextConstraint
- NewSectionMissingSubjectConstraint
- MissingCommentConstraint
- AutoSummaryMissingSummaryConstraint
- SelfRedirectConstraint
- **Create temp account**
The result is that there are numerous stopping points where an edit attempt does not result in temporary account creation.
This results in problems for {T334623}, where it is difficult to know how to log a failed edit attempt because the temporary account doesn't exist yet at time of rejection. See also {T358806} for a similar failure in SpamBlacklist.
In discussing {T307060} with @stran, @Dreamy_Jazz, @daimona and @Tchanders, one idea we discussed is that every loggable (on Special:Log) action should have a temporary account associated with it. In order to do that, we need to have the temporary account created earlier in the edit cycle, before hooks and constraint checks run.
## Proposal
Create the temporary account after core's constraints run, and before the three edit hooks (attemptSave, EditFilter, EditFilterMergedContent) run:
- Constructing a Content object
- `EditConstraintRunner()` has run:
- UnicodeConstraint
- SimpleAntiSpamConstraint
- SpamRegexConstraint
- ImageRedirectConstraint
- UserBlockConstraint
- ContentModelChangeConstraint
- ReadOnlyConstraint
- UserRateLimitConstraint
- PageSizeConstraint
- ChangeTagsConstraint
- AccidentalRecreationConstraint
- EditRightConstraint
- DefaultTextConstraint
- NewSectionMissingSubjectConstraint
- MissingCommentConstraint
- AutoSummaryMissingSummaryConstraint
- SelfRedirectConstraint
- edit conflict checks (?)
-** Create temp account**
- `onEditPage__attemptSave`
- `onEditFilter`
- EditFilterMergedContentHookConstraint
This task also proposes to perform a top-level navigation for failed edits, to ensure the temp account is not detached from loginwiki.
## Consequences
This means:
* We have a temporary account to associate with logs generated by e.g. AbuseFilter and SpamBlacklist
* We build an account history for someone repeatedly tripping AbuseFilters early on
* Increase in number of temporary accounts created per month (T334623#9587082)
* Easier to communicate with users who have tripped an edit constraint (since they'll have an account and access to Echo notifications)
* Users whose edit attempt is rejected would lose their content because of top-level navigation wiping out form contents. (VisualEditor users should be able to recover stashed content.)