Merge "Replace VisualEditor ParsoidHelper with ParsoidClient"

This commit is contained in:
jenkins-bot 2022-09-19 16:33:13 +00:00 committed by Gerrit Code Review
commit 77514eb01f
7 changed files with 58 additions and 16 deletions

View file

@ -435,12 +435,14 @@
"discussiontoolscompare": {
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsCompare",
"services": [
"VisualEditor.ParsoidClientFactory",
"DiscussionTools.CommentParser"
]
},
"discussiontoolsedit": {
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsEdit",
"services": [
"VisualEditor.ParsoidClientFactory",
"DiscussionTools.CommentParser",
"DiscussionTools.SubscriptionStore",
"SkinFactory",
@ -457,12 +459,14 @@
"discussiontoolspageinfo": {
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPageInfo",
"services": [
"VisualEditor.ParsoidClientFactory",
"DiscussionTools.CommentParser"
]
},
"discussiontoolspreview": {
"class": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsPreview",
"services": [
"VisualEditor.ParsoidClientFactory",
"DiscussionTools.CommentParser",
"SkinFactory"
]

View file

@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools;
use ApiBase;
use ApiMain;
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use MediaWiki\Revision\RevisionRecord;
use Title;
use Wikimedia\ParamValidator\ParamValidator;
@ -17,17 +18,23 @@ class ApiDiscussionToolsCompare extends ApiBase {
/** @var CommentParser */
private $commentParser;
/** @var VisualEditorParsoidClientFactory */
private $parsoidClientFactory;
/**
* @param ApiMain $main
* @param string $name
* @param VisualEditorParsoidClientFactory $parsoidClientFactory
* @param CommentParser $commentParser
*/
public function __construct(
ApiMain $main,
string $name,
VisualEditorParsoidClientFactory $parsoidClientFactory,
CommentParser $commentParser
) {
parent::__construct( $main, $name );
$this->parsoidClientFactory = $parsoidClientFactory;
$this->commentParser = $commentParser;
}

View file

@ -11,6 +11,7 @@ use DerivativeRequest;
use MediaWiki\Extension\DiscussionTools\Hooks\HookUtils;
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentCommentItem;
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use MediaWiki\Logger\LoggerFactory;
use SkinFactory;
use Title;
@ -27,6 +28,9 @@ class ApiDiscussionToolsEdit extends ApiBase {
/** @var CommentParser */
private $commentParser;
/** @var VisualEditorParsoidClientFactory */
private $parsoidClientFactory;
/** @var SubscriptionStore */
private $subscriptionStore;
@ -39,6 +43,7 @@ class ApiDiscussionToolsEdit extends ApiBase {
/**
* @param ApiMain $main
* @param string $name
* @param VisualEditorParsoidClientFactory $parsoidClientFactory
* @param CommentParser $commentParser
* @param SubscriptionStore $subscriptionStore
* @param SkinFactory $skinFactory
@ -47,12 +52,14 @@ class ApiDiscussionToolsEdit extends ApiBase {
public function __construct(
ApiMain $main,
string $name,
VisualEditorParsoidClientFactory $parsoidClientFactory,
CommentParser $commentParser,
SubscriptionStore $subscriptionStore,
SkinFactory $skinFactory,
ConfigFactory $configFactory
) {
parent::__construct( $main, $name );
$this->parsoidClientFactory = $parsoidClientFactory;
$this->commentParser = $commentParser;
$this->subscriptionStore = $subscriptionStore;
$this->skinFactory = $skinFactory;

View file

@ -8,6 +8,7 @@ use MediaWiki\Extension\DiscussionTools\ThreadItem\CommentItem;
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentHeadingItem;
use MediaWiki\Extension\DiscussionTools\ThreadItem\ContentThreadItem;
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use Title;
use Wikimedia\ParamValidator\ParamValidator;
use Wikimedia\Parsoid\DOM\Element;
@ -22,17 +23,23 @@ class ApiDiscussionToolsPageInfo extends ApiBase {
/** @var CommentParser */
private $commentParser;
/** @var VisualEditorParsoidClientFactory */
private $parsoidClientFactory;
/**
* @param ApiMain $main
* @param string $name
* @param VisualEditorParsoidClientFactory $parsoidClientFactory
* @param CommentParser $commentParser
*/
public function __construct(
ApiMain $main,
string $name,
VisualEditorParsoidClientFactory $parsoidClientFactory,
CommentParser $commentParser
) {
parent::__construct( $main, $name );
$this->parsoidClientFactory = $parsoidClientFactory;
$this->commentParser = $commentParser;
}

View file

@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools;
use ApiBase;
use ApiMain;
use MediaWiki\Extension\VisualEditor\ApiParsoidTrait;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use SkinFactory;
use Title;
use Wikimedia\ParamValidator\ParamValidator;
@ -19,22 +20,28 @@ class ApiDiscussionToolsPreview extends ApiBase {
/** @var CommentParser */
private $commentParser;
/** @var VisualEditorParsoidClientFactory */
private $parsoidClientFactory;
/** @var SkinFactory */
private $skinFactory;
/**
* @param ApiMain $main
* @param string $name
* @param VisualEditorParsoidClientFactory $parsoidClientFactory
* @param CommentParser $commentParser
* @param SkinFactory $skinFactory
*/
public function __construct(
ApiMain $main,
string $name,
VisualEditorParsoidClientFactory $parsoidClientFactory,
CommentParser $commentParser,
SkinFactory $skinFactory
) {
parent::__construct( $main, $name );
$this->parsoidClientFactory = $parsoidClientFactory;
$this->commentParser = $commentParser;
$this->skinFactory = $skinFactory;
}

View file

@ -7,6 +7,8 @@ use ApiResult;
use DerivativeContext;
use DerivativeRequest;
use IContextSource;
use MediaWiki\Extension\VisualEditor\ParsoidClient;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use MediaWiki\Revision\RevisionRecord;
use Title;
use TitleValue;
@ -16,6 +18,7 @@ use Wikimedia\Parsoid\Utils\DOMUtils;
/**
* Random methods we want to share between API modules.
*
* @property VisualEditorParsoidClientFactory $parsoidClientFactory
* @property CommentParser $commentParser
*/
trait ApiDiscussionToolsTrait {
@ -132,6 +135,16 @@ trait ApiDiscussionToolsTrait {
return $api->getResult();
}
/**
* @see VisualEditorParsoidClientFactory
* @return ParsoidClient
*/
protected function getParsoidClient(): ParsoidClient {
return $this->parsoidClientFactory->createParsoidClient(
$this->getContext()->getRequest()->getHeader( 'Cookie' )
);
}
/**
* @param RevisionRecord $revision
* @return array

View file

@ -14,7 +14,7 @@ use IContextSource;
use MediaWiki\Extension\DiscussionTools\CommentUtils;
use MediaWiki\Extension\DiscussionTools\ContentThreadItemSet;
use MediaWiki\Extension\Gadgets\GadgetRepo;
use MediaWiki\Extension\VisualEditor\ParsoidHelper;
use MediaWiki\Extension\VisualEditor\ParsoidClient;
use MediaWiki\Extension\VisualEditor\VisualEditorParsoidClientFactory;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
@ -22,7 +22,6 @@ use MediaWiki\Revision\RevisionRecord;
use MediaWiki\User\UserIdentity;
use MWException;
use OutputPage;
use Psr\Log\NullLogger;
use RequestContext;
use Title;
use TitleValue;
@ -92,23 +91,21 @@ class HookUtils {
*/
public static function parseRevisionParsoidHtml( RevisionRecord $revRecord ): ContentThreadItemSet {
$services = MediaWikiServices::getInstance();
$parsoidHelper = new ParsoidHelper(
new NullLogger(),
false,
$services->getService( VisualEditorParsoidClientFactory::SERVICE_NAME )
);
// Get HTML for the revision
$status = $parsoidHelper->requestRestbasePageHtml( $revRecord );
if ( !$status->isOK() ) {
[ 'message' => $msg, 'params' => $params ] = $status->getErrors()[0];
throw new MWException( wfMessage( $msg, ...$params )->inLanguage( 'en' )->useDatabase( false )->text() );
}
$parsoidClientFactory = $services->getService( VisualEditorParsoidClientFactory::SERVICE_NAME );
/** @var ParsoidClient $parsoidClient */
$parsoidClient = $parsoidClientFactory->createParsoidClient( false );
$title = TitleValue::newFromPage( $revRecord->getPage() );
$response = $status->getValue();
// Get HTML for the revision
// TODO Can we just use `null` for the second parameter?
$response = $parsoidClient->getPageHtml( $revRecord, Title::castFromLinkTarget( $title )->getPageLanguage() );
if ( !empty( $response['error'] ) ) {
$message = wfMessage( ...$response['error'] );
throw new MWException( $message->inLanguage( 'en' )->useDatabase( false )->text() );
}
$html = $response['body'];
// Run the discussion parser on it