$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
- $contentHandler = $pageObj->getContentHandler();
+ if ( !isset( $params['contentmodel'] ) || $params['contentmodel'] == '' ) {
+ $contentHandler = $pageObj->getContentHandler();
+ } else {
+ $contentHandler = ContentHandler::getForModelID( $params['contentmodel'] );
+ }
// @todo ask handler whether direct editing is supported at all! make allowFlatEdit() method or some such
$name = $titleObj->getPrefixedDBkey();
$model = $contentHandler->getModelID();
- $this->dieUsage( "The requested format $contentFormat is not supported for content model $model used by $name", 'badformat' );
+ $this->dieUsage( "The requested format $contentFormat is not supported for content model ".
+ " $model used by $name", 'badformat' );
}
$apiResult = $this->getResult();
if ( $titleObj->isRedirect() ) {
$oldTitle = $titleObj;
- $titles = Revision::newFromTitle( $oldTitle )->getContent( Revision::FOR_THIS_USER )->getRedirectChain();
+ $titles = Revision::newFromTitle( $oldTitle, false, Revision::READ_LATEST )
+ ->getContent( Revision::FOR_THIS_USER )
+ ->getRedirectChain();
// array_shift( $titles );
$redirValues = array();
{
$content = $pageObj->getContent();
+ // @todo: Add support for appending/prepending to the Content interface
+
if ( !( $content instanceof TextContent ) ) {
- // @todo: ContentHandler should have an isFlat() method or some such
- // @todo: XXX: or perhaps there should be Content::append(), Content::prepend() and Content::supportsConcatenation()
$mode = $contentHandler->getModelID();
$this->dieUsage( "Can't append to pages using content model $mode", 'appendnotsupported' );
}
$text = '';
}
- $content = ContentHandler::makeContent( $text, $this->getTitle() );
+ try {
+ $content = ContentHandler::makeContent( $text, $this->getTitle() );
+ } catch ( MWContentSerializationException $ex ) {
+ $this->dieUsage( $ex->getMessage(), 'parseerror' );
+ return;
+ }
}
}
$this->dieUsageMsg( array( 'revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText() ) );
}
- $newContent = $contentHandler->getUndoContent( $undoRev, $undoafterRev );
+ $newContent = $contentHandler->getUndoContent( $pageObj->getRevision(), $undoRev, $undoafterRev );
+
if ( !$newContent ) {
$this->dieUsageMsg( 'undo-failure' );
}
- $params['contentformat'] = $contentHandler->getDefaultFormat();
$params['text'] = $newContent->serialize( $params['contentformat'] );
// If no summary was given and we only undid one rev,
if ( !is_null( $params['summary'] ) ) {
$requestArray['wpSummary'] = $params['summary'];
}
-
+
if ( !is_null( $params['sectiontitle'] ) ) {
$requestArray['wpSectionTitle'] = $params['sectiontitle'];
}
$articleObject = new Article( $titleObj );
$ep = new EditPage( $articleObject );
+ // allow editing of non-textual content.
+ $ep->allowNonTextContent = true;
+
$ep->setContextTitle( $titleObj );
$ep->importFormData( $req );
case EditPage::AS_HOOK_ERROR_EXPECTED:
$this->dieUsageMsg( 'hookaborted' );
+ case EditPage::AS_PARSE_ERROR:
+ $this->dieUsage( $status->getMessage(), 'parseerror' );
+
case EditPage::AS_IMAGE_REDIRECT_ANON:
$this->dieUsageMsg( 'noimageredirect-anon' );
array( 'undo-failure' ),
array( 'hashcheckfailed' ),
array( 'hookaborted' ),
+ array( 'code' => 'parseerror', 'info' => 'Failed to parse the given text.' ),
array( 'noimageredirect-anon' ),
array( 'noimageredirect-logged' ),
array( 'spamdetected', 'spam' ),
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( 'code' => 'sectionsnotsupported', 'info' => 'Sections are not supported for this type of page.' ),
- array( 'code' => 'editnotsupported', 'info' => 'Editing of this type of page is not supported using the text based edit API.' ),
- array( 'code' => 'appendnotsupported', 'info' => 'This type of page can not be edited by appending or prepending text.' ),
- array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to the page\'s content model' ),
+ array( 'code' => 'editnotsupported', 'info' => 'Editing of this type of page is not supported using '
+ . 'the text based edit API.' ),
+ array( 'code' => 'appendnotsupported', 'info' => 'This type of page can not be edited by appending '
+ . 'or prepending text.' ),
+ array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to '
+ . 'the page\'s content model' ),
array( 'customcssprotected' ),
array( 'customjsprotected' ),
)
ApiBase::PARAM_TYPE => 'boolean',
ApiBase::PARAM_DFLT => false,
),
+ 'contentformat' => array(
+ ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
+ ),
+ 'contentmodel' => array(
+ ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
+ )
);
}
'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
'redirect' => 'Automatically resolve redirects',
+ 'contentformat' => 'Content serialization format used for the input text',
+ 'contentmodel' => 'Content model of the new content',
);
}