r105587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105586‎ | r105587 | r105588 >
Date:20:54, 8 December 2011
Author:reedy
Status:ok
Tags:
Comment:
MFT r104622, r105267 for UserDailyContribs only
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/UserDailyContribs (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/UserDailyContribs/UserDailyContribs.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/UserDailyContribs/api/ApiUserDailyContribs.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/UserDailyContribs/api/ApiUserDailyContribs.php
@@ -7,25 +7,34 @@
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 ) {
1516 $this->dieUsage( 'Invalid username', 'bad_user' );
1617 }
1718
18 - $now = time();
 19+
 20+ // Defaults to 'now' if not given
 21+ $totime = wfTimestamp( TS_UNIX, $basetimestamp );
 22+
 23+ $fromtime = $totime - ($daysago * 60 *60 *24);
 24+
1925 $result->addValue( $this->getModuleName() ,
2026 'id', $user->getId() );
21 - // returns date of registration in YYYYMMDDHHMMSS format
 27+
 28+ // Returns date of registration in YYYYMMDDHHMMSS format
 29+ $result->addValue( $this->getModuleName(),
 30+ 'registration', $user->getRegistration() ? $user->getRegistration() : '0' );
 31+
 32+ // Returns number of edits between daysago date and basetimestamp (or today)
 33+ $result->addValue( $this->getModuleName(),
 34+ 'timeFrameEdits', getUserEditCountSince( $fromtime, $user, $totime ) );
 35+
 36+ // Returns total number of edits
2237 $result->addValue( $this->getModuleName() ,
23 - 'registration', !$user->getRegistration() ? '0' : $user->getRegistration() );
24 - // returns number of edits since daysago param
25 - $result->addValue( $this->getModuleName() ,
26 - 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24), $user ) );
27 - // returns total number of edits
28 - $result->addValue( $this->getModuleName() ,
29 - 'totalEdits', ($user->getEditCount() == NULL)?0:$user->getEditCount() );
 38+ 'totalEdits', $user->getEditCount() == NULL ? 0 : $user->getEditCount() );
3039 }
3140
3241 public function getAllowedParams() {
@@ -37,6 +46,9 @@
3847 ApiBase::PARAM_TYPE => 'integer',
3948 ApiBase::PARAM_MIN => 0,
4049 ),
 50+ 'basetimestamp' => array(
 51+ ApiBase::PARAM_TYPE => 'timestamp',
 52+ ),
4153 );
4254 }
4355
@@ -44,6 +56,10 @@
4557 return array(
4658 'user' => 'Username to query',
4759 'daysago' => 'Number of edits since this many days ago',
 60+ 'basetimestamp' => array( 'Date from which daysago will be calculated (instead of "today").',
 61+ 'Count returned in timeFrameEdits will be editcount between this date and the date',
 62+ '"daysago" from it.'
 63+ ),
4864 );
4965 }
5066
Index: branches/wmf/1.18wmf1/extensions/UserDailyContribs/UserDailyContribs.php
@@ -34,25 +34,34 @@
3535 /**
3636 * Get the number of revisions a user has made since a given time
3737 *
38 - * @param $time beginning timestamp
39 - * @param $user User
 38+ * @param $fromtime: beginning timestamp
 39+ * @param $user User: (optional) User object to get edit count for
 40+ * @param $totime: (optional) ending timestamp
4041 * @return number of revsions this user has made
4142 */
42 -function getUserEditCountSince( $time = null, User $user = null ) {
 43+function getUserEditCountSince( $fromtime = null, User $user = null, $totime = null ) {
4344 global $wgUser;
4445
4546 // Fallback on current user
4647 if ( is_null( $user ) ) {
4748 $user = $wgUser;
4849 }
49 - // Round time down to a whole day
50 - $time = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $time ) );
 50+
 51+ // Round times down to a whole day, possibly letting a null value
 52+ // pass to wfTimestamp which will give us today.
 53+ $fromtime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $fromtime ) );
 54+ $totime = gmdate( 'Y-m-d', wfTimestamp( TS_UNIX, $totime ) );
 55+
5156 // Query the user contribs table
5257 $dbr = wfGetDB( DB_SLAVE );
5358 $edits = $dbr->selectField(
5459 'user_daily_contribs',
5560 'SUM(contribs)',
56 - array( 'user_id' => $user->getId(), 'day >= ' . $dbr->addQuotes( $time ) ),
 61+ array(
 62+ 'user_id' => $user->getId(),
 63+ 'day >= ' . $dbr->addQuotes( $fromtime ),
 64+ 'day <= ' . $dbr->addQuotes( $totime )
 65+ ),
5766 __METHOD__
5867 );
5968 // Return edit count as an integer
Property changes on: branches/wmf/1.18wmf1/extensions/UserDailyContribs
___________________________________________________________________
Added: svn:mergeinfo
6069 Merged /branches/new-installer/phase3/extensions/UserDailyContribs:r43664-66004
6170 Merged /branches/REL1_15/phase3/extensions/UserDailyContribs:r51646
6271 Merged /branches/REL1_18/extensions/UserDailyContribs:r101758,103190
6372 Merged /branches/REL1_17/phase3/extensions/UserDailyContribs:r81445,81448
6473 Merged /trunk/extensions/UserDailyContribs:r99592,99653,100092,100419,100686,100692,100699,103669,104337,104622,104736,105267
6574 Merged /branches/sqlite/extensions/UserDailyContribs:r58211-58321
6675 Merged /trunk/phase3/extensions/UserDailyContribs:r92580,92634,92713,92762,92765,92791,92854,92884,92886-92887,92894,92898,92907,92932,92958,93141,93149,93151,93233-93234,93258,93266,93303,93516-93518,93520,93818-93822,93847,93858,93891,93935-93936,94058,94062,94068,94107,94155,94235,94277,94346,94372,94422,94425,94444,94448,94456,94498,94517,94601,94630,94728,94738,94825,94862,94995-94997,95023,95042,95072-95073,95155,95327,95332,95410,95422,95426,95442,95468,95601,95812,98578,98598,98656

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r104622[UserDailyContribs] Add basetimestamp parameter...krinkle23:52, 29 November 2011
r105267[HarvardResearch] Swap ternary operator in registration fallback to zero...krinkle01:02, 6 December 2011

Status & tagging log