Index: trunk/phase3/includes/Parser.php |
— | — | @@ -3285,6 +3285,20 @@ |
3286 | 3286 | } |
3287 | 3287 | |
3288 | 3288 | /** |
| 3289 | + * Increment the expensive function count |
| 3290 | + * |
| 3291 | + * @return boolean False if the limit has been exceeded |
| 3292 | + */ |
| 3293 | + function incrementExpensiveFunctionCount() { |
| 3294 | + global $wgExpensiveParserFunctionLimit; |
| 3295 | + $this->mExpensiveFunctionCount++; |
| 3296 | + if($this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) { |
| 3297 | + return true; |
| 3298 | + } |
| 3299 | + return false; |
| 3300 | + } |
| 3301 | + |
| 3302 | + /** |
3289 | 3303 | * Strip double-underscore items like __NOGALLERY__ and __NOTOC__ |
3290 | 3304 | * Fills $this->mDoubleUnderscores, returns the modified text |
3291 | 3305 | */ |
Index: trunk/phase3/includes/CoreParserFunctions.php |
— | — | @@ -220,17 +220,22 @@ |
221 | 221 | * tent. This is an expensive parser function and can't be called too many |
222 | 222 | * times per page. |
223 | 223 | */ |
224 | | - static function pagesincategory( $parser, $category = '', $raw = null ) { |
225 | | - global $wgExpensiveParserFunctionLimit; |
226 | | - $category = Category::newFromName($category); |
227 | | - if( !is_object( $category ) ) { |
228 | | - return 0; |
| 224 | + static function pagesincategory( $parser, $name = '', $raw = null ) { |
| 225 | + static $cache = array(); |
| 226 | + $category = Category::newFromName( $name ); |
| 227 | + |
| 228 | + # Normalize name for cache |
| 229 | + $name = $category->getName(); |
| 230 | + |
| 231 | + if( isset( $cache[$name] ) ) { |
| 232 | + return self::formatRaw( $cache[$name], $raw ); |
229 | 233 | } |
230 | | - $parser->mExpensiveFunctionCount++; |
231 | | - if ($parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) { |
232 | | - return self::formatRaw( (int)$category->getPageCount(), $raw ); |
| 234 | + |
| 235 | + $count = 0; |
| 236 | + if( is_object( $category ) && $parser->incrementExpensiveFunctionCount() ) { |
| 237 | + $count = $cache[$name] = (int)$category->getPageCount(); |
233 | 238 | } |
234 | | - return 0; |
| 239 | + return self::formatRaw( $count, $raw ); |
235 | 240 | } |
236 | 241 | |
237 | 242 | static function language( $parser, $arg = '' ) { |