Add topic API

Bug: T259563
Change-Id: I93bb93c272f9b30df81f7f978a3952ca1d027fec
This commit is contained in:
Ed Sanders 2020-08-06 15:22:47 +01:00 committed by Bartosz Dziewoński
parent ebe2071dfd
commit 2cc39f2b84
2 changed files with 62 additions and 1 deletions

View file

@ -39,6 +39,62 @@ class ApiDiscussionToolsEdit extends ApiBase {
}
switch ( $params['paction'] ) {
case 'addtopic':
$this->requireAtLeastOneParameter( $params, 'sectiontitle' );
$this->requireOnlyOneParameter( $params, 'wikitext', 'html' );
$wikitext = $params['wikitext'];
$html = $params['html'];
if ( $wikitext !== null ) {
$wikitext = trim( $wikitext );
if ( !CommentModifier::isWikitextSigned( $wikitext ) ) {
$wikitext .=
$this->msg( 'discussiontools-signature-prefix' )->inContentLanguage()->text() . '~~~~';
}
} else {
$doc = DOMUtils::parseHTML( $html );
$container = $doc->getElementsByTagName( 'body' )->item( 0 );
'@phan-var DOMElement $container';
if ( !CommentModifier::isHtmlSigned( $container ) ) {
CommentModifier::appendSignature( $container );
}
$html = DOMCompat::getInnerHTML( $container );
$wikitext = $this->transformHTML( $title, $html )[ 'body' ];
}
// As section=new this is append only so we don't need to
// worry about edit-conflict params such as oldid/baserevid/etag.
// Edit summary is also automatically generated when section=new
$api = new ApiMain(
new DerivativeRequest(
$this->getRequest(),
[
'action' => 'visualeditoredit',
'paction' => 'save',
'page' => $params['page'],
'token' => $params['token'],
'wikitext' => $wikitext,
'section' => 'new',
'sectiontitle' => $params['sectiontitle'],
'starttimestamp' => wfTimestampNow(),
'watchlist' => $params['watchlist'],
'captchaid' => $params['captchaid'],
'captchaword' => $params['captchaword']
],
/* was posted? */ true
),
/* enable write? */ true
);
$api->execute();
$data = $api->getResult()->getResultData();
$result = $data['visualeditoredit'];
break;
case 'addcomment':
// Fetch the latest revision
$requestedRevision = $this->getLatestRevision( $title );
@ -152,6 +208,7 @@ class ApiDiscussionToolsEdit extends ApiBase {
ParamValidator::PARAM_REQUIRED => true,
ParamValidator::PARAM_TYPE => [
'addcomment',
'addtopic',
],
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-paction',
],
@ -171,6 +228,10 @@ class ApiDiscussionToolsEdit extends ApiBase {
ParamValidator::PARAM_TYPE => 'text',
ParamValidator::PARAM_DEFAULT => null,
],
'sectiontitle' => [
ParamValidator::PARAM_TYPE => 'text',
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-sectiontitle',
],
'watchlist' => [
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-watchlist',
],

View file

@ -380,7 +380,7 @@ class CommentModifier {
*
* @param DOMElement $container
*/
private static function appendSignature( DOMElement $container ) : void {
public static function appendSignature( DOMElement $container ) : void {
$doc = $container->ownerDocument;
// If the last node isn't a paragraph (e.g. it's a list created in visual mode), then