/**
  * Implementation of SMWStore::getWantedPropertiesSpecial(). Like all
  * WantedFoo specials, this function is very resource intensive and needs
  * to be cached on medium/large wikis.
  *
  * @param SMWRequestOptions $requestoptions
  *
  * @return array of array( SMWDIProperty, int )
  */
 public function getWantedPropertiesSpecial($requestoptions = null)
 {
     global $smwgPDefaultType;
     wfProfileIn("SMWSQLStore3::getWantedPropertiesSpecial (SMW)");
     // Note that Wanted Properties must have the default type.
     $proptables = SMWSQLStore3::getPropertyTables();
     $proptable = $proptables[SMWSQLStore3::findTypeTableId($smwgPDefaultType)];
     $result = array();
     if ($proptable->fixedproperty == false) {
         // anything else would be crazy, but let's fail gracefully even if the whole world is crazy
         $dbr = wfGetDB(DB_SLAVE);
         $options = $this->store->getSQLOptions($requestoptions, 'title');
         $options['ORDER BY'] = 'count DESC';
         $res = $dbr->select($dbr->tableName($proptable->name) . ' INNER JOIN ' . $dbr->tableName('smw_ids') . ' ON p_id=smw_id LEFT JOIN ' . $dbr->tableName('page') . ' ON (page_namespace=' . $dbr->addQuotes(SMW_NS_PROPERTY) . ' AND page_title=smw_title)', 'smw_title, COUNT(*) as count', 'smw_id > 50 AND page_id IS NULL GROUP BY smw_title', 'SMW::getWantedPropertiesSpecial', $options);
         foreach ($res as $row) {
             $result[] = array(new SMWDIProperty($row->smw_title), $row->count);
         }
     }
     wfProfileOut("SMWSQLStore3::getWantedPropertiesSpecial (SMW)");
     return $result;
 }
 /**
  * Implementation of SMWStore::getWantedPropertiesSpecial(). Like all
  * WantedFoo specials, this function is very resource intensive and needs
  * to be cached on medium/large wikis.
  *
  * @param SMWRequestOptions $requestoptions
  *
  * @return array of array( SMWDIProperty, int )
  */
 public function getWantedPropertiesSpecial($requestoptions = null)
 {
     global $smwgPDefaultType;
     wfProfileIn("SMWSQLStore3::getWantedPropertiesSpecial (SMW)");
     // Note that Wanted Properties must have the default type.
     $proptables = SMWSQLStore3::getPropertyTables();
     $proptable = $proptables[SMWSQLStore3::findTypeTableId($smwgPDefaultType)];
     $result = array();
     if (!$proptable->isFixedPropertyTable()) {
         // anything else would be crazy, but let's fail gracefully even if the whole world is crazy
         // Wikia change - hack for smw+
         // $dbr = wfGetDB( DB_SLAVE );
         // $options = $this->store->getSQLOptions( $requestoptions, 'title' );
         // $options['ORDER BY'] = 'count DESC';
         // $res = $dbr->select( // TODO: this is not how JOINS should be specified in the select function
         // 	$dbr->tableName( $proptable->getName() ) . ' INNER JOIN ' .
         // 		$dbr->tableName( SMWSql3SmwIds::tableName ) . ' ON p_id=smw_id LEFT JOIN ' .
         // 		$dbr->tableName( 'page' ) . ' ON (page_namespace=' .
         // 		$dbr->addQuotes( SMW_NS_PROPERTY ) . ' AND page_title=smw_title)',
         // 	'smw_title, COUNT(*) as count',
         // 	'smw_id > 50 AND page_id IS NULL GROUP BY smw_title',
         // 	'SMW::getWantedPropertiesSpecial',
         // 	$options
         // );
         $dbr = wfGetDB(DB_SLAVE, 'smw');
         $dbl = wfGetDB(DB_SLAVE);
         // local connection
         $res = $dbl->select($dbl->tableName('page'), 'page_title', ['page_namespace' => SMW_NS_PROPERTY], __METHOD__);
         $titles = [];
         foreach ($res as $row) {
             $titles[] = $row->page_title;
         }
         $condition = !empty($titles) ? ' AND smw_title NOT IN (' . $dbl->makeList($titles) . ')' : '';
         $options = $this->store->getSQLOptions($requestoptions, 'title');
         $options['ORDER BY'] = 'count DESC';
         $res = $dbr->select($dbr->tableName($proptable->getName()) . ' INNER JOIN ' . $dbr->tableName(SMWSql3SmwIds::tableName) . ' ON p_id=smw_id', 'smw_title, COUNT(*) as count', "smw_id > 50 {$condition} GROUP BY smw_title", 'SMW::getWantedPropertiesSpecial', $options);
         foreach ($res as $row) {
             $result[] = array(new SMWDIProperty($row->smw_title), $row->count);
         }
     }
     wfProfileOut("SMWSQLStore3::getWantedPropertiesSpecial (SMW)");
     return $result;
 }