Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -1396,3 +1396,57 @@ |
1397 | 1397 | return $dbr->fetchObject($queryResult)->text_text; |
1398 | 1398 | } |
1399 | 1399 | |
| 1400 | +class ClassAttribute { |
| 1401 | + public $attributeId; |
| 1402 | + public $levelName; |
| 1403 | + public $type; |
| 1404 | +} |
| 1405 | + |
| 1406 | +class ClassAttributes { |
| 1407 | + protected $classAttributes; |
| 1408 | + |
| 1409 | + public function __construct($definedMeaningId) { |
| 1410 | + $dc=wdGetDataSetContext(); |
| 1411 | + $dbr =& wfGetDB(DB_SLAVE); |
| 1412 | + |
| 1413 | + global |
| 1414 | + $classAttributesTable, $bootstrappedDefinedMeaningsTable, $classMembershipsTable; |
| 1415 | + |
| 1416 | + $queryResult = $dbr->query( |
| 1417 | + SelectLatestDistinct( |
| 1418 | + array( |
| 1419 | + $classAttributesTable->attributeMid, |
| 1420 | + $classAttributesTable->attributeType, |
| 1421 | + $bootstrappedDefinedMeaningsTable->name |
| 1422 | + ), |
| 1423 | + array($classAttributesTable, $bootstrappedDefinedMeaningsTable, $classMembershipsTable), |
| 1424 | + array( |
| 1425 | + equals($classMembershipsTable->classMemberMid, $definedMeaningId), |
| 1426 | + equals($classAttributesTable->classMid, $classMembershipsTable->classMid), |
| 1427 | + equals($classAttributesTable->levelMid, $bootstrappedDefinedMeaningsTable->definedMeaningId) |
| 1428 | + ) |
| 1429 | + ) |
| 1430 | + ); |
| 1431 | + |
| 1432 | + $this->classAttributes = array(); |
| 1433 | + |
| 1434 | + while ($row = $dbr->fetchRow($queryResult)) { |
| 1435 | + $classAttribute = new ClassAttribute(); |
| 1436 | + $classAttribute->attributeId = $row[0]; |
| 1437 | + $classAttribute->type = $row[1]; |
| 1438 | + $classAttribute->levelName = $row[2]; |
| 1439 | + |
| 1440 | + $this->classAttributes[] = $classAttribute; |
| 1441 | + } |
| 1442 | + } |
| 1443 | + |
| 1444 | + public function filterClassAttributes($levelName, $type) { |
| 1445 | + $result = array(); |
| 1446 | + |
| 1447 | + foreach ($this->classAttributes as $classAttribute) |
| 1448 | + if ($classAttribute->type == $type && $classAttribute->levelName == $levelName) |
| 1449 | + $result[] = $classAttribute->attributeId; |
| 1450 | + |
| 1451 | + return $result; |
| 1452 | + } |
| 1453 | +} |
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php |
— | — | @@ -200,8 +200,28 @@ |
201 | 201 | $this->wrappedEditor->save($idPath, $value); |
202 | 202 | $idPath->popAnnotationAttribute(); |
203 | 203 | } |
| 204 | + |
| 205 | + public function showEditField(IdStack $idPath) { |
| 206 | + return true; |
| 207 | + } |
204 | 208 | } |
205 | 209 | |
| 210 | +class ShowEditFieldForAttributeValuesChecker extends ShowEditFieldChecker { |
| 211 | + protected $levelDefinedMeaningName; |
| 212 | + protected $annotationType; |
| 213 | + |
| 214 | + public function __construct($levelDefinedMeaningName, $annotationType) { |
| 215 | + $this->levelDefinedMeaningName = $levelDefinedMeaningName; |
| 216 | + $this->annotationType = $annotationType; |
| 217 | + } |
| 218 | + |
| 219 | + public function check(IdStack $idPath) { |
| 220 | + $classAttributes = $idPath->getClassAttributes()->filterClassAttributes($this->levelDefinedMeaningName, $this->annotationType); |
| 221 | + |
| 222 | + return count($classAttributes) > 0; |
| 223 | + } |
| 224 | +} |
| 225 | + |
206 | 226 | function initializeObjectAttributeEditors(ViewInformation $viewInformation) { |
207 | 227 | global |
208 | 228 | $textValueObjectAttributesEditors, |
— | — | @@ -590,7 +610,9 @@ |
591 | 611 | |
592 | 612 | $o=OmegaWikiAttributes::getInstance(); |
593 | 613 | |
594 | | - $editor = new RecordSetTableEditor($o->textAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
| 614 | + $showEditFieldChecker = new ShowEditFieldForAttributeValuesChecker($levelDefinedMeaningName, "TEXT"); |
| 615 | + |
| 616 | + $editor = new RecordSetTableEditor($o->textAttributeValues, new SimplePermissionController(true), $showEditFieldChecker, new AllowAddController(true), true, false, $controller); |
595 | 617 | $editor->addEditor(new TextAttributeEditor($o->textAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName)); |
596 | 618 | $editor->addEditor(new TextEditor($o->text, new SimplePermissionController(true), true)); |
597 | 619 | |
— | — | @@ -606,7 +628,9 @@ |
607 | 629 | |
608 | 630 | $o=OmegaWikiAttributes::getInstance(); |
609 | 631 | |
610 | | - $editor = new RecordSetTableEditor($o->linkAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
| 632 | + $showEditFieldChecker = new ShowEditFieldForAttributeValuesChecker($levelDefinedMeaningName, "URL"); |
| 633 | + |
| 634 | + $editor = new RecordSetTableEditor($o->linkAttributeValues, new SimplePermissionController(true), $showEditFieldChecker, new AllowAddController(true), true, false, $controller); |
611 | 635 | $editor->addEditor(new LinkAttributeEditor($o->linkAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName)); |
612 | 636 | |
613 | 637 | if ($viewInformation->viewOrEdit == "view") |
— | — | @@ -631,7 +655,9 @@ |
632 | 656 | |
633 | 657 | $o=OmegaWikiAttributes::getInstance(); |
634 | 658 | |
635 | | - $editor = new RecordSetTableEditor($o->translatedTextAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
| 659 | + $showEditFieldChecker = new ShowEditFieldForAttributeValuesChecker($levelDefinedMeaningName, "TRNS"); |
| 660 | + |
| 661 | + $editor = new RecordSetTableEditor($o->translatedTextAttributeValues, new SimplePermissionController(true), $showEditFieldChecker, new AllowAddController(true), true, false, $controller); |
636 | 662 | $editor->addEditor(new TranslatedTextAttributeEditor($o->translatedTextAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName)); |
637 | 663 | $editor->addEditor(getTranslatedTextEditor( |
638 | 664 | $o->translatedTextValue, |
— | — | @@ -652,7 +678,9 @@ |
653 | 679 | |
654 | 680 | $o=OmegaWikiAttributes::getInstance(); |
655 | 681 | |
656 | | - $editor = new RecordSetTableEditor($o->optionAttributeValues, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller); |
| 682 | + $showEditFieldChecker = new ShowEditFieldForAttributeValuesChecker($levelDefinedMeaningName, "OPTN"); |
| 683 | + |
| 684 | + $editor = new RecordSetTableEditor($o->optionAttributeValues, new SimplePermissionController(true), $showEditFieldChecker, new AllowAddController(true), true, false, $controller); |
657 | 685 | |
658 | 686 | $editor->addEditor(new OptionAttributeEditor($o->optionAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName)); |
659 | 687 | $editor->addEditor(new OptionSelectEditor($o->optionAttributeOption, new SimplePermissionController(false), true)); |
— | — | @@ -772,7 +800,7 @@ |
773 | 801 | $availableEditors->addEditor($classMembershipEditor); |
774 | 802 | $availableEditors->addEditor($collectionMembershipEditor); |
775 | 803 | |
776 | | - foreach (createPropertyToColumnFilterEditors($viewInformation, $o->definedMeaningId, 0, $definedMeaningMeaningName) as $propertyToColumnEditor) |
| 804 | + foreach (createPropertyToColumnFilterEditors($viewInformation, $o->definedMeaningId, $definedMeaningMeaningName) as $propertyToColumnEditor) |
777 | 805 | $availableEditors->addEditor($propertyToColumnEditor); |
778 | 806 | |
779 | 807 | $availableEditors->addEditor(createObjectAttributesEditor($viewInformation, $o->definedMeaningAttributes, $wgPropertyAttributeName, $o->definedMeaningId, $definedMeaningMeaningName)); |
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | protected $currentClass; |
32 | 32 | protected $definedMeaningIdStack = array(); // Used to keep track of which defined meaning is being rendered |
33 | 33 | protected $annotationAttributeStack = array(); // Used to keep track of which annotation attribute currently is being rendered |
| 34 | + protected $classAttributesStack = array(); // Used to keep track of the class attributes that are currently in effect |
34 | 35 | |
35 | 36 | public function __construct($prefix) { |
36 | 37 | $this->keyStack = new RecordStack(); |
— | — | @@ -132,6 +133,23 @@ |
133 | 134 | throw new Exception("There is no annotation attribute in the current context"); |
134 | 135 | } |
135 | 136 | |
| 137 | + public function pushClassAttributes(ClassAttributes $classAttributes) { |
| 138 | + $this->classAttributesStack[] = $classAttributes; |
| 139 | + } |
| 140 | + |
| 141 | + public function popClassAttributes() { |
| 142 | + return array_pop($this->classAttributesStack); |
| 143 | + } |
| 144 | + |
| 145 | + public function getClassAttributes() { |
| 146 | + $stackSize = count($this->classAttributesStack); |
| 147 | + |
| 148 | + if ($stackSize > 0) |
| 149 | + return $this->classAttributesStack[$stackSize - 1]; |
| 150 | + else |
| 151 | + throw new Exception("There are no class attributes in the current context"); |
| 152 | + } |
| 153 | + |
136 | 154 | public function __tostring() { |
137 | 155 | return "<object of class IdStack>"; |
138 | 156 | } |
— | — | @@ -170,6 +188,7 @@ |
171 | 189 | $this->objectIdAttributeLevel = $objectIdAttributeLevel; |
172 | 190 | $this->objectIdAttribute = $objectIdAttribute; |
173 | 191 | } |
| 192 | + |
174 | 193 | public function check(IdStack $idPath) { |
175 | 194 | $objectId = $idPath->getKeyStack()->peek($this->objectIdAttributeLevel)->getAttributeValue($this->objectIdAttribute); |
176 | 195 | return isClass($objectId); |
— | — | @@ -2250,8 +2269,14 @@ |
2251 | 2270 | } |
2252 | 2271 | |
2253 | 2272 | public function edit(IdStack $idPath, $value) { |
2254 | | - $idPath->pushDefinedMeaningId($value->definedMeaningId); |
| 2273 | + $definedMeaningId = (int) $value->definedMeaningId; |
| 2274 | + |
| 2275 | + $idPath->pushDefinedMeaningId($definedMeaningId); |
| 2276 | + $idPath->pushClassAttributes(new ClassAttributes($definedMeaningId)); |
| 2277 | + |
2255 | 2278 | $result = $this->wrappedEditor->edit($idPath, $value); |
| 2279 | + |
| 2280 | + $idPath->popClassAttributes(); |
2256 | 2281 | $idPath->popDefinedMeaningId(); |
2257 | 2282 | |
2258 | 2283 | return $result; |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataTables.php |
— | — | @@ -409,8 +409,8 @@ |
410 | 410 | $optionAttributeOptionsTable = new OptionAttributeOptionsTable("option_attribute_options"); |
411 | 411 | $optionAttributeValuesTable = new OptionAttributeValuesTable("option_attribute_values"); |
412 | 412 | |
413 | | -function select(array $expressions, array $tables, array $restrictions) { |
414 | | - $result = "SELECT " . $expressions[0]->toExpression(); |
| 413 | +function genericSelect($selectCommand, array $expressions, array $tables, array $restrictions) { |
| 414 | + $result = $selectCommand . " " . $expressions[0]->toExpression(); |
415 | 415 | |
416 | 416 | for ($i = 1; $i < count($expressions); $i++) |
417 | 417 | $result .= ", " . $expressions[$i]->toExpression(); |
— | — | @@ -432,16 +432,45 @@ |
433 | 433 | return $result; |
434 | 434 | } |
435 | 435 | |
436 | | -function selectLatest(array $expressions, array $tables, array $restrictions) { |
| 436 | +function select(array $expressions, array $tables, array $restrictions) { |
| 437 | + return genericSelect("SELECT", $expressions, $tables, $restrictions); |
| 438 | +} |
| 439 | + |
| 440 | +function selectDistinct(array $expressions, array $tables, array $restrictions) { |
| 441 | + return genericSelect("SELECT DISTINCT", $expressions, $tables, $restrictions); |
| 442 | +} |
| 443 | + |
| 444 | +function genericSelectLatest($selectCommand, array $expressions, array $tables, array $restrictions) { |
437 | 445 | foreach($tables as $table) |
438 | 446 | if ($table->isVersioned) |
439 | 447 | $restrictions[] = $table->removeTransactionId->toExpression() . " IS NULL"; |
440 | 448 | |
441 | | - return select($expressions, $tables, $restrictions); |
| 449 | + return genericSelect($selectCommand, $expressions, $tables, $restrictions); |
442 | 450 | } |
443 | 451 | |
444 | | -function equals(DatabaseExpression $expression1, DatabaseExpression $expression2) { |
445 | | - return '(' . $expression1->toExpression() . ') = (' . $expression2->toExpression() . ')'; |
| 452 | +function selectLatest(array $expressions, array $tables, array $restrictions) { |
| 453 | + return genericSelectLatest("SELECT", $expressions, $tables, $restrictions); |
446 | 454 | } |
447 | 455 | |
| 456 | +function selectLatestDistinct(array $expressions, array $tables, array $restrictions) { |
| 457 | + return genericSelectLatest("SELECT DISTINCT", $expressions, $tables, $restrictions); |
| 458 | +} |
| 459 | + |
| 460 | +function expressionToSQL($expression) { |
| 461 | + if (is_int($expression)) |
| 462 | + return $expression; |
| 463 | + else if (is_string($expression)) { |
| 464 | + $dbr =& wfGetDB(DB_SLAVE); |
| 465 | + return $dbr->addQuotes($expression); |
| 466 | + } |
| 467 | + else if (is_object($expression) && $expression instanceof DatabaseExpression) |
| 468 | + return $expression->toExpression(); |
| 469 | + else |
| 470 | + throw new Exception("Cannot convert expression to SQL: " . $expression); |
| 471 | +} |
| 472 | + |
| 473 | +function equals($expression1, $expression2) { |
| 474 | + return '(' . expressionToSQL($expression1) . ') = (' . expressionToSQL($expression2) . ')'; |
| 475 | +} |
| 476 | + |
448 | 477 | ?> |
\ No newline at end of file |