mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
c26ca107db
This reverts commit96953647c3
. * Re-apply "Edit API for replies" This applies commit8829a1a412
. * Re-apply "Create a 'transcludedfrom' API endpoint" This applies commit5d8f3b9051
. * Re-apply "Use transcluded from API to avoid ever fetching Parsoid DOM in client" This applies commit9d0fc184fe
. * Re-apply "Restore error message for when comment is deleted while replying" This applies commit655c0526d6
. Change-Id: Id20d21899f87464636022aa0683f8c03e0060117
110 lines
2.3 KiB
PHP
110 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
use ApiBase;
|
|
use ApiMain;
|
|
use ApiParsoidTrait;
|
|
use DOMElement;
|
|
use Title;
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
use Wikimedia\Parsoid\Utils\DOMUtils;
|
|
|
|
class ApiDiscussionTools extends ApiBase {
|
|
|
|
use ApiParsoidTrait;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function __construct( ApiMain $main, string $name ) {
|
|
parent::__construct( $main, $name );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function execute() {
|
|
$params = $this->extractRequestParams();
|
|
$title = Title::newFromText( $params['page'] );
|
|
$result = null;
|
|
|
|
if ( !$title ) {
|
|
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['page'] ) ] );
|
|
return;
|
|
}
|
|
|
|
switch ( $params['paction'] ) {
|
|
case 'transcludedfrom':
|
|
$response = $this->requestRestbasePageHtml(
|
|
$this->getValidRevision( $title, $params['oldid'] ?? null )
|
|
);
|
|
|
|
$doc = DOMUtils::parseHTML( $response['body'] );
|
|
$container = $doc->getElementsByTagName( 'body' )->item( 0 );
|
|
'@phan-var DOMElement $container';
|
|
|
|
CommentUtils::unwrapParsoidSections( $container );
|
|
|
|
$parser = CommentParser::newFromGlobalState( $container );
|
|
$comments = $parser->getCommentItems();
|
|
|
|
$transcludedFrom = [];
|
|
foreach ( $comments as $comment ) {
|
|
$from = $comment->getTranscludedFrom();
|
|
// 'false' is the most likely result, so don't bother sending it,
|
|
// the client can just assume it if the key is missing
|
|
if ( $from !== false ) {
|
|
$transcludedFrom[ $comment->getId() ] = $from;
|
|
}
|
|
}
|
|
|
|
$result = $transcludedFrom;
|
|
break;
|
|
}
|
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $result );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getAllowedParams() {
|
|
return [
|
|
'paction' => [
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
ParamValidator::PARAM_TYPE => [
|
|
'transcludedfrom',
|
|
],
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-paction',
|
|
],
|
|
'page' => [
|
|
ParamValidator::PARAM_REQUIRED => true,
|
|
ApiBase::PARAM_HELP_MSG => 'apihelp-visualeditoredit-param-page',
|
|
],
|
|
'oldid' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function needsToken() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function isInternal() {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function isWriteMode() {
|
|
return false;
|
|
}
|
|
}
|