From 88f35cdf6eecc402b786b9cca7b0b3caaff27777 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 27 Feb 2009 16:03:01 +0000 Subject: [PATCH] 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 --- includes/api/ApiBlock.php | 2 +- includes/api/ApiEditPage.php | 6 +++--- includes/api/ApiImport.php | 2 +- includes/api/ApiLogin.php | 4 ++-- includes/api/ApiParse.php | 2 +- includes/api/ApiPatrol.php | 2 +- includes/api/ApiQueryAllCategories.php | 6 +++--- includes/api/ApiQueryAllLinks.php | 3 +-- includes/api/ApiQueryBacklinks.php | 4 ++-- includes/api/ApiQueryCategoryInfo.php | 6 +++--- includes/api/ApiQueryCategoryMembers.php | 3 +-- includes/api/ApiQueryDeletedrevs.php | 9 +++------ includes/api/ApiQueryExtLinksUsage.php | 3 +-- includes/api/ApiQueryImageInfo.php | 4 ++-- includes/api/ApiQueryInfo.php | 4 ++-- includes/api/ApiQueryRandom.php | 5 ++--- includes/api/ApiQueryRecentChanges.php | 2 +- includes/api/ApiQueryRevisions.php | 4 ++-- includes/api/ApiQuerySearch.php | 5 ++--- includes/api/ApiQuerySiteinfo.php | 8 ++++---- includes/api/ApiQueryUserInfo.php | 8 ++++---- includes/api/ApiQueryUsers.php | 6 ++---- includes/api/ApiQueryWatchlist.php | 2 -- includes/api/ApiRollback.php | 8 ++++---- includes/api/ApiUnblock.php | 2 +- includes/api/ApiUndelete.php | 6 +++--- 26 files changed, 52 insertions(+), 64 deletions(-) diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index e01b64d5b9..7d8b0877ae 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -94,7 +94,7 @@ class ApiBlock extends ApiBase { $this->dieUsageMsg($retval); $res['user'] = $params['user']; - $res['userID'] = $userID; + $res['userID'] = intval($userID); $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : wfTimestamp(TS_ISO_8601, $expiry)); $res['reason'] = $params['reason']; if($params['anononly']) diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index d09275508d..8fc3f15dd4 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -249,7 +249,7 @@ class ApiEditPage extends ApiBase { $r['new'] = ''; case EditPage::AS_SUCCESS_UPDATE: $r['result'] = "Success"; - $r['pageid'] = $titleObj->getArticleID(); + $r['pageid'] = intval($titleObj->getArticleID()); $r['title'] = $titleObj->getPrefixedText(); # HACK: We create a new Article object here because getRevIdFetched() # refuses to be run twice, and because Title::getLatestRevId() @@ -261,8 +261,8 @@ class ApiEditPage extends ApiBase { $r['nochange'] = ''; else { - $r['oldrevid'] = $oldRevId; - $r['newrevid'] = $newRevId; + $r['oldrevid'] = intval($oldRevId); + $r['newrevid'] = intval($newRevId); } break; default: diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 53fdf1799b..ef2f51eacd 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -162,7 +162,7 @@ class ApiImportReporter extends ImportReporter { // Add a result entry $r = array(); ApiQueryBase::addTitleInfo($r, $title); - $r['revisions'] = $successCount; + $r['revisions'] = intval($successCount); $this->mResultArr[] = $r; // Piggyback on the parent to do the logging diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php index 24a1314c5f..b197c20189 100644 --- a/includes/api/ApiLogin.php +++ b/includes/api/ApiLogin.php @@ -82,7 +82,7 @@ class ApiLogin extends ApiBase { wfRunHooks('UserLoginComplete', array(&$wgUser, &$injected_html)); $result['result'] = 'Success'; - $result['lguserid'] = $wgUser->getId(); + $result['lguserid'] = intval($wgUser->getId()); $result['lgusername'] = $wgUser->getName(); $result['lgtoken'] = $wgUser->getToken(); $result['cookieprefix'] = $wgCookiePrefix; @@ -114,7 +114,7 @@ class ApiLogin extends ApiBase { case LoginForm :: THROTTLED : global $wgPasswordAttemptThrottle; $result['result'] = 'Throttled'; - $result['wait'] = $wgPasswordAttemptThrottle['seconds']; + $result['wait'] = intval($wgPasswordAttemptThrottle['seconds']); break; default : ApiBase :: dieDebug(__METHOD__, "Unhandled case value: {$authRes}"); diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 050587f810..e5d1fb9b38 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -156,7 +156,7 @@ class ApiParse extends ApiBase { $p_result->getDisplayTitle() : $titleObj->getPrefixedText(); if(!is_null($oldid)) - $result_array['revid'] = $oldid; + $result_array['revid'] = intval($oldid); $result_mapping = array( 'redirects' => 'r', diff --git a/includes/api/ApiPatrol.php b/includes/api/ApiPatrol.php index 872a22bbdd..5949f00805 100644 --- a/includes/api/ApiPatrol.php +++ b/includes/api/ApiPatrol.php @@ -60,7 +60,7 @@ class ApiPatrol extends ApiBase { if($retval) $this->dieUsageMsg(current($retval)); - $result = array('rcid' => $rc->getAttribute('rc_id')); + $result = array('rcid' => intval($rc->getAttribute('rc_id'))); ApiQueryBase::addTitleInfo($result, $rc->getTitle()); $this->getResult()->addValue(null, $this->getModuleName(), $result); } diff --git a/includes/api/ApiQueryAllCategories.php b/includes/api/ApiQueryAllCategories.php index ea38742429..b8a9380dd5 100644 --- a/includes/api/ApiQueryAllCategories.php +++ b/includes/api/ApiQueryAllCategories.php @@ -103,10 +103,10 @@ class ApiQueryAllCategories extends ApiQueryGeneratorBase { $item = array(); $result->setContent( $item, $titleObj->getText() ); if( isset( $prop['size'] ) ) { - $item['size'] = $row->cat_pages; + $item['size'] = intval($row->cat_pages); $item['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files; - $item['files'] = $row->cat_files; - $item['subcats'] = $row->cat_subcats; + $item['files'] = intval($row->cat_files); + $item['subcats'] = intval($row->cat_subcats); } if( isset( $prop['hidden'] ) && $row->cat_hidden ) $item['hidden'] = ''; diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 03262a75fc..0f6e6bc69b 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -121,8 +121,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $vals['fromid'] = intval($row->pl_from); if ($fld_title) { $title = Title :: makeTitle($params['namespace'], $row->pl_title); - $vals['ns'] = intval($title->getNamespace()); - $vals['title'] = $title->getPrefixedText(); + ApiQueryBase::addTitleInfo($vals, $title); } $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals); if(!$fit) diff --git a/includes/api/ApiQueryBacklinks.php b/includes/api/ApiQueryBacklinks.php index a1a6f614a0..4b75c10399 100644 --- a/includes/api/ApiQueryBacklinks.php +++ b/includes/api/ApiQueryBacklinks.php @@ -292,7 +292,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { private function extractRowInfo($row) { $this->pageMap[$row->page_namespace][$row->page_title] = $row->page_id; $t = Title::makeTitle($row->page_namespace, $row->page_title); - $a = array('pageid' => $row->page_id); + $a = array('pageid' => intval($row->page_id)); ApiQueryBase::addTitleInfo($a, $t); if($row->page_is_redirect) { @@ -305,7 +305,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase { private function extractRedirRowInfo($row) { - $a['pageid'] = $row->page_id; + $a['pageid'] = intval($row->page_id); ApiQueryBase::addTitleInfo($a, Title::makeTitle($row->page_namespace, $row->page_title)); if($row->page_is_redirect) $a['redirect'] = ''; diff --git a/includes/api/ApiQueryCategoryInfo.php b/includes/api/ApiQueryCategoryInfo.php index a7c4fc4d0b..9e36d93554 100644 --- a/includes/api/ApiQueryCategoryInfo.php +++ b/includes/api/ApiQueryCategoryInfo.php @@ -81,10 +81,10 @@ class ApiQueryCategoryInfo extends ApiQueryBase { while($row = $db->fetchObject($res)) { $vals = array(); - $vals['size'] = $row->cat_pages; + $vals['size'] = intval($row->cat_pages); $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files; - $vals['files'] = $row->cat_files; - $vals['subcats'] = $row->cat_subcats; + $vals['files'] = intval($row->cat_files); + $vals['subcats'] = intval($row->cat_subcats); if($row->cat_hidden) $vals['hidden'] = ''; $fit = $this->addPageSubItems($catids[$row->cat_title], $vals); diff --git a/includes/api/ApiQueryCategoryMembers.php b/includes/api/ApiQueryCategoryMembers.php index 6e88012c7a..8b6bd1df9f 100644 --- a/includes/api/ApiQueryCategoryMembers.php +++ b/includes/api/ApiQueryCategoryMembers.php @@ -118,8 +118,7 @@ class ApiQueryCategoryMembers extends ApiQueryGeneratorBase { $vals['pageid'] = intval($row->page_id); if ($fld_title) { $title = Title :: makeTitle($row->page_namespace, $row->page_title); - $vals['ns'] = intval($title->getNamespace()); - $vals['title'] = $title->getPrefixedText(); + ApiQueryBase::addTitleInfo($vals, $title); } if ($fld_sortkey) $vals['sortkey'] = $row->cl_sortkey; diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index d4a6294712..adda49f637 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -192,7 +192,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $rev = array(); $rev['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ar_timestamp); if($fld_revid) - $rev['revid'] = $row->ar_rev_id; + $rev['revid'] = intval($row->ar_rev_id); if($fld_user) $rev['user'] = $row->ar_user_text; if($fld_comment) @@ -210,12 +210,9 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $pageID = $newPageID++; $pageMap[$row->ar_namespace][$row->ar_title] = $pageID; $t = Title::makeTitle($row->ar_namespace, $row->ar_title); - $a = array( - 'title' => $t->getPrefixedText(), - 'ns' => intval($row->ar_namespace), - 'revisions' => array($rev) - ); + $a['revisions'] = array($rev); $result->setIndexedTagName($a['revisions'], 'rev'); + ApiQueryBase::addTitleInfo($a, $t); if($fld_token) $a['token'] = $token; $fit = $result->addValue(array('query', $this->getModuleName()), $pageID, $a); diff --git a/includes/api/ApiQueryExtLinksUsage.php b/includes/api/ApiQueryExtLinksUsage.php index d4dcb83582..8d76e8b2ea 100644 --- a/includes/api/ApiQueryExtLinksUsage.php +++ b/includes/api/ApiQueryExtLinksUsage.php @@ -125,8 +125,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase { $vals['pageid'] = intval($row->page_id); if ($fld_title) { $title = Title :: makeTitle($row->page_namespace, $row->page_title); - $vals['ns'] = intval($title->getNamespace()); - $vals['title'] = $title->getPrefixedText(); + ApiQueryBase::addTitleInfo($vals, $title); } if ($fld_url) $vals['url'] = $row->el_to; diff --git a/includes/api/ApiQueryImageInfo.php b/includes/api/ApiQueryImageInfo.php index b98d2ad9bf..291a8fe3ff 100644 --- a/includes/api/ApiQueryImageInfo.php +++ b/includes/api/ApiQueryImageInfo.php @@ -194,8 +194,8 @@ class ApiQueryImageInfo extends ApiQueryBase { if( $mto && !$mto->isError() ) { $vals['thumburl'] = $mto->getUrl(); - $vals['thumbwidth'] = $mto->getWidth(); - $vals['thumbheight'] = $mto->getHeight(); + $vals['thumbwidth'] = intval( $mto->getWidth() ); + $vals['thumbheight'] = intval( $mto->getHeight() ); } } $vals['url'] = $file->getFullURL(); diff --git a/includes/api/ApiQueryInfo.php b/includes/api/ApiQueryInfo.php index a1d1533d05..e6b89aeced 100644 --- a/includes/api/ApiQueryInfo.php +++ b/includes/api/ApiQueryInfo.php @@ -492,10 +492,10 @@ class ApiQueryInfo extends ApiQueryBase { { if(MWNamespace::isTalk($row->page_namespace)) $this->talkids[MWNamespace::getSubject($row->page_namespace)][$row->page_title] = - $row->page_id; + intval($row->page_id); else $this->subjectids[MWNamespace::getTalk($row->page_namespace)][$row->page_title] = - $row->page_id; + intval($row->page_id); } } diff --git a/includes/api/ApiQueryRandom.php b/includes/api/ApiQueryRandom.php index a8fc147626..73c4a81c92 100644 --- a/includes/api/ApiQueryRandom.php +++ b/includes/api/ApiQueryRandom.php @@ -116,9 +116,8 @@ if (!defined('MEDIAWIKI')) { private function extractRowInfo($row) { $title = Title::makeTitle($row->page_namespace, $row->page_title); $vals = array(); - $vals['title'] = $title->getPrefixedText(); - $vals['ns'] = $row->page_namespace; - $vals['id'] = $row->page_id; + $vals['id'] = intval($row->page_id); + ApiQueryBase::addTitleInfo($vals, $title); return $vals; } diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index c900989f77..9dacb86c8e 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -311,7 +311,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { $vals['patrolled'] = ''; if ($this->fld_loginfo && $row->rc_type == RC_LOG) { - $vals['logid'] = $row->rc_logid; + $vals['logid'] = intval($row->rc_logid); $vals['logtype'] = $row->rc_log_type; $vals['logaction'] = $row->rc_log_action; ApiQueryLogEvents::addLogParams($this->getResult(), diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index d3e2125d82..9984986fd1 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -292,7 +292,7 @@ class ApiQueryRevisions extends ApiQueryBase { $vals = array (); if ($this->fld_ids) { - $vals['revid'] = $revision->getId(); + $vals['revid'] = intval($revision->getId()); // $vals['oldid'] = intval($row->rev_text_id); // todo: should this be exposed? } @@ -314,7 +314,7 @@ class ApiQueryRevisions extends ApiQueryBase { } if ($this->fld_size && !is_null($revision->getSize())) { - $vals['size'] = $revision->getSize(); + $vals['size'] = intval($revision->getSize()); } if ($this->fld_comment) { diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index a34c2f68b7..80ae14d9d1 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -102,9 +102,8 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $title = $result->getTitle(); if (is_null($resultPageSet)) { - $vals = array( - 'ns' => intval($title->getNamespace()), - 'title' => $title->getPrefixedText()); + $vals = array(); + ApiQueryBase::addTitleInfo($vals, $title); $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals); if(!$fit) { diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 27965aa9fa..348b02b1c3 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -137,7 +137,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { $offset = 0; } $data['timezone'] = $tz; - $data['timeoffset'] = $offset; + $data['timeoffset'] = intval($offset); return $this->getResult()->addValue( 'query', $property, $data ); } @@ -148,7 +148,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { foreach( $wgContLang->getFormattedNamespaces() as $ns => $title ) { $data[$ns] = array( - 'id' => $ns + 'id' => intval($ns) ); ApiResult :: setContent( $data[$ns], $title ); $canonical = MWNamespace::getCanonicalName( $ns ); @@ -176,7 +176,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { continue; } $item = array( - 'id' => $ns + 'id' => intval($ns) ); ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) ); $data[] = $item; @@ -272,7 +272,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { list( $host, $lag ) = wfGetLB()->getMaxLag(); $data[] = array( 'host' => $wgShowHostnames ? $host : '', - 'lag' => $lag + 'lag' => intval( $lag ) ); } diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index 9ab88746ba..18feb7071b 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -57,7 +57,7 @@ class ApiQueryUserInfo extends ApiQueryBase { global $wgUser; $result = $this->getResult(); $vals = array(); - $vals['id'] = $wgUser->getId(); + $vals['id'] = intval($wgUser->getId()); $vals['name'] = $wgUser->getName(); if($wgUser->isAnon()) @@ -87,7 +87,7 @@ class ApiQueryUserInfo extends ApiQueryBase { $vals['preferencestoken'] = $wgUser->editToken(); } if (isset($this->prop['editcount'])) { - $vals['editcount'] = $wgUser->getEditCount(); + $vals['editcount'] = intval($wgUser->getEditCount()); } if (isset($this->prop['ratelimits'])) { $vals['ratelimits'] = $this->getRateLimits(); @@ -128,8 +128,8 @@ class ApiQueryUserInfo extends ApiQueryBase { foreach($categories as $cat) if(isset($limits[$cat]) && !is_null($limits[$cat])) { - $retval[$action][$cat]['hits'] = $limits[$cat][0]; - $retval[$action][$cat]['seconds'] = $limits[$cat][1]; + $retval[$action][$cat]['hits'] = intval($limits[$cat][0]); + $retval[$action][$cat]['seconds'] = intval($limits[$cat][1]); } return $retval; } diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index 3efd4e0889..51fa44e368 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -103,11 +103,9 @@ if (!defined('MEDIAWIKI')) { $name = $user->getName(); $data[$name]['name'] = $name; if(isset($this->prop['editcount'])) - // No proper member function in the User class for this - $data[$name]['editcount'] = $r->user_editcount; + $data[$name]['editcount'] = intval($user->getEditCount()); if(isset($this->prop['registration'])) - // Nor for this one - $data[$name]['registration'] = wfTimestampOrNull(TS_ISO_8601, $r->user_registration); + $data[$name]['registration'] = wfTimestampOrNull(TS_ISO_8601, $user->getRegistration()); if(isset($this->prop['groups']) && !is_null($r->ug_group)) // This row contains only one group, others will be added from other rows $data[$name]['groups'][] = $r->ug_group; diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 8865a71542..fa126f865d 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -244,8 +244,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { if ($this->fld_timestamp) $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rc_timestamp); - $this->addFieldsIf('rc_new_len', $this->fld_sizes); - if ($this->fld_sizes) { $vals['oldlen'] = intval($row->rc_old_len); $vals['newlen'] = intval($row->rc_new_len); diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index 13d858363c..cb0486fd50 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -72,11 +72,11 @@ class ApiRollback extends ApiBase { $info = array( 'title' => $titleObj->getPrefixedText(), - 'pageid' => $details['current']->getPage(), + 'pageid' => intval($details['current']->getPage()), 'summary' => $details['summary'], - 'revid' => $titleObj->getLatestRevID(), - 'old_revid' => $details['current']->getID(), - 'last_revid' => $details['target']->getID() + 'revid' => intval($titleObj->getLatestRevID()), + 'old_revid' => intval($details['current']->getID()), + 'last_revid' => intval($details['target']->getID()) ); $this->getResult()->addValue(null, $this->getModuleName(), $info); diff --git a/includes/api/ApiUnblock.php b/includes/api/ApiUnblock.php index b262df2c55..b8568bc960 100644 --- a/includes/api/ApiUnblock.php +++ b/includes/api/ApiUnblock.php @@ -72,7 +72,7 @@ class ApiUnblock extends ApiBase { if($retval) $this->dieUsageMsg($retval); - $res['id'] = $id; + $res['id'] = intval($id); $res['user'] = $user; $res['reason'] = $reason; $this->getResult()->addValue(null, $this->getModuleName(), $res); diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 63fbc99932..9bb2efb992 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -78,9 +78,9 @@ class ApiUndelete extends ApiBase { array($titleObj, array(), $wgUser, $params['reason']) ); $info['title'] = $titleObj->getPrefixedText(); - $info['revisions'] = $retval[0]; - $info['fileversions'] = $retval[1]; - $info['reason'] = $retval[2]; + $info['revisions'] = intval($retval[0]); + $info['fileversions'] = intval($retval[1]); + $info['reason'] = intval($retval[2]); $this->getResult()->addValue(null, $this->getModuleName(), $info); } -- 2.20.1