X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=122e02fec77864f88d6c336eb6ab910d502e1028;hb=6cfb2e3d7a2b96d5041312fcec88248bb46573d7;hp=c92f037c9cc2e2b04ce82e5748d218b98dcbbc2a;hpb=5dcaded72649241d8f8b650be0e537352fe90d63;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index c92f037c9c..ec432d8f11 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -21,7 +21,7 @@ */ use Wikimedia\Rdbms\IDatabase; -use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IResultWrapper; /** * This is a base class for all Query modules. @@ -151,22 +151,21 @@ abstract class ApiQueryBase extends ApiBase { /** * Add a set of tables to the internal array - * @param string|string[] $tables Table name or array of table names + * @param string|array $tables Table name or array of table names + * or nested arrays for joins using parentheses for grouping * @param string|null $alias Table alias, or null for no alias. Cannot be * used with multiple tables */ protected function addTables( $tables, $alias = null ) { if ( is_array( $tables ) ) { - if ( !is_null( $alias ) ) { + if ( $alias !== null ) { ApiBase::dieDebug( __METHOD__, 'Multiple table aliases not supported' ); } $this->tables = array_merge( $this->tables, $tables ); + } elseif ( $alias !== null ) { + $this->tables[$alias] = $tables; } else { - if ( !is_null( $alias ) ) { - $this->tables[$alias] = $tables; - } else { - $this->tables[] = $tables; - } + $this->tables[] = $tables; } } @@ -253,7 +252,7 @@ abstract class ApiQueryBase extends ApiBase { } /** - * Equivalent to addWhere(array($field => $value)) + * Equivalent to addWhere( [ $field => $value ] ) * @param string $field Field name * @param string|string[] $value Value; ignored if null or empty array */ @@ -369,7 +368,7 @@ abstract class ApiQueryBase extends ApiBase { * @param array|null &$hookData If set, the ApiQueryBaseBeforeQuery and * ApiQueryBaseAfterQuery hooks will be called, and the * ApiQueryBaseProcessRow hook will be expected. - * @return ResultWrapper + * @return IResultWrapper */ protected function select( $method, $extraQuery = [], array &$hookData = null ) { $tables = array_merge( @@ -425,35 +424,6 @@ abstract class ApiQueryBase extends ApiBase { return Hooks::run( 'ApiQueryBaseProcessRow', [ $this, $row, &$data, &$hookData ] ); } - /** - * @deprecated since 1.33, use LinkFilter::getQueryConditions() instead - * @param string|null $query - * @param string|null $protocol - * @return null|string - */ - public function prepareUrlQuerySearchString( $query = null, $protocol = null ) { - wfDeprecated( __METHOD__, '1.33' ); - $db = $this->getDB(); - if ( $query !== null && $query !== '' ) { - if ( is_null( $protocol ) ) { - $protocol = 'http://'; - } - - $likeQuery = LinkFilter::makeLikeArray( $query, $protocol ); - if ( !$likeQuery ) { - $this->dieWithError( 'apierror-badquery' ); - } - - $likeQuery = LinkFilter::keepOneWildcard( $likeQuery ); - - return 'el_index ' . $db->buildLike( $likeQuery ); - } elseif ( !is_null( $protocol ) ) { - return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ); - } - - return null; - } - /** * Filters hidden users (where the user doesn't have the right to view them) * Also adds relevant block information @@ -510,7 +480,7 @@ abstract class ApiQueryBase extends ApiBase { * @param string $prefix Module prefix */ public static function addTitleInfo( &$arr, $title, $prefix = '' ) { - $arr[$prefix . 'ns'] = intval( $title->getNamespace() ); + $arr[$prefix . 'ns'] = (int)$title->getNamespace(); $arr[$prefix . 'title'] = $title->getPrefixedText(); } @@ -524,7 +494,7 @@ abstract class ApiQueryBase extends ApiBase { $result = $this->getResult(); ApiResult::setIndexedTagName( $data, $this->getModulePrefix() ); - return $result->addValue( [ 'query', 'pages', intval( $pageId ) ], + return $result->addValue( [ 'query', 'pages', (int)$pageId ], $this->getModuleName(), $data ); } @@ -532,7 +502,7 @@ abstract class ApiQueryBase extends ApiBase { /** * Same as addPageSubItems(), but one element of $data at a time * @param int $pageId Page ID - * @param array $item Data array à la ApiResult + * @param mixed $item Data à la ApiResult * @param string|null $elemname XML element name. If null, getModuleName() * is used * @return bool Whether the element fit in the result