From 8b86f3bc01e30039359dfd813431afdfb1582944 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 12 Jun 2008 13:05:07 +0000 Subject: [PATCH] (bug 14459) Added prependtext and appendtext parameters to action=edit --- RELEASE-NOTES | 1 + includes/api/ApiBase.php | 1 + includes/api/ApiEditPage.php | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c5e948cebe..910dc9da56 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -440,6 +440,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 14335) Logging in to unified account using API not possible * Added action=emailuser to send an email to a user * (bug 14471) Use HTMLTidy and generate limit report in action=parse +* (bug 14459) Added prependtext and appendtext parameters to action=edit === Languages updated in 1.13 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index e6af87e4db..f64f56e55c 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -663,6 +663,7 @@ abstract class ApiBase { 'blankpage' => array('code' => 'emptypage', 'info' => "Creating new, empty pages is not allowed"), 'editconflict' => array('code' => 'editconflict', 'info' => "Edit conflict detected"), 'hashcheckfailed' => array('code' => 'badmd5', 'info' => "The supplied MD5 hash was incorrect"), + 'missingtext' => array('code' => 'notext', 'info' => "One of the text, appendtext and prependtext parameters must be set"), ); /** diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 74074039f6..ac225d616a 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -46,8 +46,8 @@ class ApiEditPage extends ApiBase { $params = $this->extractRequestParams(); if(is_null($params['title'])) $this->dieUsageMsg(array('missingparam', 'title')); - if(is_null($params['text'])) - $this->dieUsageMsg(array('missingparam', 'text')); + if(is_null($params['text']) && is_null($params['appendtext']) && is_null($params['prependtext'])) + $this->dieUsageMsg(array('missingtext')); if(is_null($params['token'])) $this->dieUsageMsg(array('missingparam', 'token')); if(!$wgUser->matchEditToken($params['token'])) @@ -67,14 +67,19 @@ class ApiEditPage extends ApiBase { if(!empty($errors)) $this->dieUsageMsg($errors[0]); + $articleObj = new Article($titleObj); + if(!is_null($params['appendtext']) || !is_null($params['prependtext'])) + { + $content = $articleObj->getContent(); + $params['text'] = $params['prependtext'] . $content . $params['appendtext']; + } + # See if the MD5 hash checks out if(isset($params['md5'])) if(md5($params['text']) !== $params['md5']) $this->dieUsageMsg(array('hashcheckfailed')); - $articleObj = new Article($titleObj); $ep = new EditPage($articleObj); - // EditPage wants to parse its stuff from a WebRequest // That interface kind of sucks, but it's workable $reqArr = array('wpTextbox1' => $params['text'], @@ -243,6 +248,8 @@ class ApiEditPage extends ApiBase { 'watch' => false, 'unwatch' => false, 'md5' => null, + 'prependtext' => null, + 'appendtext' => null, ); } @@ -266,6 +273,9 @@ class ApiEditPage extends ApiBase { 'captchaid' => 'CAPTCHA ID from previous request', 'captchaword' => 'Answer to the CAPTCHA', 'md5' => 'The MD5 hash of the new article text. If set, the edit won\'t be done unless the hash is correct', + 'prependtext' => array( 'Add this text to the beginning of the page. Overrides text.', + 'Don\'t use together with section: that won\'t do what you expect.'), + 'appendtext' => 'Add this text to the end of the page. Overrides text', ); } -- 2.20.1