r41810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41809‎ | r41810 | r41811 >
Date:14:57, 7 October 2008
Author:catrope
Status:old
Tags:edit api 
Comment:
* (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
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiDelete.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMove.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiMove.php
@@ -44,9 +44,7 @@
4545 if(is_null($params['reason']))
4646 $params['reason'] = '';
4747
48 - $titleObj = NULL;
49 - if(!isset($params['from']))
50 - $this->dieUsageMsg(array('missingparam', 'from'));
 48+ $this->requireOnlyOneParameter($params, 'from', 'fromid');
5149 if(!isset($params['to']))
5250 $this->dieUsageMsg(array('missingparam', 'to'));
5351 if(!isset($params['token']))
@@ -54,9 +52,18 @@
5553 if(!$wgUser->matchEditToken($params['token']))
5654 $this->dieUsageMsg(array('sessionfailure'));
5755
58 - $fromTitle = Title::newFromText($params['from']);
59 - if(!$fromTitle)
60 - $this->dieUsageMsg(array('invalidtitle', $params['from']));
 56+ if(isset($params['from']))
 57+ {
 58+ $fromTitle = Title::newFromText($params['from']);
 59+ if(!$fromTitle)
 60+ $this->dieUsageMsg(array('invalidtitle', $params['from']));
 61+ }
 62+ else if(isset($params['fromid']))
 63+ {
 64+ $fromTitle = Title::newFromID($params['fromid']);
 65+ if(!$fromTitle)
 66+ $this->dieUsageMsg(array('nosuchpageid', $params['fromid']));
 67+ }
6168 if(!$fromTitle->exists())
6269 $this->dieUsageMsg(array('notanarticle'));
6370 $fromTalk = $fromTitle->getTalkPage();
@@ -112,6 +119,9 @@
113120 public function getAllowedParams() {
114121 return array (
115122 'from' => null,
 123+ 'fromid' => array(
 124+ ApiBase::PARAM_TYPE => 'integer'
 125+ ),
116126 'to' => null,
117127 'token' => null,
118128 'reason' => null,
@@ -124,7 +134,8 @@
125135
126136 public function getParamDescription() {
127137 return array (
128 - 'from' => 'Title of the page you want to move.',
 138+ 'from' => 'Title of the page you want to move. Cannot be used together with fromid.',
 139+ 'fromid' => 'Page ID of the page you want to move. Cannot be used together with from.',
129140 'to' => 'Title you want to rename the page to.',
130141 'token' => 'A move token previously retrieved through prop=info',
131142 'reason' => 'Reason for the move (optional).',
Index: trunk/phase3/includes/api/ApiDelete.php
@@ -52,15 +52,22 @@
5353 $this->getMain()->requestWriteMode();
5454 $params = $this->extractRequestParams();
5555
56 - $titleObj = NULL;
57 - if(!isset($params['title']))
58 - $this->dieUsageMsg(array('missingparam', 'title'));
 56+ $this->requireOnlyOneParameter($params, 'title', 'pageid');
5957 if(!isset($params['token']))
6058 $this->dieUsageMsg(array('missingparam', 'token'));
6159
62 - $titleObj = Title::newFromText($params['title']);
63 - if(!$titleObj)
64 - $this->dieUsageMsg(array('invalidtitle', $params['title']));
 60+ if(isset($params['title']))
 61+ {
 62+ $titleObj = Title::newFromText($params['title']);
 63+ if(!$titleObj)
 64+ $this->dieUsageMsg(array('invalidtitle', $params['title']));
 65+ }
 66+ else if(isset($params['pageid']))
 67+ {
 68+ $titleObj = Title::newFromID($params['pageid']);
 69+ if(!$titleObj)
 70+ $this->dieUsageMsg(array('nosuchpageid', $params['pageid']));
 71+ }
6572 if(!$titleObj->exists())
6673 $this->dieUsageMsg(array('notanarticle'));
6774
@@ -112,8 +119,8 @@
113120 public static function delete(&$article, $token, &$reason = NULL)
114121 {
115122 global $wgUser;
116 -
117 - $errors = self::getPermissionsError($article->getTitle(), $token);
 123+ $title = $article->getTitle();
 124+ $errors = self::getPermissionsError($title, $token);
118125 if (count($errors)) return $errors;
119126
120127 // Auto-generate a summary, if necessary
@@ -168,6 +175,9 @@
169176 public function getAllowedParams() {
170177 return array (
171178 'title' => null,
 179+ 'pageid' => array(
 180+ ApiBase::PARAM_TYPE => 'integer'
 181+ ),
172182 'token' => null,
173183 'reason' => null,
174184 'watch' => false,
@@ -178,7 +188,8 @@
179189
180190 public function getParamDescription() {
181191 return array (
182 - 'title' => 'Title of the page you want to delete.',
 192+ 'title' => 'Title of the page you want to delete. Cannot be used together with pageid',
 193+ 'pageid' => 'Page ID of the page you want to delete. Cannot be used together with title',
183194 'token' => 'A delete token previously retrieved through prop=info',
184195 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used.',
185196 'watch' => 'Add the page to your watchlist',
Index: trunk/phase3/includes/api/ApiBase.php
@@ -688,6 +688,7 @@
689689 // API-specific messages
690690 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"),
691691 'invalidtitle' => array('code' => 'invalidtitle', 'info' => "Bad title ``\$1''"),
 692+ 'nosuchpageid' => array('code' => 'nosuchpageid', 'info' => "There is no page with ID \$1"),
692693 'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''"),
693694 'invalidexpiry' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time ``\$1''"),
694695 'pastexpiry' => array('code' => 'pastexpiry', 'info' => "Expiry time ``\$1'' is in the past"),
Index: trunk/phase3/RELEASE-NOTES
@@ -309,6 +309,8 @@
310310 action=protect
311311 * Added allowsduplicates attribute to action=paraminfo output
312312 * (bug 15767) apfilterlanglinks returns duplicate results
 313+* (bug 15845) Added pageid/fromid parameter to action=delete/move, making
 314+ manipulation of legacy pages with invalid titles possible
313315
314316 === Languages updated in 1.14 ===
315317

Follow-up revisions

RevisionCommit summaryAuthorDate
r86659Follow-up r41810: avoid multiple API calls.happy-melon19:36, 21 April 2011

Status & tagging log