r93810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93809‎ | r93810 | r93811 >
Date:08:23, 3 August 2011
Author:flohack
Status:deferred
Tags:
Comment:
Fixed a bug regarding category traversal; Better category tree printing
Modified paths:
  • /trunk/extensions/CollabWatchlist/includes/CategoryTreeManip.php (modified) (history)
  • /trunk/extensions/CollabWatchlist/tests/CollabWatchlistTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CollabWatchlist/tests/CollabWatchlistTest.php
@@ -2,10 +2,13 @@
33
44 class CollabWatchlistTest extends PHPUnit_Framework_TestCase {
55 public function testCategoryTree() {
 6+ /* Workaround for eclipse xdebug
 7+ $path = '/usr/share/php';
 8+ set_include_path(get_include_path() . PATH_SEPARATOR . $path);
 9+ */
610 $catTree = new CategoryTreeManip();
7 - $catNames = array( 'Test', 'Category:Root' );
 11+ $catNames = array( "Root" );
812 $catTree->initialiseFromCategoryNames( $catNames );
9 - //var_dump( $catTree->getEnabledCategoryNames() );
1013 $catTree->printTree();
1114 }
1215 }
Index: trunk/extensions/CollabWatchlist/includes/CategoryTreeManip.php
@@ -166,17 +166,18 @@
167167 }
168168
169169 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+ }
172173 foreach( $node->children as $child ) {
173 - $this->printTreeRecursive( $child, $prefix . ' ' );
 174+ $this->printTreeRecursive( $child, $prefix . " " );
174175 }
175176 }
176177
177178 /** Build the category tree, given a list of category names.
178179 * All categories and subcategories are enabled by default.
179180 *
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)
181182 * @return
182183 */
183184 public function initialiseFromCategoryNames( $catNames ) {
@@ -248,7 +249,6 @@
249250 */
250251 protected function getChildCategories( $catNames ) {
251252 global $wgMemc;
252 - $dbr = wfGetDB( DB_SLAVE );
253253 $childList = array();
254254 $nonCachedCatNames = array();
255255 // Try cache first
@@ -269,13 +269,17 @@
270270 // Select the child categories of all categories we have not found in the cache
271271 $res = array();
272272 if( !empty( $nonCachedCatNames ) ) {
 273+ $dbr = wfGetDB( DB_SLAVE );
273274 // Select the direct child categories of all category names
274275 // 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
278282 __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
280284 );
281285 }
282286
@@ -315,7 +319,6 @@
316320 */
317321 protected function getCategoryPageIds( $catNames ) {
318322 global $wgMemc;
319 - $dbr = wfGetDB( DB_SLAVE );
320323 $pageInfo = array();
321324 $nonCachedCatNames = array();
322325 // Try cache first
@@ -332,6 +335,7 @@
333336 // Select the child categories of all categories we have not found in the cache
334337 $res = array();
335338 if( !empty( $nonCachedCatNames ) ) {
 339+ $dbr = wfGetDB( DB_SLAVE );
336340 $res = $dbr->select( array( 'page' ), # Tables
337341 array( 'page_id, page_title' ), # Fields
338342 array( 'page_title' => $nonCachedCatNames ) # Conditions

Status & tagging log