Search code examples
mediawikimediawiki-apimediawiki-extensions

Displaying edit count on MediaWiki


I would like to display number of edits / contribution on user page. Is there any way to do that?

I tried to use link mentioned here: http://en.wikipedia.org/wiki/Help:User_contributions

So if follow that, I got a URL something like this:

http://ourdomain/api.php?action=query&list=users&ususers=MYUSERNAME&usprop=editcount

And if I use it, it shows me a page with correct edit count. But it shows as XML like:

<?xml version="1.0"?>
<api>
  <query>
   <users>
      <user name="USERNAME" editcount="728" />
   </users>
  </query>
</api>

On this XML page, I can see the correct edit count. But I just want to display it as a count on a different page. Something like "Total number of edits: 728". We are using MediaWiki 1.15.5-7.


Solution

  • You have already found what you are looking for! The API will give you the best estimate of a user's editcount. You can add Javascript to be run on each pageview to MediaWiki:Common.js, to inject this data into the user page. In your API call, append &format=json to get a more JS friendly format.

    If, for some reason, you do not want to use Javascript here, you could write your own extension to handle this in the backend. This can be implemented as a parser function, to be invoked like {{USERCONTRIBS:UserName}}, or similar. The method you are looking for is User::getEditCount(). To get the user object, you can use User::newFromName. This, however, would require the user pages to be purged on each pageload, making them a lot slower to load, or you would have to accept that the count in not always up to date.

    There might also be some existing extensions that let you print the edit count. I know for sure that Extension:SemanticExtraSpecialProperties does, though that depends on the whole SemanticMediawiki package. For an example of how to display user statistics with SMW+SESP, see this page.