protected function doDBUpdates()
 {
     $this->output("Populating gl_perm column in gather_list table\n");
     $db = wfGetDB(DB_MASTER);
     $totalCount = 0;
     $batchSize = $count = $this->mBatchSize;
     while ($batchSize === $count) {
         $count = 0;
         $res = $db->select('gather_list', array('gl_id', 'gl_info', 'gl_label'), array('gl_perm' => null), __METHOD__, array('LIMIT' => $batchSize));
         foreach ($res as $row) {
             $count++;
             $info = ApiEditList::parseListInfo($row->gl_info, $row->gl_id, true);
             $perm = ApiEditList::isPublic($info) && $row->gl_label !== '' ? 1 : 0;
             unset($info->perm);
             unset($info->public);
             $db->update('gather_list', array('gl_perm' => $perm, 'gl_info' => FormatJson::encode($info, false, FormatJson::ALL_OK), 'gl_updated' => $db->timestamp(wfTimestampNow())), array('gl_id' => $row->gl_id), __METHOD__);
         }
         $totalCount += $count;
         wfWaitForSlaves();
     }
     $this->output("Done, {$totalCount} rows updated.\n");
     return true;
 }
 /**
  * Process one row, even if that row is a fake watchlist.
  * @param object|null $row A result row, e.g. from iterating a ResultWrapper. Null for the
  *   fake watchlist.
  * @param int $count Row count, will be incremented on each call.
  * @param string $mode Mode API parameter.
  * @param int $limit Row limit; used to detect when to set continuation parameters.
  * @param bool $useInfo True if one of the info fields was requested.
  * @param Title|null $title Title object corresponding to the title parameter of the API.
  * @param bool $fld_label True if the label property is requested.
  * @param bool $fld_description True if the description property is requested.
  * @param bool $fld_public True if the public property is requested.
  * @param bool $fld_review True if the review property is requested.
  * @param bool $fld_image True if the image property is requested.
  * @param bool $fld_updated True if the updated property is requested.
  * @param bool $fld_owner True if the owner property is requested.
  * @param array $path API module path.
  * @param User|null $owner The user whose lists are being shown.
  * @param callable $getContinueEnumParameter A function that receives $row and returns a
  *   continuation key that corresponds to the ordering of the query.
  * @return bool
  */
 private function processRow($row, &$count, $mode, $limit, $useInfo, $title, $fld_label, $fld_description, $fld_public, $fld_review, $fld_image, $fld_updated, $fld_owner, $path, $owner, $getContinueEnumParameter)
 {
     global $wgGatherAutohideFlagLimit;
     if ($row === null) {
         // Fake watchlist row
         $row = (object) array('gl_id' => 0, 'gl_label' => '', 'gl_perm' => ApiEditList::PERM_PRIVATE, 'gl_perm_override' => ApiEditList::PERM_OVERRIDE_NONE, 'gl_needs_review' => 0, 'gl_flag_count' => 0, 'gl_updated' => '', 'gl_info' => '');
     } else {
         $row = ApiEditList::normalizeRow($row);
     }
     $count++;
     if ($count > $limit) {
         // We've reached the one extra which shows that there are
         // additional pages to be had. Stop here...
         $this->setContinueEnumParameter('continue', $getContinueEnumParameter($row));
         return false;
     }
     $isWatchlist = property_exists($row, 'isWl') ? $row->isWl : $row->gl_label === '';
     $data = array('id' => $row->gl_id);
     if ($isWatchlist) {
         $data['watchlist'] = true;
     }
     if ($fld_label) {
         // TODO: check if this is the right wfMessage to show
         $data['label'] = !$isWatchlist ? $row->gl_label : wfMessage('watchlist')->plain();
     }
     if ($fld_owner) {
         $data['owner'] = property_exists($row, 'user_name') ? $row->user_name : $owner->getName();
     }
     if ($title) {
         if ($isWatchlist) {
             $data['title'] = $this->isTitleInWatchlist($owner, $title);
         } else {
             $data['title'] = isset($row->isIn);
         }
     }
     if ($fld_public) {
         $permMap = array_flip(ApiEditList::$permMap);
         $permOverrideMap = self::$permOverrideApiMap;
         if (!array_key_exists($row->gl_perm, $permMap)) {
             $this->dieDebug(__METHOD__, "Unknown gather perm={$row->gl_perm} for id {$row->gl_id}");
         }
         if (!array_key_exists($row->gl_perm_override, $permOverrideMap)) {
             $this->dieDebug(__METHOD__, "Unknown gather " . "perm_override={$row->gl_perm_override} for id {$row->gl_id}");
         }
         $data['perm'] = $permMap[$row->gl_perm];
         if ($permOverrideMap[$row->gl_perm_override]) {
             $data['perm_override'] = $permOverrideMap[$row->gl_perm_override];
         }
         if ($row->gl_flag_count >= $wgGatherAutohideFlagLimit) {
             $data['flagged'] = true;
         }
         if ($row->gl_perm_override === ApiEditList::PERM_OVERRIDE_HIDDEN || $row->gl_perm_override === ApiEditList::PERM_OVERRIDE_NONE && $row->gl_flag_count >= $wgGatherAutohideFlagLimit) {
             $data['hidden'] = true;
         }
     }
     if ($fld_review) {
         if ($row->gl_needs_review || $row->gl_flag_count >= $wgGatherAutohideFlagLimit) {
             $data['review'] = true;
         }
     }
     if ($useInfo) {
         $info = ApiEditList::parseListInfo($row->gl_info, $row->gl_id, false);
         if ($fld_description) {
             $data['description'] = property_exists($info, 'description') ? $info->description : '';
         }
         if ($fld_image) {
             if (property_exists($info, 'image') && $info->image) {
                 $data['image'] = $info->image;
                 $file = wfFindFile($info->image);
                 if (!$file) {
                     $data['badimage'] = true;
                 } else {
                     $data['imageurl'] = $file->getFullUrl();
                     $data['imagewidth'] = intval($file->getWidth());
                     $data['imageheight'] = intval($file->getHeight());
                 }
             } else {
                 $data['image'] = false;
             }
         }
     }
     if ($fld_updated) {
         $data['updated'] = wfTimestamp(TS_ISO_8601, $row->gl_updated);
     }
     $fit = $this->getResult()->addValue($path, null, $data);
     if (!$fit) {
         $this->setContinueEnumParameter('continue', $getContinueEnumParameter($row));
         return false;
     }
     return true;
 }