r43014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43013‎ | r43014 | r43015 >
Date:19:23, 1 November 2008
Author:catrope
Status:old
Tags:
Comment:
API: Clean up ApiQueryBlocks, which was a stylistic mess. I can't believe I actually wrote that code (I was young and foolish, I guess :P )
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryBlocks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBlocks.php
@@ -42,10 +42,6 @@
4343 }
4444
4545 public function execute() {
46 - $this->run();
47 - }
48 -
49 - private function run() {
5046 global $wgUser;
5147
5248 $params = $this->extractRequestParams();
@@ -92,12 +88,12 @@
9389 $this->addOption('LIMIT', $params['limit'] + 1);
9490 $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']);
9591 if(isset($params['ids']))
96 - $this->addWhere(array('ipb_id' => $params['ids']));
 92+ $this->addWhereFld('ipb_id', $params['ids']);
9793 if(isset($params['users']))
9894 {
9995 foreach((array)$params['users'] as $u)
10096 $this->prepareUsername($u);
101 - $this->addWhere(array('ipb_address' => $this->usernames));
 97+ $this->addWhereFld('ipb_address', $this->usernames);
10298 }
10399 if(isset($params['ip']))
104100 {
@@ -120,7 +116,7 @@
121117 ));
122118 }
123119 if(!$wgUser->isAllowed('suppress'))
124 - $this->addWhere(array('ipb_deleted' => 0));
 120+ $this->addWhereFld('ipb_deleted', 0);
125121
126122 // Purge expired entries on one in every 10 queries
127123 if(!mt_rand(0, 10))
@@ -131,7 +127,7 @@
132128 $count = 0;
133129 while($row = $res->fetchObject())
134130 {
135 - if($count++ == $params['limit'])
 131+ if(++$count > $params['limit'])
136132 {
137133 // We've had enough
138134 $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp));
@@ -141,13 +137,9 @@
142138 if($fld_id)
143139 $block['id'] = $row->ipb_id;
144140 if($fld_user && !$row->ipb_auto)
145 - {
146141 $block['user'] = $row->ipb_address;
147 - }
148142 if($fld_by)
149 - {
150143 $block['by'] = $row->user_name;
151 - }
152144 if($fld_timestamp)
153145 $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp);
154146 if($fld_expiry)
@@ -197,13 +189,14 @@
198190 {
199191 // Converts a hexadecimal IP to nnn.nnn.nnn.nnn format
200192 $dec = wfBaseConvert($ip, 16, 10);
201 - $parts[0] = (int)($dec / (256*256*256));
202 - $dec %= 256*256*256;
203 - $parts[1] = (int)($dec / (256*256));
204 - $dec %= 256*256;
205 - $parts[2] = (int)($dec / 256);
206193 $parts[3] = $dec % 256;
207 - return implode('.', $parts);
 194+ $dec /= 256;
 195+ $parts[2] = $dec % 256;
 196+ $dec /= 256;
 197+ $parts[1] = $dec % 256;
 198+ $dec /= 256;
 199+ $parts[0] = $dec % 256;
 200+ return implode('.', array_reverse($parts));
208201 }
209202
210203 public function getAllowedParams() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r43039API: Followup on r43014: clean up some morecatrope22:19, 1 November 2008

Status & tagging log