$this->dieUsageMsg( 'missingtext' );
}
- $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'] ) );
- }
+ $pageObj = $this->getTitleOrPageId( $params );
+ $titleObj = $pageObj->getTitle();
+ if ( $titleObj->isExternal() ) {
+ $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
$apiResult = $this->getResult();
// We do want getContent()'s behavior for non-existent
// MediaWiki: pages, though
if ( $articleObj->getID() == 0 && $titleObj->getNamespace() != NS_MEDIAWIKI ) {
- $content = '';
+ $content = null;
+ $text = '';
} else {
- $content = $articleObj->getContent();
+ $content = $articleObj->getContentObject();
+ $text = ContentHandler::getContentText( $content ); #FIXME: serialize?! get format from params?...
}
if ( !is_null( $params['section'] ) ) {
// Process the content for section edits
- global $wgParser;
$section = intval( $params['section'] );
- $content = $wgParser->getSection( $content, $section, false );
- if ( $content === false ) {
+ $sectionContent = $content->getSection( $section );
+ $text = ContentHandler::getContentText( $sectionContent ); #FIXME: serialize?! get format from params?...
+ if ( $text === false || $text === null ) {
$this->dieUsage( "There is no section {$section}.", 'nosuchsection' );
}
}
- $params['text'] = $params['prependtext'] . $content . $params['appendtext'];
+ $params['text'] = $params['prependtext'] . $text . $params['appendtext'];
$toMD5 = $params['prependtext'] . $params['appendtext'];
}
// TODO: Make them not or check if they still do
$wgTitle = $titleObj;
- $ep = new EditPage( $articleObj );
+ $handler = ContentHandler::getForTitle( $titleObj );
+ $ep = $handler->createEditPage( $articleObj );
+
$ep->setContextTitle( $titleObj );
$ep->importFormData( $req );
case EditPage::AS_SPAM_ERROR:
$this->dieUsageMsg( array( 'spamdetected', $result['spam'] ) );
- case EditPage::AS_FILTERING:
- $this->dieUsageMsg( 'filtered' );
-
case EditPage::AS_BLOCKED_PAGE_FOR_USER:
$this->dieUsageMsg( 'blockedtext' );
$this->dieUsageMsg( 'summaryrequired' );
case EditPage::AS_END:
+ default:
// $status came from WikiPage::doEdit()
$errors = $status->getErrorsArray();
$this->dieUsageMsg( $errors[0] ); // TODO: Add new errors to message map
break;
- default:
- if ( is_string( $status->value ) && strlen( $status->value ) ) {
- $this->dieUsage( "An unknown return value was returned by Editpage. The code returned was \"{$status->value}\"" , $status->value );
- } else {
- $this->dieUsageMsg( array( 'unknownerror', $status->value ) );
- }
}
$apiResult->addValue( null, $this->getModuleName(), $r );
}
global $wgMaxArticleSize;
return array_merge( parent::getPossibleErrors(),
- $this->getRequireOnlyOneParameterErrorMessages( array( 'title', 'pageid' ) ),
+ $this->getTitleOrPageIdErrorMessage(),
array(
- array( 'nosuchpageid', 'pageid' ),
array( 'missingtext' ),
- array( 'invalidtitle', 'title' ),
array( 'createonly-exists' ),
array( 'nocreate-missing' ),
array( 'nosuchrevid', 'undo' ),
array( 'noimageredirect-logged' ),
array( 'spamdetected', 'spam' ),
array( 'summaryrequired' ),
- array( 'filtered' ),
array( 'blockedtext' ),
array( 'contenttoobig', $wgMaxArticleSize ),
array( 'noedit-anon' ),
'sectiontitle' => 'The title for a new section',
'text' => 'Page content',
'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'
+ "The token should always be sent as the last parameter, or at least, after the {$p}text parameter"
),
- 'summary' => 'Edit summary. Also section title when section=new',
+ 'summary' => "Edit summary. Also section title when {$p}section=new and {$p}sectiontitle is not set",
'minor' => 'Minor edit',
'notminor' => 'Non-minor edit',
'bot' => 'Mark this edit as bot',
'basetimestamp' => array( 'Timestamp of the base revision (obtained through prop=revisions&rvprop=timestamp).',
- 'Used to detect edit conflicts; leave unset to ignore conflicts.'
+ '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'
'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' ),
'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",
+ 'appendtext' => array( "Add this text to the end of the page. Overrides {$p}text.",
+ "Use {$p}section=new to append a new section" ),
'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',