From 3622787eba642211c41bd758fa9a03118f22262f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Tue, 23 Jul 2019 12:02:11 -0400 Subject: [PATCH] Better handle "no accounts to unlink" case in Special:UnlinkAccounts When there are no accounts to unlink, say so rather than displaying a button that results in an error when clicked. Bug: T228717 Change-Id: I17f8aed213f114338c4b46e26ce369bc63e36a99 --- includes/specials/SpecialUnlinkAccounts.php | 15 +++++++++++++++ languages/i18n/en.json | 2 ++ languages/i18n/qqq.json | 2 ++ 3 files changed, 19 insertions(+) diff --git a/includes/specials/SpecialUnlinkAccounts.php b/includes/specials/SpecialUnlinkAccounts.php index 9564d53910..72afb03c9b 100644 --- a/includes/specials/SpecialUnlinkAccounts.php +++ b/includes/specials/SpecialUnlinkAccounts.php @@ -38,6 +38,21 @@ class SpecialUnlinkAccounts extends AuthManagerSpecialPage { public function execute( $subPage ) { $this->setHeaders(); $this->loadAuth( $subPage ); + + if ( !$this->isActionAllowed( $this->authAction ) ) { + if ( $this->authAction === AuthManager::ACTION_UNLINK ) { + // Looks like there are no linked accounts to unlink + $titleMessage = $this->msg( 'cannotunlink-no-provider-title' ); + $errorMessage = $this->msg( 'cannotunlink-no-provider' ); + throw new ErrorPageError( $titleMessage, $errorMessage ); + } else { + // user probably back-button-navigated into an auth session that no longer exists + // FIXME would be nice to show a message + $this->getOutput()->redirect( $this->getPageTitle()->getFullURL( '', false, PROTO_HTTPS ) ); + return; + } + } + $this->outputHeader(); $status = $this->trySubmit(); diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 01e1007da4..be064917f9 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -4193,6 +4193,8 @@ "linkaccounts": "Link accounts", "linkaccounts-success-text": "The account was linked.", "linkaccounts-submit": "Link accounts", + "cannotunlink-no-provider-title": "There are no linked accounts to unlink", + "cannotunlink-no-provider": "There are no linked accounts that can be unlinked.", "unlinkaccounts": "Unlink accounts", "unlinkaccounts-success": "The account was unlinked.", "authenticationdatachange-ignored": "The authentication data change was not handled. Maybe no provider was configured?", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 081bb66f43..fb6585b365 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -4402,6 +4402,8 @@ "linkaccounts": "Title of the special page [[Special:LinkAccounts]] which allows the user to connect the local user accounts with external ones such as Google or Facebook.", "linkaccounts-success-text": "Text shown on top of the form after a successful action.", "linkaccounts-submit": "Text of the main submit button on [[Special:LinkAccounts]] (when there is one)", + "cannotunlink-no-provider-title": "Error page title shown when the user visits [[Special:UnlinkAccounts]] but there is no external account that could be unlinked.", + "cannotunlink-no-provider": "Error message shown when the user visits [[Special:UnlinkAccounts]] but there is no external account that could be unlinked.", "unlinkaccounts": "Title of the special page [[Special:UnlinkAccounts]] which allows the user to remove linked remote accounts.", "unlinkaccounts-success": "Account unlinking form success message", "authenticationdatachange-ignored": "Shown when authentication data change was unsuccessful due to configuration problems.\n\nCf. e.g. {{msg-mw|Passwordreset-ignored}}.", -- 2.20.1