r25469 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25468‎ | r25469 | r25470 >
Date:13:23, 4 September 2007
Author:proes
Status:old
Tags:
Comment:
Filtered suggestion drop downs for attributes on attribute values according to configured property to column filters.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Attribute.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
@@ -46,6 +46,8 @@
4747 @$definedMeaningId = $_GET['definedMeaningId'];
4848 @$offset = $_GET['offset'];
4949 @$attributesLevel = $_GET['attributesLevel'];
 50+ @$annotationAttributeId = $_GET['annotationAttributeId'];
 51+
5052 $sql='';
5153
5254 $dbr =& wfGetDB( DB_SLAVE );
@@ -62,16 +64,16 @@
6365 $sql=constructSQLWithFallback($sqlActual, $sqlFallback, array("member_mid", "spelling", "collection_mid"));
6466 break;
6567 case 'option-attribute':
66 - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'OPTN');
 68+ $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'OPTN');
6769 break;
6870 case 'translated-text-attribute':
69 - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'TRNS');
 71+ $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'TRNS');
7072 break;
7173 case 'text-attribute':
72 - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'TEXT');
 74+ $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'TEXT');
7375 break;
7476 case 'link-attribute':
75 - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'URL');
 77+ $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'URL');
7678 break;
7779 case 'language':
7880 require_once('languages.php');
@@ -224,19 +226,81 @@
225227 return $sql;
226228 }
227229
228 -function getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $attributesType) {
 230+function getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType) {
229231 global
230232 $wgUser;
231233
232 - $sqlActual = getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $attributesType, $wgUser->getOption('language'));
233 - $sqlFallback = getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $attributesType, 'en');
 234+ $sqlActual = getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType, $wgUser->getOption('language'));
 235+ $sqlFallback = getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType, 'en');
234236
235237 return constructSQLWithFallback($sqlActual, $sqlFallback, array("attribute_mid", "spelling"));
236238 }
237239
 240+function getPropertyToColumnFilterForAttribute($annotationAttributeId) {
 241+ global
 242+ $wgPropertyToColumnFilters;
 243+
 244+ $i = 0;
 245+ $result = null;
 246+
 247+ while ($result == null && $i < count($wgPropertyToColumnFilters))
 248+ if ($wgPropertyToColumnFilters[$i]->getAttribute()->id == $annotationAttributeId)
 249+ $result = $wgPropertyToColumnFilters[$i];
 250+ else
 251+ $i++;
 252+
 253+ return $result;
 254+}
 255+
 256+function getFilteredAttributes($annotationAttributeId) {
 257+ $propertyToColumnFilter = getPropertyToColumnFilterForAttribute($annotationAttributeId);
 258+
 259+ if ($propertyToColumnFilter != null)
 260+ return $propertyToColumnFilter->attributeIDs;
 261+ else
 262+ return array();
 263+}
 264+
 265+function getAllFilteredAttributes() {
 266+ global
 267+ $wgPropertyToColumnFilters;
 268+
 269+ $result = array();
 270+
 271+ foreach ($wgPropertyToColumnFilters as $propertyToColumnFilter)
 272+ $result = array_merge($result, $propertyToColumnFilter->attributeIDs);
 273+
 274+ return $result;
 275+}
 276+
 277+function getFilteredAttributesRestriction($annotationAttributeId) {
 278+ $dc=wdGetDataSetContext();
 279+
 280+ $propertyToColumnFilter = getPropertyToColumnFilterForAttribute($annotationAttributeId);
 281+
 282+ if ($propertyToColumnFilter != null) {
 283+ $filteredAttributes = $propertyToColumnFilter->attributeIDs;
 284+
 285+ if (count($filteredAttributes) > 0)
 286+ $result = " AND {$dc}_class_attributes.attribute_mid IN (" . join($filteredAttributes, ", ") . ")";
 287+ else
 288+ $result = " AND 0 ";
 289+ }
 290+ else {
 291+ $allFilteredAttributes = getAllFilteredAttributes();
 292+
 293+ if (count($allFilteredAttributes) > 0)
 294+ $result = " AND {$dc}_class_attributes.attribute_mid NOT IN (" . join($allFilteredAttributes, ", ") . ")";
 295+ else
 296+ $result = "";
 297+ }
 298+
 299+ return $result;
 300+}
 301+
238302 # language is the 2 letter wikimedia code. use "<ANY>" if you don't want language filtering
239303 # (any does set limit 1 hmph)
240 -function getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $attributesType, $language="<ANY>") {
 304+function getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType, $language="<ANY>") {
241305 global $wgDefaultClassMids;
242306 global $wgUser;
243307 $dc=wdGetDataSetContext();
@@ -245,6 +309,8 @@
246310 $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join($wgDefaultClassMids, ", ") . ")";
247311 else
248312 $defaultClassRestriction = "";
 313+
 314+ $filteredAttributesRestriction = getFilteredAttributesRestriction($annotationAttributeId);
249315
250316 $dbr =& wfGetDB(DB_SLAVE);
251317 $sql =
@@ -254,7 +320,8 @@
255321 " AND {$dc}_bootstrapped_defined_meanings.defined_meaning_id = {$dc}_class_attributes.level_mid" .
256322 " AND {$dc}_class_attributes.attribute_type = " . $dbr->addQuotes($attributesType) .
257323 " AND {$dc}_syntrans.defined_meaning_id = {$dc}_class_attributes.attribute_mid" .
258 - " AND {$dc}_expression_ns.expression_id = {$dc}_syntrans.expression_id";
 324+ " AND {$dc}_expression_ns.expression_id = {$dc}_syntrans.expression_id" .
 325+ $filteredAttributesRestriction . " ";
259326
260327 if ($language!="<ANY>") {
261328 $sql .=
Index: trunk/extensions/Wikidata/OmegaWiki/Attribute.php
@@ -38,8 +38,12 @@
3939 $this->type->setStructureType($this->id);
4040 }
4141 }
 42+
 43+ public function getId() {
 44+ return $this->id;
 45+ }
4246
43 - function __tostring() {
 47+ public function __tostring() {
4448 $id=$this->id;
4549 $name=$this->name;
4650 $type=$this->type;
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -151,6 +151,7 @@
152152 }
153153
154154 public function view(IdStack $idPath, $value) {
 155+ $idPath->pushAnnotationAttribute($this->getAttribute());
155156 $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($value);
156157
157158 $visibleStructure = new Structure(array_merge(
@@ -173,8 +174,32 @@
174175
175176 $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleStructure);
176177
 178+ $idPath->popAnnotationAttribute();
 179+
177180 return $result;
178181 }
 182+
 183+ public function edit(IdStack $idPath, $value) {
 184+ $idPath->pushAnnotationAttribute($this->getAttribute());
 185+ $result = $this->wrappedEditor->edit($idPath, $value);
 186+ $idPath->popAnnotationAttribute();
 187+
 188+ return $result;
 189+ }
 190+
 191+ public function add(IdStack $idPath) {
 192+ $idPath->pushAnnotationAttribute($this->getAttribute());
 193+ $result = $this->wrappedEditor->add($idPath);
 194+ $idPath->popAnnotationAttribute();
 195+
 196+ return $result;
 197+ }
 198+
 199+ public function save(IdStack $idPath, $value) {
 200+ $idPath->pushAnnotationAttribute($this->getAttribute());
 201+ $this->wrappedEditor->save($idPath, $value);
 202+ $idPath->popAnnotationAttribute();
 203+ }
179204 }
180205
181206 function initializeObjectAttributeEditors(ViewInformation $viewInformation) {
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -48,7 +48,8 @@
4949
5050 var suggestAttributesLevel = document.getElementById(suggestPrefix + "parameter-level");
5151 var suggestDefinedMeaningId = document.getElementById(suggestPrefix + "parameter-definedMeaningId");
52 -
 52+ var suggestAnnotationAttributeId = document.getElementById(suggestPrefix + "parameter-annotationAttributeId");
 53+
5354 var URL = 'index.php';
5455 var location = "" + document.location;
5556
@@ -62,12 +63,13 @@
6364 '&query=' + encodeURI(suggestQuery) +
6465 '&offset=' + encodeURI(suggestOffset) +
6566 '&dataset='+dataSet;
66 -
67 - if((suggestAttributesLevel != null) && (suggestDefinedMeaningId != null))
68 - URL =
69 - URL +
 67+
 68+ if (suggestAttributesLevel != null && suggestDefinedMeaningId != null && suggestAnnotationAttributeId != null)
 69+ URL = URL +
7070 '&attributesLevel=' + encodeURI(suggestAttributesLevel.value) +
71 - '&definedMeaningId=' + encodeURI(suggestDefinedMeaningId.value);
 71+ '&definedMeaningId=' + encodeURI(suggestDefinedMeaningId.value) +
 72+ '&annotationAttributeId=' + encodeURI(suggestAnnotationAttributeId.value);
 73+
7274 http.open('GET', URL, true);
7375 http.onreadystatechange = function() {
7476 if (http.readyState == 4) {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -28,7 +28,8 @@
2929 protected $currentId;
3030 protected $classStack = array();
3131 protected $currentClass;
32 - protected $definedMeaningIdStack = array(); // Used to keep track of which defined meaning is being rendered
 32+ protected $definedMeaningIdStack = array(); // Used to keep track of which defined meaning is being rendered
 33+ protected $annotationAttributeStack = array(); // Used to keep track of which annotation attribute currently is being rendered
3334
3435 public function __construct($prefix) {
3536 $this->keyStack = new RecordStack();
@@ -98,7 +99,7 @@
99100 }
100101
101102 public function pushDefinedMeaningId($definedMeaningId) {
102 - return $this->definedMeaningIdStack[] = $definedMeaningId;
 103+ $this->definedMeaningIdStack[] = $definedMeaningId;
103104 }
104105
105106 public function popDefinedMeaningId() {
@@ -114,6 +115,23 @@
115116 throw new Exception("There is no defined meaning defined in the current context");
116117 }
117118
 119+ public function pushAnnotationAttribute(Attribute $annotationAttribute) {
 120+ $this->annotationAttributeStack[] = $annotationAttribute;
 121+ }
 122+
 123+ public function popAnnotationAttribute() {
 124+ return array_pop($this->annotationAttributeStack);
 125+ }
 126+
 127+ public function getAnnotationAttribute() {
 128+ $stackSize = count($this->annotationAttributeStack);
 129+
 130+ if ($stackSize > 0)
 131+ return $this->annotationAttributeStack[$stackSize - 1];
 132+ else
 133+ throw new Exception("There is no annotation attribute in the current context");
 134+ }
 135+
118136 public function __tostring() {
119137 return "<object of class IdStack>";
120138 }
@@ -1264,7 +1282,8 @@
12651283 if ($this->isAddField) {
12661284 $parameters = array(
12671285 "level" => $this->attributesLevelName,
1268 - "definedMeaningId" => $idPath->getDefinedMeaningId()
 1286+ "definedMeaningId" => $idPath->getDefinedMeaningId(),
 1287+ "annotationAttributeId" => $idPath->getAnnotationAttribute()->getId()
12691288 );
12701289
12711290 return getSuggest($this->addId($idPath->getId()), $this->suggestType(), $parameters);

Status & tagging log