Merge "api: Replace deprecated Linker::formatComment"

This commit is contained in:
jenkins-bot 2022-12-15 23:33:12 +00:00 committed by Gerrit Code Review
commit 26281987e9
13 changed files with 62 additions and 22 deletions

View file

@ -229,7 +229,7 @@ class ApiFeedWatchlist extends ApiBase {
// Create an anchor to section.
// The anchor won't work for sections that have dupes on page
// as there's no way to strip that info from ApiWatchlist (apparently?).
// RegExp in the line below is equal to Linker::formatAutocomments().
// RegExp in the line below is equal to MediaWiki\CommentFormatter\CommentParser::doSectionLinks().
if ( $this->linkToSections && $comment !== null &&
preg_match( '!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment, $matches )
) {

View file

@ -70,6 +70,7 @@ class ApiQuery extends ApiBase {
'LinkBatchFactory',
'ContentRenderer',
'ContentTransformer',
'CommentFormatter',
]
],
'duplicatefiles' => [
@ -163,6 +164,7 @@ class ApiQuery extends ApiBase {
'ActorMigration',
'ContentRenderer',
'ContentTransformer',
'CommentFormatter',
]
],
'stashimageinfo' => [
@ -209,6 +211,7 @@ class ApiQuery extends ApiBase {
'NamespaceInfo',
'ContentRenderer',
'ContentTransformer',
'CommentFormatter',
]
],
'allfileusages' => [
@ -264,6 +267,7 @@ class ApiQuery extends ApiBase {
'NamespaceInfo',
'ContentRenderer',
'ContentTransformer',
'CommentFormatter',
]
],
'mystashedfiles' => [
@ -411,6 +415,7 @@ class ApiQuery extends ApiBase {
'RevisionStore',
'ChangeTagDefStore',
'ActorMigration',
'CommentFormatter',
],
],
'users' => [
@ -431,6 +436,7 @@ class ApiQuery extends ApiBase {
'ContentLanguage',
'NamespaceInfo',
'GenderCache',
'CommentFormatter',
],
],
'watchlistraw' => [

View file

@ -23,6 +23,7 @@
* @file
*/
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Content\Transform\ContentTransformer;
@ -62,6 +63,7 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
* @param NamespaceInfo $namespaceInfo
* @param ContentRenderer $contentRenderer
* @param ContentTransformer $contentTransformer
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -73,7 +75,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
NameTableStore $changeTagDefStore,
NamespaceInfo $namespaceInfo,
ContentRenderer $contentRenderer,
ContentTransformer $contentTransformer
ContentTransformer $contentTransformer,
CommentFormatter $commentFormatter
) {
parent::__construct(
$query,
@ -84,7 +87,8 @@ class ApiQueryAllDeletedRevisions extends ApiQueryRevisionsBase {
$parserFactory,
$slotRoleRegistry,
$contentRenderer,
$contentTransformer
$contentTransformer,
$commentFormatter
);
$this->revisionStore = $revisionStore;
$this->changeTagDefStore = $changeTagDefStore;

View file

@ -20,6 +20,7 @@
* @file
*/
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Content\Transform\ContentTransformer;
@ -58,6 +59,7 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
* @param NamespaceInfo $namespaceInfo
* @param ContentRenderer $contentRenderer
* @param ContentTransformer $contentTransformer
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -69,7 +71,8 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
ActorMigration $actorMigration,
NamespaceInfo $namespaceInfo,
ContentRenderer $contentRenderer,
ContentTransformer $contentTransformer
ContentTransformer $contentTransformer,
CommentFormatter $commentFormatter
) {
parent::__construct(
$query,
@ -80,7 +83,8 @@ class ApiQueryAllRevisions extends ApiQueryRevisionsBase {
$parserFactory,
$slotRoleRegistry,
$contentRenderer,
$contentTransformer
$contentTransformer,
$commentFormatter
);
$this->revisionStore = $revisionStore;
$this->actorMigration = $actorMigration;

View file

@ -24,6 +24,7 @@
*/
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Content\Transform\ContentTransformer;
@ -62,6 +63,7 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
* @param LinkBatchFactory $linkBatchFactory
* @param ContentRenderer $contentRenderer
* @param ContentTransformer $contentTransformer
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -73,7 +75,8 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
NameTableStore $changeTagDefStore,
LinkBatchFactory $linkBatchFactory,
ContentRenderer $contentRenderer,
ContentTransformer $contentTransformer
ContentTransformer $contentTransformer,
CommentFormatter $commentFormatter
) {
parent::__construct(
$query,
@ -84,7 +87,8 @@ class ApiQueryDeletedRevisions extends ApiQueryRevisionsBase {
$parserFactory,
$slotRoleRegistry,
$contentRenderer,
$contentTransformer
$contentTransformer,
$commentFormatter
);
$this->revisionStore = $revisionStore;
$this->changeTagDefStore = $changeTagDefStore;

View file

@ -513,7 +513,7 @@ class ApiQueryImageInfo extends ApiQueryBase {
}
if ( $canShowField( File::DELETED_COMMENT ) ) {
if ( $pcomment ) {
$vals['parsedcomment'] = Linker::formatComment(
$vals['parsedcomment'] = MediaWikiServices::getInstance()->getCommentFormatter()->format(
$file->getDescription( File::RAW ), $file->getTitle() );
}
if ( $comment ) {

View file

@ -420,7 +420,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
return 'private';
}
if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
// formatComment() calls wfMessage() among other things
// MediaWiki\CommentFormatter\CommentFormatter::formatItems() calls wfMessage() among other things
return 'anon-public-user-private';
} elseif ( LogEventsList::getExcludeClause( $this->getDB(), 'user', $this->getAuthority() )
=== LogEventsList::getExcludeClause( $this->getDB(), 'public' )

View file

@ -199,7 +199,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
public function getCacheMode( $params ) {
if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
// formatComment() calls wfMessage() among other things
// MediaWiki\CommentFormatter\CommentFormatter::formatItems() calls wfMessage() among other things
return 'anon-public-user-private';
} else {
return 'public';

View file

@ -671,7 +671,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
return 'private';
}
if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
// formatComment() calls wfMessage() among other things
// MediaWiki\CommentFormatter\CommentFormatter::formatItems() calls wfMessage() among other things
return 'anon-public-user-private';
}

View file

@ -20,6 +20,7 @@
* @file
*/
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Content\Transform\ContentTransformer;
@ -61,6 +62,7 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
* @param ActorMigration $actorMigration
* @param ContentRenderer $contentRenderer
* @param ContentTransformer $contentTransformer
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -72,7 +74,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
NameTableStore $changeTagDefStore,
ActorMigration $actorMigration,
ContentRenderer $contentRenderer,
ContentTransformer $contentTransformer
ContentTransformer $contentTransformer,
CommentFormatter $commentFormatter
) {
parent::__construct(
$query,
@ -83,7 +86,8 @@ class ApiQueryRevisions extends ApiQueryRevisionsBase {
$parserFactory,
$slotRoleRegistry,
$contentRenderer,
$contentTransformer
$contentTransformer,
$commentFormatter
);
$this->revisionStore = $revisionStore;
$this->changeTagDefStore = $changeTagDefStore;

View file

@ -20,10 +20,10 @@
* @file
*/
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Content\Renderer\ContentRenderer;
use MediaWiki\Content\Transform\ContentTransformer;
use MediaWiki\Linker\Linker;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
@ -89,6 +89,9 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
/** @var ContentTransformer */
private $contentTransformer;
/** @var CommentFormatter */
private $commentFormatter;
/**
* @since 1.37 Support injection of services
* @stable to call
@ -101,6 +104,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
* @param SlotRoleRegistry|null $slotRoleRegistry
* @param ContentRenderer|null $contentRenderer
* @param ContentTransformer|null $contentTransformer
* @param CommentFormatter|null $commentFormatter
*/
public function __construct(
ApiQuery $queryModule,
@ -111,7 +115,8 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
ParserFactory $parserFactory = null,
SlotRoleRegistry $slotRoleRegistry = null,
ContentRenderer $contentRenderer = null,
ContentTransformer $contentTransformer = null
ContentTransformer $contentTransformer = null,
CommentFormatter $commentFormatter = null
) {
parent::__construct( $queryModule, $moduleName, $paramPrefix );
// This class is part of the stable interface and
@ -123,6 +128,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
$this->slotRoleRegistry = $slotRoleRegistry ?? $services->getSlotRoleRegistry();
$this->contentRenderer = $contentRenderer ?? $services->getContentRenderer();
$this->contentTransformer = $contentTransformer ?? $services->getContentTransformer();
$this->commentFormatter = $commentFormatter ?? $services->getCommentFormatter();
}
public function execute() {
@ -405,7 +411,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
}
if ( $this->fld_parsedcomment ) {
$vals['parsedcomment'] = Linker::formatComment(
$vals['parsedcomment'] = $this->commentFormatter->format(
$comment, Title::newFromLinkTarget( $revision->getPageAsLinkTarget() )
);
}

View file

@ -20,7 +20,7 @@
* @file
*/
use MediaWiki\Linker\Linker;
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\MainConfigNames;
use MediaWiki\ParamValidator\TypeDef\UserDef;
use MediaWiki\Revision\RevisionRecord;
@ -60,6 +60,9 @@ class ApiQueryUserContribs extends ApiQueryBase {
/** @var ActorMigration */
private $actorMigration;
/** @var CommentFormatter */
private $commentFormatter;
/**
* @param ApiQuery $query
* @param string $moduleName
@ -69,6 +72,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
* @param RevisionStore $revisionStore
* @param NameTableStore $changeTagDefStore
* @param ActorMigration $actorMigration
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -78,7 +82,8 @@ class ApiQueryUserContribs extends ApiQueryBase {
UserNameUtils $userNameUtils,
RevisionStore $revisionStore,
NameTableStore $changeTagDefStore,
ActorMigration $actorMigration
ActorMigration $actorMigration,
CommentFormatter $commentFormatter
) {
parent::__construct( $query, $moduleName, 'uc' );
$this->commentStore = $commentStore;
@ -87,6 +92,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
$this->revisionStore = $revisionStore;
$this->changeTagDefStore = $changeTagDefStore;
$this->actorMigration = $actorMigration;
$this->commentFormatter = $commentFormatter;
}
private $params, $multiUserMode, $orderBy, $parentLens;
@ -600,7 +606,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
}
if ( $this->fld_parsedcomment ) {
$vals['parsedcomment'] = Linker::formatComment( $comment, $title );
$vals['parsedcomment'] = $this->commentFormatter->format( $comment, $title );
}
}
}

View file

@ -20,7 +20,7 @@
* @file
*/
use MediaWiki\Linker\Linker;
use MediaWiki\CommentFormatter\CommentFormatter;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\ParamValidator\TypeDef\UserDef;
use MediaWiki\Revision\RevisionRecord;
@ -50,6 +50,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
/** @var GenderCache */
private $genderCache;
/** @var CommentFormatter */
private $commentFormatter;
/**
* @param ApiQuery $query
* @param string $moduleName
@ -58,6 +61,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
* @param Language $contentLanguage
* @param NamespaceInfo $namespaceInfo
* @param GenderCache $genderCache
* @param CommentFormatter $commentFormatter
*/
public function __construct(
ApiQuery $query,
@ -66,7 +70,8 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
WatchedItemQueryService $watchedItemQueryService,
Language $contentLanguage,
NamespaceInfo $namespaceInfo,
GenderCache $genderCache
GenderCache $genderCache,
CommentFormatter $commentFormatter
) {
parent::__construct( $query, $moduleName, 'wl' );
$this->commentStore = $commentStore;
@ -74,6 +79,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
$this->contentLanguage = $contentLanguage;
$this->namespaceInfo = $namespaceInfo;
$this->genderCache = $genderCache;
$this->commentFormatter = $commentFormatter;
}
public function execute() {
@ -415,7 +421,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
}
if ( $this->fld_parsedcomment ) {
$vals['parsedcomment'] = Linker::formatComment( $comment, $title );
$vals['parsedcomment'] = $this->commentFormatter->format( $comment, $title );
}
}
}