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
This commit is contained in:
parent
a4b89293d6
commit
88f35cdf6e
26 changed files with 52 additions and 64 deletions
|
|
@ -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'])
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'] = '';
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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'] = '';
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue