aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiQueryBase.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryBase.php')
-rw-r--r--includes/api/ApiQueryBase.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php
index 36ad3a4be7ed..bba53755c111 100644
--- a/includes/api/ApiQueryBase.php
+++ b/includes/api/ApiQueryBase.php
@@ -347,9 +347,12 @@ abstract class ApiQueryBase extends ApiBase {
* 'options' => ...,
* 'join_conds' => ...
* ]
+ * @param array|null &$hookData If set, the ApiQueryBaseBeforeQuery and
+ * ApiQueryBaseAfterQuery hooks will be called, and the
+ * ApiQueryBaseProcessRow hook will be expected.
* @return ResultWrapper
*/
- protected function select( $method, $extraQuery = [] ) {
+ protected function select( $method, $extraQuery = [], array &$hookData = null ) {
$tables = array_merge(
$this->tables,
@@ -372,12 +375,39 @@ abstract class ApiQueryBase extends ApiBase {
isset( $extraQuery['join_conds'] ) ? (array)$extraQuery['join_conds'] : []
);
+ if ( $hookData !== null ) {
+ Hooks::run( 'ApiQueryBaseBeforeQuery',
+ [ $this, &$tables, &$fields, &$where, &$options, &$join_conds, &$hookData ]
+ );
+ }
+
$res = $this->getDB()->select( $tables, $fields, $where, $method, $options, $join_conds );
+ if ( $hookData !== null ) {
+ Hooks::run( 'ApiQueryBaseAfterQuery', [ $this, $res, &$hookData ] );
+ }
+
return $res;
}
/**
+ * Call the ApiQueryBaseProcessRow hook
+ *
+ * Generally, a module that passed $hookData to self::select() will call
+ * this just before calling ApiResult::addValue(), and treat a false return
+ * here in the same way it treats a false return from addValue().
+ *
+ * @since 1.28
+ * @param object $row Database row
+ * @param array &$data Data to be added to the result
+ * @param array &$hookData Hook data from ApiQueryBase::select()
+ * @return bool Return false if row processing should end with continuation
+ */
+ protected function processRow( $row, array &$data, array &$hookData ) {
+ return Hooks::run( 'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] );
+ }
+
+ /**
* @param string $query
* @param string $protocol
* @return null|string