public function execute()
 {
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     if (is_null($params['lang'])) {
         $langCode = false;
     } elseif (!Language::isValidCode($params['lang'])) {
         $this->dieUsage('Invalid language code for parameter lang', 'invalidlang');
     } else {
         $langCode = $params['lang'];
     }
     $pageSet = $this->getPageSet();
     $pageSet->execute();
     $titles = $pageSet->getGoodTitles();
     // page_id => Title object
     if (!count($titles)) {
         $result->addValue(null, 'pages', (object) array());
         return;
     }
     $db = $this->getDB();
     $res = $db->select('page_props', array('pp_page', 'pp_value'), array('pp_page' => array_keys($titles), 'pp_propname' => 'templatedata'), __METHOD__, array('ORDER BY', 'pp_page'));
     $resp = array();
     foreach ($res as $row) {
         $rawData = $row->pp_value;
         $tdb = TemplateDataBlob::newFromDatabase($rawData);
         $status = $tdb->getStatus();
         if (!$status->isOK()) {
             $this->dieUsage('Page #' . intval($row->pp_page) . ' templatedata contains invalid data: ' . $status->getMessage(), 'templatedata-corrupt');
         }
         if ($langCode) {
             $data = $tdb->getDataInLanguage($langCode);
         } else {
             $data = $tdb->getData();
         }
         $resp[$row->pp_page] = array('title' => strval($titles[$row->pp_page])) + (array) $data;
     }
     // Set top level element
     $result->addValue(null, 'pages', (object) $resp);
     $values = $pageSet->getNormalizedTitlesAsResult();
     if ($values) {
         $result->addValue(null, 'normalized', $values);
     }
     $redirects = $pageSet->getRedirectTitlesAsResult();
     if ($redirects) {
         $result->addValue(null, 'redirects', $redirects);
     }
 }
 /**
  * Verify we can gzdecode() which came in PHP 5.4.0. Mediawiki needs a
  * fallback function for it.
  * If this test fail, we are most probably attempting to use gzdecode()
  * with PHP before 5.4.
  *
  * @see bug 54058
  */
 public function testGetJsonForDatabase()
 {
     // Compress JSON to trigger the code pass in newFromDatabase that ends
     // up calling gzdecode().
     $gzJson = gzencode('{}');
     $templateData = TemplateDataBlob::newFromDatabase($gzJson);
     $this->assertInstanceOf('TemplateDataBlob', $templateData);
 }