Umherirrender has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/51386


Change subject: API: Throw error when interwiki is given for various title param
......................................................................

API: Throw error when interwiki is given for various title param

See bug 44341 for action=parse, but the problem with interwiki
processing can also be happen in other modules.

This gives clearer error message on some modules
For example:
Bad title "*title*"
instead of:
Unknown error: "immobile-target-namespace-iw"

Change-Id: I86524533dfd778a169b39968999918a1f531efeb
---
M includes/api/ApiBase.php
M includes/api/ApiComparePages.php
M includes/api/ApiEditPage.php
M includes/api/ApiExpandTemplates.php
M includes/api/ApiFileRevert.php
M includes/api/ApiMove.php
M includes/api/ApiParse.php
M includes/api/ApiQueryAllMessages.php
M includes/api/ApiRollback.php
M includes/api/ApiUndelete.php
M includes/api/ApiWatch.php
11 files changed, 12 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/86/51386/1

diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php
index aff7a2e..d90ea26 100644
--- a/includes/api/ApiBase.php
+++ b/includes/api/ApiBase.php
@@ -756,7 +756,7 @@
                $pageObj = null;
                if ( isset( $params['title'] ) ) {
                        $titleObj = Title::newFromText( $params['title'] );
-                       if ( !$titleObj ) {
+                       if ( !$titleObj || $titleObj->isExternal() ) {
                                $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
                        }
                        if ( !$titleObj->canExist() ) {
diff --git a/includes/api/ApiComparePages.php b/includes/api/ApiComparePages.php
index 6b894c1..79ffcb0 100644
--- a/includes/api/ApiComparePages.php
+++ b/includes/api/ApiComparePages.php
@@ -85,7 +85,7 @@
                        return $revision;
                } elseif( $titleText ) {
                        $title = Title::newFromText( $titleText );
-                       if( !$title ) {
+                       if( !$title || $title->isExternal() ) {
                                $this->dieUsageMsg( array( 'invalidtitle', 
$titleText ) );
                        }
                        return $title->getLatestRevID();
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php
index b642c6d..1b9df68 100644
--- a/includes/api/ApiEditPage.php
+++ b/includes/api/ApiEditPage.php
@@ -46,10 +46,6 @@
 
                $pageObj = $this->getTitleOrPageId( $params );
                $titleObj = $pageObj->getTitle();
-               if ( $titleObj->isExternal() ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
-               }
-
                $apiResult = $this->getResult();
 
                if ( $params['redirect'] ) {
diff --git a/includes/api/ApiExpandTemplates.php 
b/includes/api/ApiExpandTemplates.php
index 826171b..f5898fb 100644
--- a/includes/api/ApiExpandTemplates.php
+++ b/includes/api/ApiExpandTemplates.php
@@ -42,7 +42,7 @@
 
                // Create title for parser
                $title_obj = Title::newFromText( $params['title'] );
-               if ( !$title_obj ) {
+               if ( !$title_obj || $title_obj->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
                }
 
diff --git a/includes/api/ApiFileRevert.php b/includes/api/ApiFileRevert.php
index 9520dc7..b14a45a 100644
--- a/includes/api/ApiFileRevert.php
+++ b/includes/api/ApiFileRevert.php
@@ -85,7 +85,7 @@
        protected function validateParameters() {
                // Validate the input title
                $title = Title::makeTitleSafe( NS_FILE, 
$this->params['filename'] );
-               if ( is_null( $title ) ) {
+               if ( is_null( $title ) || $title->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$this->params['filename'] ) );
                }
                $localRepo = RepoGroup::singleton()->getLocalRepo();
diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php
index 3f54fee..6788c4f 100644
--- a/includes/api/ApiMove.php
+++ b/includes/api/ApiMove.php
@@ -38,12 +38,12 @@
 
                if ( isset( $params['from'] ) ) {
                        $fromTitle = Title::newFromText( $params['from'] );
-                       if ( !$fromTitle ) {
+                       if ( !$fromTitle || $fromTitle->isExternal() ) {
                                $this->dieUsageMsg( array( 'invalidtitle', 
$params['from'] ) );
                        }
                } elseif ( isset( $params['fromid'] ) ) {
                        $fromTitle = Title::newFromID( $params['fromid'] );
-                       if ( !$fromTitle ) {
+                       if ( !$fromTitle || $fromTitle->isExternal() ) {
                                $this->dieUsageMsg( array( 'nosuchpageid', 
$params['fromid'] ) );
                        }
                }
@@ -54,7 +54,7 @@
                $fromTalk = $fromTitle->getTalkPage();
 
                $toTitle = Title::newFromText( $params['to'] );
-               if ( !$toTitle ) {
+               if ( !$toTitle || $toTitle->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$params['to'] ) );
                }
                $toTalk = $toTitle->getTalkPage();
diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index b81e5c7..ec8bfee 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -161,7 +161,7 @@
                        }
                } else { // Not $oldid, $pageid, $page. Hence based on $text
                        $titleObj = Title::newFromText( $title );
-                       if ( !$titleObj ) {
+                       if ( !$titleObj || $titleObj->isExternal() ) {
                                $this->dieUsageMsg( array( 'invalidtitle', 
$title ) );
                        }
                        if ( !$titleObj->canExist() ) {
diff --git a/includes/api/ApiQueryAllMessages.php 
b/includes/api/ApiQueryAllMessages.php
index 6b6b1a3..b0ecca8 100644
--- a/includes/api/ApiQueryAllMessages.php
+++ b/includes/api/ApiQueryAllMessages.php
@@ -48,7 +48,7 @@
                if ( $params['enableparser'] ) {
                        if ( !is_null( $params['title'] ) ) {
                                $title = Title::newFromText( $params['title'] );
-                               if ( !$title ) {
+                               if ( !$title || $title->isExternal() ) {
                                        $this->dieUsageMsg( array( 
'invalidtitle', $params['title'] ) );
                                }
                        } else {
diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php
index 6e55a5e..b9873f4 100644
--- a/includes/api/ApiRollback.php
+++ b/includes/api/ApiRollback.php
@@ -181,7 +181,7 @@
 
                $this->mTitleObj = Title::newFromText( $params['title'] );
 
-               if ( !$this->mTitleObj ) {
+               if ( !$this->mTitleObj || $this->mTitleObj->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
                }
                if ( !$this->mTitleObj->exists() ) {
diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php
index f53f065..4bbe568 100644
--- a/includes/api/ApiUndelete.php
+++ b/includes/api/ApiUndelete.php
@@ -41,7 +41,7 @@
                }
 
                $titleObj = Title::newFromText( $params['title'] );
-               if ( !$titleObj ) {
+               if ( !$titleObj || $titleObj->isExternal() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
                }
 
diff --git a/includes/api/ApiWatch.php b/includes/api/ApiWatch.php
index 2454e33..7106b06 100644
--- a/includes/api/ApiWatch.php
+++ b/includes/api/ApiWatch.php
@@ -40,7 +40,7 @@
                $params = $this->extractRequestParams();
                $title = Title::newFromText( $params['title'] );
 
-               if ( !$title || $title->getNamespace() < 0 ) {
+               if ( !$title || $title->isExternal() || !$title->canExist() ) {
                        $this->dieUsageMsg( array( 'invalidtitle', 
$params['title'] ) );
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/51386
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I86524533dfd778a169b39968999918a1f531efeb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to