Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php |
— | — | @@ -46,6 +46,8 @@ |
47 | 47 | @$definedMeaningId = $_GET['definedMeaningId']; |
48 | 48 | @$offset = $_GET['offset']; |
49 | 49 | @$attributesLevel = $_GET['attributesLevel']; |
| 50 | + @$annotationAttributeId = $_GET['annotationAttributeId']; |
| 51 | + |
50 | 52 | $sql=''; |
51 | 53 | |
52 | 54 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -62,16 +64,16 @@ |
63 | 65 | $sql=constructSQLWithFallback($sqlActual, $sqlFallback, array("member_mid", "spelling", "collection_mid")); |
64 | 66 | break; |
65 | 67 | case 'option-attribute': |
66 | | - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'OPTN'); |
| 68 | + $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'OPTN'); |
67 | 69 | break; |
68 | 70 | case 'translated-text-attribute': |
69 | | - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'TRNS'); |
| 71 | + $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'TRNS'); |
70 | 72 | break; |
71 | 73 | case 'text-attribute': |
72 | | - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'TEXT'); |
| 74 | + $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'TEXT'); |
73 | 75 | break; |
74 | 76 | case 'link-attribute': |
75 | | - $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, 'URL'); |
| 77 | + $sql = getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, 'URL'); |
76 | 78 | break; |
77 | 79 | case 'language': |
78 | 80 | require_once('languages.php'); |
— | — | @@ -224,19 +226,81 @@ |
225 | 227 | return $sql; |
226 | 228 | } |
227 | 229 | |
228 | | -function getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $attributesType) { |
| 230 | +function getSQLToSelectPossibleAttributes($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType) { |
229 | 231 | global |
230 | 232 | $wgUser; |
231 | 233 | |
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'); |
234 | 236 | |
235 | 237 | return constructSQLWithFallback($sqlActual, $sqlFallback, array("attribute_mid", "spelling")); |
236 | 238 | } |
237 | 239 | |
| 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 | + |
238 | 302 | # language is the 2 letter wikimedia code. use "<ANY>" if you don't want language filtering |
239 | 303 | # (any does set limit 1 hmph) |
240 | | -function getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $attributesType, $language="<ANY>") { |
| 304 | +function getSQLToSelectPossibleAttributesForLanguage($definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType, $language="<ANY>") { |
241 | 305 | global $wgDefaultClassMids; |
242 | 306 | global $wgUser; |
243 | 307 | $dc=wdGetDataSetContext(); |
— | — | @@ -245,6 +309,8 @@ |
246 | 310 | $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join($wgDefaultClassMids, ", ") . ")"; |
247 | 311 | else |
248 | 312 | $defaultClassRestriction = ""; |
| 313 | + |
| 314 | + $filteredAttributesRestriction = getFilteredAttributesRestriction($annotationAttributeId); |
249 | 315 | |
250 | 316 | $dbr =& wfGetDB(DB_SLAVE); |
251 | 317 | $sql = |
— | — | @@ -254,7 +320,8 @@ |
255 | 321 | " AND {$dc}_bootstrapped_defined_meanings.defined_meaning_id = {$dc}_class_attributes.level_mid" . |
256 | 322 | " AND {$dc}_class_attributes.attribute_type = " . $dbr->addQuotes($attributesType) . |
257 | 323 | " 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 . " "; |
259 | 326 | |
260 | 327 | if ($language!="<ANY>") { |
261 | 328 | $sql .= |
Index: trunk/extensions/Wikidata/OmegaWiki/Attribute.php |
— | — | @@ -38,8 +38,12 @@ |
39 | 39 | $this->type->setStructureType($this->id); |
40 | 40 | } |
41 | 41 | } |
| 42 | + |
| 43 | + public function getId() { |
| 44 | + return $this->id; |
| 45 | + } |
42 | 46 | |
43 | | - function __tostring() { |
| 47 | + public function __tostring() { |
44 | 48 | $id=$this->id; |
45 | 49 | $name=$this->name; |
46 | 50 | $type=$this->type; |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -151,6 +151,7 @@ |
152 | 152 | } |
153 | 153 | |
154 | 154 | public function view(IdStack $idPath, $value) { |
| 155 | + $idPath->pushAnnotationAttribute($this->getAttribute()); |
155 | 156 | $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($value); |
156 | 157 | |
157 | 158 | $visibleStructure = new Structure(array_merge( |
— | — | @@ -173,8 +174,32 @@ |
174 | 175 | |
175 | 176 | $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleStructure); |
176 | 177 | |
| 178 | + $idPath->popAnnotationAttribute(); |
| 179 | + |
177 | 180 | return $result; |
178 | 181 | } |
| 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 | + } |
179 | 204 | } |
180 | 205 | |
181 | 206 | function initializeObjectAttributeEditors(ViewInformation $viewInformation) { |
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js |
— | — | @@ -48,7 +48,8 @@ |
49 | 49 | |
50 | 50 | var suggestAttributesLevel = document.getElementById(suggestPrefix + "parameter-level"); |
51 | 51 | var suggestDefinedMeaningId = document.getElementById(suggestPrefix + "parameter-definedMeaningId"); |
52 | | - |
| 52 | + var suggestAnnotationAttributeId = document.getElementById(suggestPrefix + "parameter-annotationAttributeId"); |
| 53 | + |
53 | 54 | var URL = 'index.php'; |
54 | 55 | var location = "" + document.location; |
55 | 56 | |
— | — | @@ -62,12 +63,13 @@ |
63 | 64 | '&query=' + encodeURI(suggestQuery) + |
64 | 65 | '&offset=' + encodeURI(suggestOffset) + |
65 | 66 | '&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 + |
70 | 70 | '&attributesLevel=' + encodeURI(suggestAttributesLevel.value) + |
71 | | - '&definedMeaningId=' + encodeURI(suggestDefinedMeaningId.value); |
| 71 | + '&definedMeaningId=' + encodeURI(suggestDefinedMeaningId.value) + |
| 72 | + '&annotationAttributeId=' + encodeURI(suggestAnnotationAttributeId.value); |
| 73 | + |
72 | 74 | http.open('GET', URL, true); |
73 | 75 | http.onreadystatechange = function() { |
74 | 76 | if (http.readyState == 4) { |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -28,7 +28,8 @@ |
29 | 29 | protected $currentId; |
30 | 30 | protected $classStack = array(); |
31 | 31 | 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 |
33 | 34 | |
34 | 35 | public function __construct($prefix) { |
35 | 36 | $this->keyStack = new RecordStack(); |
— | — | @@ -98,7 +99,7 @@ |
99 | 100 | } |
100 | 101 | |
101 | 102 | public function pushDefinedMeaningId($definedMeaningId) { |
102 | | - return $this->definedMeaningIdStack[] = $definedMeaningId; |
| 103 | + $this->definedMeaningIdStack[] = $definedMeaningId; |
103 | 104 | } |
104 | 105 | |
105 | 106 | public function popDefinedMeaningId() { |
— | — | @@ -114,6 +115,23 @@ |
115 | 116 | throw new Exception("There is no defined meaning defined in the current context"); |
116 | 117 | } |
117 | 118 | |
| 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 | + |
118 | 136 | public function __tostring() { |
119 | 137 | return "<object of class IdStack>"; |
120 | 138 | } |
— | — | @@ -1264,7 +1282,8 @@ |
1265 | 1283 | if ($this->isAddField) { |
1266 | 1284 | $parameters = array( |
1267 | 1285 | "level" => $this->attributesLevelName, |
1268 | | - "definedMeaningId" => $idPath->getDefinedMeaningId() |
| 1286 | + "definedMeaningId" => $idPath->getDefinedMeaningId(), |
| 1287 | + "annotationAttributeId" => $idPath->getAnnotationAttribute()->getId() |
1269 | 1288 | ); |
1270 | 1289 | |
1271 | 1290 | return getSuggest($this->addId($idPath->getId()), $this->suggestType(), $parameters); |