$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
+ $apiResult = $this->getResult();
+
if ( $params['redirect'] ) {
if ( $titleObj->isRedirect() ) {
$oldTitle = $titleObj;
$titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
// array_shift( $titles );
- $this->getResult()->addValue( null, 'foo', $titles );
-
$redirValues = array();
foreach ( $titles as $id => $newTitle ) {
$titleObj = $newTitle;
}
- $this->getResult()->setIndexedTagName( $redirValues, 'r' );
- $this->getResult()->addValue( null, 'redirects', $redirValues );
-
+ $apiResult->setIndexedTagName( $redirValues, 'r' );
+ $apiResult->addValue( null, 'redirects', $redirValues );
}
}
if ( !wfRunHooks( 'APIEditBeforeSave', array( $ep, $ep->textbox1, &$r ) ) ) {
if ( count( $r ) ) {
$r['result'] = 'Failure';
- $this->getResult()->addValue( null, $this->getModuleName(), $r );
+ $apiResult->addValue( null, $this->getModuleName(), $r );
return;
} else {
$this->dieUsageMsg( 'hookaborted' );
$oldRequest = $wgRequest;
$wgRequest = $req;
- $retval = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
+ $status = $ep->internalAttemptSave( $result, $wgUser->isAllowed( 'bot' ) && $params['bot'] );
$wgRequest = $oldRequest;
global $wgMaxArticleSize;
- switch( $retval ) {
+ switch( $status->value ) {
case EditPage::AS_HOOK_ERROR:
case EditPage::AS_HOOK_ERROR_EXPECTED:
$this->dieUsageMsg( 'hookaborted' );
$this->dieUsageMsg( 'summaryrequired' );
case EditPage::AS_END:
- // This usually means some kind of race condition
- // or DB weirdness occurred. Fall through to throw an unknown
- // error.
-
- // This needs fixing higher up, as EditPage::internalAttemptSave
- // should return the Status object, so that specific error
- // conditions can be returned
+ // $status came from WikiPage::doEdit()
+ $errors = $status->getErrorsArray();
+ $this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
+ break;
default:
- $this->dieUsageMsg( array( 'unknownerror', $retval ) );
+ $this->dieUsageMsg( array( 'unknownerror', $status->value ) );
}
- $this->getResult()->addValue( null, $this->getModuleName(), $r );
+ $apiResult->addValue( null, $this->getModuleName(), $r );
}
public function mustBePosted() {
return true;
}
- protected function getDescription() {
+ public function getDescription() {
return 'Create and edit pages.';
}
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' ),
) );
}
- protected function getAllowedParams() {
+ public function getAllowedParams() {
return array(
'title' => array(
ApiBase::PARAM_TYPE => 'string',
);
}
- protected function getParamDescription() {
+ public function getParamDescription() {
$p = $this->getModulePrefix();
return array(
'title' => 'Page title',
'section' => 'Section number. 0 for the top section, \'new\' for a new section',
'text' => 'Page content',
- 'token' => 'Edit token. You can get one of these through prop=info',
+ 'token' => array( 'Edit token. You can get one of these through prop=info.',
+ 'The token should always be sent as the last parameter, or at least, after the text parameter'
+ ),
'summary' => 'Edit summary. Also section title when section=new',
'minor' => 'Minor edit',
'notminor' => 'Non-minor edit',
'bot' => 'Mark this edit as bot',
- 'basetimestamp' => array( 'Timestamp of the base revision (gotten through prop=revisions&rvprop=timestamp).',
+ 'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
'Used to detect edit conflicts; leave unset to ignore conflicts.'
),
'starttimestamp' => array( 'Timestamp when you obtained the edit token.',
'captchaid' => 'CAPTCHA ID from previous request',
'captchaword' => 'Answer to the CAPTCHA',
'md5' => array( "The MD5 hash of the {$p}text parameter, or the {$p}prependtext and {$p}appendtext parameters concatenated.",
- 'If set, the edit won\'t be done unless the hash is correct' ),
+ 'If set, the edit won\'t be done unless the hash is correct' ),
'prependtext' => "Add this text to the beginning of the page. Overrides {$p}text",
'appendtext' => "Add this text to the end of the page. Overrides {$p}text",
'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
return '';
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'Edit a page (anonymous user):',
' api.php?action=edit&title=Test&summary=test%20summary&text=article%20content&basetimestamp=20070824123454&token=%2B\\',
);
}
+ public function getHelpUrls() {
+ return 'http://www.mediawiki.org/wiki/API:Edit';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}