From: Bryan Tong Minh Date: Tue, 26 Oct 2010 19:31:47 +0000 (+0000) Subject: Follow-up r75282 X-Git-Tag: 1.31.0-rc.0~34292 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=9af2264645b6714462c0e05aab5514d4111ed138;p=lhc%2Fweb%2Fwiklou.git Follow-up r75282 * Use addWhere instead of addWhereFld * Don't add properties twice if there is a continue * Add comments --- diff --git a/includes/api/ApiQueryPageProps.php b/includes/api/ApiQueryPageProps.php index 8aaa750d66..8ed839880d 100644 --- a/includes/api/ApiQueryPageProps.php +++ b/includes/api/ApiQueryPageProps.php @@ -45,6 +45,7 @@ class ApiQueryPageProps extends ApiQueryBase { public function execute() { $this->params = $this->extractRequestParams(); + # Only operate on existing pages $pages = $this->getPageSet()->getGoodTitles(); $this->addTables( 'page_props' ); @@ -52,32 +53,43 @@ class ApiQueryPageProps extends ApiQueryBase { $this->addWhereFld( 'pp_page', array_keys( $pages ) ); if ( $this->params['continue'] ) { - $this->addWhereFld( 'pp_page >=' . intval( $this->params['continue'] ) ); + $this->addWhere( 'pp_page >=' . intval( $this->params['continue'] ) ); } + # Force a sort order to ensure that properties are grouped by page $this->addOption( 'ORDER BY', 'pp_page' ); $res = $this->select( __METHOD__ ); - $currentPage = 0; + $currentPage = 0; # Id of the page currently processed $props = array(); $result = $this->getResult(); + foreach ( $res as $row ) { if ( $currentPage != $row->pp_page ) { + # Different page than previous row, so add the properties to + # the result and save the new page id + if ( $currentPage ) { if ( !$this->addPageProps( $result, $currentPage, $props ) ) { + # addPageProps() indicated that the result did not fit + # so stop adding data. Reset props so that it doesn't + # get added again after loop exit + + $props = array(); break; } $props = array(); - } else { - $currentPage = $row->pp_page; } + + $currentPage = $row->pp_page; } $props[$row->pp_propname] = $row->pp_value; } if ( count( $props ) ) { + # Add any remaining properties to the results $this->addPageProps( $result, $currentPage, $props ); } }