r24877 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24876‎ | r24877 | r24878 >
Date:15:23, 17 August 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Storage access methods for property special pages
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -851,6 +851,83 @@
852852 return $result;
853853 }
854854
 855+///// Special page functions /////
 856+
 857+ function getPropertiesSpecial($requestoptions = NULL) {
 858+ $db =& wfGetDB( DB_SLAVE );
 859+ $options = ' ORDER BY title';
 860+ if ($requestoptions->limit >= 0) {
 861+ $options .= ' LIMIT ' . $requestoptions->limit;
 862+ }
 863+ if ($requestoptions->offset > 0) {
 864+ $options .= ' OFFSET ' . $requestoptions->offset;
 865+ }
 866+ $res = $db->query('(SELECT relation_title as title, COUNT(*) as count FROM ' .
 867+ $db->tableName('smw_relations') . 'GROUP BY relation_title) UNION ' .
 868+ '(SELECT attribute_title as title, COUNT(*) as count FROM ' .
 869+ $db->tableName('smw_attributes') . 'GROUP BY attribute_title) UNION ' .
 870+ '(SELECT attribute_title as title, COUNT(*) as count FROM ' .
 871+ $db->tableName('smw_longstrings') . 'GROUP BY attribute_title) UNION ' .
 872+ '(SELECT attribute_title as title, COUNT(*) as count FROM ' .
 873+ $db->tableName('smw_nary') . 'GROUP BY attribute_title)' . $options,
 874+ 'SMW::getPropertySubjects');
 875+ $result = array();
 876+ while($row = $db->fetchObject($res)) {
 877+ $title = Title::newFromText($row->title, SMW_NS_PROPERTY);
 878+ $result[] = array($title, $row->count);
 879+ }
 880+ $db->freeResult($res);
 881+ return $result;
 882+ }
 883+
 884+ function getUnusedPropertiesSpecial($requestoptions = NULL) {
 885+ $db =& wfGetDB( DB_SLAVE );
 886+ $options = ' ORDER BY page_title';
 887+ if ($requestoptions->limit >= 0) {
 888+ $options .= ' LIMIT ' . $requestoptions->limit;
 889+ }
 890+ if ($requestoptions->offset > 0) {
 891+ $options .= ' OFFSET ' . $requestoptions->offset;
 892+ }
 893+ extract( $db->tableNames('page', 'smw_relations', 'smw_attributes', 'smw_longstrings', 'smw_nary', 'smw_subprops') );
 894+ /// TODO: any chance of making this more efficient?
 895+ $res = $db->query("SELECT page_title FROM $page LEFT JOIN $smw_relations ON page_title=$smw_relations.relation_title" .
 896+ " LEFT JOIN $smw_attributes ON page_title=$smw_attributes.attribute_title " .
 897+ " LEFT JOIN $smw_longstrings ON page_title=$smw_longstrings.attribute_title " .
 898+ " LEFT JOIN $smw_nary ON page_title=$smw_nary.attribute_title " .
 899+ " LEFT JOIN $smw_subprops ON page_title=$smw_subprops.object_title " .
 900+ " WHERE page_namespace=" . SMW_NS_PROPERTY . " AND $smw_relations.subject_id IS NULL" .
 901+ " AND $smw_attributes.subject_id IS NULL AND $smw_longstrings.subject_id IS NULL" .
 902+ " AND $smw_nary.subject_id IS NULL AND $smw_subprops.subject_title IS NULL" . $options,
 903+ 'SMW::getUnusedPropertySubjects');
 904+ $result = array();
 905+ while($row = $db->fetchObject($res)) {
 906+ $result[] = Title::newFromText($row->page_title, SMW_NS_PROPERTY);
 907+ }
 908+ return $result;
 909+ }
 910+
 911+ function getWantedPropertiesSpecial($requestoptions = NULL) {
 912+ $db =& wfGetDB( DB_SLAVE );
 913+ $options = ' ORDER BY count DESC';
 914+ if ($requestoptions->limit >= 0) {
 915+ $options .= ' LIMIT ' . $requestoptions->limit;
 916+ }
 917+ if ($requestoptions->offset > 0) {
 918+ $options .= ' OFFSET ' . $requestoptions->offset;
 919+ }
 920+ $res = $db->query('SELECT relation_title as title, COUNT(*) as count FROM ' .
 921+ $db->tableName('smw_relations') . ' LEFT JOIN page ON (page_namespace=' . SMW_NS_PROPERTY .
 922+ ' AND page_title=relation_title) WHERE page_id IS NULL GROUP BY relation_title' . $options,
 923+ 'SMW::getPropertySubjects');
 924+ $result = array();
 925+ while($row = $db->fetchObject($res)) {
 926+ $title = Title::newFromText($row->title, SMW_NS_PROPERTY);
 927+ $result[] = array($title, $row->count);
 928+ }
 929+ return $result;
 930+ }
 931+
855932 ///// Setup store /////
856933
857934 function setup($verbose = true) {
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
@@ -304,6 +304,31 @@
305305 */
306306 abstract function getQueryResult(SMWQuery $query);
307307
 308+///// Special page functions /////
 309+
 310+ /**
 311+ * Return all properties that have been used on pages in the wiki. The result is an array
 312+ * of arrays, each containing a property title and a count. The expected order is
 313+ * alphabetical w.r.t. to property title texts.
 314+ */
 315+ abstract function getPropertiesSpecial($requestoptions = NULL);
 316+
 317+ /**
 318+ * Return all properties that have been declared in the wiki but that
 319+ * are not used on any page. Stores might restrict here to those properties
 320+ * that have been given a type if they have no efficient means of accessing
 321+ * the set of all pages in the property namespace.
 322+ */
 323+ abstract function getUnusedPropertiesSpecial($requestoptions = NULL);
 324+
 325+ /**
 326+ * Return all properties that are used on some page but that do not have any
 327+ * page describing them. Stores that have no efficient way of accessing the
 328+ * set of all existing pages can extend this list to all properties that are
 329+ * used but do not have a type assigned to them.
 330+ */
 331+ abstract function getWantedPropertiesSpecial($requestoptions = NULL);
 332+
308333 ///// Setup store /////
309334
310335 /**

Status & tagging log