r104879 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104878‎ | r104879 | r104880 >
Date:17:58, 1 December 2011
Author:petrb
Status:deferred
Tags:
Comment:
Improved check for required parameter
Modified paths:
  • /trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OnlineStatusBar/OnlineStatusBar.api.php
@@ -17,30 +17,28 @@
1818
1919 public function execute() {
2020 $params = $this->extractRequestParams();
21 - if (is_string ( $params['user'] )) {
22 - $result = OnlineStatusBar::getUserInfoFromString( $params['user'] );
23 - // if user is IP and we track them
24 - if ( User::isIP( $params['user'] ) && $result === false ) {
25 - $result = OnlineStatusBar::getAnonFromString( $params['user'] );
26 - }
27 - if ( $result === false ) {
28 - $ret = 'unknown';
29 - } else {
30 - $ret = $result[0];
31 - }
32 -
33 - $this->getResult()->addValue(
34 - null, $this->getModuleName(), array( 'result' => $ret ) );
35 - } else
36 - {
37 - $this->dieUsage( "You provided an invalid user." );
 21+ $result = OnlineStatusBar::getUserInfoFromString( $params['user'] );
 22+ // if user is IP and we track them
 23+ if ( User::isIP( $params['user'] ) && $result === false ) {
 24+ $result = OnlineStatusBar::getAnonFromString( $params['user'] );
3825 }
 26+ if ( $result === false ) {
 27+ $ret = 'unknown';
 28+ } else {
 29+ $ret = $result[0];
 30+ }
 31+
 32+ $this->getResult()->addValue(
 33+ null, $this->getModuleName(), array( 'result' => $ret ) );
3934 }
4035
4136 public function getAllowedParams() {
4237 // params
4338 return array(
44 - 'user' => null,
 39+ 'user' => array (
 40+ ApiBase::PARAM_TYPE => 'string',
 41+ ApiBase::PARAM_REQUIRED => true
 42+ ),
4543 );
4644 }
4745

Status & tagging log