2020-08-19 20:03:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
|
|
|
|
use ApiBase;
|
|
|
|
use ApiMain;
|
2022-10-28 18:24:02 +00:00
|
|
|
use ApiUsageException;
|
2022-09-02 02:05:02 +00:00
|
|
|
use Config;
|
|
|
|
use ConfigFactory;
|
2021-04-29 00:06:56 +00:00
|
|
|
use DerivativeContext;
|
2020-08-19 20:03:41 +00:00
|
|
|
use DerivativeRequest;
|
2021-09-01 22:16:49 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils;
|
2022-03-18 03:28:06 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentCommentItem;
|
2022-03-29 19:29:46 +00:00
|
|
|
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
|
2022-09-08 00:29:35 +00:00
|
|
|
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
|
2020-08-20 16:12:10 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2022-09-02 01:49:44 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2022-09-02 02:05:02 +00:00
|
|
|
use SkinFactory;
|
2020-08-19 20:03:41 +00:00
|
|
|
use Title;
|
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2022-04-03 20:03:42 +00:00
|
|
|
use Wikimedia\ParamValidator\TypeDef\StringDef;
|
2020-08-19 20:03:41 +00:00
|
|
|
use Wikimedia\Parsoid\Utils\DOMCompat;
|
|
|
|
use Wikimedia\Parsoid\Utils\DOMUtils;
|
|
|
|
|
|
|
|
class ApiDiscussionToolsEdit extends ApiBase {
|
2022-02-04 21:58:20 +00:00
|
|
|
use ApiDiscussionToolsTrait;
|
2020-08-19 20:03:41 +00:00
|
|
|
use ApiParsoidTrait;
|
|
|
|
|
2022-10-21 19:34:18 +00:00
|
|
|
private CommentParser $commentParser;
|
|
|
|
private VisualEditorParsoidClientFactory $parsoidClientFactory;
|
|
|
|
private SubscriptionStore $subscriptionStore;
|
|
|
|
private SkinFactory $skinFactory;
|
|
|
|
private Config $config;
|
|
|
|
private RevisionLookup $revisionLookup;
|
2022-09-02 01:49:44 +00:00
|
|
|
|
2022-02-04 21:58:20 +00:00
|
|
|
public function __construct(
|
|
|
|
ApiMain $main,
|
2022-09-02 02:05:02 +00:00
|
|
|
string $name,
|
2022-09-08 00:29:35 +00:00
|
|
|
VisualEditorParsoidClientFactory $parsoidClientFactory,
|
2022-09-02 02:05:02 +00:00
|
|
|
CommentParser $commentParser,
|
|
|
|
SubscriptionStore $subscriptionStore,
|
|
|
|
SkinFactory $skinFactory,
|
2022-09-02 01:49:44 +00:00
|
|
|
ConfigFactory $configFactory,
|
|
|
|
RevisionLookup $revisionLookup
|
2022-02-04 21:58:20 +00:00
|
|
|
) {
|
2020-08-19 20:03:41 +00:00
|
|
|
parent::__construct( $main, $name );
|
2022-09-08 00:29:35 +00:00
|
|
|
$this->parsoidClientFactory = $parsoidClientFactory;
|
2022-02-04 21:58:20 +00:00
|
|
|
$this->commentParser = $commentParser;
|
2022-09-02 02:05:02 +00:00
|
|
|
$this->subscriptionStore = $subscriptionStore;
|
|
|
|
$this->skinFactory = $skinFactory;
|
|
|
|
$this->config = $configFactory->makeConfig( 'discussiontools' );
|
2022-09-02 01:49:44 +00:00
|
|
|
$this->revisionLookup = $revisionLookup;
|
2020-08-20 16:12:10 +00:00
|
|
|
$this->setLogger( LoggerFactory::getInstance( 'DiscussionTools' ) );
|
2020-08-19 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
2022-10-28 18:24:02 +00:00
|
|
|
* @throws ApiUsageException
|
2020-08-19 20:03:41 +00:00
|
|
|
*/
|
|
|
|
public function execute() {
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
$title = Title::newFromText( $params['page'] );
|
|
|
|
$result = null;
|
|
|
|
|
2021-09-01 22:16:49 +00:00
|
|
|
$autoSubscribe =
|
2022-09-02 02:05:02 +00:00
|
|
|
$this->config->get( 'DiscussionToolsAutoTopicSubEditor' ) === 'discussiontoolsapi' &&
|
2021-09-01 22:16:49 +00:00
|
|
|
HookUtils::shouldAddAutoSubscription( $this->getUser(), $title );
|
|
|
|
$subscribableHeadingName = null;
|
|
|
|
$subscribableSectionTitle = '';
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
if ( !$title ) {
|
|
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
|
|
|
}
|
|
|
|
|
2021-05-21 16:03:39 +00:00
|
|
|
$this->getErrorFormatter()->setContextTitle( $title );
|
|
|
|
|
2021-10-18 22:18:07 +00:00
|
|
|
$session = null;
|
|
|
|
$usedFormTokensKey = 'DiscussionTools:usedFormTokens';
|
|
|
|
$formToken = $params['formtoken'];
|
|
|
|
if ( $formToken ) {
|
|
|
|
$session = $this->getContext()->getRequest()->getSession();
|
|
|
|
$usedFormTokens = $session->get( $usedFormTokensKey ) ?? [];
|
2023-06-06 12:08:00 +00:00
|
|
|
if ( in_array( $formToken, $usedFormTokens, true ) ) {
|
2021-10-18 22:18:07 +00:00
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-formtoken-used' ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-04 21:58:20 +00:00
|
|
|
$this->requireOnlyOneParameter( $params, 'wikitext', 'html' );
|
|
|
|
if ( $params['paction'] === 'addtopic' ) {
|
|
|
|
$this->requireAtLeastOneParameter( $params, 'sectiontitle' );
|
|
|
|
}
|
|
|
|
|
|
|
|
// To determine if we need to add a signature,
|
|
|
|
// preview the comment without adding one and check if the result is signed properly.
|
2022-06-27 11:50:10 +00:00
|
|
|
$previewResult = $this->previewMessage(
|
|
|
|
$params['paction'] === 'addtopic' ? 'topic' : 'reply',
|
|
|
|
$title,
|
|
|
|
[
|
|
|
|
'wikitext' => $params['wikitext'],
|
|
|
|
'html' => $params['html'],
|
|
|
|
'sectiontitle' => $params['sectiontitle'],
|
2022-06-27 13:40:41 +00:00
|
|
|
],
|
|
|
|
$params
|
2022-06-27 11:50:10 +00:00
|
|
|
);
|
2022-02-04 21:58:20 +00:00
|
|
|
$previewResultHtml = $previewResult->getResultData( [ 'parse', 'text' ] );
|
2022-03-28 17:32:39 +00:00
|
|
|
$previewContainer = DOMCompat::getBody( DOMUtils::parseHTML( $previewResultHtml ) );
|
|
|
|
$previewThreadItemSet = $this->commentParser->parse( $previewContainer, $title->getTitleValue() );
|
|
|
|
if ( CommentUtils::isSingleCommentSignedBy(
|
|
|
|
$previewThreadItemSet, $this->getUser()->getName(), $previewContainer
|
|
|
|
) ) {
|
2022-02-04 21:58:20 +00:00
|
|
|
$signature = null;
|
|
|
|
} else {
|
|
|
|
$signature = $this->msg( 'discussiontools-signature-prefix' )->inContentLanguage()->text() . '~~~~';
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
switch ( $params['paction'] ) {
|
2020-08-06 14:22:47 +00:00
|
|
|
case 'addtopic':
|
|
|
|
$wikitext = $params['wikitext'];
|
|
|
|
$html = $params['html'];
|
|
|
|
|
|
|
|
if ( $wikitext !== null ) {
|
2022-02-04 21:58:20 +00:00
|
|
|
if ( $signature !== null ) {
|
2022-08-06 12:51:02 +00:00
|
|
|
$wikitext = CommentModifier::appendSignatureWikitext( $wikitext, $signature );
|
2020-08-06 14:22:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-01-29 20:20:51 +00:00
|
|
|
$doc = DOMUtils::parseHTML( '' );
|
|
|
|
$container = DOMUtils::parseHTMLToFragment( $doc, $html );
|
2022-02-04 21:58:20 +00:00
|
|
|
if ( $signature !== null ) {
|
2022-01-29 20:20:51 +00:00
|
|
|
CommentModifier::appendSignature( $container, $signature );
|
2020-08-06 14:22:47 +00:00
|
|
|
}
|
2022-01-29 20:20:51 +00:00
|
|
|
$html = DOMUtils::getFragmentInnerHTML( $container );
|
2020-08-06 14:22:47 +00:00
|
|
|
$wikitext = $this->transformHTML( $title, $html )[ 'body' ];
|
|
|
|
}
|
|
|
|
|
2022-03-08 13:00:22 +00:00
|
|
|
$mobileFormatParams = [];
|
|
|
|
// Boolean parameters must be omitted completely to be treated as false.
|
|
|
|
// Param is added by hook in MobileFrontend, so it may be unset.
|
|
|
|
if ( isset( $params['mobileformat'] ) && $params['mobileformat'] ) {
|
|
|
|
$mobileFormatParams['mobileformat'] = '1';
|
|
|
|
}
|
2020-08-06 14:22:47 +00:00
|
|
|
// 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
|
2021-04-29 00:06:56 +00:00
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
|
|
|
$context->setRequest(
|
2020-08-06 14:22:47 +00:00
|
|
|
new DerivativeRequest(
|
2021-04-29 00:06:56 +00:00
|
|
|
$context->getRequest(),
|
2020-08-06 14:22:47 +00:00
|
|
|
[
|
|
|
|
'action' => 'visualeditoredit',
|
|
|
|
'paction' => 'save',
|
|
|
|
'page' => $params['page'],
|
|
|
|
'token' => $params['token'],
|
|
|
|
'wikitext' => $wikitext,
|
2020-08-25 12:31:54 +00:00
|
|
|
// A default is provided automatically by the Edit API
|
|
|
|
// for new sections when the summary is empty.
|
|
|
|
'summary' => $params['summary'],
|
2020-08-06 14:22:47 +00:00
|
|
|
'section' => 'new',
|
|
|
|
'sectiontitle' => $params['sectiontitle'],
|
|
|
|
'starttimestamp' => wfTimestampNow(),
|
2022-02-18 16:40:38 +00:00
|
|
|
'useskin' => $params['useskin'],
|
2020-08-06 14:22:47 +00:00
|
|
|
'watchlist' => $params['watchlist'],
|
|
|
|
'captchaid' => $params['captchaid'],
|
2023-06-12 20:19:12 +00:00
|
|
|
'captchaword' => $params['captchaword'],
|
|
|
|
'nocontent' => $params['nocontent'],
|
2022-03-08 13:00:22 +00:00
|
|
|
] + $mobileFormatParams,
|
2020-08-06 14:22:47 +00:00
|
|
|
/* was posted? */ true
|
2021-04-29 00:06:56 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$api = new ApiMain(
|
|
|
|
$context,
|
2020-08-06 14:22:47 +00:00
|
|
|
/* enable write? */ true
|
|
|
|
);
|
|
|
|
|
|
|
|
$api->execute();
|
|
|
|
|
|
|
|
$data = $api->getResult()->getResultData();
|
|
|
|
$result = $data['visualeditoredit'];
|
|
|
|
|
2021-09-01 22:16:49 +00:00
|
|
|
if ( $autoSubscribe && isset( $result['content'] ) ) {
|
|
|
|
// Determining the added topic's name directly is hard (we'd have to ensure we have the
|
|
|
|
// same timestamp, and replicate some CommentParser stuff). Just pull it out of the response.
|
|
|
|
$doc = DOMUtils::parseHTML( $result['content'] );
|
2022-03-28 21:29:14 +00:00
|
|
|
$container = DOMCompat::getBody( $doc );
|
|
|
|
$threadItemSet = $this->commentParser->parse( $container, $title->getTitleValue() );
|
|
|
|
$threads = $threadItemSet->getThreads();
|
|
|
|
if ( count( $threads ) ) {
|
|
|
|
$lastHeading = end( $threads );
|
|
|
|
$subscribableHeadingName = $lastHeading->getName();
|
|
|
|
$subscribableSectionTitle = $lastHeading->getLinkableTitle();
|
2021-09-01 22:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 14:22:47 +00:00
|
|
|
break;
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
case 'addcomment':
|
2021-02-12 19:16:13 +00:00
|
|
|
$this->requireAtLeastOneParameter( $params, 'commentid', 'commentname' );
|
2021-01-27 15:40:57 +00:00
|
|
|
|
2021-02-12 19:16:13 +00:00
|
|
|
$commentId = $params['commentid'] ?? null;
|
|
|
|
$commentName = $params['commentname'] ?? null;
|
2021-01-27 15:40:57 +00:00
|
|
|
|
|
|
|
if ( !$title->exists() ) {
|
|
|
|
// The page does not exist, so the comment we're trying to reply to can't exist either.
|
2021-02-12 19:16:13 +00:00
|
|
|
if ( $commentId ) {
|
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-commentid-notfound', $commentId ] );
|
|
|
|
} else {
|
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-commentname-notfound', $commentName ] );
|
|
|
|
}
|
2021-01-27 15:40:57 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
// Fetch the latest revision
|
2022-09-02 01:49:44 +00:00
|
|
|
$requestedRevision = $this->revisionLookup->getRevisionByTitle( $title );
|
|
|
|
if ( !$requestedRevision ) {
|
|
|
|
$this->dieWithError(
|
|
|
|
[ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ],
|
|
|
|
'nosuchrevid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-20 16:12:10 +00:00
|
|
|
$response = $this->requestRestbasePageHtml( $requestedRevision );
|
2020-08-19 20:03:41 +00:00
|
|
|
|
2020-08-20 16:12:10 +00:00
|
|
|
$headers = $response['headers'];
|
2020-08-19 20:03:41 +00:00
|
|
|
$doc = DOMUtils::parseHTML( $response['body'] );
|
2020-08-20 16:12:10 +00:00
|
|
|
|
|
|
|
// Don't trust RESTBase to always give us the revision we requested,
|
|
|
|
// instead get the revision ID from the document and use that.
|
|
|
|
// Ported from ve.init.mw.ArticleTarget.prototype.parseMetadata
|
|
|
|
$docRevId = null;
|
|
|
|
$aboutDoc = $doc->documentElement->getAttribute( 'about' );
|
|
|
|
|
|
|
|
if ( $aboutDoc ) {
|
|
|
|
preg_match( '/revision\\/([0-9]+)$/', $aboutDoc, $docRevIdMatches );
|
|
|
|
if ( $docRevIdMatches ) {
|
|
|
|
$docRevId = (int)$docRevIdMatches[ 1 ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !$docRevId ) {
|
|
|
|
$this->dieWithError( 'apierror-visualeditor-docserver', 'docserver' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $docRevId !== $requestedRevision->getId() ) {
|
|
|
|
// TODO: If this never triggers, consider removing the check.
|
|
|
|
$this->getLogger()->warning(
|
|
|
|
"Requested revision {$requestedRevision->getId()} " .
|
|
|
|
"but received {$docRevId}."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-02 13:45:39 +00:00
|
|
|
$container = DOMCompat::getBody( $doc );
|
2020-08-19 20:03:41 +00:00
|
|
|
|
2023-01-27 16:07:56 +00:00
|
|
|
// Unwrap sections, so that transclusions overlapping section boundaries don't cause all
|
|
|
|
// comments in the sections to be treated as transcluded from another page.
|
2023-01-26 19:09:27 +00:00
|
|
|
CommentUtils::unwrapParsoidSections( $container );
|
|
|
|
|
2022-03-28 17:30:01 +00:00
|
|
|
$threadItemSet = $this->commentParser->parse( $container, $title->getTitleValue() );
|
2020-09-01 23:00:08 +00:00
|
|
|
|
2021-02-12 19:16:13 +00:00
|
|
|
if ( $commentId ) {
|
2022-02-19 06:31:34 +00:00
|
|
|
$comment = $threadItemSet->findCommentById( $commentId );
|
2021-02-12 19:16:13 +00:00
|
|
|
|
2022-03-18 03:28:06 +00:00
|
|
|
if ( !$comment || !( $comment instanceof ContentCommentItem ) ) {
|
2021-02-12 19:16:13 +00:00
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-commentid-notfound', $commentId ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2022-02-19 06:31:34 +00:00
|
|
|
$comments = $threadItemSet->findCommentsByName( $commentName );
|
2021-02-12 19:16:13 +00:00
|
|
|
$comment = $comments[ 0 ] ?? null;
|
|
|
|
|
|
|
|
if ( count( $comments ) > 1 ) {
|
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-commentname-ambiguous', $commentName ] );
|
2022-03-18 03:28:06 +00:00
|
|
|
} elseif ( !$comment || !( $comment instanceof ContentCommentItem ) ) {
|
2021-02-12 19:16:13 +00:00
|
|
|
$this->dieWithError( [ 'apierror-discussiontools-commentname-notfound', $commentName ] );
|
|
|
|
}
|
2020-08-19 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 16:25:39 +00:00
|
|
|
if ( $comment->getTranscludedFrom() ) {
|
|
|
|
// Replying to transcluded comments should not be possible. We check this client-side, but
|
|
|
|
// the comment might have become transcluded in the meantime (T268069), so check again. We
|
|
|
|
// didn't have this check before T313100, since usually the reply would just disappear in
|
|
|
|
// Parsoid, but now it would be placed after the transclusion, which would be wrong.
|
|
|
|
$this->dieWithError( 'discussiontools-error-comment-not-saved', 'comment-became-transcluded' );
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
if ( $params['wikitext'] !== null ) {
|
2022-02-04 21:58:20 +00:00
|
|
|
CommentModifier::addWikitextReply( $comment, $params['wikitext'], $signature );
|
2020-08-19 20:03:41 +00:00
|
|
|
} else {
|
2022-02-04 21:58:20 +00:00
|
|
|
CommentModifier::addHtmlReply( $comment, $params['html'], $signature );
|
2020-08-19 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 12:31:54 +00:00
|
|
|
if ( isset( $params['summary'] ) ) {
|
|
|
|
$summary = $params['summary'];
|
2020-08-19 20:03:41 +00:00
|
|
|
} else {
|
2021-09-01 22:16:49 +00:00
|
|
|
$sectionTitle = $comment->getHeading()->getLinkableTitle();
|
|
|
|
$summary = ( $sectionTitle ? '/* ' . $sectionTitle . ' */ ' : '' ) .
|
2020-11-05 16:07:56 +00:00
|
|
|
$this->msg( 'discussiontools-defaultsummary-reply' )->inContentLanguage()->text();
|
2020-08-19 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 22:16:49 +00:00
|
|
|
if ( $autoSubscribe ) {
|
|
|
|
$heading = $comment->getSubscribableHeading();
|
|
|
|
if ( $heading ) {
|
|
|
|
$subscribableHeadingName = $heading->getName();
|
|
|
|
$subscribableSectionTitle = $heading->getLinkableTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 00:06:56 +00:00
|
|
|
$context = new DerivativeContext( $this->getContext() );
|
|
|
|
$context->setRequest(
|
2020-08-19 20:03:41 +00:00
|
|
|
new DerivativeRequest(
|
2021-04-29 00:06:56 +00:00
|
|
|
$context->getRequest(),
|
2020-08-19 20:03:41 +00:00
|
|
|
[
|
|
|
|
'action' => 'visualeditoredit',
|
|
|
|
'paction' => 'save',
|
|
|
|
'page' => $params['page'],
|
|
|
|
'token' => $params['token'],
|
2020-08-20 16:12:10 +00:00
|
|
|
'oldid' => $docRevId,
|
2020-08-19 20:03:41 +00:00
|
|
|
'html' => DOMCompat::getOuterHTML( $doc->documentElement ),
|
|
|
|
'summary' => $summary,
|
2020-08-20 16:12:10 +00:00
|
|
|
'baserevid' => $docRevId,
|
2020-08-19 20:03:41 +00:00
|
|
|
'starttimestamp' => wfTimestampNow(),
|
2022-08-25 19:18:09 +00:00
|
|
|
'etag' => $headers['etag'] ?? null,
|
2022-02-18 16:40:38 +00:00
|
|
|
'useskin' => $params['useskin'],
|
2020-08-19 20:03:41 +00:00
|
|
|
'watchlist' => $params['watchlist'],
|
|
|
|
'captchaid' => $params['captchaid'],
|
2023-06-12 20:19:12 +00:00
|
|
|
'captchaword' => $params['captchaword'],
|
|
|
|
'nocontent' => $params['nocontent'],
|
2020-08-19 20:03:41 +00:00
|
|
|
],
|
|
|
|
/* was posted? */ true
|
2021-04-29 00:06:56 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$api = new ApiMain(
|
|
|
|
$context,
|
2020-08-19 20:03:41 +00:00
|
|
|
/* enable write? */ true
|
|
|
|
);
|
|
|
|
|
|
|
|
$api->execute();
|
|
|
|
|
|
|
|
// TODO: Tags are only added by 'dttags' existing on the original request
|
|
|
|
// context (see Hook::onRecentChangeSave). What tags (if any) should be
|
|
|
|
// added in this API?
|
|
|
|
|
|
|
|
$data = $api->getResult()->getResultData();
|
|
|
|
$result = $data['visualeditoredit'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-25 23:02:15 +00:00
|
|
|
if ( !isset( $result['newrevid'] ) && isset( $result['result'] ) && $result['result'] === 'success' ) {
|
2020-11-18 19:40:05 +00:00
|
|
|
// No new revision, so no changes were made to the page (null edit).
|
|
|
|
// Comment was not actually saved, so for this API, that's an error.
|
2022-10-08 16:25:39 +00:00
|
|
|
// This should not be possible after T313100.
|
2020-11-18 19:40:05 +00:00
|
|
|
$this->dieWithError( 'discussiontools-error-comment-not-saved', 'comment-comment-not-saved' );
|
|
|
|
}
|
|
|
|
|
2021-09-01 22:16:49 +00:00
|
|
|
if ( $autoSubscribe && $subscribableHeadingName ) {
|
|
|
|
$subsTitle = $title->createFragmentTarget( $subscribableSectionTitle );
|
2022-09-02 02:05:02 +00:00
|
|
|
$this->subscriptionStore
|
|
|
|
->addAutoSubscriptionForUser( $this->getUser(), $subsTitle, $subscribableHeadingName );
|
2021-09-01 22:16:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 22:18:07 +00:00
|
|
|
// Check the post was successful (could have been blocked by ConfirmEdit) before
|
|
|
|
// marking the form token as used.
|
|
|
|
if ( $formToken && isset( $result['result'] ) && $result['result'] === 'success' ) {
|
|
|
|
$usedFormTokens[] = $formToken;
|
|
|
|
// Set an arbitrary limit of the number of form tokens to
|
|
|
|
// store to prevent session storage from becoming full.
|
|
|
|
// It is unlikely that form tokens other than the few most
|
|
|
|
// recently used will be needed.
|
|
|
|
while ( count( $usedFormTokens ) > 50 ) {
|
|
|
|
// Discard the oldest tokens first
|
|
|
|
array_shift( $usedFormTokens );
|
|
|
|
}
|
|
|
|
$session->set( $usedFormTokensKey, $usedFormTokens );
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:03:41 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getAllowedParams() {
|
|
|
|
return [
|
|
|
|
'paction' => [
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
|
|
ParamValidator::PARAM_TYPE => [
|
|
|
|
'addcomment',
|
2020-08-06 14:22:47 +00:00
|
|
|
'addtopic',
|
2020-08-19 20:03:41 +00:00
|
|
|
],
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-paction',
|
2021-02-10 23:05:38 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
2020-08-19 20:03:41 +00:00
|
|
|
],
|
|
|
|
'page' => [
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-page',
|
|
|
|
],
|
|
|
|
'token' => [
|
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
|
|
],
|
2021-10-18 22:18:07 +00:00
|
|
|
'formtoken' => [
|
2022-04-03 23:26:15 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2022-04-03 20:03:42 +00:00
|
|
|
StringDef::PARAM_MAX_CHARS => 16,
|
2021-10-18 22:18:07 +00:00
|
|
|
],
|
2021-02-12 19:16:13 +00:00
|
|
|
'commentname' => null,
|
2020-08-19 20:03:41 +00:00
|
|
|
'commentid' => null,
|
|
|
|
'wikitext' => [
|
|
|
|
ParamValidator::PARAM_TYPE => 'text',
|
|
|
|
ParamValidator::PARAM_DEFAULT => null,
|
|
|
|
],
|
|
|
|
'html' => [
|
|
|
|
ParamValidator::PARAM_TYPE => 'text',
|
|
|
|
ParamValidator::PARAM_DEFAULT => null,
|
|
|
|
],
|
2020-08-25 12:31:54 +00:00
|
|
|
'summary' => [
|
2020-09-14 20:44:03 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2020-08-25 12:31:54 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => null,
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-summary',
|
|
|
|
],
|
2020-08-06 14:22:47 +00:00
|
|
|
'sectiontitle' => [
|
2020-09-14 20:44:03 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'string',
|
2020-08-06 14:22:47 +00:00
|
|
|
],
|
2022-02-18 16:40:38 +00:00
|
|
|
'useskin' => [
|
2022-09-02 02:05:02 +00:00
|
|
|
ParamValidator::PARAM_TYPE => array_keys( $this->skinFactory->getInstalledSkins() ),
|
2022-02-18 16:40:38 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-parse-param-useskin',
|
|
|
|
],
|
2020-08-19 20:03:41 +00:00
|
|
|
'watchlist' => [
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-edit-param-watchlist',
|
|
|
|
],
|
|
|
|
'captchaid' => [
|
2020-08-25 12:24:31 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-captchaid',
|
2020-08-19 20:03:41 +00:00
|
|
|
],
|
|
|
|
'captchaword' => [
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-captchaword',
|
|
|
|
],
|
2023-06-12 20:19:12 +00:00
|
|
|
'nocontent' => [
|
|
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-nocontent',
|
|
|
|
],
|
2020-08-19 20:03:41 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function needsToken() {
|
|
|
|
return 'csrf';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function isInternal() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function isWriteMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|