Some followup to r51200:
authorAlex Z <mrzman@users.mediawiki.org>
Sun, 31 May 2009 18:55:38 +0000 (18:55 +0000)
committerAlex Z <mrzman@users.mediawiki.org>
Sun, 31 May 2009 18:55:38 +0000 (18:55 +0000)
* Save a query by not using User::edits()
* Mark as an expensive function (it needs at least 1 query for each use)
* Use number formatting/raw option rather than pointless wfEscapeWikiText()

includes/parser/CoreParserFunctions.php

index a07d67f..9ba8554 100644 (file)
@@ -596,16 +596,19 @@ class CoreParserFunctions {
        }
        
        /**
-       * Returns the number of contributions by a certain user
+       * Returns the number of contributions by a certain user. This is an 
+       * expensive parser function and can't be called too many times per page
        */
-       static function numberofcontribs( $parser, $user = null ) {
-               if ( is_null($user) || !User::isValidUserName( $user ) )
+       static function numberofcontribs( $parser, $user = null, $raw = null ) {
+               if ( is_null($user) || !User::isValidUserName( $user ) ) {
                        return '';
-                       
+               }
+               if ( !$parser->incrementExpensiveFunctionCount() ) {
+                       return '';
+               }
                $u = User::newFromName( $user );
                $u->load();
-
-               return wfEscapeWikiText( $u->edits( $u->mId ) );
+               return self::formatRaw( $u->mEditCount, $raw );
        }
 
        /**