r47865 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47864‎ | r47865 | r47866 >
Date:16:03, 27 February 2009
Author:catrope
Status:deferred
Tags:
Comment:
API: Some cleanup
* Aggressively intval() numeric things; addresses the concerns raised on bug 11633
* Use ApiQueryBase::addTitleInfo() everywhere
* Remove a drug-induced-looking line from ApiQueryWatchlist.php
Modified paths:
  • /trunk/phase3/includes/api/ApiBlock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiImport.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogin.php (modified) (history)
  • /trunk/phase3/includes/api/ApiParse.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPatrol.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllCategories.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllLinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBacklinks.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryCategoryMembers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExtLinksUsage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryImageInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRandom.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRecentChanges.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryRevisions.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySearch.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUserInfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryUsers.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryWatchlist.php (modified) (history)
  • /trunk/phase3/includes/api/ApiRollback.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryImageInfo.php
@@ -194,8 +194,8 @@
195195 if( $mto && !$mto->isError() )
196196 {
197197 $vals['thumburl'] = $mto->getUrl();
198 - $vals['thumbwidth'] = $mto->getWidth();
199 - $vals['thumbheight'] = $mto->getHeight();
 198+ $vals['thumbwidth'] = intval( $mto->getWidth() );
 199+ $vals['thumbheight'] = intval( $mto->getHeight() );
200200 }
201201 }
202202 $vals['url'] = $file->getFullURL();
Index: trunk/phase3/includes/api/ApiQueryWatchlist.php
@@ -244,8 +244,6 @@
245245 if ($this->fld_timestamp)
246246 $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rc_timestamp);
247247
248 - $this->addFieldsIf('rc_new_len', $this->fld_sizes);
249 -
250248 if ($this->fld_sizes) {
251249 $vals['oldlen'] = intval($row->rc_old_len);
252250 $vals['newlen'] = intval($row->rc_new_len);
Index: trunk/phase3/includes/api/ApiRollback.php
@@ -72,11 +72,11 @@
7373
7474 $info = array(
7575 'title' => $titleObj->getPrefixedText(),
76 - 'pageid' => $details['current']->getPage(),
 76+ 'pageid' => intval($details['current']->getPage()),
7777 'summary' => $details['summary'],
78 - 'revid' => $titleObj->getLatestRevID(),
79 - 'old_revid' => $details['current']->getID(),
80 - 'last_revid' => $details['target']->getID()
 78+ 'revid' => intval($titleObj->getLatestRevID()),
 79+ 'old_revid' => intval($details['current']->getID()),
 80+ 'last_revid' => intval($details['target']->getID())
8181 );
8282
8383 $this->getResult()->addValue(null, $this->getModuleName(), $info);
Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -192,7 +192,7 @@
193193 $rev = array();
194194 $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp);
195195 if($fld_revid)
196 - $rev['revid'] = $row->ar_rev_id;
 196+ $rev['revid'] = intval($row->ar_rev_id);
197197 if($fld_user)
198198 $rev['user'] = $row->ar_user_text;
199199 if($fld_comment)
@@ -210,12 +210,9 @@
211211 $pageID = $newPageID++;
212212 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
213213 $t = Title::makeTitle($row->ar_namespace, $row->ar_title);
214 - $a = array(
215 - 'title' => $t->getPrefixedText(),
216 - 'ns' => intval($row->ar_namespace),
217 - 'revisions' => array($rev)
218 - );
 214+ $a['revisions'] = array($rev);
219215 $result->setIndexedTagName($a['revisions'], 'rev');
 216+ ApiQueryBase::addTitleInfo($a, $t);
220217 if($fld_token)
221218 $a['token'] = $token;
222219 $fit = $result->addValue(array('query', $this->getModuleName()), $pageID, $a);
Index: trunk/phase3/includes/api/ApiPatrol.php
@@ -60,7 +60,7 @@
6161 if($retval)
6262 $this->dieUsageMsg(current($retval));
6363
64 - $result = array('rcid' => $rc->getAttribute('rc_id'));
 64+ $result = array('rcid' => intval($rc->getAttribute('rc_id')));
6565 ApiQueryBase::addTitleInfo($result, $rc->getTitle());
6666 $this->getResult()->addValue(null, $this->getModuleName(), $result);
6767 }
Index: trunk/phase3/includes/api/ApiQueryRandom.php
@@ -116,9 +116,8 @@
117117 private function extractRowInfo($row) {
118118 $title = Title::makeTitle($row->page_namespace, $row->page_title);
119119 $vals = array();
120 - $vals['title'] = $title->getPrefixedText();
121 - $vals['ns'] = $row->page_namespace;
122 - $vals['id'] = $row->page_id;
 120+ $vals['id'] = intval($row->page_id);
 121+ ApiQueryBase::addTitleInfo($vals, $title);
123122 return $vals;
124123 }
125124
Index: trunk/phase3/includes/api/ApiQueryRevisions.php
@@ -292,7 +292,7 @@
293293 $vals = array ();
294294
295295 if ($this->fld_ids) {
296 - $vals['revid'] = $revision->getId();
 296+ $vals['revid'] = intval($revision->getId());
297297 // $vals['oldid'] = intval($row->rev_text_id); // todo: should this be exposed?
298298 }
299299
@@ -314,7 +314,7 @@
315315 }
316316
317317 if ($this->fld_size && !is_null($revision->getSize())) {
318 - $vals['size'] = $revision->getSize();
 318+ $vals['size'] = intval($revision->getSize());
319319 }
320320
321321 if ($this->fld_comment) {
Index: trunk/phase3/includes/api/ApiLogin.php
@@ -82,7 +82,7 @@
8383 wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html));
8484
8585 $result['result'] = 'Success';
86 - $result['lguserid'] = $wgUser->getId();
 86+ $result['lguserid'] = intval($wgUser->getId());
8787 $result['lgusername'] = $wgUser->getName();
8888 $result['lgtoken'] = $wgUser->getToken();
8989 $result['cookieprefix'] = $wgCookiePrefix;
@@ -114,7 +114,7 @@
115115 case LoginForm :: THROTTLED :
116116 global $wgPasswordAttemptThrottle;
117117 $result['result'] = 'Throttled';
118 - $result['wait'] = $wgPasswordAttemptThrottle['seconds'];
 118+ $result['wait'] = intval($wgPasswordAttemptThrottle['seconds']);
119119 break;
120120 default :
121121 ApiBase :: dieDebug(__METHOD__, "Unhandled case value: {$authRes}");
Index: trunk/phase3/includes/api/ApiQueryCategoryMembers.php
@@ -118,8 +118,7 @@
119119 $vals['pageid'] = intval($row->page_id);
120120 if ($fld_title) {
121121 $title = Title :: makeTitle($row->page_namespace, $row->page_title);
122 - $vals['ns'] = intval($title->getNamespace());
123 - $vals['title'] = $title->getPrefixedText();
 122+ ApiQueryBase::addTitleInfo($vals, $title);
124123 }
125124 if ($fld_sortkey)
126125 $vals['sortkey'] = $row->cl_sortkey;
Index: trunk/phase3/includes/api/ApiQueryUserInfo.php
@@ -57,7 +57,7 @@
5858 global $wgUser;
5959 $result = $this->getResult();
6060 $vals = array();
61 - $vals['id'] = $wgUser->getId();
 61+ $vals['id'] = intval($wgUser->getId());
6262 $vals['name'] = $wgUser->getName();
6363
6464 if($wgUser->isAnon())
@@ -87,7 +87,7 @@
8888 $vals['preferencestoken'] = $wgUser->editToken();
8989 }
9090 if (isset($this->prop['editcount'])) {
91 - $vals['editcount'] = $wgUser->getEditCount();
 91+ $vals['editcount'] = intval($wgUser->getEditCount());
9292 }
9393 if (isset($this->prop['ratelimits'])) {
9494 $vals['ratelimits'] = $this->getRateLimits();
@@ -128,8 +128,8 @@
129129 foreach($categories as $cat)
130130 if(isset($limits[$cat]) && !is_null($limits[$cat]))
131131 {
132 - $retval[$action][$cat]['hits'] = $limits[$cat][0];
133 - $retval[$action][$cat]['seconds'] = $limits[$cat][1];
 132+ $retval[$action][$cat]['hits'] = intval($limits[$cat][0]);
 133+ $retval[$action][$cat]['seconds'] = intval($limits[$cat][1]);
134134 }
135135 return $retval;
136136 }
Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -249,7 +249,7 @@
250250 $r['new'] = '';
251251 case EditPage::AS_SUCCESS_UPDATE:
252252 $r['result'] = "Success";
253 - $r['pageid'] = $titleObj->getArticleID();
 253+ $r['pageid'] = intval($titleObj->getArticleID());
254254 $r['title'] = $titleObj->getPrefixedText();
255255 # HACK: We create a new Article object here because getRevIdFetched()
256256 # refuses to be run twice, and because Title::getLatestRevId()
@@ -261,8 +261,8 @@
262262 $r['nochange'] = '';
263263 else
264264 {
265 - $r['oldrevid'] = $oldRevId;
266 - $r['newrevid'] = $newRevId;
 265+ $r['oldrevid'] = intval($oldRevId);
 266+ $r['newrevid'] = intval($newRevId);
267267 }
268268 break;
269269 default:
Index: trunk/phase3/includes/api/ApiQueryUsers.php
@@ -103,11 +103,9 @@
104104 $name = $user->getName();
105105 $data[$name]['name'] = $name;
106106 if(isset($this->prop['editcount']))
107 - // No proper member function in the User class for this
108 - $data[$name]['editcount'] = $r->user_editcount;
 107+ $data[$name]['editcount'] = intval($user->getEditCount());
109108 if(isset($this->prop['registration']))
110 - // Nor for this one
111 - $data[$name]['registration'] = wfTimestampOrNull(TS_ISO_8601, $r->user_registration);
 109+ $data[$name]['registration'] = wfTimestampOrNull(TS_ISO_8601, $user->getRegistration());
112110 if(isset($this->prop['groups']) && !is_null($r->ug_group))
113111 // This row contains only one group, others will be added from other rows
114112 $data[$name]['groups'][] = $r->ug_group;
Index: trunk/phase3/includes/api/ApiBlock.php
@@ -94,7 +94,7 @@
9595 $this->dieUsageMsg($retval);
9696
9797 $res['user'] = $params['user'];
98 - $res['userID'] = $userID;
 98+ $res['userID'] = intval($userID);
9999 $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : wfTimestamp(TS_ISO_8601, $expiry));
100100 $res['reason'] = $params['reason'];
101101 if($params['anononly'])
Index: trunk/phase3/includes/api/ApiQueryRecentChanges.php
@@ -311,7 +311,7 @@
312312 $vals['patrolled'] = '';
313313
314314 if ($this->fld_loginfo && $row->rc_type == RC_LOG) {
315 - $vals['logid'] = $row->rc_logid;
 315+ $vals['logid'] = intval($row->rc_logid);
316316 $vals['logtype'] = $row->rc_log_type;
317317 $vals['logaction'] = $row->rc_log_action;
318318 ApiQueryLogEvents::addLogParams($this->getResult(),
Index: trunk/phase3/includes/api/ApiQueryAllCategories.php
@@ -103,10 +103,10 @@
104104 $item = array();
105105 $result->setContent( $item, $titleObj->getText() );
106106 if( isset( $prop['size'] ) ) {
107 - $item['size'] = $row->cat_pages;
 107+ $item['size'] = intval($row->cat_pages);
108108 $item['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
109 - $item['files'] = $row->cat_files;
110 - $item['subcats'] = $row->cat_subcats;
 109+ $item['files'] = intval($row->cat_files);
 110+ $item['subcats'] = intval($row->cat_subcats);
111111 }
112112 if( isset( $prop['hidden'] ) && $row->cat_hidden )
113113 $item['hidden'] = '';
Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
@@ -125,8 +125,7 @@
126126 $vals['pageid'] = intval($row->page_id);
127127 if ($fld_title) {
128128 $title = Title :: makeTitle($row->page_namespace, $row->page_title);
129 - $vals['ns'] = intval($title->getNamespace());
130 - $vals['title'] = $title->getPrefixedText();
 129+ ApiQueryBase::addTitleInfo($vals, $title);
131130 }
132131 if ($fld_url)
133132 $vals['url'] = $row->el_to;
Index: trunk/phase3/includes/api/ApiQueryInfo.php
@@ -492,10 +492,10 @@
493493 {
494494 if(MWNamespace::isTalk($row->page_namespace))
495495 $this->talkids[MWNamespace::getSubject($row->page_namespace)][$row->page_title] =
496 - $row->page_id;
 496+ intval($row->page_id);
497497 else
498498 $this->subjectids[MWNamespace::getTalk($row->page_namespace)][$row->page_title] =
499 - $row->page_id;
 499+ intval($row->page_id);
500500 }
501501 }
502502
Index: trunk/phase3/includes/api/ApiQueryBacklinks.php
@@ -292,7 +292,7 @@
293293 private function extractRowInfo($row) {
294294 $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id;
295295 $t = Title::makeTitle($row->page_namespace, $row->page_title);
296 - $a = array('pageid' => $row->page_id);
 296+ $a = array('pageid' => intval($row->page_id));
297297 ApiQueryBase::addTitleInfo($a, $t);
298298 if($row->page_is_redirect)
299299 {
@@ -305,7 +305,7 @@
306306
307307 private function extractRedirRowInfo($row)
308308 {
309 - $a['pageid'] = $row->page_id;
 309+ $a['pageid'] = intval($row->page_id);
310310 ApiQueryBase::addTitleInfo($a, Title::makeTitle($row->page_namespace, $row->page_title));
311311 if($row->page_is_redirect)
312312 $a['redirect'] = '';
Index: trunk/phase3/includes/api/ApiQuerySearch.php
@@ -102,9 +102,8 @@
103103
104104 $title = $result->getTitle();
105105 if (is_null($resultPageSet)) {
106 - $vals = array(
107 - 'ns' => intval($title->getNamespace()),
108 - 'title' => $title->getPrefixedText());
 106+ $vals = array();
 107+ ApiQueryBase::addTitleInfo($vals, $title);
109108 $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals);
110109 if(!$fit)
111110 {
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -72,7 +72,7 @@
7373 if($retval)
7474 $this->dieUsageMsg($retval);
7575
76 - $res['id'] = $id;
 76+ $res['id'] = intval($id);
7777 $res['user'] = $user;
7878 $res['reason'] = $reason;
7979 $this->getResult()->addValue(null, $this->getModuleName(), $res);
Index: trunk/phase3/includes/api/ApiQueryAllLinks.php
@@ -121,8 +121,7 @@
122122 $vals['fromid'] = intval($row->pl_from);
123123 if ($fld_title) {
124124 $title = Title :: makeTitle($params['namespace'], $row->pl_title);
125 - $vals['ns'] = intval($title->getNamespace());
126 - $vals['title'] = $title->getPrefixedText();
 125+ ApiQueryBase::addTitleInfo($vals, $title);
127126 }
128127 $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals);
129128 if(!$fit)
Index: trunk/phase3/includes/api/ApiUndelete.php
@@ -78,9 +78,9 @@
7979 array($titleObj, array(), $wgUser, $params['reason']) );
8080
8181 $info['title'] = $titleObj->getPrefixedText();
82 - $info['revisions'] = $retval[0];
83 - $info['fileversions'] = $retval[1];
84 - $info['reason'] = $retval[2];
 82+ $info['revisions'] = intval($retval[0]);
 83+ $info['fileversions'] = intval($retval[1]);
 84+ $info['reason'] = intval($retval[2]);
8585 $this->getResult()->addValue(null, $this->getModuleName(), $info);
8686 }
8787
Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -137,7 +137,7 @@
138138 $offset = 0;
139139 }
140140 $data['timezone'] = $tz;
141 - $data['timeoffset'] = $offset;
 141+ $data['timeoffset'] = intval($offset);
142142
143143 return $this->getResult()->addValue( 'query', $property, $data );
144144 }
@@ -148,7 +148,7 @@
149149 foreach( $wgContLang->getFormattedNamespaces() as $ns => $title )
150150 {
151151 $data[$ns] = array(
152 - 'id' => $ns
 152+ 'id' => intval($ns)
153153 );
154154 ApiResult :: setContent( $data[$ns], $title );
155155 $canonical = MWNamespace::getCanonicalName( $ns );
@@ -176,7 +176,7 @@
177177 continue;
178178 }
179179 $item = array(
180 - 'id' => $ns
 180+ 'id' => intval($ns)
181181 );
182182 ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) );
183183 $data[] = $item;
@@ -272,7 +272,7 @@
273273 list( $host, $lag ) = wfGetLB()->getMaxLag();
274274 $data[] = array(
275275 'host' => $wgShowHostnames ? $host : '',
276 - 'lag' => $lag
 276+ 'lag' => intval( $lag )
277277 );
278278 }
279279
Index: trunk/phase3/includes/api/ApiImport.php
@@ -162,7 +162,7 @@
163163 // Add a result entry
164164 $r = array();
165165 ApiQueryBase::addTitleInfo($r, $title);
166 - $r['revisions'] = $successCount;
 166+ $r['revisions'] = intval($successCount);
167167 $this->mResultArr[] = $r;
168168
169169 // Piggyback on the parent to do the logging
Index: trunk/phase3/includes/api/ApiParse.php
@@ -156,7 +156,7 @@
157157 $p_result->getDisplayTitle() :
158158 $titleObj->getPrefixedText();
159159 if(!is_null($oldid))
160 - $result_array['revid'] = $oldid;
 160+ $result_array['revid'] = intval($oldid);
161161
162162 $result_mapping = array(
163163 'redirects' => 'r',
Index: trunk/phase3/includes/api/ApiQueryCategoryInfo.php
@@ -81,10 +81,10 @@
8282 while($row = $db->fetchObject($res))
8383 {
8484 $vals = array();
85 - $vals['size'] = $row->cat_pages;
 85+ $vals['size'] = intval($row->cat_pages);
8686 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
87 - $vals['files'] = $row->cat_files;
88 - $vals['subcats'] = $row->cat_subcats;
 87+ $vals['files'] = intval($row->cat_files);
 88+ $vals['subcats'] = intval($row->cat_subcats);
8989 if($row->cat_hidden)
9090 $vals['hidden'] = '';
9191 $fit = $this->addPageSubItems($catids[$row->cat_title], $vals);

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r32820(bug 11633) Explicitly convert redirect titles to strings due to PHP's very w...btongminh18:34, 5 April 2008
r37506Backporting fixes to API that caused it to output plain wrong data:...btongminh14:37, 10 July 2008

Status & tagging log