---- skizzerz(a)svn.wikimedia.org schrijft:
> Revision: 37754
> Author: skizzerz
> Date: 2008-07-16 16:55:59 +0000 (Wed, 16 Jul 2008)
>
> Log Message:
> -----------
> * Add extension to svn: CategoryTests - parser functions for testing categories
>
> --- trunk/extensions/CategoryTests/CategoryTests.php (rev 0)
> +++ trunk/extensions/CategoryTests/CategoryTests.php 2008-07-16 16:55:59 UTC (rev 37754)
> (...)
> + function ifcategory( &$parser, $category = '', $then = '', $else = '', > + foreach( $data['query']['pages'][$id]['categories'] as $key => $value ) {
> (...)
> + if("Category:{$category}" == $data['query']['pages'][$id]['categories'][$key]['title']) {
Why don't you just use $value['title'] here?
> + function ifnocategories( &$parser, $then = '', $else = '', $pagename = '' ) {
> (...)
> + $params = new FauxRequest(array ('action' => 'query', 'titles' => $page, 'prop' => 'categories') );
> + $api = new ApiMain($params);
> + $api->execute();
> + $data =& $api->getResultData();
> + if(!array_key_exists('categories', $data['query']['pages'][$id])) {
> + return $then;
> + }
Since you're just checking for the presence of categories here, you could use cllimit=1 to spare the server a little bit.
Roan Kattouw (Catrope)