api: Report external titles in more places as apierror-invalidtitle

It is only useful to use local titles for various api parameters

Change-Id: Ife2a951e6b48b59e2b77d455c8343f79f1163b0a
This commit is contained in:
Umherirrender 2022-04-16 21:20:47 +02:00
parent 3444abf547
commit 00bc7a2b28
5 changed files with 6 additions and 6 deletions

View file

@ -121,7 +121,7 @@ class ApiFeedRecentChanges extends ApiBase {
private function getFeedObject( $feedFormat, $specialPageName ) {
if ( $specialPageName === 'Recentchangeslinked' ) {
$title = Title::newFromText( $this->params['target'] );
if ( !$title ) {
if ( !$title || $title->isExternal() ) {
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $this->params['target'] ) ] );
}

View file

@ -97,7 +97,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
if ( isset( $params['badfilecontexttitle'] ) ) {
$badFileContextTitle = Title::newFromText( $params['badfilecontexttitle'] );
if ( !$badFileContextTitle ) {
if ( !$badFileContextTitle || $badFileContextTitle->isExternal() ) {
$p = $this->getModulePrefix();
$this->dieWithError( [ 'apierror-bad-badfilecontexttitle', $p ], 'invalid-title' );
}

View file

@ -109,7 +109,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
$lb = $this->linkBatchFactory->newLinkBatch();
foreach ( $params[$this->titlesParam] as $t ) {
$title = Title::newFromText( $t );
if ( !$title ) {
if ( !$title || $title->isExternal() ) {
$this->addWarning( [ 'apiwarn-invalidtitle', wfEscapeWikiText( $t ) ] );
} elseif ( !$filterNS || isset( $filterNS[$title->getNamespace()] ) ) {
$lb->addObj( $title );

View file

@ -207,7 +207,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
$title = $params['title'];
if ( $title !== null ) {
$titleObj = Title::newFromText( $title );
if ( $titleObj === null ) {
if ( $titleObj === null || $titleObj->isExternal() ) {
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
}
$this->addWhereFld( 'log_namespace', $titleObj->getNamespace() );
@ -226,7 +226,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
}
$title = Title::newFromText( $prefix );
if ( $title === null ) {
if ( $title === null || $title->isExternal() ) {
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $prefix ) ] );
}
$this->addWhereFld( 'log_namespace', $title->getNamespace() );

View file

@ -164,7 +164,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
$title = $params['title'];
if ( $title !== null ) {
$titleObj = Title::newFromText( $title );
if ( $titleObj === null ) {
if ( $titleObj === null || $titleObj->isExternal() ) {
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $title ) ] );
}
$this->addWhereFld( 'rc_namespace', $titleObj->getNamespace() );