* Aggressively intval() numeric things; addresses the concerns raised on bug 11633
* Use ApiQueryBase::addTitleInfo() everywhere
* Remove a drug-induced-looking line from ApiQueryWatchlist.php
$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'])
$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()
$r['nochange'] = '';
else
{
- $r['oldrevid'] = $oldRevId;
- $r['newrevid'] = $newRevId;
+ $r['oldrevid'] = intval($oldRevId);
+ $r['newrevid'] = intval($newRevId);
}
break;
default:
// 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
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;
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}");
$p_result->getDisplayTitle() :
$titleObj->getPrefixedText();
if(!is_null($oldid))
- $result_array['revid'] = $oldid;
+ $result_array['revid'] = intval($oldid);
$result_mapping = array(
'redirects' => 'r',
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);
}
$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'] = '';
$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)
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)
{
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'] = '';
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);
$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;
$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)
$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);
$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;
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();
{
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);
}
}
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;
}
$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(),
$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?
}
}
if ($this->fld_size && !is_null($revision->getSize())) {
- $vals['size'] = $revision->getSize();
+ $vals['size'] = intval($revision->getSize());
}
if ($this->fld_comment) {
$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)
{
$offset = 0;
}
$data['timezone'] = $tz;
- $data['timeoffset'] = $offset;
+ $data['timeoffset'] = intval($offset);
return $this->getResult()->addValue( 'query', $property, $data );
}
foreach( $wgContLang->getFormattedNamespaces() as $ns => $title )
{
$data[$ns] = array(
- 'id' => $ns
+ 'id' => intval($ns)
);
ApiResult :: setContent( $data[$ns], $title );
$canonical = MWNamespace::getCanonicalName( $ns );
continue;
}
$item = array(
- 'id' => $ns
+ 'id' => intval($ns)
);
ApiResult :: setContent( $item, strtr( $title, '_', ' ' ) );
$data[] = $item;
list( $host, $lag ) = wfGetLB()->getMaxLag();
$data[] = array(
'host' => $wgShowHostnames ? $host : '',
- 'lag' => $lag
+ 'lag' => intval( $lag )
);
}
global $wgUser;
$result = $this->getResult();
$vals = array();
- $vals['id'] = $wgUser->getId();
+ $vals['id'] = intval($wgUser->getId());
$vals['name'] = $wgUser->getName();
if($wgUser->isAnon())
$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();
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;
}
$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;
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);
$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);
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);
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);
}