API fixes

This commit is contained in:
Max Semenik 2012-03-01 23:44:37 +04:00
parent 703e6ef8a9
commit 65e098e79c

View file

@ -27,13 +27,18 @@ class ApiQueryPageImages extends ApiQueryBase {
} }
$this->addWhere( array( 'pp_page' => array_keys( $titles ), 'pp_propname' => $propNames ) ); $this->addWhere( array( 'pp_page' => array_keys( $titles ), 'pp_propname' => $propNames ) );
$this->addOption( 'ORDER BY', 'pp_page' ); $this->addOption( 'ORDER BY', 'pp_page' );
$res = $this->select( __METHOD__ ); $res = $this->select( __METHOD__ );
foreach ( $res as $row ) { $lastId = 0;
$vals = array(); $vals = array();
foreach ( $res as $row ) {
if ( $lastId && $lastId != $row->pp_page && !$this->addData( $lastId, $vals ) ) {
break;
}
$lastId = $row->pp_page;
if ( $row->pp_propname == 'has_photos' ) { if ( $row->pp_propname == 'has_photos' ) {
$vals['hasphotos'] = ''; $vals['hasphotos'] = '';
} elseif ( $row->pp_propname == 'page_image' ) { } elseif ( $row->pp_propname == 'page_image' ) {
//$title = Title::makeTitle( NS_FILE, );
$file = wfFindFile( $row->pp_value ); $file = wfFindFile( $row->pp_value );
if ( $file ) { if ( $file ) {
$thumb = $file->transform( array( 'width' => $size, 'height' => $size ) ); $thumb = $file->transform( array( 'width' => $size, 'height' => $size ) );
@ -46,10 +51,20 @@ class ApiQueryPageImages extends ApiQueryBase {
} }
} }
} }
if ( count( $vals ) ) {
$this->addPageSubItem( $row->pp_page, $vals );
} }
$this->addData( $lastId, $vals );
} }
private function addData( $pageId, array &$data ) {
$fit = true;
if ( count( $data ) ) {
$fit = $this->getResult()->addValue( array( 'query', 'pages' ), $pageId, $data );
$data = array();
}
if ( !$fit ) {
$this->setContinueEnumParameter( 'continue', $pageId );
}
return $fit;
} }
public function getAllowedParams() { public function getAllowedParams() {