Use injection for LinksMigration on LinkBatch, action, api, special page
Even the service does not long stay in that classes, it should be injected to avoid global state Bug: T304780 Change-Id: Ib488037f5a6966ab61042ed3cd889ddc50f1ba8e
This commit is contained in:
parent
e47c441078
commit
d79fd02d4b
21 changed files with 173 additions and 61 deletions
|
|
@ -820,6 +820,7 @@ return [
|
|||
$services->getContentLanguage(),
|
||||
$services->getGenderCache(),
|
||||
$services->getDBLoadBalancer(),
|
||||
$services->getLinksMigration(),
|
||||
LoggerFactory::getInstance( 'LinkBatch' )
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ class ActionFactory {
|
|||
'WatchedItemStore',
|
||||
'RedirectLookup',
|
||||
'RestrictionStore',
|
||||
'LinksMigration',
|
||||
'MainConfig'
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use MediaWiki\HookContainer\HookContainer;
|
|||
use MediaWiki\HookContainer\HookRunner;
|
||||
use MediaWiki\Languages\LanguageNameUtils;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageIdentity;
|
||||
|
|
@ -90,6 +91,9 @@ class InfoAction extends FormlessAction {
|
|||
/** @var RestrictionStore */
|
||||
private $restrictionStore;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/** @var int */
|
||||
private $actorTableSchemaMigrationStage;
|
||||
|
||||
|
|
@ -111,6 +115,7 @@ class InfoAction extends FormlessAction {
|
|||
* @param WatchedItemStoreInterface $watchedItemStore
|
||||
* @param RedirectLookup $redirectLookup
|
||||
* @param RestrictionStore $restrictionStore
|
||||
* @param LinksMigration $linksMigration
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -131,6 +136,7 @@ class InfoAction extends FormlessAction {
|
|||
WatchedItemStoreInterface $watchedItemStore,
|
||||
RedirectLookup $redirectLookup,
|
||||
RestrictionStore $restrictionStore,
|
||||
LinksMigration $linksMigration,
|
||||
Config $config
|
||||
) {
|
||||
parent::__construct( $page, $context );
|
||||
|
|
@ -149,6 +155,7 @@ class InfoAction extends FormlessAction {
|
|||
$this->watchedItemStore = $watchedItemStore;
|
||||
$this->redirectLookup = $redirectLookup;
|
||||
$this->restrictionStore = $restrictionStore;
|
||||
$this->linksMigration = $linksMigration;
|
||||
$this->actorTableSchemaMigrationStage = $config->get( MainConfigNames::ActorTableSchemaMigrationStage );
|
||||
}
|
||||
|
||||
|
|
@ -1049,11 +1056,10 @@ class InfoAction extends FormlessAction {
|
|||
if ( $config->get( MainConfigNames::MiserMode ) ) {
|
||||
$result['transclusion']['to'] = 0;
|
||||
} else {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$result['transclusion']['to'] = (int)$dbr->selectField(
|
||||
'templatelinks',
|
||||
'COUNT(tl_from)',
|
||||
$linksMigration->getLinksConditions( 'templatelinks', $title ),
|
||||
$this->linksMigration->getLinksConditions( 'templatelinks', $title ),
|
||||
$fname
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,10 @@ class ApiQuery extends ApiBase {
|
|||
],
|
||||
'fileusage' => [
|
||||
'class' => ApiQueryBacklinksprop::class,
|
||||
'services' => [
|
||||
// Same as for linkshere, redirects, transcludedin
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'images' => [
|
||||
'class' => ApiQueryImages::class,
|
||||
|
|
@ -106,16 +110,23 @@ class ApiQuery extends ApiBase {
|
|||
'WatchedItemStore',
|
||||
'LanguageConverterFactory',
|
||||
'RestrictionStore',
|
||||
'LinksMigration',
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
'class' => ApiQueryLinks::class,
|
||||
'services' => [
|
||||
// Same as for templates
|
||||
'LinkBatchFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'linkshere' => [
|
||||
'class' => ApiQueryBacklinksprop::class,
|
||||
'services' => [
|
||||
// Same as for fileusage, redirects, transcludedin
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'iwlinks' => [
|
||||
'class' => ApiQueryIWLinks::class,
|
||||
|
|
@ -135,6 +146,10 @@ class ApiQuery extends ApiBase {
|
|||
],
|
||||
'redirects' => [
|
||||
'class' => ApiQueryBacklinksprop::class,
|
||||
'services' => [
|
||||
// Same as for fileusage, linkshere, transcludedin
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'revisions' => [
|
||||
'class' => ApiQueryRevisions::class,
|
||||
|
|
@ -161,11 +176,17 @@ class ApiQuery extends ApiBase {
|
|||
'templates' => [
|
||||
'class' => ApiQueryLinks::class,
|
||||
'services' => [
|
||||
// Same as for links
|
||||
'LinkBatchFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'transcludedin' => [
|
||||
'class' => ApiQueryBacklinksprop::class,
|
||||
'services' => [
|
||||
// Same as for fileusage, linkshere, redirects
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
|
|
@ -195,6 +216,7 @@ class ApiQuery extends ApiBase {
|
|||
// Same as for alllinks, allredirects, alltransclusions
|
||||
'NamespaceInfo',
|
||||
'GenderCache',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'allimages' => [
|
||||
|
|
@ -210,6 +232,7 @@ class ApiQuery extends ApiBase {
|
|||
// Same as for allfileusages, allredirects, alltransclusions
|
||||
'NamespaceInfo',
|
||||
'GenderCache',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'allpages' => [
|
||||
|
|
@ -226,6 +249,7 @@ class ApiQuery extends ApiBase {
|
|||
// Same as for allfileusages, alllinks, alltransclusions
|
||||
'NamespaceInfo',
|
||||
'GenderCache',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'allrevisions' => [
|
||||
|
|
@ -250,6 +274,7 @@ class ApiQuery extends ApiBase {
|
|||
// Same as for allfileusages, alllinks, allredirects
|
||||
'NamespaceInfo',
|
||||
'GenderCache',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'allusers' => [
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Query module to enumerate links from all pages together.
|
||||
|
|
@ -51,12 +50,14 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
|
|||
* @param string $moduleName
|
||||
* @param NamespaceInfo $namespaceInfo
|
||||
* @param GenderCache $genderCache
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ApiQuery $query,
|
||||
$moduleName,
|
||||
NamespaceInfo $namespaceInfo,
|
||||
GenderCache $genderCache
|
||||
GenderCache $genderCache,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
switch ( $moduleName ) {
|
||||
case 'alllinks':
|
||||
|
|
@ -100,6 +101,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
|
|||
parent::__construct( $query, $moduleName, $prefix );
|
||||
$this->namespaceInfo = $namespaceInfo;
|
||||
$this->genderCache = $genderCache;
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
|
|
@ -121,7 +123,6 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
|
|||
private function run( $resultPageSet = null ) {
|
||||
$db = $this->getDB();
|
||||
$params = $this->extractRequestParams();
|
||||
$this->linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
|
||||
$pfx = $this->tablePrefix;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
* @since 1.24
|
||||
*/
|
||||
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* This implements prop=redirects, prop=linkshere, prop=catmembers,
|
||||
|
|
@ -78,12 +78,21 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|||
],
|
||||
];
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ApiQuery $query
|
||||
* @param string $moduleName
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct( ApiQuery $query, $moduleName ) {
|
||||
public function __construct(
|
||||
ApiQuery $query,
|
||||
$moduleName,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( $query, $moduleName, self::$settings[$moduleName]['code'] );
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
|
|
@ -108,7 +117,6 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|||
$pageSet = $this->getPageSet();
|
||||
$titles = $pageSet->getGoodAndMissingPages();
|
||||
$map = $pageSet->getGoodAndMissingTitlesByNamespace();
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
|
||||
// Add in special pages, they can theoretically have backlinks too.
|
||||
// (although currently they only do for prop=redirects)
|
||||
|
|
@ -121,8 +129,8 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|||
$p = $settings['prefix'];
|
||||
$hasNS = !isset( $settings['to_namespace'] );
|
||||
if ( $hasNS ) {
|
||||
if ( isset( $linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
list( $bl_namespace, $bl_title ) = $linksMigration->getTitleFields( $settings['linktable'] );
|
||||
if ( isset( $this->linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
list( $bl_namespace, $bl_title ) = $this->linksMigration->getTitleFields( $settings['linktable'] );
|
||||
} else {
|
||||
$bl_namespace = "{$p}_namespace";
|
||||
$bl_title = "{$p}_title";
|
||||
|
|
@ -216,9 +224,9 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|||
|
||||
// Populate the rest of the query
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
if ( isset( $linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
if ( isset( $this->linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
$queryInfo = $linksMigration->getQueryInfo( $settings['linktable'] );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( $settings['linktable'] );
|
||||
$this->addTables( array_merge( [ 'page' ], $queryInfo['tables'] ) );
|
||||
$this->addJoinConds( $queryInfo['joins'] );
|
||||
} else {
|
||||
|
|
@ -294,7 +302,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase {
|
|||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
$this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxWithFromNS ] );
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
} elseif ( !isset( $linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
} elseif ( !isset( $this->linksMigration::$mapping[$settings['linktable']] ) ) {
|
||||
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset False positive
|
||||
$this->addOption( 'USE INDEX', [ $settings['linktable'] => $idxNoFromNS ] );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@
|
|||
*/
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\ParamValidator\TypeDef\TitleDef;
|
||||
use MediaWiki\Permissions\PermissionStatus;
|
||||
use MediaWiki\Permissions\RestrictionStore;
|
||||
|
|
@ -49,6 +49,8 @@ class ApiQueryInfo extends ApiQueryBase {
|
|||
private $watchedItemStore;
|
||||
/** @var RestrictionStore */
|
||||
private $restrictionStore;
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
private $fld_protection = false, $fld_talkid = false,
|
||||
$fld_subjectid = false, $fld_url = false,
|
||||
|
|
@ -110,6 +112,7 @@ class ApiQueryInfo extends ApiQueryBase {
|
|||
* @param WatchedItemStore $watchedItemStore
|
||||
* @param LanguageConverterFactory $languageConverterFactory
|
||||
* @param RestrictionStore $restrictionStore
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ApiQuery $queryModule,
|
||||
|
|
@ -121,7 +124,8 @@ class ApiQueryInfo extends ApiQueryBase {
|
|||
TitleFormatter $titleFormatter,
|
||||
WatchedItemStore $watchedItemStore,
|
||||
LanguageConverterFactory $languageConverterFactory,
|
||||
RestrictionStore $restrictionStore
|
||||
RestrictionStore $restrictionStore,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( $queryModule, $moduleName, 'in' );
|
||||
$this->languageConverter = $languageConverterFactory->getLanguageConverter( $contentLanguage );
|
||||
|
|
@ -131,6 +135,7 @@ class ApiQueryInfo extends ApiQueryBase {
|
|||
$this->titleFormatter = $titleFormatter;
|
||||
$this->watchedItemStore = $watchedItemStore;
|
||||
$this->restrictionStore = $restrictionStore;
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -528,9 +533,8 @@ class ApiQueryInfo extends ApiQueryBase {
|
|||
array_values( $this->restrictionStore->listApplicableRestrictionTypes( $title ) );
|
||||
}
|
||||
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
list( $blNamespace, $blTitle ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $blNamespace, $blTitle ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
|
||||
|
||||
if ( count( $others ) ) {
|
||||
// Non-images: check templatelinks
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
|
||||
/**
|
||||
* A query module to list all wiki links on a given set of pages.
|
||||
|
|
@ -38,15 +38,20 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
|
|||
/** @var LinkBatchFactory */
|
||||
private $linkBatchFactory;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ApiQuery $query
|
||||
* @param string $moduleName
|
||||
* @param LinkBatchFactory $linkBatchFactory
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ApiQuery $query,
|
||||
$moduleName,
|
||||
LinkBatchFactory $linkBatchFactory
|
||||
LinkBatchFactory $linkBatchFactory,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
switch ( $moduleName ) {
|
||||
case self::LINKS:
|
||||
|
|
@ -67,6 +72,7 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
|
|||
|
||||
parent::__construct( $query, $moduleName, $this->prefix );
|
||||
$this->linkBatchFactory = $linkBatchFactory;
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
|
|
@ -89,13 +95,12 @@ class ApiQueryLinks extends ApiQueryGeneratorBase {
|
|||
if ( $pages === [] ) {
|
||||
return; // nothing to do
|
||||
}
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
|
||||
$params = $this->extractRequestParams();
|
||||
|
||||
if ( isset( $linksMigration::$mapping[$this->table] ) ) {
|
||||
list( $nsField, $titleField ) = $linksMigration->getTitleFields( $this->table );
|
||||
$queryInfo = $linksMigration->getQueryInfo( $this->table );
|
||||
if ( isset( $this->linksMigration::$mapping[$this->table] ) ) {
|
||||
list( $nsField, $titleField ) = $this->linksMigration->getTitleFields( $this->table );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( $this->table );
|
||||
$this->addTables( $queryInfo['tables'] );
|
||||
$this->addJoinConds( $queryInfo['joins'] );
|
||||
} else {
|
||||
|
|
|
|||
14
includes/cache/LinkBatch.php
vendored
14
includes/cache/LinkBatch.php
vendored
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Cache\CacheKeyHelper;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
|
@ -81,6 +82,9 @@ class LinkBatch {
|
|||
*/
|
||||
private $loadBalancer;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
|
|
@ -91,6 +95,7 @@ class LinkBatch {
|
|||
* @param Language|null $contentLanguage
|
||||
* @param GenderCache|null $genderCache
|
||||
* @param ILoadBalancer|null $loadBalancer
|
||||
* @param LinksMigration|null $linksMigration
|
||||
* @param LoggerInterface|null $logger
|
||||
* @deprecated since 1.35 Use makeLinkBatch of the LinkBatchFactory service instead
|
||||
*/
|
||||
|
|
@ -101,6 +106,7 @@ class LinkBatch {
|
|||
?Language $contentLanguage = null,
|
||||
?GenderCache $genderCache = null,
|
||||
?ILoadBalancer $loadBalancer = null,
|
||||
?LinksMigration $linksMigration = null,
|
||||
?LoggerInterface $logger = null
|
||||
) {
|
||||
$getServices = static function () {
|
||||
|
|
@ -113,6 +119,7 @@ class LinkBatch {
|
|||
$this->contentLanguage = $contentLanguage ?? $getServices()->getContentLanguage();
|
||||
$this->genderCache = $genderCache ?? $getServices()->getGenderCache();
|
||||
$this->loadBalancer = $loadBalancer ?? $getServices()->getDBLoadBalancer();
|
||||
$this->linksMigration = $linksMigration ?? $getServices()->getLinksMigration();
|
||||
$this->logger = $logger ?? LoggerFactory::getInstance( 'LinkBatch' );
|
||||
|
||||
foreach ( $arr as $item ) {
|
||||
|
|
@ -370,10 +377,9 @@ class LinkBatch {
|
|||
* @return string|bool String with SQL where clause fragment, or false if no items.
|
||||
*/
|
||||
public function constructSet( $prefix, $db ) {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
if ( isset( $linksMigration::$prefixToTableMapping[$prefix] ) ) {
|
||||
list( $blNamespace, $blTitle ) = $linksMigration->getTitleFields(
|
||||
$linksMigration::$prefixToTableMapping[$prefix]
|
||||
if ( isset( $this->linksMigration::$prefixToTableMapping[$prefix] ) ) {
|
||||
list( $blNamespace, $blTitle ) = $this->linksMigration->getTitleFields(
|
||||
$this->linksMigration::$prefixToTableMapping[$prefix]
|
||||
);
|
||||
} else {
|
||||
$blNamespace = "{$prefix}_namespace";
|
||||
|
|
|
|||
7
includes/cache/LinkBatchFactory.php
vendored
7
includes/cache/LinkBatchFactory.php
vendored
|
|
@ -27,6 +27,7 @@ use GenderCache;
|
|||
use Language;
|
||||
use LinkBatch;
|
||||
use LinkCache;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Page\PageReference;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
@ -64,6 +65,9 @@ class LinkBatchFactory {
|
|||
*/
|
||||
private $loadBalancer;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
|
|
@ -73,6 +77,7 @@ class LinkBatchFactory {
|
|||
Language $contentLanguage,
|
||||
GenderCache $genderCache,
|
||||
ILoadBalancer $loadBalancer,
|
||||
LinksMigration $linksMigration,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->linkCache = $linkCache;
|
||||
|
|
@ -80,6 +85,7 @@ class LinkBatchFactory {
|
|||
$this->contentLanguage = $contentLanguage;
|
||||
$this->genderCache = $genderCache;
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->linksMigration = $linksMigration;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +102,7 @@ class LinkBatchFactory {
|
|||
$this->contentLanguage,
|
||||
$this->genderCache,
|
||||
$this->loadBalancer,
|
||||
$this->linksMigration,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ class SpecialPageFactory {
|
|||
'DBLoadBalancer',
|
||||
'LinkBatchFactory',
|
||||
'LanguageConverterFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'Fewestrevisions' => [
|
||||
|
|
@ -219,6 +220,7 @@ class SpecialPageFactory {
|
|||
'class' => \SpecialUnusedTemplates::class,
|
||||
'services' => [
|
||||
'DBLoadBalancer',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'Unwatchedpages' => [
|
||||
|
|
@ -257,6 +259,7 @@ class SpecialPageFactory {
|
|||
'services' => [
|
||||
'DBLoadBalancer',
|
||||
'LinkBatchFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
|
||||
|
|
@ -740,6 +743,7 @@ class SpecialPageFactory {
|
|||
'services' => [
|
||||
'DBLoadBalancer',
|
||||
'LinkBatchFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'Mostcategories' => [
|
||||
|
|
@ -775,6 +779,7 @@ class SpecialPageFactory {
|
|||
'DBLoadBalancer',
|
||||
'WikiExporterFactory',
|
||||
'TitleFormatter',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'Import' => [
|
||||
|
|
@ -811,6 +816,7 @@ class SpecialPageFactory {
|
|||
'SearchEngineFactory',
|
||||
'NamespaceInfo',
|
||||
'TitleFactory',
|
||||
'LinksMigration',
|
||||
]
|
||||
],
|
||||
'MergeHistory' => [
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Export\WikiExporterFactory;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
|
|
@ -46,20 +46,26 @@ class SpecialExport extends SpecialPage {
|
|||
/** @var TitleFormatter */
|
||||
private $titleFormatter;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param WikiExporterFactory $wikiExporterFactory
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ILoadBalancer $loadBalancer,
|
||||
WikiExporterFactory $wikiExporterFactory,
|
||||
TitleFormatter $titleFormatter
|
||||
TitleFormatter $titleFormatter,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Export' );
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->wikiExporterFactory = $wikiExporterFactory;
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function execute( $par ) {
|
||||
|
|
@ -498,9 +504,8 @@ class SpecialExport extends SpecialPage {
|
|||
* @return array Associative array index by titles
|
||||
*/
|
||||
protected function getTemplates( $inputPages, $pageSet ) {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
list( $nsField, $titleField ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $nsField, $titleField ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
|
||||
return $this->getLinks( $inputPages, $pageSet,
|
||||
$queryInfo['tables'],
|
||||
[ 'namespace' => $nsField, 'title' => $titleField ],
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
|
|
@ -37,23 +37,29 @@ class SpecialLonelyPages extends PageQueryPage {
|
|||
/** @var NamespaceInfo */
|
||||
private $namespaceInfo;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param NamespaceInfo $namespaceInfo
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param LinkBatchFactory $linkBatchFactory
|
||||
* @param LanguageConverterFactory $languageConverterFactory
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
NamespaceInfo $namespaceInfo,
|
||||
ILoadBalancer $loadBalancer,
|
||||
LinkBatchFactory $linkBatchFactory,
|
||||
LanguageConverterFactory $languageConverterFactory
|
||||
LanguageConverterFactory $languageConverterFactory,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Lonelypages' );
|
||||
$this->namespaceInfo = $namespaceInfo;
|
||||
$this->setDBLoadBalancer( $loadBalancer );
|
||||
$this->setLinkBatchFactory( $linkBatchFactory );
|
||||
$this->setLanguageConverter( $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() ) );
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
protected function getPageHeader() {
|
||||
|
|
@ -73,13 +79,12 @@ class SpecialLonelyPages extends PageQueryPage {
|
|||
}
|
||||
|
||||
public function getQueryInfo() {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$queryInfo = $linksMigration->getQueryInfo(
|
||||
$queryInfo = $this->linksMigration->getQueryInfo(
|
||||
'templatelinks',
|
||||
'templatelinks',
|
||||
'LEFT JOIN'
|
||||
);
|
||||
list( $ns, $title ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
list( $ns, $title ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
$tables = array_merge( [ 'page', 'pagelinks' ], $queryInfo['tables'] );
|
||||
$conds = [
|
||||
'pl_namespace IS NULL',
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
use Wikimedia\Rdbms\IResultWrapper;
|
||||
|
|
@ -36,17 +36,23 @@ use Wikimedia\Rdbms\IResultWrapper;
|
|||
*/
|
||||
class SpecialMostLinkedTemplates extends QueryPage {
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param LinkBatchFactory $linkBatchFactory
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ILoadBalancer $loadBalancer,
|
||||
LinkBatchFactory $linkBatchFactory
|
||||
LinkBatchFactory $linkBatchFactory,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Mostlinkedtemplates' );
|
||||
$this->setDBLoadBalancer( $loadBalancer );
|
||||
$this->setLinkBatchFactory( $linkBatchFactory );
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,9 +83,8 @@ class SpecialMostLinkedTemplates extends QueryPage {
|
|||
}
|
||||
|
||||
public function getQueryInfo() {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$queryInfo = $linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $ns, $title ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $ns, $title ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
return [
|
||||
'tables' => $queryInfo['tables'],
|
||||
'fields' => [
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
* @author Rob Church <robchur@gmail.com>
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
|
|
@ -34,12 +34,20 @@ use Wikimedia\Rdbms\ILoadBalancer;
|
|||
*/
|
||||
class SpecialUnusedTemplates extends QueryPage {
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct( ILoadBalancer $loadBalancer ) {
|
||||
public function __construct(
|
||||
ILoadBalancer $loadBalancer,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Unusedtemplates' );
|
||||
$this->setDBLoadBalancer( $loadBalancer );
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function isExpensive() {
|
||||
|
|
@ -59,13 +67,12 @@ class SpecialUnusedTemplates extends QueryPage {
|
|||
}
|
||||
|
||||
public function getQueryInfo() {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$queryInfo = $linksMigration->getQueryInfo(
|
||||
$queryInfo = $this->linksMigration->getQueryInfo(
|
||||
'templatelinks',
|
||||
'templatelinks',
|
||||
'LEFT JOIN'
|
||||
);
|
||||
list( $ns, $title ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
list( $ns, $title ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
$joinConds = [];
|
||||
$templatelinksJoin = [
|
||||
'LEFT JOIN', [ "$title = page_title",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
|
|
@ -37,23 +37,28 @@ use Wikimedia\Rdbms\ILoadBalancer;
|
|||
*/
|
||||
class SpecialWantedTemplates extends WantedQueryPage {
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
/**
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param LinkBatchFactory $linkBatchFactory
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ILoadBalancer $loadBalancer,
|
||||
LinkBatchFactory $linkBatchFactory
|
||||
LinkBatchFactory $linkBatchFactory,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Wantedtemplates' );
|
||||
$this->setDBLoadBalancer( $loadBalancer );
|
||||
$this->setLinkBatchFactory( $linkBatchFactory );
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function getQueryInfo() {
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$queryInfo = $linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $ns, $title ) = $linksMigration->getTitleFields( 'templatelinks' );
|
||||
$queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' );
|
||||
list( $ns, $title ) = $this->linksMigration->getTitleFields( 'templatelinks' );
|
||||
return [
|
||||
'tables' => array_merge( $queryInfo['tables'], [ 'page' ] ),
|
||||
'fields' => [
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
use Wikimedia\Rdbms\SelectQueryBuilder;
|
||||
|
|
@ -61,6 +61,9 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
|
|||
/** @var TitleFactory */
|
||||
private $titleFactory;
|
||||
|
||||
/** @var LinksMigration */
|
||||
private $linksMigration;
|
||||
|
||||
protected $limits = [ 20, 50, 100, 250, 500 ];
|
||||
|
||||
/**
|
||||
|
|
@ -70,6 +73,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
|
|||
* @param SearchEngineFactory $searchEngineFactory
|
||||
* @param NamespaceInfo $namespaceInfo
|
||||
* @param TitleFactory $titleFactory
|
||||
* @param LinksMigration $linksMigration
|
||||
*/
|
||||
public function __construct(
|
||||
ILoadBalancer $loadBalancer,
|
||||
|
|
@ -77,7 +81,8 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
|
|||
IContentHandlerFactory $contentHandlerFactory,
|
||||
SearchEngineFactory $searchEngineFactory,
|
||||
NamespaceInfo $namespaceInfo,
|
||||
TitleFactory $titleFactory
|
||||
TitleFactory $titleFactory,
|
||||
LinksMigration $linksMigration
|
||||
) {
|
||||
parent::__construct( 'Whatlinkshere' );
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
|
|
@ -86,6 +91,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
|
|||
$this->searchEngineFactory = $searchEngineFactory;
|
||||
$this->namespaceInfo = $namespaceInfo;
|
||||
$this->titleFactory = $titleFactory;
|
||||
$this->linksMigration = $linksMigration;
|
||||
}
|
||||
|
||||
public function execute( $par ) {
|
||||
|
|
@ -228,8 +234,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
|
|||
'pl_namespace' => $target->getNamespace(),
|
||||
'pl_title' => $target->getDBkey(),
|
||||
];
|
||||
$linksMigration = MediaWikiServices::getInstance()->getLinksMigration();
|
||||
$conds['templatelinks'] = $linksMigration->getLinksConditions( 'templatelinks', $target );
|
||||
$conds['templatelinks'] = $this->linksMigration->getLinksConditions( 'templatelinks', $target );
|
||||
$conds['imagelinks'] = [
|
||||
'il_to' => $target->getDBkey(),
|
||||
];
|
||||
|
|
|
|||
13
tests/phpunit/includes/cache/LinkBatchTest.php
vendored
13
tests/phpunit/includes/cache/LinkBatchTest.php
vendored
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Cache\CacheKeyHelper;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Page\PageReference;
|
||||
use MediaWiki\Page\PageReferenceValue;
|
||||
|
|
@ -52,7 +53,8 @@ class LinkBatchTest extends MediaWikiIntegrationTestCase {
|
|||
$this->createMock( TitleFormatter::class ),
|
||||
$this->createMock( Language::class ),
|
||||
$this->createMock( GenderCache::class ),
|
||||
$this->createMock( ILoadBalancer::class )
|
||||
$this->createMock( ILoadBalancer::class ),
|
||||
$this->createMock( LinksMigration::class )
|
||||
);
|
||||
|
||||
$this->assertTrue( $batch->isEmpty() );
|
||||
|
|
@ -74,7 +76,8 @@ class LinkBatchTest extends MediaWikiIntegrationTestCase {
|
|||
$this->createMock( TitleFormatter::class ),
|
||||
$this->createMock( Language::class ),
|
||||
$this->createMock( GenderCache::class ),
|
||||
$this->createMock( ILoadBalancer::class )
|
||||
$this->createMock( ILoadBalancer::class ),
|
||||
$this->createMock( LinksMigration::class )
|
||||
);
|
||||
|
||||
$this->assertFalse( $batch->isEmpty() );
|
||||
|
|
@ -94,7 +97,8 @@ class LinkBatchTest extends MediaWikiIntegrationTestCase {
|
|||
$this->createMock( TitleFormatter::class ),
|
||||
$this->createMock( Language::class ),
|
||||
$this->createMock( GenderCache::class ),
|
||||
$this->getServiceContainer()->getDBLoadBalancer()
|
||||
$this->getServiceContainer()->getDBLoadBalancer(),
|
||||
$this->getServiceContainer()->getLinksMigration()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +255,8 @@ class LinkBatchTest extends MediaWikiIntegrationTestCase {
|
|||
$this->createMock( TitleFormatter::class ),
|
||||
$language,
|
||||
$genderCache,
|
||||
$this->createMock( ILoadBalancer::class )
|
||||
$this->createMock( ILoadBalancer::class ),
|
||||
$this->createMock( LinksMigration::class )
|
||||
);
|
||||
$batch->addObj(
|
||||
new TitleValue( NS_MAIN, 'Foo' )
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Linker\LinkTarget;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\Page\PageIdentityValue;
|
||||
|
|
@ -148,6 +149,7 @@ class WatchedItemStoreUnitTest extends MediaWikiIntegrationTestCase {
|
|||
$this->createMock( Language::class ),
|
||||
$this->createMock( GenderCache::class ),
|
||||
$this->getMockLoadBalancer( $mockDb ),
|
||||
$this->createMock( LinksMigration::class ),
|
||||
LoggerFactory::getInstance( 'LinkBatch' )
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -406,6 +406,7 @@ class CommentParserTest extends \MediaWikiIntegrationTestCase {
|
|||
$services->getContentLanguage(),
|
||||
$services->getGenderCache(),
|
||||
$fakeLB,
|
||||
$services->getLinksMigration(),
|
||||
LoggerFactory::getInstance( 'LinkBatch' )
|
||||
);
|
||||
$parser = new CommentParser(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Linker\LinksMigration;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\Page\PageReference;
|
||||
use MediaWiki\Page\PageReferenceValue;
|
||||
|
|
@ -40,6 +41,7 @@ class LinkBatchFactoryTest extends MediaWikiUnitTestCase {
|
|||
$this->createMock( Language::class ),
|
||||
$this->createMock( GenderCache::class ),
|
||||
$this->createMock( ILoadBalancer::class ),
|
||||
$this->createMock( LinksMigration::class ),
|
||||
LoggerFactory::getInstance( 'LinkBatch' )
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue