From a90cbb48f82726857de2384b2932c640a404bc84 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 6 May 2015 11:33:08 -0400 Subject: [PATCH] Cast various things that are supposed to be ints Mysqli is returning SELECTed ints as strings rather than as ints, I'm guessing to avoid problems with 64-bit int types on 32-bit systems. PHP mostly doesn't care, but it causes API JSON output to have strings instead of ints all over the place. This also fixes ForeignAPIFile::getUser( 'id' ) returning the user *name*. Bug: T98276 Change-Id: Ie6591d72b3ac40172f8176a8ca8b6fad8e9275a5 --- includes/Block.php | 2 +- includes/api/ApiQueryAllUsers.php | 6 +++--- includes/api/ApiQueryBacklinksprop.php | 2 +- includes/api/ApiQueryBlocks.php | 6 +++--- includes/api/ApiQueryContributors.php | 4 ++-- includes/api/ApiQueryDeletedrevs.php | 2 +- includes/api/ApiQueryFilearchive.php | 4 ++-- includes/api/ApiQueryProtectedTitles.php | 2 +- includes/api/ApiQueryRecentChanges.php | 2 +- includes/api/ApiQueryUserContributions.php | 2 +- includes/api/ApiQueryUsers.php | 4 ++-- includes/api/ApiQueryWatchlist.php | 4 ++-- includes/db/DatabaseMysqli.php | 2 +- includes/filerepo/file/ArchivedFile.php | 2 +- includes/filerepo/file/ForeignAPIFile.php | 10 +++++++--- includes/filerepo/file/LocalFile.php | 4 ++-- 16 files changed, 31 insertions(+), 27 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 76667511b8..d58220144a 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -371,7 +371,7 @@ class Block { $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp ); $this->mAuto = $row->ipb_auto; $this->mHideName = $row->ipb_deleted; - $this->mId = $row->ipb_id; + $this->mId = (int)$row->ipb_id; $this->mParentBlockId = $row->ipb_parent_block_id; // I wish I didn't have to do this diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 516885917f..faaf1fde3f 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -235,14 +235,14 @@ class ApiQueryAllUsers extends ApiQueryBase { } $data = array( - 'userid' => $row->user_id, + 'userid' => (int)$row->user_id, 'name' => $row->user_name, ); if ( $fld_blockinfo && !is_null( $row->ipb_by_text ) ) { - $data['blockid'] = $row->ipb_id; + $data['blockid'] = (int)$row->ipb_id; $data['blockedby'] = $row->ipb_by_text; - $data['blockedbyid'] = $row->ipb_by; + $data['blockedbyid'] = (int)$row->ipb_by; $data['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp ); $data['blockreason'] = $row->ipb_reason; $data['blockexpiry'] = $row->ipb_expiry; diff --git a/includes/api/ApiQueryBacklinksprop.php b/includes/api/ApiQueryBacklinksprop.php index fe77882915..dbed36c1cb 100644 --- a/includes/api/ApiQueryBacklinksprop.php +++ b/includes/api/ApiQueryBacklinksprop.php @@ -277,7 +277,7 @@ class ApiQueryBacklinksprop extends ApiQueryGeneratorBase { $vals = array(); if ( $fld_pageid ) { - $vals['pageid'] = $row->page_id; + $vals['pageid'] = (int)$row->page_id; } if ( $fld_title ) { ApiQueryBase::addTitleInfo( $vals, diff --git a/includes/api/ApiQueryBlocks.php b/includes/api/ApiQueryBlocks.php index 4a7023b763..25f0bf70d9 100644 --- a/includes/api/ApiQueryBlocks.php +++ b/includes/api/ApiQueryBlocks.php @@ -191,19 +191,19 @@ class ApiQueryBlocks extends ApiQueryBase { ApiResult::META_TYPE => 'assoc', ); if ( $fld_id ) { - $block['id'] = $row->ipb_id; + $block['id'] = (int)$row->ipb_id; } if ( $fld_user && !$row->ipb_auto ) { $block['user'] = $row->ipb_address; } if ( $fld_userid && !$row->ipb_auto ) { - $block['userid'] = $row->ipb_user; + $block['userid'] = (int)$row->ipb_user; } if ( $fld_by ) { $block['by'] = $row->ipb_by_text; } if ( $fld_byid ) { - $block['byid'] = $row->ipb_by; + $block['byid'] = (int)$row->ipb_by; } if ( $fld_timestamp ) { $block['timestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp ); diff --git a/includes/api/ApiQueryContributors.php b/includes/api/ApiQueryContributors.php index 4514fa9214..524bffd45d 100644 --- a/includes/api/ApiQueryContributors.php +++ b/includes/api/ApiQueryContributors.php @@ -89,7 +89,7 @@ class ApiQueryContributors extends ApiQueryBase { $res = $this->select( __METHOD__ ); foreach ( $res as $row ) { $fit = $result->addValue( array( 'query', 'pages', $row->page ), - 'anoncontributors', $row->anons + 'anoncontributors', (int)$row->anons ); if ( !$fit ) { // This not fitting isn't reasonable, so it probably means that @@ -189,7 +189,7 @@ class ApiQueryContributors extends ApiQueryBase { } $fit = $this->addPageSubItem( $row->page, - array( 'userid' => $row->user, 'name' => $row->username ), + array( 'userid' => (int)$row->user, 'name' => $row->username ), 'user' ); if ( !$fit ) { diff --git a/includes/api/ApiQueryDeletedrevs.php b/includes/api/ApiQueryDeletedrevs.php index 72a331f1cc..76f594e277 100644 --- a/includes/api/ApiQueryDeletedrevs.php +++ b/includes/api/ApiQueryDeletedrevs.php @@ -328,7 +328,7 @@ class ApiQueryDeletedrevs extends ApiQueryBase { $rev['user'] = $row->ar_user_text; } if ( $fld_userid ) { - $rev['userid'] = $row->ar_user; + $rev['userid'] = (int)$row->ar_user; } } } diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 4d357a7f4c..54889846f1 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -162,7 +162,7 @@ class ApiQueryFilearchive extends ApiQueryBase { } $file = array(); - $file['id'] = $row->fa_id; + $file['id'] = (int)$row->fa_id; $file['name'] = $row->fa_name; $title = Title::makeTitle( NS_FILE, $row->fa_name ); self::addTitleInfo( $file, $title ); @@ -179,7 +179,7 @@ class ApiQueryFilearchive extends ApiQueryBase { if ( $fld_user && Revision::userCanBitfield( $row->fa_deleted, File::DELETED_USER, $user ) ) { - $file['userid'] = $row->fa_user; + $file['userid'] = (int)$row->fa_user; $file['user'] = $row->fa_user_text; } if ( $fld_sha1 ) { diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index fb65e5e2e2..033310d737 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -123,7 +123,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { } if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) { - $vals['userid'] = $row->pt_user; + $vals['userid'] = (int)$row->pt_user; } if ( isset( $prop['comment'] ) ) { diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index f6a64785c4..74bccc2e85 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -458,7 +458,7 @@ class ApiQueryRecentChanges extends ApiQueryGeneratorBase { } if ( $this->fld_userid ) { - $vals['userid'] = $row->rc_user; + $vals['userid'] = (int)$row->rc_user; } if ( !$row->rc_user ) { diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index e5ec67d0fd..480a1ab36b 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -340,7 +340,7 @@ class ApiQueryContributions extends ApiQueryBase { } // Any rows where we can't view the user were filtered out in the query. - $vals['userid'] = $row->rev_user; + $vals['userid'] = (int)$row->rev_user; $vals['user'] = $row->rev_user_text; if ( $row->rev_deleted & Revision::DELETED_USER ) { $vals['userhidden'] = true; diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index f22c21340e..8b1a07503a 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -193,9 +193,9 @@ class ApiQueryUsers extends ApiQueryBase { $data[$name]['hidden'] = true; } if ( isset( $this->prop['blockinfo'] ) && !is_null( $row->ipb_by_text ) ) { - $data[$name]['blockid'] = $row->ipb_id; + $data[$name]['blockid'] = (int)$row->ipb_id; $data[$name]['blockedby'] = $row->ipb_by_text; - $data[$name]['blockedbyid'] = $row->ipb_by; + $data[$name]['blockedbyid'] = (int)$row->ipb_by; $data[$name]['blockedtimestamp'] = wfTimestamp( TS_ISO_8601, $row->ipb_timestamp ); $data[$name]['blockreason'] = $row->ipb_reason; $data[$name]['blockexpiry'] = $row->ipb_expiry; diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index 9f7387c710..3eb57fd53e 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -332,9 +332,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) { if ( $this->fld_userid ) { - $vals['userid'] = $row->rc_user; + $vals['userid'] = (int)$row->rc_user; // for backwards compatibility - $vals['user'] = $row->rc_user; + $vals['user'] = (int)$row->rc_user; } if ( $this->fld_user ) { diff --git a/includes/db/DatabaseMysqli.php b/includes/db/DatabaseMysqli.php index ad12e196ed..d2b5ecb1cf 100644 --- a/includes/db/DatabaseMysqli.php +++ b/includes/db/DatabaseMysqli.php @@ -134,7 +134,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { * @return int */ function insertId() { - return $this->mConn->insert_id; + return (int)$this->mConn->insert_id; } /** diff --git a/includes/filerepo/file/ArchivedFile.php b/includes/filerepo/file/ArchivedFile.php index 1d45428310..0713a9258f 100644 --- a/includes/filerepo/file/ArchivedFile.php +++ b/includes/filerepo/file/ArchivedFile.php @@ -485,7 +485,7 @@ class ArchivedFile { if ( $type == 'text' ) { return $this->user_text; } elseif ( $type == 'id' ) { - return $this->user; + return (int)$this->user; } throw new MWException( "Unknown type '$type'." ); diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 3d5d5d60e5..e51f381c31 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -219,11 +219,15 @@ class ForeignAPIFile extends File { } /** - * @param string $method + * @param string $type * @return int|null|string */ - public function getUser( $method = 'text' ) { - return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null; + public function getUser( $type = 'text' ) { + if ( $type == 'text' ) { + return isset( $this->mInfo['user'] ) ? strval( $this->mInfo['user'] ) : null; + } elseif ( $type == 'id' ) { + return 0; // What makes sense here, for a remote user? + } } /** diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index d368d901e5..ba437f09a2 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -734,7 +734,7 @@ class LocalFile extends File { if ( $type == 'text' ) { return $this->user_text; } elseif ( $type == 'id' ) { - return $this->user; + return (int)$this->user; } } @@ -753,7 +753,7 @@ class LocalFile extends File { function getBitDepth() { $this->load(); - return $this->bits; + return (int)$this->bits; } /** -- 2.20.1