Better handle "no accounts to unlink" case in Special:UnlinkAccounts
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 23 Jul 2019 16:02:11 +0000 (12:02 -0400)
committerTim Starling <tstarling@wikimedia.org>
Mon, 29 Jul 2019 03:48:54 +0000 (03:48 +0000)
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
languages/i18n/en.json
languages/i18n/qqq.json

index 9564d53..72afb03 100644 (file)
@@ -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();
index 01e1007..be06491 100644 (file)
        "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?",
index 081bb66..fb6585b 100644 (file)
        "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}}.",