(bug 32492) API now allows editing using pageid
authorMax Semenik <maxsem.wiki@gmail.com>
Thu, 5 Apr 2012 20:54:18 +0000 (00:54 +0400)
committerAlex Monk <krenair@gmail.com>
Fri, 6 Apr 2012 15:40:08 +0000 (16:40 +0100)
Change-Id: I9fdbda962777e11a51e4200d44f225c6d01292e9

CREDITS
RELEASE-NOTES-1.20
includes/api/ApiEditPage.php

diff --git a/CREDITS b/CREDITS
index d0c4623..f0e5c27 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -123,6 +123,7 @@ following names for their contribution to the product.
 * John N
 * Karun Dambietz
 * Kim Hyun-Joon
+* Krenair
 * Lee Worden
 * Lejonel
 * liangent
index 3f6a79f..7ca0b96 100644 (file)
@@ -78,6 +78,7 @@ production.
   the format parameter.
 * (bug 32384) Allow descending order for list=watchlistraw.
 * (bug 31883) Limit of bkusers of list=blocks and titles of action=query is not documented in API help.
+* (bug 32492) API now allows editing using pageid
 
 === Languages updated in 1.20 ===
 
index 9ed6d08..229afde 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?php
 /**
  *
  *
@@ -48,9 +48,18 @@ class ApiEditPage extends ApiBase {
                        $this->dieUsageMsg( 'missingtext' );
                }
 
-               $titleObj = Title::newFromText( $params['title'] );
-               if ( !$titleObj || $titleObj->isExternal() ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+               $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
+
+               if ( isset( $params['title'] ) ) {
+                       $titleObj = Title::newFromText( $params['title'] );
+                       if ( !$titleObj || $titleObj->isExternal() ) {
+                               $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+                       }
+               } elseif ( isset( $params['pageid'] ) ) {
+                       $titleObj = Title::newFromID( $params['pageid'] );
+                       if ( !$titleObj ) {
+                               $this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
+                       }
                }
 
                $apiResult = $this->getResult();
@@ -371,45 +380,51 @@ class ApiEditPage extends ApiBase {
        public function getPossibleErrors() {
                global $wgMaxArticleSize;
 
-               return array_merge( parent::getPossibleErrors(), array(
-                       array( 'missingtext' ),
-                       array( 'invalidtitle', 'title' ),
-                       array( 'createonly-exists' ),
-                       array( 'nocreate-missing' ),
-                       array( 'nosuchrevid', 'undo' ),
-                       array( 'nosuchrevid', 'undoafter' ),
-                       array( 'revwrongpage', 'id', 'text' ),
-                       array( 'undo-failure' ),
-                       array( 'hashcheckfailed' ),
-                       array( 'hookaborted' ),
-                       array( 'noimageredirect-anon' ),
-                       array( 'noimageredirect-logged' ),
-                       array( 'spamdetected', 'spam' ),
-                       array( 'summaryrequired' ),
-                       array( 'filtered' ),
-                       array( 'blockedtext' ),
-                       array( 'contenttoobig', $wgMaxArticleSize ),
-                       array( 'noedit-anon' ),
-                       array( 'noedit' ),
-                       array( 'actionthrottledtext' ),
-                       array( 'wasdeleted' ),
-                       array( 'nocreate-loggedin' ),
-                       array( 'blankpage' ),
-                       array( 'editconflict' ),
-                       array( 'emptynewsection' ),
-                       array( 'unknownerror', 'retval' ),
-                       array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
-                       array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
-                       array( 'customcssprotected' ),
-                       array( 'customjsprotected' ),
-               ) );
+               return array_merge( parent::getPossibleErrors(),
+                       $this->getRequireOnlyOneParameterErrorMessages( 'title', 'pageid' ),
+                       array(
+                               array( 'nosuchpageid', 'pageid' ),
+                               array( 'missingtext' ),
+                               array( 'invalidtitle', 'title' ),
+                               array( 'createonly-exists' ),
+                               array( 'nocreate-missing' ),
+                               array( 'nosuchrevid', 'undo' ),
+                               array( 'nosuchrevid', 'undoafter' ),
+                               array( 'revwrongpage', 'id', 'text' ),
+                               array( 'undo-failure' ),
+                               array( 'hashcheckfailed' ),
+                               array( 'hookaborted' ),
+                               array( 'noimageredirect-anon' ),
+                               array( 'noimageredirect-logged' ),
+                               array( 'spamdetected', 'spam' ),
+                               array( 'summaryrequired' ),
+                               array( 'filtered' ),
+                               array( 'blockedtext' ),
+                               array( 'contenttoobig', $wgMaxArticleSize ),
+                               array( 'noedit-anon' ),
+                               array( 'noedit' ),
+                               array( 'actionthrottledtext' ),
+                               array( 'wasdeleted' ),
+                               array( 'nocreate-loggedin' ),
+                               array( 'blankpage' ),
+                               array( 'editconflict' ),
+                               array( 'emptynewsection' ),
+                               array( 'unknownerror', 'retval' ),
+                               array( 'code' => 'nosuchsection', 'info' => 'There is no section section.' ),
+                               array( 'code' => 'invalidsection', 'info' => 'The section parameter must be set to an integer or \'new\'' ),
+                               array( 'customcssprotected' ),
+                               array( 'customjsprotected' ),
+                       )
+               );
        }
 
        public function getAllowedParams() {
                return array(
                        'title' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true
+                       ),
+                       'pageid' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
                        ),
                        'section' => null,
                        'sectiontitle' => array(
@@ -463,7 +478,8 @@ class ApiEditPage extends ApiBase {
        public function getParamDescription() {
                $p = $this->getModulePrefix();
                return array(
-                       'title' => 'Page title',
+                       'title' => "Title of the page you want to edit. Cannot be used together with {$p}pageid",
+                       'pageid' => "Page ID of the page you want to edit. Cannot be used together with {$p}title,
                        'section' => 'Section number. 0 for the top section, \'new\' for a new section',
                        'sectiontitle' => 'The title for a new section',
                        'text' => 'Page content',