X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryCategoryMembers.php;h=35f76176c39a1a88f48cbc9c04258fb8e2a4f7ff;hb=49748181dd56ec97e7ba7c13e684a16abceb3cc0;hp=6dcfe0eb0098d95e38eda31735d9091371e08cbc;hpb=55bc0a7a421f5f9ea99061189b6d851987cd54b2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index 6dcfe0eb00..3a8847c339 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -53,7 +53,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { */ private function validateHexSortkey( $hexSortkey ) { // A hex sortkey has an unbound number of 2 letter pairs - return preg_match( '/^(?:[a-fA-F0-9]{2})*$/', $hexSortkey ); + return (bool)preg_match( '/^(?:[a-fA-F0-9]{2})*$/D', $hexSortkey ); } /** @@ -65,7 +65,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $categoryTitle = $this->getTitleOrPageId( $params )->getTitle(); if ( $categoryTitle->getNamespace() != NS_CATEGORY ) { - $this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' ); + $this->dieWithError( 'apierror-invalidcategory' ); } $prop = array_flip( $params['prop'] ); @@ -77,17 +77,17 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $fld_type = isset( $prop['type'] ); if ( is_null( $resultPageSet ) ) { - $this->addFields( array( 'cl_from', 'cl_sortkey', 'cl_type', 'page_namespace', 'page_title' ) ); + $this->addFields( [ 'cl_from', 'cl_sortkey', 'cl_type', 'page_namespace', 'page_title' ] ); $this->addFieldsIf( 'page_id', $fld_ids ); $this->addFieldsIf( 'cl_sortkey_prefix', $fld_sortkeyprefix ); } else { $this->addFields( $resultPageSet->getPageTableFields() ); // will include page_ id, ns, title - $this->addFields( array( 'cl_from', 'cl_sortkey', 'cl_type' ) ); + $this->addFields( [ 'cl_from', 'cl_sortkey', 'cl_type' ] ); } $this->addFieldsIf( 'cl_timestamp', $fld_timestamp || $params['sort'] == 'timestamp' ); - $this->addTables( array( 'page', 'categorylinks' ) ); // must be in this order for 'USE INDEX' + $this->addTables( [ 'page', 'categorylinks' ] ); // must be in this order for 'USE INDEX' $this->addWhereFld( 'cl_to', $categoryTitle->getDBkey() ); $queryTypes = $params['type']; @@ -95,14 +95,14 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { // Scanning large datasets for rare categories sucks, and I already told // how to have efficient subcategory access :-) ~~~~ (oh well, domas) - $miser_ns = array(); + $miser_ns = []; if ( $this->getConfig()->get( 'MiserMode' ) ) { $miser_ns = $params['namespace']; } else { $this->addWhereFld( 'page_namespace', $params['namespace'] ); } - $dir = in_array( $params['dir'], array( 'asc', 'ascending', 'newer' ) ) ? 'newer' : 'older'; + $dir = in_array( $params['dir'], [ 'asc', 'ascending', 'newer' ] ) ? 'newer' : 'older'; if ( $params['sort'] == 'timestamp' ) { $this->addTimestampWhereRange( 'cl_timestamp', @@ -138,8 +138,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { // Add a WHERE clause for sortkey and from $this->dieContinueUsageIf( !$this->validateHexSortkey( $cont[1] ) ); - // pack( "H*", $foo ) is used to convert hex back to binary - $escSortkey = $this->getDB()->addQuotes( pack( 'H*', $cont[1] ) ); + $escSortkey = $this->getDB()->addQuotes( hex2bin( $cont[1] ) ); $from = intval( $cont[2] ); $op = $dir == 'newer' ? '>' : '<'; // $contWhere is used further down @@ -151,29 +150,25 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $this->addWhereRange( 'cl_from', $dir, null, null ); } else { if ( $params['startsortkeyprefix'] !== null ) { - $startsortkey = Collation::singleton()->getSortkey( $params['startsortkeyprefix'] ); + $startsortkey = Collation::singleton()->getSortKey( $params['startsortkeyprefix'] ); } elseif ( $params['starthexsortkey'] !== null ) { if ( !$this->validateHexSortkey( $params['starthexsortkey'] ) ) { - $this->dieUsage( 'The starthexsortkey provided is not valid', 'bad_starthexsortkey' ); + $encParamName = $this->encodeParamName( 'starthexsortkey' ); + $this->dieWithError( [ 'apierror-badparameter', $encParamName ], "badvalue_$encParamName" ); } - $startsortkey = pack( 'H*', $params['starthexsortkey'] ); + $startsortkey = hex2bin( $params['starthexsortkey'] ); } else { - if ( $params['startsortkey'] !== null ) { - $this->logFeatureUsage( 'list=categorymembers&cmstartsortkey' ); - } $startsortkey = $params['startsortkey']; } if ( $params['endsortkeyprefix'] !== null ) { - $endsortkey = Collation::singleton()->getSortkey( $params['endsortkeyprefix'] ); + $endsortkey = Collation::singleton()->getSortKey( $params['endsortkeyprefix'] ); } elseif ( $params['endhexsortkey'] !== null ) { if ( !$this->validateHexSortkey( $params['endhexsortkey'] ) ) { - $this->dieUsage( 'The endhexsortkey provided is not valid', 'bad_endhexsortkey' ); + $encParamName = $this->encodeParamName( 'endhexsortkey' ); + $this->dieWithError( [ 'apierror-badparameter', $encParamName ], "badvalue_$encParamName" ); } - $endsortkey = pack( 'H*', $params['endhexsortkey'] ); + $endsortkey = hex2bin( $params['endhexsortkey'] ); } else { - if ( $params['endsortkey'] !== null ) { - $this->logFeatureUsage( 'list=categorymembers&cmendsortkey' ); - } $endsortkey = $params['endsortkey']; } @@ -198,16 +193,16 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { // inconsistencies between ORDER BY cl_type and // WHERE cl_type >= 'foo' making proper paging impossible // and unindexed. - $rows = array(); + $rows = []; $first = true; foreach ( $queryTypes as $type ) { - $extraConds = array( 'cl_type' => $type ); + $extraConds = [ 'cl_type' => $type ]; if ( $first && $contWhere ) { // Continuation condition. Only added to the // first query, otherwise we'll skip things $extraConds[] = $contWhere; } - $res = $this->select( __METHOD__, array( 'where' => $extraConds ) ); + $res = $this->select( __METHOD__, [ 'where' => $extraConds ] ); $rows = array_merge( $rows, iterator_to_array( $res ) ); if ( count( $rows ) >= $limit + 1 ) { break; @@ -250,9 +245,9 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $vals = array( + $vals = [ ApiResult::META_TYPE => 'assoc', - ); + ]; if ( $fld_ids ) { $vals['pageid'] = intval( $row->page_id ); } @@ -272,7 +267,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { if ( $fld_timestamp ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cl_timestamp ); } - $fit = $result->addValue( array( 'query', $this->getModuleName() ), + $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { if ( $params['sort'] == 'timestamp' ) { @@ -292,64 +287,64 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { if ( is_null( $resultPageSet ) ) { $result->addIndexedTagName( - array( 'query', $this->getModuleName() ), 'cm' ); + [ 'query', $this->getModuleName() ], 'cm' ); } } public function getAllowedParams() { - $ret = array( - 'title' => array( + $ret = [ + 'title' => [ ApiBase::PARAM_TYPE => 'string', - ), - 'pageid' => array( + ], + 'pageid' => [ ApiBase::PARAM_TYPE => 'integer' - ), - 'prop' => array( + ], + 'prop' => [ ApiBase::PARAM_DFLT => 'ids|title', ApiBase::PARAM_ISMULTI => true, - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'ids', 'title', 'sortkey', 'sortkeyprefix', 'type', 'timestamp', - ), - ApiBase::PARAM_HELP_MSG_PER_VALUE => array(), - ), - 'namespace' => array( + ], + ApiBase::PARAM_HELP_MSG_PER_VALUE => [], + ], + 'namespace' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => 'namespace', - ), - 'type' => array( + ], + 'type' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'page|subcat|file', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'page', 'subcat', 'file' - ) - ), - 'continue' => array( + ] + ], + 'continue' => [ ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', - ), - 'limit' => array( + ], + 'limit' => [ ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 - ), - 'sort' => array( + ], + 'sort' => [ ApiBase::PARAM_DFLT => 'sortkey', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'sortkey', 'timestamp' - ) - ), - 'dir' => array( + ] + ], + 'dir' => [ ApiBase::PARAM_DFLT => 'ascending', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'asc', 'desc', // Normalising with other modules @@ -357,42 +352,42 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { 'descending', 'newer', 'older', - ) - ), - 'start' => array( + ] + ], + 'start' => [ ApiBase::PARAM_TYPE => 'timestamp' - ), - 'end' => array( + ], + 'end' => [ ApiBase::PARAM_TYPE => 'timestamp' - ), + ], 'starthexsortkey' => null, 'endhexsortkey' => null, 'startsortkeyprefix' => null, 'endsortkeyprefix' => null, - 'startsortkey' => array( + 'startsortkey' => [ ApiBase::PARAM_DEPRECATED => true, - ), - 'endsortkey' => array( + ], + 'endsortkey' => [ ApiBase::PARAM_DEPRECATED => true, - ), - ); + ], + ]; if ( $this->getConfig()->get( 'MiserMode' ) ) { - $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = array( + $ret['namespace'][ApiBase::PARAM_HELP_MSG_APPEND] = [ 'api-help-param-limited-in-miser-mode', - ); + ]; } return $ret; } protected function getExamplesMessages() { - return array( + return [ 'action=query&list=categorymembers&cmtitle=Category:Physics' => 'apihelp-query+categorymembers-example-simple', 'action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=info' => 'apihelp-query+categorymembers-example-generator', - ); + ]; } public function getHelpUrls() {