Index: trunk/extensions/CollabWatchlist/tests/CollabWatchlistTest.php |
— | — | @@ -2,10 +2,13 @@ |
3 | 3 | |
4 | 4 | class CollabWatchlistTest extends PHPUnit_Framework_TestCase { |
5 | 5 | public function testCategoryTree() { |
| 6 | + /* Workaround for eclipse xdebug |
| 7 | + $path = '/usr/share/php'; |
| 8 | + set_include_path(get_include_path() . PATH_SEPARATOR . $path); |
| 9 | + */ |
6 | 10 | $catTree = new CategoryTreeManip(); |
7 | | - $catNames = array( 'Test', 'Category:Root' ); |
| 11 | + $catNames = array( "Root" ); |
8 | 12 | $catTree->initialiseFromCategoryNames( $catNames ); |
9 | | - //var_dump( $catTree->getEnabledCategoryNames() ); |
10 | 13 | $catTree->printTree(); |
11 | 14 | } |
12 | 15 | } |
Index: trunk/extensions/CollabWatchlist/includes/CategoryTreeManip.php |
— | — | @@ -166,17 +166,18 @@ |
167 | 167 | } |
168 | 168 | |
169 | 169 | protected function printTreeRecursive( $node, $prefix ) { |
170 | | - if( $node->id ) |
171 | | - print $node->id . ": " . $node->name . " enabled: " . $node->enabled . "\n"; |
| 170 | + if( $node->id ) { |
| 171 | + print $prefix . $node->id . ": " . $node->name . " enabled: " . $node->enabled . "\n"; |
| 172 | + } |
172 | 173 | foreach( $node->children as $child ) { |
173 | | - $this->printTreeRecursive( $child, $prefix . ' ' ); |
| 174 | + $this->printTreeRecursive( $child, $prefix . " " ); |
174 | 175 | } |
175 | 176 | } |
176 | 177 | |
177 | 178 | /** Build the category tree, given a list of category names. |
178 | 179 | * All categories and subcategories are enabled by default. |
179 | 180 | * |
180 | | - * @param array $catNames An array of strings representing category names |
| 181 | + * @param array $catNames An array of strings representing category names (without namespace prefix) |
181 | 182 | * @return |
182 | 183 | */ |
183 | 184 | public function initialiseFromCategoryNames( $catNames ) { |
— | — | @@ -248,7 +249,6 @@ |
249 | 250 | */ |
250 | 251 | protected function getChildCategories( $catNames ) { |
251 | 252 | global $wgMemc; |
252 | | - $dbr = wfGetDB( DB_SLAVE ); |
253 | 253 | $childList = array(); |
254 | 254 | $nonCachedCatNames = array(); |
255 | 255 | // Try cache first |
— | — | @@ -269,13 +269,17 @@ |
270 | 270 | // Select the child categories of all categories we have not found in the cache |
271 | 271 | $res = array(); |
272 | 272 | if( !empty( $nonCachedCatNames ) ) { |
| 273 | + $dbr = wfGetDB( DB_SLAVE ); |
273 | 274 | // Select the direct child categories of all category names |
274 | 275 | // I.e. category name, child category id and child category name |
275 | | - $res = $dbr->select( array( 'categorylinks', 'page' ), # Tables |
276 | | - array( 'cl_to AS parName', 'cl_from AS childId', 'page_title AS childName' ), # Fields |
277 | | - array( 'cl_to' => array_keys($nonCachedCatNames), 'page_namespace' => NS_CATEGORY ), # Conditions |
| 276 | + // select cp.page_title AS parName, cl.cl_from AS childId, p.page_title AS childName |
| 277 | + // from page cp join categorylinks cl on cp.page_title = cl.cl_to |
| 278 | + // join page p on p.page_id = cl.cl_from where p.page_namespace = '14'; |
| 279 | + $res = $dbr->select( array( 'cp' => 'page', 'cl' => 'categorylinks', 'p' => 'page' ), # Tables |
| 280 | + array( 'cp.page_title AS parName', 'cl.cl_from AS childId', 'p.page_title AS childName' ), # Fields |
| 281 | + array( 'cp.page_title' => array_keys($nonCachedCatNames), 'cp.page_namespace' => NS_CATEGORY ), # Conditions |
278 | 282 | __METHOD__, array( 'GROUP BY' => 'cl_to' ), # Options |
279 | | - array( 'page' => array( 'JOIN', 'page_id = cl_from' ) ) # Join conditions |
| 283 | + array( 'cl' => array( 'JOIN', 'cp.page_title = cl.cl_to' ), 'p' => array( 'JOIN', 'p.page_id = cl.cl_from') ) # Join conditions |
280 | 284 | ); |
281 | 285 | } |
282 | 286 | |
— | — | @@ -315,7 +319,6 @@ |
316 | 320 | */ |
317 | 321 | protected function getCategoryPageIds( $catNames ) { |
318 | 322 | global $wgMemc; |
319 | | - $dbr = wfGetDB( DB_SLAVE ); |
320 | 323 | $pageInfo = array(); |
321 | 324 | $nonCachedCatNames = array(); |
322 | 325 | // Try cache first |
— | — | @@ -332,6 +335,7 @@ |
333 | 336 | // Select the child categories of all categories we have not found in the cache |
334 | 337 | $res = array(); |
335 | 338 | if( !empty( $nonCachedCatNames ) ) { |
| 339 | + $dbr = wfGetDB( DB_SLAVE ); |
336 | 340 | $res = $dbr->select( array( 'page' ), # Tables |
337 | 341 | array( 'page_id, page_title' ), # Fields |
338 | 342 | array( 'page_title' => $nonCachedCatNames ) # Conditions |