- ));
-
- $fld_sortkey = $fld_timestamp = false;
- if (!is_null($prop)) {
- foreach($prop as $p) {
- switch ($p) {
- case 'sortkey':
- $this->addFields('cl_sortkey');
- $fld_sortkey = true;
- break;
- case 'timestamp':
- $this->addFields('cl_timestamp');
- $fld_timestamp = true;
- break;
- default :
- ApiBase :: dieDebug(__METHOD__, "Unknown prop=$p");
+ ) );
+
+ $this->addFieldsIf( array( 'cl_sortkey', 'cl_sortkey_prefix' ), isset( $prop['sortkey'] ) );
+ $this->addFieldsIf( 'cl_timestamp', isset( $prop['timestamp'] ) );
+
+ $this->addTables( 'categorylinks' );
+ $this->addWhereFld( 'cl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
+ if ( !is_null( $params['categories'] ) ) {
+ $cats = array();
+ foreach ( $params['categories'] as $cat ) {
+ $title = Title::newFromText( $cat );
+ if ( !$title || $title->getNamespace() != NS_CATEGORY ) {
+ $this->setWarning( "``$cat'' is not a category" );
+ } else {
+ $cats[] = $title->getDBkey();