[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add hooks for WatchedItemQueryService / ApiQueryWatchlist
jenkins-bot has submitted this change and it was merged. Change subject: Add hooks for WatchedItemQueryService / ApiQueryWatchlist .. Add hooks for WatchedItemQueryService / ApiQueryWatchlist In order for an extension to add data to ApiQueryWatchlist, we need to provide a way to allow it to manipulate the database query made by WatchedItemQueryService. We also need some hooks in ApiQueryWatchlist to handle the marshalling of data to and from WatchedItemQueryService. To better handle hooking, this also moves some of the continuation logic from ApiQueryWatchlist to WatchedItemQueryService. Bug: T147939 Change-Id: Ie45376980f92da964a579887b28175c00fd8f57e --- M autoload.php M docs/hooks.txt M includes/WatchedItemQueryService.php A includes/WatchedItemQueryServiceExtension.php M includes/api/ApiQueryWatchlist.php M tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php 6 files changed, 387 insertions(+), 54 deletions(-) Approvals: Addshore: Looks good to me, approved jenkins-bot: Verified diff --git a/autoload.php b/autoload.php index b96250d..bbf4bd0 100644 --- a/autoload.php +++ b/autoload.php @@ -1532,6 +1532,7 @@ 'WatchAction' => __DIR__ . '/includes/actions/WatchAction.php', 'WatchedItem' => __DIR__ . '/includes/WatchedItem.php', 'WatchedItemQueryService' => __DIR__ . '/includes/WatchedItemQueryService.php', + 'WatchedItemQueryServiceExtension' => __DIR__ . '/includes/WatchedItemQueryServiceExtension.php', 'WatchedItemStore' => __DIR__ . '/includes/WatchedItemStore.php', 'WatchlistCleanup' => __DIR__ . '/maintenance/cleanupWatchlist.php', 'WebInstaller' => __DIR__ . '/includes/installer/WebInstaller.php', diff --git a/docs/hooks.txt b/docs/hooks.txt index 562d7b4..ea662cc 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -565,6 +565,18 @@ makes no sense). &$tokenFunctions: array(action => callback) +'ApiQueryWatchlistExtractOutputData': Extract row data for ApiQueryWatchlist. +$module: ApiQueryWatchlist instance +$watchedItem: WatchedItem instance +$recentChangeInfo: Array of recent change info data +&$vals: Associative array of data to be output for the row + +'ApiQueryWatchlistPrepareWatchedItemQueryServiceOptions': Populate the options +to be passed from ApiQueryWatchlist to WatchedItemQueryService. +$module: ApiQueryWatchlist instance +$params: Array of parameters, as would be returned by $module->extractRequestParams() +&$options: Array of options for WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo() + 'ApiRsdServiceApis': Add or remove APIs from the RSD services list. Each service should have its own entry in the $apis array and have a unique name, passed as key for the array that represents the service data. In this data array, the @@ -3735,6 +3747,10 @@ &$user: user that watched &$page: WikiPage object watched +'WatchedItemQueryServiceExtensions': Create a WatchedItemQueryServiceExtension. +&$extensions: Add WatchedItemQueryServiceExtension objects to this array +$watchedItemQueryService: Service object + 'WatchlistEditorBeforeFormRender': Before building the Special:EditWatchlist form, used to manipulate the list of pages or preload data based on that list. &$watchlistInfo: array of watchlisted pages in diff --git a/includes/WatchedItemQueryService.php b/includes/WatchedItemQueryService.php index b7cdc53..0c3d52a 100644 --- a/includes/WatchedItemQueryService.php +++ b/includes/WatchedItemQueryService.php @@ -50,8 +50,22 @@ */ private $loadBalancer; + /** @var WatchedItemQueryServiceExtension[]|null */ + private $extensions = null; + public function __construct( LoadBalancer $loadBalancer ) { $this->loadBalancer = $loadBalancer; + } + + /** +* @return WatchedItemQueryServiceExtension[] +*/ + private function getExtensions() { + if ( $this->extensions === null ) { + $this->extensions = []; + Hooks::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions, $this ] ); + } + return $this->extensions; } /** @@ -84,9 +98,6 @@ * timestamp to start enumerating from *'end' => string (format accepted by wfTimestamp) requires 'dir' option, * timestamp to end enumerating -*'startFrom' => [ string $rcTimestamp, int $rcId ] requires 'dir' option, -* return items starting from the RecentChange specified by this, -* $rcTimestamp should be in the format accepted by wfTimestamp *'watchlistOwner' => User user whose watchlist items should be listed if different *
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Add hooks for WatchedItemQueryService / ApiQueryWatchlist
Anomie has uploaded a new change for review. https://gerrit.wikimedia.org/r/315521 Change subject: Add hooks for WatchedItemQueryService / ApiQueryWatchlist .. Add hooks for WatchedItemQueryService / ApiQueryWatchlist In order for an extension to add data to ApiQueryWatchlist, we need to provide a way to allow it to manipulate the database query made by WatchedItemQueryService. We also need some hooks in ApiQueryWatchlist to handle the marshalling of data to and from WatchedItemQueryService. To better handle hooking, this also moves some of the continuation logic from ApiQueryWatchlist to WatchedItemQueryService. Bug: T147939 Change-Id: Ie45376980f92da964a579887b28175c00fd8f57e --- M autoload.php M docs/hooks.txt M includes/WatchedItemQueryService.php A includes/WatchedItemQueryServiceExtension.php M includes/api/ApiQueryWatchlist.php M tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php 6 files changed, 384 insertions(+), 54 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/21/315521/1 diff --git a/autoload.php b/autoload.php index 748d954..7dca1b7 100644 --- a/autoload.php +++ b/autoload.php @@ -1527,6 +1527,7 @@ 'WatchAction' => __DIR__ . '/includes/actions/WatchAction.php', 'WatchedItem' => __DIR__ . '/includes/WatchedItem.php', 'WatchedItemQueryService' => __DIR__ . '/includes/WatchedItemQueryService.php', + 'WatchedItemQueryServiceExtension' => __DIR__ . '/includes/WatchedItemQueryServiceExtension.php', 'WatchedItemStore' => __DIR__ . '/includes/WatchedItemStore.php', 'WatchlistCleanup' => __DIR__ . '/maintenance/cleanupWatchlist.php', 'WebInstaller' => __DIR__ . '/includes/installer/WebInstaller.php', diff --git a/docs/hooks.txt b/docs/hooks.txt index 3b3741a..61417c0 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -565,6 +565,18 @@ makes no sense). &$tokenFunctions: array(action => callback) +'ApiQueryWatchlistExtractOutputData': Extract row data for ApiQueryWatchlist. +$module: ApiQueryWatchlist instance +$watchedItem: WatchedItem instance +$recentChangeInfo: Array of recent change info data +&$vals: Array to be output for the row + +'ApiQueryWatchlistPrepareWatchedItemQueryServiceOptions': Populate the options +to be passed from ApiQueryWatchlist to WatchedItemQueryService. +$module: ApiQueryWatchlist instance +$params: Array of parameters +&$options: Array of options for WatchedItemQueryService::getWatchedItemsWithRecentChangeInfo() + 'ApiRsdServiceApis': Add or remove APIs from the RSD services list. Each service should have its own entry in the $apis array and have a unique name, passed as key for the array that represents the service data. In this data array, the @@ -3735,6 +3747,10 @@ &$user: user that watched &$page: WikiPage object watched +'WatchedItemQueryServiceExtensions': Create a WatchedItemQueryServiceExtension. +&$extensions: Add extension objects to this array +$watchedItemQueryService: Service object + 'WatchlistEditorBeforeFormRender': Before building the Special:EditWatchlist form, used to manipulate the list of pages or preload data based on that list. &$watchlistInfo: array of watchlisted pages in diff --git a/includes/WatchedItemQueryService.php b/includes/WatchedItemQueryService.php index 8497224..ede6a90 100644 --- a/includes/WatchedItemQueryService.php +++ b/includes/WatchedItemQueryService.php @@ -50,8 +50,22 @@ */ private $loadBalancer; + /** @var WatchedItemQueryServiceExtension[] */ + private $extensions = null; + public function __construct( LoadBalancer $loadBalancer ) { $this->loadBalancer = $loadBalancer; + } + + /** +* @return WatchedItemQueryServiceExtension[] +*/ + private function getExtensions() { + if ( $this->extensions === null ) { + $this->extensions = []; + Hooks::run( 'WatchedItemQueryServiceExtensions', [ &$this->extensions, $this ] ); + } + return $this->extensions; } /** @@ -84,9 +98,6 @@ * timestamp to start enumerating from *'end' => string (format accepted by wfTimestamp) requires 'dir' option, * timestamp to end enumerating -*'startFrom' => [ string $rcTimestamp, int $rcId ] requires 'dir' option, -* return items starting from the RecentChange specified by this, -* $rcTimestamp should be in the format accepted by wfTimestamp *'watchlistOwner' => User user whose watchlist items should be listed if different * than the one specified with $user param, *