From 1b6c4bc3c7d2e78a060b5bb5b6d51bb48ce26bf9 Mon Sep 17 00:00:00 2001 From: Juliusz Gonera Date: Thu, 18 Jul 2013 13:12:15 -0700 Subject: [PATCH] Make User::getEditCount() always return an integer The docs comment says it returns an int but it often returned a string. This led to casting this value into an integer in other parts of the codebase and in extensions (grep MobileFrontend or Echo for EditCount). Bug: 51633 Change-Id: I6fe5b26c24e674e8148c1fd278774b3fabe844c5 --- includes/User.php | 6 +++--- includes/api/ApiQueryUserInfo.php | 2 ++ includes/api/ApiQueryUsers.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/User.php b/includes/User.php index 685bce741f..30e618a7d9 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2665,7 +2665,7 @@ class User { /** * Get the user's edit count. - * @return int + * @return int, null for anonymous users */ public function getEditCount() { if ( !$this->getId() ) { @@ -2687,10 +2687,10 @@ class User { // it has not been initialized. do so. $count = $this->initEditCount(); } - $this->mEditCount = intval( $count ); + $this->mEditCount = $count; wfProfileOut( __METHOD__ ); } - return $this->mEditCount; + return (int) $this->mEditCount; } /** diff --git a/includes/api/ApiQueryUserInfo.php b/includes/api/ApiQueryUserInfo.php index 2b7e7cc962..3c85ea69d5 100644 --- a/includes/api/ApiQueryUserInfo.php +++ b/includes/api/ApiQueryUserInfo.php @@ -111,6 +111,8 @@ class ApiQueryUserInfo extends ApiQueryBase { } if ( isset( $this->prop['editcount'] ) ) { + // use intval to prevent null if a non-logged-in user calls + // api.php?format=jsonfm&action=query&meta=userinfo&uiprop=editcount $vals['editcount'] = intval( $user->getEditCount() ); } diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php index aec57a0ed8..dccfee67e6 100644 --- a/includes/api/ApiQueryUsers.php +++ b/includes/api/ApiQueryUsers.php @@ -149,7 +149,7 @@ class ApiQueryUsers extends ApiQueryBase { $data[$name]['name'] = $name; if ( isset( $this->prop['editcount'] ) ) { - $data[$name]['editcount'] = intval( $user->getEditCount() ); + $data[$name]['editcount'] = $user->getEditCount(); } if ( isset( $this->prop['registration'] ) ) { -- 2.20.1