/** * Returns a virtual 'smw_ob_properties' table with properties matching $stringConditions * */ protected function createVirtualTableWithPropertiesByName($requestoptions, &$db) { global $smwgDefaultCollation; if (!isset($smwgDefaultCollation)) { $collation = ''; } else { $collation = 'COLLATE ' . $smwgDefaultCollation; } $page = $db->tableName('page'); $redirect = $db->tableName('redirect'); $redirects = $db->tableName('redirect'); $db->query('CREATE TEMPORARY TABLE smw_ob_properties (id INT(8) NOT NULL, property VARCHAR(255) ' . $collation . ') TYPE=MEMORY', 'SMW::createVirtualTableForInstances'); $sql = DBHelper::getSQLConditions($requestoptions, 'page_title', 'page_title'); // add properties which match and which are no redirects $db->query('INSERT INTO smw_ob_properties (SELECT page_id, page_title FROM ' . $page . ' WHERE page_is_redirect = 0 AND page_namespace = ' . SMW_NS_PROPERTY . ' ' . $sql . ')'); $sql = DBHelper::getSQLConditions($requestoptions, 'p1.page_title', 'p1.page_title'); // add targets of matching redirects $db->query('INSERT INTO smw_ob_properties (SELECT p2.page_id, p2.page_title FROM ' . $page . ' p1 JOIN ' . $redirect . ' ON p1.page_id = rd_from JOIN ' . $page . ' p2 ON p2.page_title = rd_title AND p2.page_namespace = rd_namespace WHERE p1.page_namespace = ' . SMW_NS_PROPERTY . ' ' . $sql . ')'); }
protected function createVirtualTableWithPropertiesByName($requestoptions, &$db) { global $smwgDefaultCollation; if (!isset($smwgDefaultCollation)) { $collation = ''; } else { $collation = 'COLLATE ' . $smwgDefaultCollation; } $smw_ids = $db->tableName('smw_ids'); $page = $db->tableName('page'); $redirect = $db->tableName('redirect'); $redirects = $db->tableName('redirect'); $db->query('CREATE TEMPORARY TABLE smw_ob_properties (id INT(8) NOT NULL, property VARCHAR(255) ' . $collation . ') TYPE=MEMORY', 'SMW::createVirtualTableForInstances'); $sql = DBHelper::getSQLConditions($requestoptions, 'smw_title', 'smw_title'); // add properties which match and which are no redirects $db->query('INSERT INTO smw_ob_properties (SELECT smw_id, smw_title FROM ' . $smw_ids . ' JOIN ' . $page . ' ON smw_title = page_title AND page_namespace=' . SMW_NS_PROPERTY . ' WHERE smw_iw != ":smw-redi" AND smw_namespace = ' . SMW_NS_PROPERTY . ' ' . $sql . ')'); $sql = DBHelper::getSQLConditions($requestoptions, 's.smw_title', 's.smw_title'); // add targets of matching redirects $db->query('INSERT INTO smw_ob_properties (SELECT s2.smw_id, s2.smw_title FROM ' . $smw_ids . ' s JOIN ' . $page . ' ON smw_title = page_title AND page_namespace=' . SMW_NS_PROPERTY . ' JOIN ' . $smw_ids . ' s2 ON s.smw_sortkey = s2.smw_title WHERE s.smw_namespace = ' . SMW_NS_PROPERTY . ' AND s.smw_iw=":smw-redi"' . $sql . ')'); }
/** * Retrieves the articles that use the given web service. * * @param int $wsPageID * The unique page ID of the web service's WWSD. * * @return array: * An array of page ids of articles that use the web service. */ public function getWSArticles($wsPageID, SMWRequestOptions $options) { $db =& wfGetDB(DB_SLAVE); $atbl = $db->tableName('smw_ws_articles'); $page = $db->tableName('page'); $sql = "SELECT DISTINCT art.page_id, p.page_title FROM " . $atbl . " art " . "JOIN " . $page . " p ON art.page_id = p.page_id " . "WHERE art.web_service_id='" . $wsPageID . "' "; $cond = DBHelper::getSQLConditions($options, 'p.page_title'); $opt = DBHelper::getSQLOptionsAsString($options, 'p.page_title'); $articles = array(); $res = $db->query($sql . $cond . ' ' . $opt); if ($db->numRows($res) > 0) { while ($row = $db->fetchObject($res)) { $articles[] = $row->page_id; } } $db->freeResult($res); return $articles; }