| Index: trunk/phase3/includes/api/ApiQueryPageProps.php |
| — | — | @@ -45,6 +45,7 @@ |
| 46 | 46 | public function execute() { |
| 47 | 47 | $this->params = $this->extractRequestParams(); |
| 48 | 48 | |
| | 49 | + # Only operate on existing pages |
| 49 | 50 | $pages = $this->getPageSet()->getGoodTitles(); |
| 50 | 51 | |
| 51 | 52 | $this->addTables( 'page_props' ); |
| — | — | @@ -52,32 +53,43 @@ |
| 53 | 54 | $this->addWhereFld( 'pp_page', array_keys( $pages ) ); |
| 54 | 55 | |
| 55 | 56 | if ( $this->params['continue'] ) { |
| 56 | | - $this->addWhereFld( 'pp_page >=' . intval( $this->params['continue'] ) ); |
| | 57 | + $this->addWhere( 'pp_page >=' . intval( $this->params['continue'] ) ); |
| 57 | 58 | } |
| 58 | 59 | |
| | 60 | + # Force a sort order to ensure that properties are grouped by page |
| 59 | 61 | $this->addOption( 'ORDER BY', 'pp_page' ); |
| 60 | 62 | |
| 61 | 63 | $res = $this->select( __METHOD__ ); |
| 62 | | - $currentPage = 0; |
| | 64 | + $currentPage = 0; # Id of the page currently processed |
| 63 | 65 | $props = array(); |
| 64 | 66 | $result = $this->getResult(); |
| | 67 | + |
| 65 | 68 | foreach ( $res as $row ) { |
| 66 | 69 | if ( $currentPage != $row->pp_page ) { |
| | 70 | + # Different page than previous row, so add the properties to |
| | 71 | + # the result and save the new page id |
| | 72 | + |
| 67 | 73 | if ( $currentPage ) { |
| 68 | 74 | if ( !$this->addPageProps( $result, $currentPage, $props ) ) { |
| | 75 | + # addPageProps() indicated that the result did not fit |
| | 76 | + # so stop adding data. Reset props so that it doesn't |
| | 77 | + # get added again after loop exit |
| | 78 | + |
| | 79 | + $props = array(); |
| 69 | 80 | break; |
| 70 | 81 | } |
| 71 | 82 | |
| 72 | 83 | $props = array(); |
| 73 | | - } else { |
| 74 | | - $currentPage = $row->pp_page; |
| 75 | 84 | } |
| | 85 | + |
| | 86 | + $currentPage = $row->pp_page; |
| 76 | 87 | } |
| 77 | 88 | |
| 78 | 89 | $props[$row->pp_propname] = $row->pp_value; |
| 79 | 90 | } |
| 80 | 91 | |
| 81 | 92 | if ( count( $props ) ) { |
| | 93 | + # Add any remaining properties to the results |
| 82 | 94 | $this->addPageProps( $result, $currentPage, $props ); |
| 83 | 95 | } |
| 84 | 96 | } |