From 9af2264645b6714462c0e05aab5514d4111ed138 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Tue, 26 Oct 2010 19:31:47 +0000 Subject: [PATCH] Follow-up r75282 * Use addWhere instead of addWhereFld * Don't add properties twice if there is a continue * Add comments --- includes/api/ApiQueryPageProps.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 ); } } -- 2.20.1