From 00bc7a2b28886d291bd4e2a69b00fec964a94910 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Sat, 16 Apr 2022 21:20:47 +0200 Subject: [PATCH] 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 --- includes/api/ApiFeedRecentChanges.php | 2 +- includes/api/ApiQueryImageInfo.php | 2 +- includes/api/ApiQueryLinks.php | 2 +- includes/api/ApiQueryLogEvents.php | 4 ++-- includes/api/ApiQueryRecentChanges.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiFeedRecentChanges.php b/includes/api/ApiFeedRecentChanges.php index 3104e083b4a..8d2aa64db60 100644 --- a/includes/api/ApiFeedRecentChanges.php +++ b/includes/api/ApiFeedRecentChanges.php @@ -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'] ) ] ); } diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index 27f38e317f9..5238ab16476 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -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' ); } diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index c639fbd2d21..0ccc521b087 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -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 ); diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index c2087b35e47..b065d4a17a5 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -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() ); diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index b3a50482b04..0feea08d676 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -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() );