aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api
diff options
context:
space:
mode:
authorKosta Harlan <kharlan@wikimedia.org>2024-04-19 09:13:09 +0200
committerKosta Harlan <kharlan@wikimedia.org>2024-04-29 10:55:23 +0200
commit48c8cee1831429ac4c980f3a607e1d2daec35945 (patch)
treeb66fd2b844c069d72ec6f1be06f4a8cab014c1fe /includes/api
parent30287f6be67d8912fe9c4f6cc57798c586b6ef1e (diff)
downloadmediawikicore-48c8cee1831429ac4c980f3a607e1d2daec35945.tar.gz
mediawikicore-48c8cee1831429ac4c980f3a607e1d2daec35945.zip
Temporary accounts: Perform redirect for first successful edit
Why: - We want to make sure that the top-level redirect fires for temporary accounts which were created in an edit attempt, but did not yet save an edit What: - In EditPage and ApiEditPage, perform the redirect if there is a saved temp user as part of the current process, or if the user account is a temporary one and it has no edits. Note that this means the top-level redirect would be performed if a temp user creates a first edit on a non-home wiki: - logged out user makes a failed attempt on wiki A, temp account is created - same user makes a successful edit on wiki A, redirect hook fires - same user visits wiki B and makes a succesful edit, redirect hook fires Note: - We could consider setting a query parameter like `createdinrequest=1` to signal to TempUserCreatedRedirect implementations that the temporary account was created in the current request, and did not exist earlier. But I am not sure if we have a use case for needing that, so have left it out of this patch. Bug: T359405 Change-Id: If4b8c561383f993606c0ba565591871195a1f8c2
Diffstat (limited to 'includes/api')
-rw-r--r--includes/api/ApiEditPage.php14
1 files changed, 12 insertions, 2 deletions
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index 14203f935726..52ded5688b8d 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -607,12 +607,22 @@ class ApiEditPage extends ApiBase {
}
$this->persistGlobalSession();
- if ( isset( $result['savedTempUser'] ) ) {
+ // If the temporary account was created in this request,
+ // or if the temporary account has zero edits (implying
+ // that the account was created during a failed edit
+ // attempt in a previous request), perform the top-level
+ // redirect to ensure the account is attached.
+ // Note that the temp user could already have performed
+ // the top-level redirect if this a first edit on
+ // a wiki that is not the user's home wiki.
+ $shouldRedirectForTempUser = isset( $result['savedTempUser'] ) ||
+ $user->isTemp() && $user->getEditCount() === 0;
+ if ( $shouldRedirectForTempUser ) {
$r['tempusercreated'] = true;
$params['returnto'] ??= $titleObj->getPrefixedDBkey();
$redirectUrl = $this->getTempUserRedirectUrl(
$params,
- $result['savedTempUser']
+ $result['savedTempUser'] ?? $user
);
if ( $redirectUrl ) {
$r['tempusercreatedredirect'] = $redirectUrl;