Community Central
Community Central
Forums: Index Support Requests Adding Personal EditCount as a JS Variable
Fandom's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Archive
Note: This topic has been unedited for 4196 days. It is considered archived - the discussion is over. Information in this thread may be out of date. Do not add to unless it really needs a response.


I'm trying to create a "Level" system to motivate users to edit, since I don't like the achievement system. The idea is to have a progress bar that resets every time you get so many edits, or "level up". For example, Level 1 will be 0 edits, Level 2 will be 1 edit, Level 3 will be 3 edits, Level 4 will be 6 edits, etc. The problem is, throughout all of the "wg" variables in the default Javascript, there is none for edit counts. So I set out to create one. I'm learning jQuery, don't know Javascript, and am stuck with the following results so far:

var wgEditCount = ('http://' + encodeURIComponent(wgDBname) + '.wikia.com/wiki/User:' + encodeURIComponent(wgUserName) + '?printable=1 .tally em');

The idea is to import the number that's on their user page as a variable, which can be used to carry out functions for the rest of the project. The code is modified from a snippet I got from Wikia Staff a while back when trying to do the same thing:

$(function() { :$('.editcount').load( 'http://' + encodeURIComponent(wgDBname) + '.wikia.com/wiki/Special:Editcount/' + encodeURIComponent( wgUserName ) + '?printable=1 #editcount .TablePager > tbody > tr:eq(1) > th:first' ); } );

As seen, this takes any element with the class "editcount" and loads in the user's number of edits from their Editcount page (user page in the case of my own code, above). Any ideas on whether/if this can be put into a variable for use in another function? Thanks. -Sherm/Talk

A few things - your code above (that you wrote) doesn't do what you want - you're setting wgEditCount to a string that is the url for the user's userpage, plus a CSS selector. The CSS selector is specifically for the $().load() jQuery method, which is specifically for using ajax to put HTML on the page. What you want to do is get the HTML for the editcount page, convert the table into a set of variables, and then create your progress bar accordingly. You can do this without creating another wg variable (and, in fact, you will find it easier not to). You can use jQuery's $.get() method to get the HTML for the editcount page. It accepts a callback function, which you can use to first parse the table for the information you want, and then build your progress bar. I would also suggest using ?action=render instead of ?printable=1, because this will decrease your bandwidth consumption.  Monchoman45  Talk  Contribs  Skystone  18:22,10/22/2012 
Special pages ignore any action= values in the URL, e.g. http://community.wikia.com/index.php?title=Special:Editcount&action=render is not rendered, so printable=1 is your only recourse in that case.
Normally I would suggest that you should use the MediaWiki API (mw:API:Users) for this, but it doesn't seem to be very accommodating when it comes to getting user edit counts. E.g. http://community.wikia.com/api.php?action=query&list=users&ususers=Mathmagician&usprop=editcount doesn't display the correct user edit count (and that module can't get edit counts in individual namespaces, only the overall total).
Monch's suggestion about ajax-ing the edit count page may be your best option, because you can get edit counts by namespace that way. If you just need total edit counts, your plan to ajax the user's profile page will also work. 20px_Rin_Tohsaka_Avatar.png Mathmagician ƒ(♫) 19:03 UTC, Monday, 22 October 2012
Okay, thanks for the help. As I said, I don't know JavaScript, so I'll be asking a friend what this means in literal terms, but the basics made sense. Thanks. -Sherm/Talk