RedirectSpecialArticle: Avoid double redirect for action=edit&redlink=1
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 8 Aug 2019 19:45:04 +0000 (21:45 +0200)
committerMobrovac <mobrovac@wikimedia.org>
Mon, 12 Aug 2019 13:58:22 +0000 (13:58 +0000)
If you visit `Special:MyPage?action=edit&redlink=1` and your user page
exists, this would redirect to `User:Yourname?action=edit&redlink=1`,
which then would redirect further to `User:Yourname`. Just redirect
there directly.

Additionally, the double-redirect seems to somehow conflict with the
fake-redirect code for $wgHideIdentifiableRedirects. I couldn't figure
out why this happens, but you end up on a blank page and no redirect
of either kind occurs.

Bug: T229794
Change-Id: I952fc9df91b1243db22f956ec09bee457c8a21bf

includes/specialpage/RedirectSpecialArticle.php

index b8dce3f..27cd2ab 100644 (file)
@@ -106,4 +106,25 @@ abstract class RedirectSpecialArticle extends RedirectSpecialPage {
                Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
                $this->mAllowedRedirectParams = $redirectParams;
        }
+
+       /**
+        * @inheritDoc
+        */
+       public function getRedirectQuery( $subpage ) {
+               $query = parent::getRedirectQuery( $subpage );
+               $title = $this->getRedirect( $subpage );
+               // Avoid double redirect for action=edit&redlink=1 for existing pages
+               // (compare to the check in EditPage::edit)
+               if (
+                       $query &&
+                       ( $query['action'] === 'edit' || $query['action'] === 'submit' ) &&
+                       (bool)$query['redlink'] &&
+                       $title instanceof Title &&
+                       $title->exists()
+               ) {
+                       return false;
+               }
+               return $query;
+       }
+
 }