[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mediawiki-l
Subject:    Re: [Mediawiki-l] DB query: Articles of a given Category
From:       Gunter <News2006 () freenet ! de>
Date:       2007-02-25 20:33:31
Message-ID: 45E1F29B.7010201 () freenet ! de
[Download RAW message or body]


Vernon Thommeret schrieb:
> Hi,
>
> I'm trying to come up with code that can tell me whether or not a  
> given category has articles or not. Naturally, I borrowed some code  
> from CategoryPage.php. This is what I got up to:
>
> $res2 = $dbr->select(
> 	array( 'page', 'categorylinks' ),
> 	array( 'page_title' ),
> 	array( 'cl_from =  page_id', 'cl_to' => $title->getArticleID()),
> 	$fname,
> 	array('LIMIT'    => 1 ));
> echo $res2;
> echo $dbr->fetchObject($res2);
>   
If you only want to check, if a category has articles, this would be faster:
$catCount = $dbr->selectField( 'categorylinks', 'count(*)', 
array('cl_to' => $title->getDbKey() ), $fname);

This statement only counts the number of articles pointing to the 
category, or do you need the name of each article?

Vernon Thommeret schrieb:
> Thanks for your help. I got the code working perfectly. One thing,  
> however, is that the category will never update on their own. I have  
> to modify LocalSettings.php, and then it reparses the page. Is this  
> something I have to live with?
>   
Seems to be coincidal. Categories get updated by job queue, meaning as 
long as you have entries in table job, you need to work with your wiki, 
as it executes one job entry for every click.

GunterS

_______________________________________________
MediaWiki-l mailing list
MediaWiki-l@lists.wikimedia.org
http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic