(bug 15647) API edit with basetimestamp fails if the page has been deleted and undele...
[lhc/web/wiklou.git] / includes / api / ApiEditPage.php
index aaa2559..9220f6d 100644 (file)
@@ -29,8 +29,10 @@ if (!defined('MEDIAWIKI')) {
 }
 
 /**
- * A query module to list all external URLs found on a given set of pages.
+ * A module that allows for editing and creating pages.
  *
+ * Currently, this wraps around the EditPage class in an ugly way,
+ * EditPage.php should be rewritten to provide a cleaner interface
  * @ingroup API
  */
 class ApiEditPage extends ApiBase {
@@ -98,8 +100,11 @@ class ApiEditPage extends ApiBase {
                        $reqArr['wpEdittime'] = wfTimestamp(TS_MW, $params['basetimestamp']);
                else
                        $reqArr['wpEdittime'] = $articleObj->getTimestamp();
-               # Fake wpStartime
-               $reqArr['wpStarttime'] = $reqArr['wpEdittime'];
+               if(!is_null($params['starttimestamp']) && $params['starttimestamp'] != '')
+                       $reqArr['wpStarttime'] = wfTimestamp(TS_MW, $params['starttimestamp']);
+               else
+                       # Fake wpStartime
+                       $reqArr['wpStarttime'] = $reqArr['wpEdittime'];
                if($params['minor'] || (!$params['notminor'] && $wgUser->getOption('minordefault')))
                        $reqArr['wpMinoredit'] = '';
                if($params['recreate'])
@@ -134,9 +139,9 @@ class ApiEditPage extends ApiBase {
                # Handle CAPTCHA parameters
                global $wgRequest;
                if(isset($params['captchaid']))
-                       $wgRequest->data['wpCaptchaId'] = $params['captchaid'];
+                       $wgRequest->setVal( 'wpCaptchaId', $params['captchaid'] );
                if(isset($params['captchaword']))
-                       $wgRequest->data['wpCaptchaWord'] = $params['captchaword'];
+                       $wgRequest->setVal( 'wpCaptchaWord', $params['captchaword'] );
                $r = array();
                if(!wfRunHooks('APIEditBeforeSave', array(&$ep, $ep->textbox1, &$r)))
                {
@@ -205,7 +210,7 @@ class ApiEditPage extends ApiBase {
                        case EditPage::AS_END:
                                # This usually means some kind of race condition
                                # or DB weirdness occurred. Throw an unknown error here.
-                               $this->dieUsageMsg(array('unknownerror', 'AS_END'));
+                               $this->dieUsageMsg(array('unknownerror'));
                        case EditPage::AS_SUCCESS_NEW_ARTICLE:
                                $r['new'] = '';
                        case EditPage::AS_SUCCESS_UPDATE:
@@ -251,6 +256,7 @@ class ApiEditPage extends ApiBase {
                        'notminor' => false,
                        'bot' => false,
                        'basetimestamp' => null,
+                       'starttimestamp' => null,
                        'recreate' => false,
                        'createonly' => false,
                        'nocreate' => false,
@@ -277,6 +283,9 @@ class ApiEditPage extends ApiBase {
                        'basetimestamp' => array('Timestamp of the base revision (gotten through prop=revisions&rvprop=timestamp).',
                                                'Used to detect edit conflicts; leave unset to ignore conflicts.'
                        ),
+                       'starttimestamp' => array('Timestamp when you obtained the edit token.',
+                                               'Used to detect edit conflicts; leave unset to ignore conflicts.'
+                       ),
                        'recreate' => 'Override any errors about the article having been deleted in the meantime',
                        'createonly' => 'Don\'t edit the page if it exists already',
                        'nocreate' => 'Throw an error if the page doesn\'t exist',