Handle bad redirect target for personally identifiable special pages
Special:MyPage and Special:MyTalk with an invalid redirect (title too
long) throws exception "This is not an article: {title}" instead of the
BadTitle error shown with HideIdentifiableRedirects = false
Special:MyPage and Special:MyTalk using Title::makeTitle which always
returns an Title object. Using makeTitleSafe etc. does not gives the
reason what is wrong.
Bug: T297407
Change-Id: If97064595d63a973f5db657a819c611f890c91f9
This commit is contained in:
parent
05d701a2a4
commit
c2754d44bc
2 changed files with 35 additions and 0 deletions
|
|
@ -305,6 +305,17 @@ class MediaWiki {
|
|||
'wgInternalRedirectTargetUrl' => $target->getLinkURL( $query ),
|
||||
] );
|
||||
$output->addModules( 'mediawiki.action.view.redirect' );
|
||||
|
||||
// If the title is invalid, redirect but show the correct bad title error - T297407
|
||||
if ( !$target->isValid() ) {
|
||||
try {
|
||||
MediaWikiServices::getInstance()->getTitleParser()
|
||||
->parseTitle( $target->getPrefixedText() );
|
||||
} catch ( MalformedTitleException $ex ) {
|
||||
throw new BadTitleError( $ex );
|
||||
}
|
||||
throw new BadTitleError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
class MediaWikiTest extends MediaWikiIntegrationTestCase {
|
||||
private $oldServer, $oldGet, $oldPost;
|
||||
|
|
@ -237,4 +238,27 @@ class MediaWikiTest extends MediaWikiIntegrationTestCase {
|
|||
$logger->getBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MediaWiki::performRequest
|
||||
*/
|
||||
public function testInvalidRedirectingOnSpecialPageWithPersonallyIdentifiableTarget() {
|
||||
$this->overrideConfigValue( MainConfigNames::HideIdentifiableRedirects, true );
|
||||
|
||||
$specialTitle = SpecialPage::getTitleFor( 'Mypage', 'in<valid' );
|
||||
$req = new FauxRequest( [
|
||||
'title' => $specialTitle->getPrefixedDbKey(),
|
||||
] );
|
||||
$req->setRequestURL( $specialTitle->getFullUrl() );
|
||||
|
||||
$context = RequestContext::getMain();
|
||||
$context->setRequest( $req );
|
||||
$context->setTitle( $specialTitle );
|
||||
|
||||
$mw = TestingAccessWrapper::newFromObject( new MediaWiki( $context ) );
|
||||
|
||||
$this->expectException( BadTitleError::class );
|
||||
$this->expectExceptionMessage( 'The requested page title contains invalid characters: "<".' );
|
||||
$mw->performRequest();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue