diff --git a/extension.json b/extension.json index d98d1488a..6b7284821 100644 --- a/extension.json +++ b/extension.json @@ -903,7 +903,7 @@ }, "manifest_version": 2, "AutoloadClasses": { - "ApiCrossWikiBase": "includes/api/ApiCrossWikiBase.php", + "ApiCrossWiki": "includes/api/ApiCrossWiki.php", "ApiEchoArticleReminder": "includes/api/ApiEchoArticleReminder.php", "ApiEchoMarkRead": "includes/api/ApiEchoMarkRead.php", "ApiEchoMarkReadTest": "tests/phpunit/api/ApiEchoMarkReadTest.php", diff --git a/includes/api/ApiCrossWikiBase.php b/includes/api/ApiCrossWiki.php similarity index 71% rename from includes/api/ApiCrossWikiBase.php rename to includes/api/ApiCrossWiki.php index 871ecddb0..a46981ed9 100644 --- a/includes/api/ApiCrossWikiBase.php +++ b/includes/api/ApiCrossWiki.php @@ -1,24 +1,21 @@ foreignNotifications = new EchoForeignNotifications( $this->getUser() ); - } - - /** - * This will turn the current API call (with all of it's params) and execute + * This will take the current API call (with all of its params) and execute * it on all foreign wikis, returning an array of results per wiki. * * @param array|null $wikis List of wikis to query. Defaults to the result of getRequestedForeignWikis(). @@ -27,6 +24,10 @@ abstract class ApiCrossWikiBase extends ApiQueryBase { * @throws Exception */ protected function getFromForeign( $wikis = null, array $paramOverrides = [] ) { + $wikis = $wikis ?? $this->getRequestedForeignWikis(); + if ( $wikis === [] ) { + return []; + } $foreignReq = new EchoForeignWikiRequest( $this->getUser(), $paramOverrides + $this->getForeignQueryParams(), @@ -38,8 +39,8 @@ abstract class ApiCrossWikiBase extends ApiQueryBase { /** * Get the query parameters to use for the foreign API requests. - * Subclasses should override this if they need to customize the - * parameters. + * Implementing classes should override this if they need to customize + * the parameters. * @return array Query parameters */ protected function getForeignQueryParams() { @@ -91,17 +92,27 @@ abstract class ApiCrossWikiBase extends ApiQueryBase { return array_diff( $this->getRequestedWikis(), [ wfWikiID() ] ); } + /** + * @return EchoForeignNotifications + */ + protected function getForeignNotifications() { + if ( $this->foreignNotifications === null ) { + $this->foreignNotifications = new EchoForeignNotifications( $this->getUser() ); + } + return $this->foreignNotifications; + } + /** * @return string[] Wiki names */ protected function getForeignWikisWithUnreadNotifications() { - return $this->foreignNotifications->getWikis(); + return $this->getForeignNotifications()->getWikis(); } /** * @return array[] */ - public function getAllowedParams() { + public function getCrossWikiParams() { global $wgConf; $params = []; diff --git a/includes/api/ApiEchoNotifications.php b/includes/api/ApiEchoNotifications.php index c58a9ba4b..b232e4abd 100644 --- a/includes/api/ApiEchoNotifications.php +++ b/includes/api/ApiEchoNotifications.php @@ -1,6 +1,8 @@ foreignNotifications->getWikis( + $potentialWikis = $this->getForeignNotifications()->getWikis( $wgEchoSectionTransition ? EchoAttributeManager::ALL : $section ); if ( !$potentialWikis ) { return false; @@ -417,12 +419,12 @@ class ApiEchoNotifications extends ApiCrossWikiBase { }, $timestampsByWiki ); } else { // In non-transition mode, or when querying all sections, we can trust the euw table - $wikis = $this->foreignNotifications->getWikis( $section ); - $count = $this->foreignNotifications->getCount( $section ); - $maxTimestamp = $this->foreignNotifications->getTimestamp( $section ); + $wikis = $this->getForeignNotifications()->getWikis( $section ); + $count = $this->getForeignNotifications()->getCount( $section ); + $maxTimestamp = $this->getForeignNotifications()->getTimestamp( $section ); $timestampsByWiki = []; foreach ( $wikis as $wiki ) { - $timestampsByWiki[$wiki] = $this->foreignNotifications->getWikiTimestamp( $wiki, $section ); + $timestampsByWiki[$wiki] = $this->getForeignNotifications()->getWikiTimestamp( $wiki, $section ); } } @@ -474,7 +476,7 @@ class ApiEchoNotifications extends ApiCrossWikiBase { } protected function getForeignQueryParams() { - $params = parent::getForeignQueryParams(); + $params = $this->getRequest()->getValues(); // don't request cross-wiki notification summaries unset( $params['notcrosswikisummary'] ); @@ -577,8 +579,7 @@ class ApiEchoNotifications extends ApiCrossWikiBase { public function getAllowedParams() { $sections = EchoAttributeManager::$sections; - $params = parent::getAllowedParams(); - $params += [ + $params = $this->getCrossWikiParams() + [ 'filter' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'read|!read', diff --git a/includes/api/ApiEchoUnreadNotificationPages.php b/includes/api/ApiEchoUnreadNotificationPages.php index 77f288c2f..f085f3ca3 100644 --- a/includes/api/ApiEchoUnreadNotificationPages.php +++ b/includes/api/ApiEchoUnreadNotificationPages.php @@ -1,6 +1,8 @@ getUnreadNotificationPagesFromForeign(); } - $apis = $this->foreignNotifications->getApiEndpoints( $this->getRequestedWikis() ); + $apis = $this->getForeignNotifications()->getApiEndpoints( $this->getRequestedWikis() ); foreach ( $result as $wiki => $data ) { $result[$wiki]['source'] = $apis[$wiki]; $result[$wiki]['pages'] = $data['pages'] ?: []; @@ -177,7 +179,7 @@ class ApiEchoUnreadNotificationPages extends ApiCrossWikiBase { public function getAllowedParams() { global $wgEchoMaxUpdateCount; - return parent::getAllowedParams() + [ + return $this->getCrossWikiParams() + [ 'grouppages' => [ ApiBase::PARAM_TYPE => 'boolean', ApiBase::PARAM_DFLT => false,