Use SpecialPageFactory to create special pages in ApiFeedRecentChanges
This makes it easier to change the constructor of both special pages Change-Id: Id485ffa9fc1c1a9818ab487aed6ef886a7eb35a5
This commit is contained in:
parent
6e6fb0eba9
commit
27816323e5
4 changed files with 46 additions and 16 deletions
|
|
@ -284,6 +284,8 @@ because of Phabricator reports.
|
|||
* ProcessCacheLRU class, deprecated in 1.32, has been removed.
|
||||
* wfForeignMemcKey(), deprecated in 1.35, has been removed.
|
||||
* LoadBalancer::safeWaitForMasterPos(), deprecated in 1.35, has been removed.
|
||||
* ApiFeedRecentChanges::getFeedObject has been changed to private, and appears
|
||||
unused outside of MediaWiki core.
|
||||
* …
|
||||
|
||||
=== Deprecations in 1.36 ===
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
* @since 1.23
|
||||
*/
|
||||
|
||||
use MediaWiki\SpecialPage\SpecialPageFactory;
|
||||
|
||||
/**
|
||||
* Recent changes feed.
|
||||
*
|
||||
|
|
@ -28,6 +30,23 @@ class ApiFeedRecentChanges extends ApiBase {
|
|||
|
||||
private $params;
|
||||
|
||||
/** @var SpecialPageFactory */
|
||||
private $specialPageFactory;
|
||||
|
||||
/**
|
||||
* @param ApiMain $mainModule
|
||||
* @param string $moduleName
|
||||
* @param SpecialPageFactory $specialPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ApiMain $mainModule,
|
||||
string $moduleName,
|
||||
SpecialPageFactory $specialPageFactory
|
||||
) {
|
||||
parent::__construct( $mainModule, $moduleName );
|
||||
$this->specialPageFactory = $specialPageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* This module uses a custom feed wrapper printer.
|
||||
*
|
||||
|
|
@ -62,11 +81,11 @@ class ApiFeedRecentChanges extends ApiBase {
|
|||
}
|
||||
|
||||
$feedFormat = $this->params['feedformat'];
|
||||
$specialClass = $this->params['target'] !== null
|
||||
? SpecialRecentChangesLinked::class
|
||||
: SpecialRecentChanges::class;
|
||||
$specialPageName = $this->params['target'] !== null
|
||||
? 'Recentchangeslinked'
|
||||
: 'Recentchanges';
|
||||
|
||||
$formatter = $this->getFeedObject( $feedFormat, $specialClass );
|
||||
$formatter = $this->getFeedObject( $feedFormat, $specialPageName );
|
||||
|
||||
// Parameters are passed via the request in the context… :(
|
||||
$context = new DerivativeContext( $this );
|
||||
|
|
@ -77,7 +96,11 @@ class ApiFeedRecentChanges extends ApiBase {
|
|||
) );
|
||||
|
||||
// The row-getting functionality should be factored out of ChangesListSpecialPage too…
|
||||
$rc = new $specialClass();
|
||||
$rc = $this->specialPageFactory->getPage( $specialPageName );
|
||||
if ( $rc === null ) {
|
||||
throw new RuntimeException( __METHOD__ . ' not able to instance special page ' . $specialPageName );
|
||||
}
|
||||
'@phan-var ChangesListSpecialPage $rc';
|
||||
$rc->setContext( $context );
|
||||
$rows = $rc->getRows();
|
||||
|
||||
|
|
@ -90,12 +113,12 @@ class ApiFeedRecentChanges extends ApiBase {
|
|||
* Return a ChannelFeed object.
|
||||
*
|
||||
* @param string $feedFormat Feed's format (either 'rss' or 'atom')
|
||||
* @param string $specialClass Relevant special page name (either 'SpecialRecentChanges' or
|
||||
* 'SpecialRecentChangesLinked')
|
||||
* @param string $specialPageName Relevant special page name (either 'Recentchanges' or
|
||||
* 'Recentchangeslinked')
|
||||
* @return ChannelFeed
|
||||
*/
|
||||
public function getFeedObject( $feedFormat, $specialClass ) {
|
||||
if ( $specialClass === SpecialRecentChangesLinked::class ) {
|
||||
private function getFeedObject( $feedFormat, $specialPageName ) {
|
||||
if ( $specialPageName === 'Recentchangeslinked' ) {
|
||||
$title = Title::newFromText( $this->params['target'] );
|
||||
if ( !$title ) {
|
||||
$this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $this->params['target'] ) ] );
|
||||
|
|
|
|||
|
|
@ -88,7 +88,12 @@ class ApiMain extends ApiBase {
|
|||
],
|
||||
'opensearch' => ApiOpenSearch::class,
|
||||
'feedcontributions' => ApiFeedContributions::class,
|
||||
'feedrecentchanges' => ApiFeedRecentChanges::class,
|
||||
'feedrecentchanges' => [
|
||||
'class' => ApiFeedRecentChanges::class,
|
||||
'services' => [
|
||||
'SpecialPageFactory',
|
||||
]
|
||||
],
|
||||
'feedwatchlist' => ApiFeedWatchlist::class,
|
||||
'help' => ApiHelp::class,
|
||||
'paraminfo' => ApiParamInfo::class,
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ class ApiModuleManagerTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
public function getModuleProvider() {
|
||||
$modules = [
|
||||
'feedrecentchanges' => ApiFeedRecentChanges::class,
|
||||
'feedcontributions' => [ 'class' => ApiFeedContributions::class ],
|
||||
'disabled' => ApiDisabled::class,
|
||||
'disabled2' => [ 'class' => ApiDisabled::class ],
|
||||
'login' => [
|
||||
'class' => ApiLogin::class,
|
||||
'factory' => [ $this, 'newApiLogin' ],
|
||||
|
|
@ -159,14 +159,14 @@ class ApiModuleManagerTest extends MediaWikiIntegrationTestCase {
|
|||
return [
|
||||
'legacy entry' => [
|
||||
$modules,
|
||||
'feedrecentchanges',
|
||||
ApiFeedRecentChanges::class,
|
||||
'disabled',
|
||||
ApiDisabled::class,
|
||||
],
|
||||
|
||||
'just a class' => [
|
||||
$modules,
|
||||
'feedcontributions',
|
||||
ApiFeedContributions::class,
|
||||
'disabled2',
|
||||
ApiDisabled::class,
|
||||
],
|
||||
|
||||
'with factory' => [
|
||||
|
|
|
|||
Loading…
Reference in a new issue