Fix ApiQueryInfo response for prop=watchers
authorLeszek Manicki <leszek.manicki@wikimedia.de>
Wed, 16 Mar 2016 16:07:31 +0000 (17:07 +0100)
committerAddshore <addshorewiki@gmail.com>
Thu, 17 Mar 2016 09:48:30 +0000 (09:48 +0000)
Ie84e6feaa42db1bc7a1f89b56aed37dd7fe95ea4 part of them problem
with incorrect API response but if when no watchers data is
fetched (ie. due to early return in ApiQueryInfo::getWatcherInfo),
response contains "watchers": null instead of skipping "watchers"
key entirely.

Bug: T129482
Change-Id: I9cab120ec4e6a9cf4626678e45ef14ea8efc8cbc

includes/api/ApiQueryInfo.php

index 3aa0122..f33da1e 100644 (file)
@@ -453,8 +453,10 @@ class ApiQueryInfo extends ApiQueryBase {
                }
 
                if ( $this->fld_watchers ) {
-                       if ( $this->watchers[$ns][$dbkey] !== 0 || $this->showZeroWatchers ) {
+                       if ( $this->watchers !== null && $this->watchers[$ns][$dbkey] !== 0 ) {
                                $pageInfo['watchers'] = $this->watchers[$ns][$dbkey];
+                       } elseif ( $this->showZeroWatchers ) {
+                               $pageInfo['watchers'] = 0;
                        }
                }