From 77b72c24fc75fd8da5d304cf33172054031095fa Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 6 Apr 2012 00:54:18 +0400 Subject: [PATCH] (bug 32492) API now allows editing using pageid Change-Id: I9fdbda962777e11a51e4200d44f225c6d01292e9 --- CREDITS | 1 + RELEASE-NOTES-1.20 | 1 + includes/api/ApiEditPage.php | 92 +++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/CREDITS b/CREDITS index d0c4623d1a..f0e5c27715 100644 --- 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 diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 3f6a79f653..7ca0b96548 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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 === diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 9ed6d08da7..229afde816 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -1,4 +1,4 @@ -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', -- 2.20.1