r99005 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99004‎ | r99005 | r99006 >
Date:14:19, 5 October 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
http://en.wikipedia.org/w/api.php?action=userdailycontribs&user=WikiSysop&daysago=5

<error code="internal_api_error_MWException" info="Exception Caught: Internal error in ApiResult::setElement: Bad parameter" xml:space="preserve">

#0 /usr/local/apache/common-local/php-1.18/includes/api/ApiBase.php(1241): wfDebugDieBacktrace('Internal error ...')
#1 /usr/local/apache/common-local/php-1.18/includes/api/ApiResult.php(149): ApiBase::dieDebug('ApiResult::setE...', 'Bad parameter')
#2 /usr/local/apache/common-local/php-1.18/includes/api/ApiResult.php(293): ApiResult::setElement(Array, 'registration', NULL, false)
#3 /usr/local/apache/common-local/php-1.18/extensions/UserDailyContribs/api/ApiUserDailyContribs.php(21): ApiResult->addValue('userdailycontri...', 'registration', NULL)
#4 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(692): ApiUserDailyContribs->execute()
#5 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(358): ApiMain->executeAction()
#6 /usr/local/apache/common-local/php-1.18/includes/api/ApiMain.php(342): ApiMain->executeActionWithErrorHandling()
#7 /usr/local/apache/common-local/php-1.18/api.php(115): ApiMain->execute()
#8 /usr/local/apache/common-local/live-1.5/api.php(3): require('/usr/local/apac...')
#9 {main}

</error>
</api>

Some documentation and other tweaks
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
@@ -1,4 +1,4 @@
2 -<?php
 2+<?php
33
44 class ApiUserDailyContribs extends ApiBase {
55
@@ -8,17 +8,18 @@
99
1010 $userName = $params['user'];
1111 $days = $params['daysago'];
12 - $user = User::newFromName($userName);
 12+ $user = User::newFromName( $userName );
 13+
1314 if ( !$user ) {
14 - $this->dieUsage( 'Specified user does not exist', 'bad_user' );
 15+ $this->dieUsage( 'Invalid username', 'bad_user' );
1516 }
16 -
 17+
1718 $now = time();
1819 $result->addValue( $this->getModuleName() ,
1920 'id', $user->getId() );
2021 // returns date of registration in YYYYMMDDHHMMSS format
2122 $result->addValue( $this->getModuleName() ,
22 - 'registration', $user->getRegistration() ? '0' : $user->getRegistration() );
 23+ 'registration', !$user->getRegistration() ? '0' : $user->getRegistration() );
2324 // returns number of edits since daysago param
2425 $result->addValue( $this->getModuleName() ,
2526 'timeFrameEdits', getUserEditCountSince( $now - ($days * 60 *60 *24), $user ) );
@@ -30,13 +31,12 @@
3132 public function getAllowedParams() {
3233 return array(
3334 'user' => array(
34 - ApiBase::PARAM_TYPE => 'user',
35 - ),
 35+ ApiBase::PARAM_TYPE => 'user',
 36+ ),
3637 'daysago' => array(
3738 ApiBase::PARAM_TYPE => 'integer',
3839 ApiBase::PARAM_MIN => 0,
39 - ),
40 -
 40+ ),
4141 );
4242 }
4343
@@ -51,6 +51,12 @@
5252 return 'Get the total number of user edits, time of registration, and edits in a given timeframe';
5353 }
5454
 55+ public function getPossibleErrors() {
 56+ return array_merge( parent::getPossibleErrors(), array(
 57+ array( 'code' => 'bad_user', 'info' => 'Invalid username' )
 58+ ) );
 59+ }
 60+
5561 protected function getExamples() {
5662 return 'api.php?action=userdailycontribs&user=WikiSysop&daysago=5';
5763 }
@@ -58,5 +64,5 @@
5965 public function getVersion() {
6066 return __CLASS__ . ': $Id$';
6167 }
62 -
 68+
6369 }
\ No newline at end of file
Index: trunk/extensions/UserDailyContribs/UserDailyContribs.php
@@ -1,12 +1,12 @@
22 <?php
33 /**
44 * User Daily Contributions extension
5 - *
 5+ *
66 * This extension adds a step to saving an article that incriments a counter for a user's activity in a given day.
7 - *
 7+ *
88 * @file
99 * @ingroup Extensions
10 - *
 10+ *
1111 * @author Nimish Gautam <ngautam@wikimedia.org>
1212 * @author Trevor Parscal <tparscal@wikimedia.org>
1313 * @license GPL v2 or later
@@ -35,11 +35,12 @@
3636 * Get the number of revisions a user has made since a given time
3737 *
3838 * @param $time beginning timestamp
 39+ * @param $user User
3940 * @return number of revsions this user has made
4041 */
4142 function getUserEditCountSince( $time = null, User $user = null ) {
4243 global $wgUser;
43 -
 44+
4445 // Fallback on current user
4546 if ( is_null( $user ) ) {
4647 $user = $wgUser;

Follow-up revisions

RevisionCommit summaryAuthorDate
r99006MFT r99005reedy14:22, 5 October 2011
r105267[HarvardResearch] Swap ternary operator in registration fallback to zero...krinkle01:02, 6 December 2011

Comments

#Comment by Jack Phoenix (talk | contribs)   14:40, 5 October 2011
Index: trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php
===================================================================
--- trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php	(revision 99004)
+++ trunk/extensions/UserDailyContribs/api/ApiUserDailyContribs.php	(revision 99005)
@@ -1,4 +1,4 @@
-<?php 
+<?php

BOM or removal of a BOM?

#Comment by Jack Phoenix (talk | contribs)   14:41, 5 October 2011

...or just whitespace that I failed to see. Nevermind my comment.

Status & tagging log