* (bug 15845) API: Added pageid/fromid parameter to action=delete/move, making manipu...
authorRoan Kattouw <catrope@users.mediawiki.org>
Tue, 7 Oct 2008 14:57:59 +0000 (14:57 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Tue, 7 Oct 2008 14:57:59 +0000 (14:57 +0000)
* Fix an E_STRICT while I'm at it

RELEASE-NOTES
includes/api/ApiBase.php
includes/api/ApiDelete.php
includes/api/ApiMove.php

index deded94..73c3c3b 100644 (file)
@@ -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 ===
 
index 8a4b34c..b26a6b3 100644 (file)
@@ -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"),
index 79540b9..98b2467 100644 (file)
@@ -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',
index e0c321d..cba5f91 100644 (file)
@@ -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).',