Convert MovePageFactory to interface, implement in PageHandlerFactory
Bug: T249446 Change-Id: I1335d976b992f44c8609c298f0ec19d81afa7b84
This commit is contained in:
parent
5acc9de773
commit
b14965e75e
6 changed files with 135 additions and 90 deletions
|
|
@ -22,7 +22,7 @@
|
|||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\MovePageFactory;
|
||||
use MediaWiki\Page\PageHandlerFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
|
|
@ -117,7 +117,7 @@ class MovePage {
|
|||
$this->oldTitle = $oldTitle;
|
||||
$this->newTitle = $newTitle;
|
||||
$this->options = $options ??
|
||||
new ServiceOptions( MovePageFactory::CONSTRUCTOR_OPTIONS,
|
||||
new ServiceOptions( PageHandlerFactory::CONSTRUCTOR_OPTIONS,
|
||||
MediaWikiServices::getInstance()->getMainConfig() );
|
||||
$this->loadBalancer =
|
||||
$loadBalancer ?? MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ use MediaWiki\Mail\IEmailer;
|
|||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Message\MessageFormatterFactory;
|
||||
use MediaWiki\Page\MovePageFactory;
|
||||
use MediaWiki\Page\PageHandlerFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Preferences\DefaultPreferencesFactory;
|
||||
use MediaWiki\Preferences\PreferencesFactory;
|
||||
|
|
@ -675,16 +676,7 @@ return [
|
|||
},
|
||||
|
||||
'MovePageFactory' => function ( MediaWikiServices $services ) : MovePageFactory {
|
||||
return new MovePageFactory(
|
||||
new ServiceOptions( MovePageFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
|
||||
$services->getDBLoadBalancer(),
|
||||
$services->getNamespaceInfo(),
|
||||
$services->getWatchedItemStore(),
|
||||
$services->getPermissionManager(),
|
||||
$services->getRepoGroup(),
|
||||
$services->getContentHandlerFactory(),
|
||||
$services->getRevisionStore()
|
||||
);
|
||||
return $services->getService( '_PageHandlerFactory' );
|
||||
},
|
||||
|
||||
'NamespaceInfo' => function ( MediaWikiServices $services ) : NamespaceInfo {
|
||||
|
|
@ -1177,6 +1169,19 @@ return [
|
|||
);
|
||||
},
|
||||
|
||||
'_PageHandlerFactory' => function ( MediaWikiServices $services ) : PageHandlerFactory {
|
||||
return new PageHandlerFactory(
|
||||
new ServiceOptions( PageHandlerFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
|
||||
$services->getDBLoadBalancer(),
|
||||
$services->getNamespaceInfo(),
|
||||
$services->getWatchedItemStore(),
|
||||
$services->getPermissionManager(),
|
||||
$services->getRepoGroup(),
|
||||
$services->getContentHandlerFactory(),
|
||||
$services->getRevisionStore()
|
||||
);
|
||||
},
|
||||
|
||||
'_SqlBlobStore' => function ( MediaWikiServices $services ) : SqlBlobStore {
|
||||
return $services->getBlobStoreFactory()->newSqlBlobStore();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -21,86 +21,18 @@
|
|||
|
||||
namespace MediaWiki\Page;
|
||||
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MovePage;
|
||||
use NamespaceInfo;
|
||||
use RepoGroup;
|
||||
use Title;
|
||||
use WatchedItemStoreInterface;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
* @since 1.34
|
||||
* @since 1.35
|
||||
*/
|
||||
class MovePageFactory {
|
||||
/** @var ServiceOptions */
|
||||
private $options;
|
||||
|
||||
/** @var ILoadBalancer */
|
||||
private $loadBalancer;
|
||||
|
||||
/** @var NamespaceInfo */
|
||||
private $nsInfo;
|
||||
|
||||
/** @var WatchedItemStoreInterface */
|
||||
private $watchedItems;
|
||||
|
||||
/** @var PermissionManager */
|
||||
private $permMgr;
|
||||
|
||||
/** @var RepoGroup */
|
||||
private $repoGroup;
|
||||
|
||||
/** @var IContentHandlerFactory */
|
||||
private $contentHandlerFactory;
|
||||
|
||||
/** @var RevisionStore */
|
||||
private $revisionStore;
|
||||
|
||||
public const CONSTRUCTOR_OPTIONS = [
|
||||
'CategoryCollation'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
ServiceOptions $options,
|
||||
ILoadBalancer $loadBalancer,
|
||||
NamespaceInfo $nsInfo,
|
||||
WatchedItemStoreInterface $watchedItems,
|
||||
PermissionManager $permMgr,
|
||||
RepoGroup $repoGroup,
|
||||
IContentHandlerFactory $contentHandlerFactory,
|
||||
RevisionStore $revisionStore
|
||||
) {
|
||||
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
||||
|
||||
$this->options = $options;
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->nsInfo = $nsInfo;
|
||||
$this->watchedItems = $watchedItems;
|
||||
$this->permMgr = $permMgr;
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->contentHandlerFactory = $contentHandlerFactory;
|
||||
$this->revisionStore = $revisionStore;
|
||||
}
|
||||
interface MovePageFactory {
|
||||
|
||||
/**
|
||||
* @param Title $from
|
||||
* @param Title $to
|
||||
* @return MovePage
|
||||
*/
|
||||
public function newMovePage( Title $from, Title $to ) : MovePage {
|
||||
return new MovePage( $from, $to,
|
||||
$this->options,
|
||||
$this->loadBalancer,
|
||||
$this->nsInfo,
|
||||
$this->watchedItems,
|
||||
$this->permMgr,
|
||||
$this->repoGroup,
|
||||
$this->contentHandlerFactory,
|
||||
$this->revisionStore
|
||||
);
|
||||
}
|
||||
public function newMovePage( Title $from, Title $to ) : MovePage;
|
||||
}
|
||||
|
|
|
|||
108
includes/page/PageHandlerFactory.php
Normal file
108
includes/page/PageHandlerFactory.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Page;
|
||||
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MovePage;
|
||||
use NamespaceInfo;
|
||||
use RepoGroup;
|
||||
use Title;
|
||||
use WatchedItemStoreInterface;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
* Common factory to construct page handling classes.
|
||||
*
|
||||
* @since 1.35
|
||||
*/
|
||||
class PageHandlerFactory implements MovePageFactory {
|
||||
/** @var ServiceOptions */
|
||||
private $options;
|
||||
|
||||
/** @var ILoadBalancer */
|
||||
private $loadBalancer;
|
||||
|
||||
/** @var NamespaceInfo */
|
||||
private $nsInfo;
|
||||
|
||||
/** @var WatchedItemStoreInterface */
|
||||
private $watchedItems;
|
||||
|
||||
/** @var PermissionManager */
|
||||
private $permMgr;
|
||||
|
||||
/** @var RepoGroup */
|
||||
private $repoGroup;
|
||||
|
||||
/** @var IContentHandlerFactory */
|
||||
private $contentHandlerFactory;
|
||||
|
||||
/** @var RevisionStore */
|
||||
private $revisionStore;
|
||||
|
||||
public const CONSTRUCTOR_OPTIONS = [
|
||||
'CategoryCollation'
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
ServiceOptions $options,
|
||||
ILoadBalancer $loadBalancer,
|
||||
NamespaceInfo $nsInfo,
|
||||
WatchedItemStoreInterface $watchedItems,
|
||||
PermissionManager $permMgr,
|
||||
RepoGroup $repoGroup,
|
||||
IContentHandlerFactory $contentHandlerFactory,
|
||||
RevisionStore $revisionStore
|
||||
) {
|
||||
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
|
||||
|
||||
$this->options = $options;
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->nsInfo = $nsInfo;
|
||||
$this->watchedItems = $watchedItems;
|
||||
$this->permMgr = $permMgr;
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->contentHandlerFactory = $contentHandlerFactory;
|
||||
$this->revisionStore = $revisionStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Title $from
|
||||
* @param Title $to
|
||||
* @return MovePage
|
||||
*/
|
||||
public function newMovePage( Title $from, Title $to ) : MovePage {
|
||||
return new MovePage( $from, $to,
|
||||
$this->options,
|
||||
$this->loadBalancer,
|
||||
$this->nsInfo,
|
||||
$this->watchedItems,
|
||||
$this->permMgr,
|
||||
$this->repoGroup,
|
||||
$this->contentHandlerFactory,
|
||||
$this->revisionStore
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Interwiki\InterwikiLookup;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\MovePageFactory;
|
||||
use MediaWiki\Page\PageHandlerFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -81,7 +81,7 @@ class MovePageTest extends MediaWikiTestCase {
|
|||
$old,
|
||||
$new,
|
||||
new ServiceOptions(
|
||||
MovePageFactory::CONSTRUCTOR_OPTIONS,
|
||||
PageHandlerFactory::CONSTRUCTOR_OPTIONS,
|
||||
$params['options'] ?? [],
|
||||
[
|
||||
'CategoryCollation' => 'uppercase',
|
||||
|
|
@ -148,7 +148,7 @@ class MovePageTest extends MediaWikiTestCase {
|
|||
$obj2 = new MovePage(
|
||||
Title::newFromText( 'A' ),
|
||||
Title::newFromText( 'B' ),
|
||||
new ServiceOptions( MovePageFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
|
||||
new ServiceOptions( PageHandlerFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
|
||||
$services->getDBLoadBalancer(),
|
||||
$services->getNamespaceInfo(),
|
||||
$services->getWatchedItemStore(),
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Page\MovePageFactory;
|
||||
use MediaWiki\Page\PageHandlerFactory;
|
||||
|
||||
/**
|
||||
* @covers MediaWiki\Page\MovePageFactory
|
||||
* @covers MediaWiki\Page\PageHandlerFactory
|
||||
*/
|
||||
class MovePageFactoryTest extends MediaWikiUnitTestCase {
|
||||
class PageHandlerFactoryTest extends MediaWikiUnitTestCase {
|
||||
use FactoryArgTestTrait;
|
||||
|
||||
protected function getFactoryClass() {
|
||||
return MovePageFactory::class;
|
||||
return PageHandlerFactory::class;
|
||||
}
|
||||
|
||||
protected function getInstanceClass() {
|
||||
Loading…
Reference in a new issue