r23874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23873‎ | r23874 | r23875 >
Date:17:47, 8 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Support for redirect normalisation in relation and fixed subject queries.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -822,6 +822,26 @@
823823 }
824824 return $sql_conds;
825825 }
 826+
 827+ /**
 828+ * Find out if the given page is a redirect and determine its target.
 829+ * Return the target or the page itself if it is not redirect.
 830+ */
 831+ protected function getRedirectTarget($page, &$db) {
 832+ $options = array('LIMIT' => '1');
 833+ $id = $page->getArticleID();
 834+ if ($id == 0) { // page not existing, return
 835+ return $page;
 836+ }
 837+ $res = $db->select($db->tableName('redirect'), 'rd_namespace, rd_title', 'rd_from=' . $id, 'SMW::getRedirectTarget', $options);
 838+ if ($row = $db->fetchObject($res)) {
 839+ $result = Title::newFromText($row->rd_title, $row->rd_namespace);
 840+ if ($result !== NULL) {
 841+ return $result;
 842+ }
 843+ }
 844+ return $page;
 845+ }
826846
827847 /**
828848 * Add the table $tablename to the $from condition via an inner join,
@@ -865,6 +885,12 @@
866886 $from .= ' INNER JOIN ' . $db->tableName('smw_longstrings') . ' AS ' . $curtables['TEXT'] . ' ON ' . $curtables['TEXT'] . '.subject_id=' . $curtables['PAGE'] . '.page_id';
867887 return true;
868888 }
 889+ } elseif ($tablename == 'REDIRECT') {
 890+ if ($this->addInnerJoin('PAGE', $from, $db, $curtables)) { // try to add PAGE
 891+ $curtables['REDIRECT'] = 'rd' . $this->m_tablenum++;
 892+ $from .= ' INNER JOIN ' . $db->tableName('redirect') . ' AS ' . $curtables['REDIRECT'] . ' ON ' . $curtables['REDIRECT'] . '.rd_from=' . $curtables['PAGE'] . '.page_id';
 893+ return true;
 894+ }
869895 }
870896 return false;
871897 }
@@ -912,16 +938,34 @@
913939 $where .= $curtables['PAGE'] . '.page_namespace=' . $db->addQuotes($description->getNamespace());
914940 }
915941 } elseif ($description instanceof SMWNominalDescription) {
 942+ global $smwgIQRedirectNormalization;
 943+ if ($smwgIQRedirectNormalization) {
 944+ $page = $this->getRedirectTarget($description->getIndividual(), $db);
 945+ } else {
 946+ $page = $description->getIndividual();
 947+ }
916948 if (array_key_exists('PREVREL', $curtables)) {
917 - $where .= $curtables['PREVREL'] . '.object_title=' .
918 - $db->addQuotes($description->getIndividual()->getDBKey()) . ' AND ' .
919 - $curtables['PREVREL'] . '.object_namespace=' .
920 - $description->getIndividual()->getNamespace();
 949+ $cond = $curtables['PREVREL'] . '.object_title=' .
 950+ $db->addQuotes($page->getDBKey()) . ' AND ' .
 951+ $curtables['PREVREL'] . '.object_namespace=' .
 952+ $page->getNamespace();
 953+ if ( $smwgIQRedirectNormalization && ($this->addInnerJoin('PAGE', $from, $db, $curtables)) ) {
 954+ $rdtable = 'rd' . $this->m_tablenum++;
 955+ $from .= ' INNER JOIN ' . $db->tableName('redirect') . ' AS ' . $rdtable;
 956+ $cond = '(' . $cond . ') OR (' .
 957+ $rdtable . '.rd_from=' .
 958+ $curtables['PAGE'] . '.page_id AND ' .
 959+ $rdtable . '.rd_title=' .
 960+ $db->addQuotes($page->getDBKey()) . ' AND ' .
 961+ $rdtable . '.rd_namespace=' .
 962+ $page->getNamespace() . ')';
 963+ }
 964+ $where .= $cond;
921965 } elseif ($this->addInnerJoin('PAGE', $from, $db, $curtables)) {
922966 $where .= $curtables['PAGE'] . '.page_title=' .
923 - $db->addQuotes($description->getIndividual()->getDBKey()) . ' AND ' .
 967+ $db->addQuotes($page->getDBKey()) . ' AND ' .
924968 $curtables['PAGE'] . '.page_namespace=' .
925 - $description->getIndividual()->getNamespace();
 969+ $page->getNamespace();
926970 }
927971 } elseif ($description instanceof SMWValueDescription) {
928972 switch ($description->getDatavalue()->getTypeID()) {

Status & tagging log