aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDannyS712 <dannys712.wiki@gmail.com>2021-04-23 14:51:18 +0000
committerDannyS712 <dannys712.wiki@gmail.com>2021-04-23 15:09:48 +0000
commit523342c7811840e91fc0be660cc232a4d91c8bff (patch)
treed35ccc6a975adf5f135d2d10a0fe79ea3589b3f6
parent89b00fcfbe966092f405f0cc939eb6f052cf2a2b (diff)
downloadmediawikicore-523342c7811840e91fc0be660cc232a4d91c8bff.tar.gz
mediawikicore-523342c7811840e91fc0be660cc232a4d91c8bff.zip
Inject CommentStore service into api query modules
- ApiQueryBlocks - ApiQueryDeletedrevs - ApiQueryFilearchive - ApiQueryLogEvents - ApiQueryProtectedTitles - ApiQueryRecentChanges - ApiQueryUserContribs - ApiQueryWatchlist Bug: T259960 Change-Id: Ib7ee815fcea3e72523124eb6a2eaf20ad9565cfe
-rw-r--r--includes/api/ApiQuery.php44
-rw-r--r--includes/api/ApiQueryBlocks.php13
-rw-r--r--includes/api/ApiQueryDeletedrevs.php18
-rw-r--r--includes/api/ApiQueryFilearchive.php18
-rw-r--r--includes/api/ApiQueryLogEvents.php13
-rw-r--r--includes/api/ApiQueryProtectedTitles.php18
-rw-r--r--includes/api/ApiQueryRecentChanges.php15
-rw-r--r--includes/api/ApiQueryUserContribs.php16
-rw-r--r--includes/api/ApiQueryWatchlist.php12
9 files changed, 129 insertions, 38 deletions
diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php
index 27415afcbf0e..dad4cc6b66d3 100644
--- a/includes/api/ApiQuery.php
+++ b/includes/api/ApiQuery.php
@@ -91,34 +91,66 @@ class ApiQuery extends ApiBase {
'class' => ApiQueryBlocks::class,
'services' => [
'BlockRestrictionStore',
+ 'CommentStore',
],
],
'categorymembers' => ApiQueryCategoryMembers::class,
- 'deletedrevs' => ApiQueryDeletedrevs::class,
+ 'deletedrevs' => [
+ 'class' => ApiQueryDeletedrevs::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'embeddedin' => ApiQueryBacklinks::class,
'exturlusage' => ApiQueryExtLinksUsage::class,
- 'filearchive' => ApiQueryFilearchive::class,
+ 'filearchive' => [
+ 'class' => ApiQueryFilearchive::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'imageusage' => ApiQueryBacklinks::class,
'iwbacklinks' => ApiQueryIWBacklinks::class,
'langbacklinks' => ApiQueryLangBacklinks::class,
- 'logevents' => ApiQueryLogEvents::class,
+ 'logevents' => [
+ 'class' => ApiQueryLogEvents::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'pageswithprop' => ApiQueryPagesWithProp::class,
'pagepropnames' => ApiQueryPagePropNames::class,
'prefixsearch' => ApiQueryPrefixSearch::class,
- 'protectedtitles' => ApiQueryProtectedTitles::class,
+ 'protectedtitles' => [
+ 'class' => ApiQueryProtectedTitles::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'querypage' => ApiQueryQueryPage::class,
'random' => ApiQueryRandom::class,
- 'recentchanges' => ApiQueryRecentChanges::class,
+ 'recentchanges' => [
+ 'class' => ApiQueryRecentChanges::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'search' => ApiQuerySearch::class,
'tags' => ApiQueryTags::class,
'usercontribs' => [
'class' => ApiQueryUserContribs::class,
'services' => [
+ 'CommentStore',
'UserIdentityLookup',
],
],
'users' => ApiQueryUsers::class,
- 'watchlist' => ApiQueryWatchlist::class,
+ 'watchlist' => [
+ 'class' => ApiQueryWatchlist::class,
+ 'services' => [
+ 'CommentStore',
+ ],
+ ],
'watchlistraw' => ApiQueryWatchlistRaw::class,
];
diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php
index e3bffafcf64a..e56079160412 100644
--- a/includes/api/ApiQueryBlocks.php
+++ b/includes/api/ApiQueryBlocks.php
@@ -35,23 +35,28 @@ class ApiQueryBlocks extends ApiQueryBase {
/** @var BlockRestrictionStore */
private $blockRestrictionStore;
+ /** @var CommentStore */
+ private $commentStore;
+
/**
* @param ApiQuery $query
* @param string $moduleName
* @param BlockRestrictionStore $blockRestrictionStore
+ * @param CommentStore $commentStore
*/
public function __construct(
ApiQuery $query,
$moduleName,
- BlockRestrictionStore $blockRestrictionStore
+ BlockRestrictionStore $blockRestrictionStore,
+ CommentStore $commentStore
) {
parent::__construct( $query, $moduleName, 'bk' );
$this->blockRestrictionStore = $blockRestrictionStore;
+ $this->commentStore = $commentStore;
}
public function execute() {
$db = $this->getDB();
- $commentStore = CommentStore::getStore();
$params = $this->extractRequestParams();
$this->requireMaxOneParameter( $params, 'users', 'ip' );
@@ -88,7 +93,7 @@ class ApiQueryBlocks extends ApiQueryBase {
$this->addFieldsIf( 'ipb_sitewide', $fld_restrictions );
if ( $fld_reason ) {
- $commentQuery = $commentStore->getJoin( 'ipb_reason' );
+ $commentQuery = $this->commentStore->getJoin( 'ipb_reason' );
$this->addTables( $commentQuery['tables'] );
$this->addFields( $commentQuery['fields'] );
$this->addJoinConds( $commentQuery['joins'] );
@@ -237,7 +242,7 @@ class ApiQueryBlocks extends ApiQueryBase {
$block['expiry'] = ApiResult::formatExpiry( $row->ipb_expiry );
}
if ( $fld_reason ) {
- $block['reason'] = $commentStore->getComment( 'ipb_reason', $row )->text;
+ $block['reason'] = $this->commentStore->getComment( 'ipb_reason', $row )->text;
}
if ( $fld_range && !$row->ipb_auto ) {
$block['rangestart'] = IPUtils::formatHex( $row->ipb_range_start );
diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php
index e8a4013a21f4..7dc5e831d2bc 100644
--- a/includes/api/ApiQueryDeletedrevs.php
+++ b/includes/api/ApiQueryDeletedrevs.php
@@ -36,8 +36,21 @@ use Wikimedia\ParamValidator\TypeDef\IntegerDef;
*/
class ApiQueryDeletedrevs extends ApiQueryBase {
- public function __construct( ApiQuery $query, $moduleName ) {
+ /** @var CommentStore */
+ private $commentStore;
+
+ /**
+ * @param ApiQuery $query
+ * @param string $moduleName
+ * @param CommentStore $commentStore
+ */
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'dr' );
+ $this->commentStore = $commentStore;
}
public function execute() {
@@ -48,7 +61,6 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
$user = $this->getUser();
$db = $this->getDB();
- $commentStore = CommentStore::getStore();
$params = $this->extractRequestParams( false );
$prop = array_flip( $params['prop'] );
$fld_parentid = isset( $prop['parentid'] );
@@ -321,7 +333,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase {
RevisionRecord::DELETED_COMMENT,
$user
) ) {
- $comment = $commentStore->getComment( 'ar_comment', $row )->text;
+ $comment = $this->commentStore->getComment( 'ar_comment', $row )->text;
if ( $fld_comment ) {
$rev['comment'] = $comment;
}
diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php
index 2e3f6cc26bce..5b04e9ea1407 100644
--- a/includes/api/ApiQueryFilearchive.php
+++ b/includes/api/ApiQueryFilearchive.php
@@ -33,14 +33,26 @@ use MediaWiki\Revision\RevisionRecord;
*/
class ApiQueryFilearchive extends ApiQueryBase {
- public function __construct( ApiQuery $query, $moduleName ) {
+ /** @var CommentStore */
+ private $commentStore;
+
+ /**
+ * @param ApiQuery $query
+ * @param string $moduleName
+ * @param CommentStore $commentStore
+ */
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'fa' );
+ $this->commentStore = $commentStore;
}
public function execute() {
$user = $this->getUser();
$db = $this->getDB();
- $commentStore = CommentStore::getStore();
$params = $this->extractRequestParams();
@@ -162,7 +174,7 @@ class ApiQueryFilearchive extends ApiQueryBase {
if ( $fld_description &&
RevisionRecord::userCanBitfield( $row->fa_deleted, File::DELETED_COMMENT, $user )
) {
- $file['description'] = $commentStore->getComment( 'fa_description', $row )->text;
+ $file['description'] = $this->commentStore->getComment( 'fa_description', $row )->text;
if ( isset( $prop['parseddescription'] ) ) {
$file['parseddescription'] = Linker::formatComment(
$file['description'], $title );
diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php
index 228d008e8221..79419af15a87 100644
--- a/includes/api/ApiQueryLogEvents.php
+++ b/includes/api/ApiQueryLogEvents.php
@@ -34,8 +34,18 @@ class ApiQueryLogEvents extends ApiQueryBase {
/** @var CommentStore */
private $commentStore;
- public function __construct( ApiQuery $query, $moduleName ) {
+ /**
+ * @param ApiQuery $query
+ * @param string $moduleName
+ * @param CommentStore $commentStore
+ */
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'le' );
+ $this->commentStore = $commentStore;
}
private $fld_ids = false, $fld_title = false, $fld_type = false,
@@ -46,7 +56,6 @@ class ApiQueryLogEvents extends ApiQueryBase {
public function execute() {
$params = $this->extractRequestParams();
$db = $this->getDB();
- $this->commentStore = CommentStore::getStore();
$this->requireMaxOneParameter( $params, 'title', 'prefix', 'namespace' );
$prop = array_flip( $params['prop'] );
diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php
index e330244524c4..bc77c8f05e8d 100644
--- a/includes/api/ApiQueryProtectedTitles.php
+++ b/includes/api/ApiQueryProtectedTitles.php
@@ -27,12 +27,21 @@
*/
class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
+ /** @var CommentStore */
+ private $commentStore;
+
/**
* @param ApiQuery $query
* @param string $moduleName
+ * @param CommentStore $commentStore
*/
- public function __construct( ApiQuery $query, $moduleName ) {
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'pt' );
+ $this->commentStore = $commentStore;
}
public function execute() {
@@ -59,8 +68,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
$this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
if ( isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ) {
- $commentStore = CommentStore::getStore();
- $commentQuery = $commentStore->getJoin( 'pt_reason' );
+ $commentQuery = $this->commentStore->getJoin( 'pt_reason' );
$this->addTables( $commentQuery['tables'] );
$this->addFields( $commentQuery['fields'] );
$this->addJoinConds( $commentQuery['joins'] );
@@ -138,12 +146,12 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
}
if ( isset( $prop['comment'] ) ) {
- $vals['comment'] = $commentStore->getComment( 'pt_reason', $row )->text;
+ $vals['comment'] = $this->commentStore->getComment( 'pt_reason', $row )->text;
}
if ( isset( $prop['parsedcomment'] ) ) {
$vals['parsedcomment'] = Linker::formatComment(
- $commentStore->getComment( 'pt_reason', $row )->text
+ $this->commentStore->getComment( 'pt_reason', $row )->text
);
}
diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php
index 44b870e97ecc..a0a3b252769e 100644
--- a/includes/api/ApiQueryRecentChanges.php
+++ b/includes/api/ApiQueryRecentChanges.php
@@ -33,17 +33,23 @@ use MediaWiki\Storage\NameTableAccessException;
*/
class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
+ /** @var CommentStore */
+ private $commentStore;
+
/**
* @param ApiQuery $query
* @param string $moduleName
+ * @param CommentStore $commentStore
*/
- public function __construct( ApiQuery $query, $moduleName ) {
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'rc' );
+ $this->commentStore = $commentStore;
}
- /** @var CommentStore */
- private $commentStore;
-
private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
$fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
$fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
@@ -394,7 +400,6 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
$this->token = $params['token'];
if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
- $this->commentStore = CommentStore::getStore();
$commentQuery = $this->commentStore->getJoin( 'rc_comment' );
$this->addTables( $commentQuery['tables'] );
$this->addFields( $commentQuery['fields'] );
diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php
index 2e834987fee0..07a3ae624d0f 100644
--- a/includes/api/ApiQueryUserContribs.php
+++ b/includes/api/ApiQueryUserContribs.php
@@ -35,23 +35,31 @@ use Wikimedia\Rdbms\SelectQueryBuilder;
*/
class ApiQueryUserContribs extends ApiQueryBase {
+ /** @var CommentStore */
+ private $commentStore;
+
/** @var UserIdentityLookup */
private $userIdentityLookup;
+ /**
+ * @param ApiQuery $query
+ * @param string $moduleName
+ * @param CommentStore $commentStore
+ * @param UserIdentityLookup $userIdentityLookup
+ */
public function __construct(
ApiQuery $query,
$moduleName,
+ CommentStore $commentStore,
UserIdentityLookup $userIdentityLookup
) {
parent::__construct( $query, $moduleName, 'uc' );
+ $this->commentStore = $commentStore;
$this->userIdentityLookup = $userIdentityLookup;
}
private $params, $multiUserMode, $orderBy, $parentLens;
- /** @var CommentStore */
- private $commentStore;
-
private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
$fld_comment = false, $fld_parsedcomment = false, $fld_flags = false,
$fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false;
@@ -60,8 +68,6 @@ class ApiQueryUserContribs extends ApiQueryBase {
// Parse some parameters
$this->params = $this->extractRequestParams();
- $this->commentStore = CommentStore::getStore();
-
$prop = array_flip( $this->params['prop'] );
$this->fld_ids = isset( $prop['ids'] );
$this->fld_title = isset( $prop['title'] );
diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php
index 88be90bfffbc..c7476583ab9b 100644
--- a/includes/api/ApiQueryWatchlist.php
+++ b/includes/api/ApiQueryWatchlist.php
@@ -39,9 +39,15 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
/**
* @param ApiQuery $query
* @param string $moduleName
+ * @param CommentStore $commentStore
*/
- public function __construct( ApiQuery $query, $moduleName ) {
+ public function __construct(
+ ApiQuery $query,
+ $moduleName,
+ CommentStore $commentStore
+ ) {
parent::__construct( $query, $moduleName, 'wl' );
+ $this->commentStore = $commentStore;
}
public function execute() {
@@ -94,10 +100,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase {
if ( $this->fld_patrol && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
$this->dieWithError( 'apierror-permissiondenied-patrolflag', 'patrol' );
}
-
- if ( $this->fld_comment || $this->fld_parsedcomment ) {
- $this->commentStore = CommentStore::getStore();
- }
}
$options = [