r23230 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23229‎ | r23230 | r23231 >
Date:16:47, 22 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for namespace restrictions implemented
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -483,14 +483,21 @@
484484 $result = $this->addDescription($result, $this->getSubqueryDescription(), false);
485485 break;
486486 default:
487 - $list = preg_split('/:/', $chunk, 3);
488 - if ($list[0] == '') {
489 - $list = array_slice($list, 2);
 487+ $list = preg_split('/:/', $chunk, 3); // ":Category:Foo" "User:bar" ":baz" ":+"
 488+ if ( ($list[0] == '') && (count($list)==3) ) {
 489+ $list = array_slice($list, 1);
490490 }
491 - if ( (count($list) == 3) && ($list[2] == '+') ) { // namespace restriction
492 - // TODO
 491+ if ( (count($list) == 2) && ($list[1] == '+') ) { // try namespace restriction
 492+ global $wgContLang;
 493+ $idx = $wgContLang->getNsIndex($list[0]);
 494+ if ($idx !== false) {
 495+ $result = $this->addDescription($result, new SMWNamespaceDescription($idx), false);
 496+ }
493497 } else {
494 - $result = $this->addDescription($result, new SMWNominalDescription(Title::newFromText($chunk)), false);
 498+ $title = Title::newFromText($chunk);
 499+ if ($title !== NULL) {
 500+ $result = $this->addDescription($result, new SMWNominalDescription($title), false);
 501+ }
495502 }
496503 }
497504
@@ -558,7 +565,7 @@
559566 */
560567 protected function readChunk($stoppattern = '') {
561568 if ($stoppattern == '') {
562 - $stoppattern = '\[\[|\]\]|::|:=|<q>|<\/q>|' . $this->m_categoryprefix . '|\|\||\|';
 569+ $stoppattern = '\[\[|\]\]|::|:=|<q>|<\/q>|^' . $this->m_categoryprefix . '|\|\||\|';
563570 }
564571 $chunks = preg_split('/[\s]*(' . $stoppattern . ')[\s]*/', $this->m_curstring, 2, PREG_SPLIT_DELIM_CAPTURE);
565572 if (count($chunks) == 1) { // no matches anymore, strip spaces and finish
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -189,6 +189,34 @@
190190 }
191191
192192 /**
 193+ * Description of all pages within a given wiki namespace,
 194+ * given by a numerical constant.
 195+ * Corresponds to a class restriction with a special class
 196+ * that characterises the given namespace (or at least that
 197+ * is how one could map this to OWL etc.).
 198+ */
 199+class SMWNamespaceDescription extends SMWDescription {
 200+ protected $m_namespace;
 201+
 202+ public function SMWNamespaceDescription($namespace) {
 203+ $this->m_namespace = $namespace;
 204+ }
 205+
 206+ public function getNamespace() {
 207+ return $this->m_namespace;
 208+ }
 209+
 210+ public function getQueryString() {
 211+ global $wgContlang;
 212+ if ($this->m_title !== NULL) {
 213+ return '[[' . $wgContLang->getNSText($this->m_namespace) . ']]';
 214+ } else {
 215+ return '';
 216+ }
 217+ }
 218+}
 219+
 220+/**
193221 * Description of a class that contains exactly one explicitly given
194222 * object.
195223 *
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -866,6 +866,10 @@
867867 if ($this->addInnerJoin('CATS', $from, $db, $curtables)) {
868868 $where .= $curtables['CATS'] . '.cl_to=' . $db->addQuotes($description->getCategory()->getDBKey());
869869 }
 870+ } elseif ($description instanceof SMWNamespaceDescription) {
 871+ if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) {
 872+ $where .= $curtables['PAGE'] . '.page_namespace=' . $db->addQuotes($description->getNamespace());
 873+ }
870874 } elseif ($description instanceof SMWNominalDescription) {
871875 if (array_key_exists('PREVREL', $curtables)) {
872876 $where .= $curtables['PREVREL'] . '.object_title=' .

Status & tagging log