Make User::getEditCount() always return an integer
authorJuliusz Gonera <jgonera@wikimedia.org>
Thu, 18 Jul 2013 20:12:15 +0000 (13:12 -0700)
committerJuliusz Gonera <jgonera@wikimedia.org>
Thu, 18 Jul 2013 22:46:15 +0000 (15:46 -0700)
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
includes/api/ApiQueryUserInfo.php
includes/api/ApiQueryUsers.php

index 685bce7..30e618a 100644 (file)
@@ -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;
        }
 
        /**
index 2b7e7cc..3c85ea6 100644 (file)
@@ -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() );
                }
 
index aec57a0..dccfee6 100644 (file)
@@ -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'] ) ) {