*/
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 );
}
/**
$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'] );
$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'];
// 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',
// 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
$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 {
$startsortkey = $params['startsortkey'];
}
$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 {
$endsortkey = $params['endsortkey'];
}
// 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;
}
if ( is_null( $resultPageSet ) ) {
- $vals = array(
+ $vals = [
ApiResult::META_TYPE => 'assoc',
- );
+ ];
if ( $fld_ids ) {
$vals['pageid'] = intval( $row->page_id );
}
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' ) {
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
'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() {