r37037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37036‎ | r37037 | r37038 >
Date:09:46, 4 July 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
New more fine grained control over inline query features, e.g. to only allow category intersections, or even
just single categories (easy and presumably fast, does not even need semantic data in wiki).
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -160,6 +160,7 @@
161161 * Abstract base class for all descriptions.
162162 */
163163 abstract class SMWDescription {
 164+
164165 protected $m_printreqs = array();
165166 // add code for managing printouts, including iteration
166167
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -980,6 +980,27 @@
981981 * also be changed (if it was non-NULL).
982982 */
983983 protected function addDescription($curdesc, $newdesc, $conjunction = true) {
 984+ global $smwgQFeatures;
 985+ $notallowedmessage = 'smw_noqueryfeature';
 986+ if ($newdesc instanceof SMWSomeProperty) {
 987+ $allowed = $smwgQFeatures & SMW_PROPERTY_QUERY;
 988+ } elseif ($newdesc instanceof SMWClassDescription) {
 989+ $allowed = $smwgQFeatures & SMW_CATEGORY_QUERY;
 990+ } elseif ($newdesc instanceof SMWConceptDescription) {
 991+ $allowed = $smwgQFeatures & SMW_CONCEPT_QUERY;
 992+ } elseif ($newdesc instanceof SMWConjunction) {
 993+ $allowed = $smwgQFeatures & SMW_CONJUNCTION_QUERY;
 994+ $notallowedmessage = 'smw_noconjunctions';
 995+ } elseif ($newdesc instanceof SMWDisjunction) {
 996+ $allowed = $smwgQFeatures & SMW_DISJUNCTION_QUERY;
 997+ $notallowedmessage = 'smw_nodisjunctions';
 998+ } else {
 999+ $allowed = true;
 1000+ }
 1001+ if (!$allowed) {
 1002+ $this->m_errors[] = wfMsgForContent($notallowedmessage, str_replace('[', '[', $newdesc->getQueryString()));
 1003+ return $curdesc;
 1004+ }
9841005 if ($newdesc === NULL) {
9851006 return $curdesc;
9861007 } elseif ($curdesc === NULL) {
@@ -990,13 +1011,17 @@
9911012 $curdesc->addDescription($newdesc);
9921013 return $curdesc;
9931014 } elseif ($conjunction) { // make new conjunction
994 - return new SMWConjunction(array($curdesc,$newdesc));
 1015+ if ($smwgQFeatures & SMW_CONJUNCTION_QUERY) {
 1016+ return new SMWConjunction(array($curdesc,$newdesc));
 1017+ } else {
 1018+ $this->m_errors[] = wfMsgForContent('smw_noconjunctions', str_replace('[', '[', $newdesc->getQueryString()));
 1019+ return $curdesc;
 1020+ }
9951021 } else { // make new disjunction
996 - global $smwgQDisjunctionSupport;
997 - if ($smwgQDisjunctionSupport) {
 1022+ if ($smwgQFeatures & SMW_DISJUNCTION_QUERY) {
9981023 return new SMWDisjunction(array($curdesc,$newdesc));
9991024 } else {
1000 - $this->m_errors[] = wfMsgForContent('smw_nodisjunctions', $newdesc->getQueryString());
 1025+ $this->m_errors[] = wfMsgForContent('smw_nodisjunctions', str_replace('[', '[', $newdesc->getQueryString()));
10011026 return $curdesc;
10021027 }
10031028 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -38,6 +38,14 @@
3939 define('SMW_EQ_SOME', 1);
4040 define('SMW_EQ_FULL', 2);
4141
 42+// flags to classify available query descriptions, used to enable/disable certain features
 43+define('SMW_PROPERTY_QUERY', 1); // [[some property::...]]
 44+define('SMW_CATEGORY_QUERY', 2); // [[Category:...]]
 45+define('SMW_CONCEPT_QUERY', 4); // [[Concept:...]]
 46+define('SMW_NAMESPACE_QUERY', 8); // [[User:+]] etc.
 47+define('SMW_CONJUNCTION_QUERY', 16); // any conjunctions
 48+define('SMW_DISJUNCTION_QUERY', 32); // any disjunctions (OR, ||)
 49+
4250 // constants for identifying javascripts as used in smwfRequireHeadItem
4351 define('SMW_HEADER_TIMELINE', 1);
4452 define('SMW_HEADER_TOOLTIP', 2);
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Settings.php
@@ -93,7 +93,8 @@
9494 $smwgQSubcategoryDepth = 10; // Restrict level of sub-category inclusion (steps within category hierarchy)
9595 $smwgQSubpropertyDepth = 10; // Restrict level of sub-property inclusion (steps within property hierarchy)
9696 // (Use 0 to disable hierarchy-inferencing in queries)
97 -$smwgQEqualitySupport = SMW_EQ_SOME; // Evaluate #redirects as equality between page names in simple cases
 97+$smwgQEqualitySupport = SMW_EQ_SOME; // Evaluate #redirects as equality between page names, with possible
 98+ // performance-relevant restrictions depending on the storage engine
9899 //$smwgQEqualitySupport = SMW_EQ_FULL; // Evaluate #redirects as equality between page names in all cases
99100 //$smwgQEqualitySupport = SMW_EQ_NONE; // Never evaluate #redirects as equality between page names
100101 $smwgQSortingSupport = true; // (De)activate sorting of results.
@@ -101,18 +102,22 @@
102103 // (value NULL switches off default restrictions on searching -- this is faster)
103104 // Example with namespaces: $smwgQDefaultNamespaces = array(NS_MAIN, NS_IMAGE);
104105 $smwgQMaxLimit = 10000; // Max number of results ever retrieved, even when using special query pages.
105 -$smwgQDisjunctionSupport = true; // Support disjunctions in queries ("||" and "OR")?
106 - // (Note: things like namespace defaults and property/category hierarchies
107 - // can also cause disjunctions!)
 106+// The next defines which query features should be available by default.
 107+// Examples:
 108+// only cateory intersections: $smwgQFeatures = SMW_CATEGORY_QUERY | SMW_CONJUNCTION_QUERY
 109+// only single concepts: $smwgQFeatures = SMW_CONCEPT_QUERY
 110+// The default is to support all basic features.
 111+$smwgQFeatures = SMW_PROPERTY_QUERY | SMW_CATEGORY_QUERY | SMW_CONCEPT_QUERY |
 112+ SMW_NAMESPACE_QUERY | SMW_CONJUNCTION_QUERY | SMW_DISJUNCTION_QUERY;
108113 $smwgQComparators = '<|>|!'; // List of comparator characters supported by queries, separated by '|'
109114 // Available entries: < (smaller than), < (greater than), ! (unequal to),
110115 // ~ (pattern with '*' as wildcard, only for Type:String)
111116 // If unsupported comparators are used, they are treated as part of the queried value
112117
113118 ### Settings about printout of (especially inline) queries:
114 -$smwgQDefaultLimit = 50; // Default number of rows returned in a query. Can be increased with <ask limit="num">...
 119+$smwgQDefaultLimit = 50; // Default number of rows returned in a query. Can be increased with limit=num in #ask
115120 $smwgQMaxInlineLimit = 500; // Max number of rows ever printed in a single inline query on a single page.
116 -$smwgQPrintoutLimit = 100; // Max number of supported printouts (added columns in result table, ?-statements)
 121+$smwgQPrintoutLimit = 100; // Max number of supported printouts (added columns in result table, ?-statements)
117122
118123 ### Formatting settings
119124 $smwgQDefaultLinking = 'all'; // Default linking behaviour. Can be one of "none", "subject", "all"
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -98,6 +98,8 @@
9999 'smw_badtitle' => 'Sorry, but “$1” is no valid page title.',
100100 'smw_badqueryatom' => 'Some part “[&#x005B;&hellip;]]” of the query was not understood.',
101101 'smw_propvalueproblem' => 'The value of property “$1” was not understood.',
 102+ 'smw_noqueryfeature' => 'Some query feature was not supported in this wiki and part of the query was dropped ($1).',
 103+ 'smw_noconjunctions' => 'Conjunctions in queries are not supported in this wiki and part of the query was dropped ($1).',
102104 'smw_nodisjunctions' => 'Disjunctions in queries are not supported in this wiki and part of the query was dropped ($1).',
103105 'smw_querytoolarge' => 'The following query conditions could not be considered due to the wikis restrictions in query size or depth: $1.',
104106 'smw_devel_warning' => 'This feature is currently under development, and might not be fully functional.

Status & tagging log