r104622 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104621‎ | r104622 | r104623 >
Date:23:52, 29 November 2011
Author:krinkle
Status:ok
Tags:
Comment:
[UserDailyContribs] Add basetimestamp parameter
* Restructure getUserEditCountSince a bit to allow setting $totime.
-- Yes both the name of this function and the function arguments are unfortunate, that's for another time.
* Default behavior remains unchanged.
* Minor whitespace/code conventions clean up and adding a bit of documentation
Modified paths:
  • /trunk/extensions/UserDailyContribs/UserDailyContribs.php (modified) (history)
  • /trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php
@@ -7,7 +7,8 @@
88 $result = $this->getResult();
99
1010 $userName = $params['user'];
11 - $days = $params['daysago'];
 11+ $daysago = $params['daysago'];
 12+ $basetimestamp = $params['basetimestamp'];
1213 $user = User::newFromName( $userName );
1314
1415 if ( !$user ) {
@@ -19,18 +20,26 @@
2021 if ( $wgUserDailyContributionsApiCheckAuthPlugin && !$wgAuth->userExists( $userName ) ) {
2122 $this->dieUsage( 'Specified user does not exist', 'bad_user' );
2223 }
23 - $now = time();
 24+
 25+ // Defaults to 'now' if not given
 26+ $totime = wfTimestamp( TS_UNIX, $basetimestamp );
 27+
 28+ $fromtime = $totime - ($daysago * 60 *60 *24);
 29+
2430 $result->addValue( $this->getModuleName() ,
2531 'id', $user->getId() );
26 - // returns date of registration in YYYYMMDDHHMMSS format
27 - $result->addValue( $this->getModuleName() ,
 32+
 33+ // Returns date of registration in YYYYMMDDHHMMSS format
 34+ $result->addValue( $this->getModuleName(),
2835 'registration', !$user->getRegistration() ? '0' : $user->getRegistration() );
29 - // returns number of edits since daysago param
 36+
 37+ // Returns number of edits between daysago date and basetimestamp (or today)
 38+ $result->addValue( $this->getModuleName(),
 39+ 'timeFrameEdits', getUserEditCountSince( $fromtime, $user, $totime ) );
 40+
 41+ // Returns total number of edits
3042 $result->addValue( $this->getModuleName() ,
31 - 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24), $user ) );
32 - // returns total number of edits
33 - $result->addValue( $this->getModuleName() ,
34 - 'totalEdits', ($user->getEditCount() == NULL)?0:$user->getEditCount() );
 43+ 'totalEdits', $user->getEditCount() == NULL ? 0 : $user->getEditCount() );
3544 }
3645
3746 public function getAllowedParams() {
@@ -42,6 +51,9 @@
4352 ApiBase::PARAM_TYPE => 'integer',
4453 ApiBase::PARAM_MIN => 0,
4554 ),
 55+ 'basetimestamp' => array(
 56+ ApiBase::PARAM_TYPE => 'timestamp',
 57+ ),
4658 );
4759 }
4860
@@ -49,6 +61,10 @@
5062 return array(
5163 'user' => 'Username to query',
5264 'daysago' => 'Number of edits since this many days ago',
 65+ 'basetimestamp' => array( 'Date from which daysago will be calculated (instead of "today").',
 66+ 'Count returned in timeFrameEdits will be editcount between this date and the date',
 67+ '"daysago" from it.'
 68+ ),
5369 );
5470 }
5571
Index: trunk/extensions/UserDailyContribs/UserDailyContribs.php
@@ -44,25 +44,34 @@
4545 /**
4646 * Get the number of revisions a user has made since a given time
4747 *
48 - * @param $time beginning timestamp
49 - * @param $user User
 48+ * @param $fromtime: beginning timestamp
 49+ * @param $user User: (optional) User object to get edit count for
 50+ * @param $totime: (optional) ending timestamp
5051 * @return number of revsions this user has made
5152 */
52 -function getUserEditCountSince( $time = null, User $user = null ) {
 53+function getUserEditCountSince( $fromtime = null, User $user = null, $totime = null ) {
5354 global $wgUser;
5455
5556 // Fallback on current user
5657 if ( is_null( $user ) ) {
5758 $user = $wgUser;
5859 }
59 - // Round time down to a whole day
60 - $time = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $time ) );
 60+
 61+ // Round times down to a whole day, possibly letting a null value
 62+ // pass to wfTimestamp which will give us today.
 63+ $fromtime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $fromtime ) );
 64+ $totime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $totime ) );
 65+
6166 // Query the user contribs table
6267 $dbr = wfGetDB( DB_SLAVE );
6368 $edits = $dbr->selectField(
6469 'user_daily_contribs',
6570 'SUM(contribs)',
66 - array( 'user_id' => $user->getId(), 'day >= ' . $dbr->addQuotes( $time ) ),
 71+ array(
 72+ 'user_id' => $user->getId(),
 73+ 'day >= ' . $dbr->addQuotes( $fromtime ),
 74+ 'day <= ' . $dbr->addQuotes( $totime )
 75+ ),
6776 __METHOD__
6877 );
6978 // Return edit count as an integer

Follow-up revisions

RevisionCommit summaryAuthorDate
r105239[HarvardResearch][CentralNotice] Temporary wgNoticeBanner_Harvard2011 data....krinkle22:54, 5 December 2011
r105587MFT r104622, r105267 for UserDailyContribs onlyreedy20:54, 8 December 2011
r107929MFT r104622, r104867, r107120, r107337reedy19:34, 3 January 2012

Status & tagging log