From: Juliusz Gonera Date: Thu, 18 Jul 2013 20:12:15 +0000 (-0700) Subject: Make User::getEditCount() always return an integer X-Git-Tag: 1.31.0-rc.0~19160^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=1b6c4bc3c7d2e78a060b5bb5b6d51bb48ce26bf9;p=lhc%2Fweb%2Fwiklou.git 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 --- 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'] ) ) {