From 3ff1f89e0c35274e08bac232ffd74870cdbb9a57 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 7 Oct 2008 14:57:59 +0000 Subject: [PATCH] * (bug 15845) API: Added pageid/fromid parameter to action=delete/move, making manipulation of legacy pages with invalid titles possible * Fix an E_STRICT while I'm at it --- RELEASE-NOTES | 2 ++ includes/api/ApiBase.php | 1 + includes/api/ApiDelete.php | 29 ++++++++++++++++++++--------- includes/api/ApiMove.php | 25 ++++++++++++++++++------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index deded94eb8..73c3c3b11b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -309,6 +309,8 @@ The following extensions are migrated into MediaWiki 1.14: action=protect * Added allowsduplicates attribute to action=paraminfo output * (bug 15767) apfilterlanglinks returns duplicate results +* (bug 15845) Added pageid/fromid parameter to action=delete/move, making + manipulation of legacy pages with invalid titles possible === Languages updated in 1.14 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 8a4b34cae2..b26a6b3d47 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -688,6 +688,7 @@ abstract class ApiBase { // API-specific messages 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"), 'invalidtitle' => array('code' => 'invalidtitle', 'info' => "Bad title ``\$1''"), + 'nosuchpageid' => array('code' => 'nosuchpageid', 'info' => "There is no page with ID \$1"), 'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''"), 'invalidexpiry' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time ``\$1''"), 'pastexpiry' => array('code' => 'pastexpiry', 'info' => "Expiry time ``\$1'' is in the past"), diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 79540b9d46..98b2467fa4 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -52,15 +52,22 @@ class ApiDelete extends ApiBase { $this->getMain()->requestWriteMode(); $params = $this->extractRequestParams(); - $titleObj = NULL; - if(!isset($params['title'])) - $this->dieUsageMsg(array('missingparam', 'title')); + $this->requireOnlyOneParameter($params, 'title', 'pageid'); if(!isset($params['token'])) $this->dieUsageMsg(array('missingparam', 'token')); - $titleObj = Title::newFromText($params['title']); - if(!$titleObj) - $this->dieUsageMsg(array('invalidtitle', $params['title'])); + if(isset($params['title'])) + { + $titleObj = Title::newFromText($params['title']); + if(!$titleObj) + $this->dieUsageMsg(array('invalidtitle', $params['title'])); + } + else if(isset($params['pageid'])) + { + $titleObj = Title::newFromID($params['pageid']); + if(!$titleObj) + $this->dieUsageMsg(array('nosuchpageid', $params['pageid'])); + } if(!$titleObj->exists()) $this->dieUsageMsg(array('notanarticle')); @@ -112,8 +119,8 @@ class ApiDelete extends ApiBase { public static function delete(&$article, $token, &$reason = NULL) { global $wgUser; - - $errors = self::getPermissionsError($article->getTitle(), $token); + $title = $article->getTitle(); + $errors = self::getPermissionsError($title, $token); if (count($errors)) return $errors; // Auto-generate a summary, if necessary @@ -168,6 +175,9 @@ class ApiDelete extends ApiBase { public function getAllowedParams() { return array ( 'title' => null, + 'pageid' => array( + ApiBase::PARAM_TYPE => 'integer' + ), 'token' => null, 'reason' => null, 'watch' => false, @@ -178,7 +188,8 @@ class ApiDelete extends ApiBase { public function getParamDescription() { return array ( - 'title' => 'Title of the page you want to delete.', + 'title' => 'Title of the page you want to delete. Cannot be used together with pageid', + 'pageid' => 'Page ID of the page you want to delete. Cannot be used together with title', 'token' => 'A delete token previously retrieved through prop=info', 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.', 'watch' => 'Add the page to your watchlist', diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index e0c321d20e..cba5f91617 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -44,9 +44,7 @@ class ApiMove extends ApiBase { if(is_null($params['reason'])) $params['reason'] = ''; - $titleObj = NULL; - if(!isset($params['from'])) - $this->dieUsageMsg(array('missingparam', 'from')); + $this->requireOnlyOneParameter($params, 'from', 'fromid'); if(!isset($params['to'])) $this->dieUsageMsg(array('missingparam', 'to')); if(!isset($params['token'])) @@ -54,9 +52,18 @@ class ApiMove extends ApiBase { if(!$wgUser->matchEditToken($params['token'])) $this->dieUsageMsg(array('sessionfailure')); - $fromTitle = Title::newFromText($params['from']); - if(!$fromTitle) - $this->dieUsageMsg(array('invalidtitle', $params['from'])); + if(isset($params['from'])) + { + $fromTitle = Title::newFromText($params['from']); + if(!$fromTitle) + $this->dieUsageMsg(array('invalidtitle', $params['from'])); + } + else if(isset($params['fromid'])) + { + $fromTitle = Title::newFromID($params['fromid']); + if(!$fromTitle) + $this->dieUsageMsg(array('nosuchpageid', $params['fromid'])); + } if(!$fromTitle->exists()) $this->dieUsageMsg(array('notanarticle')); $fromTalk = $fromTitle->getTalkPage(); @@ -112,6 +119,9 @@ class ApiMove extends ApiBase { public function getAllowedParams() { return array ( 'from' => null, + 'fromid' => array( + ApiBase::PARAM_TYPE => 'integer' + ), 'to' => null, 'token' => null, 'reason' => null, @@ -124,7 +134,8 @@ class ApiMove extends ApiBase { public function getParamDescription() { return array ( - 'from' => 'Title of the page you want to move.', + 'from' => 'Title of the page you want to move. Cannot be used together with fromid.', + 'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.', 'to' => 'Title you want to rename the page to.', 'token' => 'A move token previously retrieved through prop=info', 'reason' => 'Reason for the move (optional).', -- 2.20.1