Steps to replicate the issue:
- Create a redirect to a special page, e.g. redirect [[SP:SP]] as a shortcut to [[Special:SpecialPages]]. This can only be done on some wikis that permit this, where $wgDisableHardRedirects=false (see below)
- Type the redirect into the search box and press enter.
What happens?:
The redirect works as intended, 👍 but doesn't display [[Mediawiki:Redirectfrom]] 😔
What should have happened instead?:
It should display [[Mediawiki:Redirectfrom]] below the page title, like other redirects.
Impact on $wgDisableHardRedirects
The setting $wgDisableHardRedirects disables two different things. It disables interwiki redirects, but it also disables redirects to special pages. This is legacy code from 2006. It violates the Single Responsibility Principle, and it's somewhat opaque as to what exactly a hard redirect is. Both contribute to Technical-Debt
Shortcut redirects to special pages do make some sense (👍). It's convenient to type in a shortcut into the search box and press enter. But third-party wikis really do not want users to be whisked off to a completely different website, that's not controlled by the 3rd party, without warning having clicked on a normal-looking blue link (🤦).
Setting up redirects to special pages so that they work properly means that this situation can be fixed by splitting $wgDisableHardRedirects per T395326: `$wgDisableHardRedirects` should be split into 2 config settings.
Notes
At present, mw-redirectfrom is only called from includes/page/Article.php. The code looks something like this:
public function showRedirectedFromHeader() { $context = $this->getContext(); $redirectSources = $context->getConfig()->get( MainConfigNames::RedirectSources ); $outputPage = $context->getOutput(); $request = $context->getRequest(); $rdfrom = $request->getVal( 'rdfrom' ); // Construct a URL for the current page view, but with the target title $query = $request->getQueryValues(); unset( $query['rdfrom'] ); unset( $query['title'] ); if ( $this->getTitle()->isRedirect() ) { // Prevent double redirects $query['redirect'] = 'no'; } $redirectTargetUrl = $this->getTitle()->getLinkURL( $query ); if ( $this->mRedirectedFrom ) { // This is an internally redirected page view. // We'll need a backlink to the source page for navigation. if ( $this->getHookRunner()->onArticleViewRedirect( $this ) ) { $redir = $this->linkRenderer->makeKnownLink( $this->mRedirectedFrom, null, [], [ 'redirect' => 'no' ] ); $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" . $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse() . "</span>" ); // Add the script to update the displayed URL and // set the fragment if one was specified in the redirect $outputPage->addJsConfigVars( [ 'wgInternalRedirectTargetUrl' => $redirectTargetUrl, ] ); $outputPage->addModules( 'mediawiki.action.view.redirect' ); // Add a <link rel="canonical"> tag $outputPage->setCanonicalUrl( $this->getTitle()->getCanonicalURL() ); // Tell the output object that the user arrived at this article through a redirect $outputPage->setRedirectedFrom( $this->mRedirectedFrom ); return true; } } elseif ( $rdfrom ) { // This is an externally redirected view, from some other wiki. // If it was reported from a trusted site, supply a backlink. if ( $redirectSources && preg_match( $redirectSources, $rdfrom ) ) { $redir = $this->linkRenderer->makeExternalLink( $rdfrom, $rdfrom, $this->getTitle() ); $outputPage->addSubtitle( "<span class=\"mw-redirectedfrom\">" . $context->msg( 'redirectedfrom' )->rawParams( $redir )->parse() . "</span>" ); // Add the script to update the displayed URL $outputPage->addJsConfigVars( [ 'wgInternalRedirectTargetUrl' => $redirectTargetUrl, ] ); $outputPage->addModules( 'mediawiki.action.view.redirect' ); return true; } } return false; }
- This function needs to be called from both includes/page/Article.php AND includes/specialpage/SpecialPage.php
- It might be a good idea to move this function into its own include, but then we need to decide (1) where it goes and (2) what to call it. Please discuss:
- Keep it in the same place
- Move it into its own include, located where and called what?
- Move it into MediaWiki\Rest\Handler\RedirectHandler (which is the code that does the actual redirecting)
Thanks.