X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=bba53755c111c926ec21a4c4b54f3438ffe6c5e7;hp=b35eec2c398ae315209afe202deb3bfad60b5ca9;hb=9964ca1a390c446397dcd466916ffed356cdc3c9;hpb=bb8608c98a3d677d8557dd7056a7434c7c38c055 diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index b35eec2c39..bba53755c1 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -103,7 +103,7 @@ abstract class ApiQueryBase extends ApiBase { /** * Get the Query database connection (read-only) - * @return DatabaseBase + * @return Database */ protected function getDB() { if ( is_null( $this->mDb ) ) { @@ -119,7 +119,7 @@ abstract class ApiQueryBase extends ApiBase { * @param string $name Name to assign to the database connection * @param int $db One of the DB_* constants * @param array $groups Query groups - * @return DatabaseBase + * @return Database */ public function selectNamedDB( $name, $db, $groups ) { $this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups ); @@ -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,11 +375,38 @@ 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