r100310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100309‎ | r100310 | r100311 >
Date:00:59, 20 October 2011
Author:johnduhart
Status:resolved (Comments)
Tags:
Comment:
Clean up some odd looping
Modified paths:
  • /trunk/extensions/CheckUser/api/ApiQueryCheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/api/ApiQueryCheckUser.php
@@ -65,16 +65,15 @@
6666 }
6767 }
6868
69 - $count = 0;
 69+ $resultIPs = array();
7070 foreach ( array_keys( $ips ) as $ip ) {
71 - $ips[$count] = $ips[$ip];
72 - $ips[$count]['address'] = $ip;
73 - unset( $ips[$ip] );
74 - $count++;
 71+ $newIp = $ips[$ip];
 72+ $newIp['address'] = $ip;
 73+ $resultIPs[] = $newIp;
7574 }
7675
7776 CheckUser::addLogEntry( 'userips', 'user', $target, $reason, $user_id );
78 - $result->addValue( array( 'query', $this->getModuleName() ), 'userips', $ips );
 77+ $result->addValue( array( 'query', $this->getModuleName() ), 'userips', $resultIPs );
7978 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'userips' ), 'ip' );
8079 break;
8180
@@ -109,26 +108,27 @@
110109 $result = $this->getResult();
111110
112111 $edits = array();
113 - $count = 0;
114112 foreach ( $res as $row ) {
115 - $edits[$count]['timestamp'] = $row->cuc_timestamp;
116 - $edits[$count]['ns'] = $row->cuc_namespace;
117 - $edits[$count]['title'] = $row->cuc_title;
118 - $edits[$count]['user'] = $row->cuc_user_text;
 113+ $edit = array(
 114+ 'timetamp' => $row->cuc_timestamp,
 115+ 'ns' => $row->cuc_namespace,
 116+ 'title' => $row->cuc_title,
 117+ 'user' => $row->cuc_user_text,
 118+ 'ip' => $row->cuc_ip,
 119+ 'agent' => $row->cuc_agent,
 120+ );
119121 if ( $row->cuc_actiontext ) {
120 - $edits[$count]['summary'] = $row->cuc_actiontext;
 122+ $edit['summary'] = $row->cuc_actiontext;
121123 } elseif ( $row->cuc_comment ) {
122 - $edits[$count]['summary'] = $row->cuc_comment;
 124+ $edit['summary'] = $row->cuc_comment;
123125 }
124126 if ( $row->cuc_minor ) {
125 - $edits[$count]['minor'] = 'm';
 127+ $edit['minor'] = 'm';
126128 }
127 - $edits[$count]['ip'] = $row->cuc_ip;
128129 if ( $row->cuc_xff ) {
129 - $edits[$count]['xff'] = $row->cuc_xff;
 130+ $edit['xff'] = $row->cuc_xff;
130131 }
131 - $edits[$count]['agent'] = $row->cuc_agent;
132 - $count++;
 132+ $edits[] = $edit;
133133 }
134134
135135 CheckUser::addLogEntry( $log_type[0], $log_type[1], $target, $reason, $user_id ? $user_id : '0' );
@@ -176,20 +176,17 @@
177177 }
178178 }
179179
180 - $count = 0;
181 - foreach ( array_keys( $users ) as $user ) {
182 - $users[$count] = $users[$user];
183 - $users[$count]['name'] = $user;
184 - unset( $users[$user] );
 180+ $resultUsers = array();
 181+ foreach ( $users as $userName => $userData ) {
 182+ $userData['name'] = $userName;
 183+ $result->setIndexedTagName( $userData['ips'], 'ip' );
 184+ $result->setIndexedTagName( $userData['agents'], 'agent' );
185185
186 - $result->setIndexedTagName( $users[$count]['ips'], 'ip' );
187 - $result->setIndexedTagName( $users[$count]['agents'], 'agent' );
188 -
189 - $count++;
 186+ $resultUsers[] = $userData;
190187 }
191188
192189 CheckUser::addLogEntry( $log_type, 'ip', $target, $reason );
193 - $result->addValue( array( 'query', $this->getModuleName() ), 'ipusers', $users );
 190+ $result->addValue( array( 'query', $this->getModuleName() ), 'ipusers', $resultUsers );
194191 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName(), 'ipusers' ), 'user' );
195192 break;
196193
Index: trunk/extensions/CheckUser/api/ApiQueryCheckUserLog.php
@@ -39,15 +39,15 @@
4040 $res = $this->select( __METHOD__ );
4141 $result = $this->getResult();
4242
43 - $count = 0;
4443 $log = array();
4544 foreach ( $res as $row ) {
46 - $log[$count]['timestamp'] = $row->cul_timestamp;
47 - $log[$count]['checkuser'] = $row->cul_user_text;
48 - $log[$count]['type'] = $row->cul_type;
49 - $log[$count]['reason'] = $row->cul_reason;
50 - $log[$count]['target'] = $row->cul_target_text;
51 - $count++;
 45+ $log[] = array(
 46+ 'timestamp' => $row->cul_timestamp,
 47+ 'checkuser' => $row->cul_user_text,
 48+ 'type' => $row->cul_type,
 49+ 'reason' => $row->cul_reason,
 50+ 'target' => $row->curl_target_text,
 51+ );
5252 }
5353
5454 $result->addValue( array( 'query', $this->getModuleName() ), 'entries', $log );

Follow-up revisions

RevisionCommit summaryAuthorDate
r100312Followup r100310, one more thingjohnduhart01:01, 20 October 2011
r107831Fixup for r100310: timetamp -> timestampdemon14:09, 2 January 2012

Comments

#Comment by Catrope (talk | contribs)   16:35, 21 December 2011
+						'timetamp' => $row->cuc_timestamp,

Typo, missing s in timestamp. OK otherwise.

Status & tagging log