r25484 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25483‎ | r25484 | r25485 >
Date:16:11, 4 September 2007
Author:proes
Status:old
Tags:
Comment:
First step in cleaning up edit page: nodes with specific types that aren't supported by class attribute settings will be hidden.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataTables.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1396,3 +1396,57 @@
13971397 return $dbr->fetchObject($queryResult)->text_text;
13981398 }
13991399
 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 @@
201201 $this->wrappedEditor->save($idPath, $value);
202202 $idPath->popAnnotationAttribute();
203203 }
 204+
 205+ public function showEditField(IdStack $idPath) {
 206+ return true;
 207+ }
204208 }
205209
 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+
206226 function initializeObjectAttributeEditors(ViewInformation $viewInformation) {
207227 global
208228 $textValueObjectAttributesEditors,
@@ -590,7 +610,9 @@
591611
592612 $o=OmegaWikiAttributes::getInstance();
593613
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);
595617 $editor->addEditor(new TextAttributeEditor($o->textAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
596618 $editor->addEditor(new TextEditor($o->text, new SimplePermissionController(true), true));
597619
@@ -606,7 +628,9 @@
607629
608630 $o=OmegaWikiAttributes::getInstance();
609631
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);
611635 $editor->addEditor(new LinkAttributeEditor($o->linkAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
612636
613637 if ($viewInformation->viewOrEdit == "view")
@@ -631,7 +655,9 @@
632656
633657 $o=OmegaWikiAttributes::getInstance();
634658
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);
636662 $editor->addEditor(new TranslatedTextAttributeEditor($o->translatedTextAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
637663 $editor->addEditor(getTranslatedTextEditor(
638664 $o->translatedTextValue,
@@ -652,7 +678,9 @@
653679
654680 $o=OmegaWikiAttributes::getInstance();
655681
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);
657685
658686 $editor->addEditor(new OptionAttributeEditor($o->optionAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName));
659687 $editor->addEditor(new OptionSelectEditor($o->optionAttributeOption, new SimplePermissionController(false), true));
@@ -772,7 +800,7 @@
773801 $availableEditors->addEditor($classMembershipEditor);
774802 $availableEditors->addEditor($collectionMembershipEditor);
775803
776 - foreach (createPropertyToColumnFilterEditors($viewInformation, $o->definedMeaningId, 0, $definedMeaningMeaningName) as $propertyToColumnEditor)
 804+ foreach (createPropertyToColumnFilterEditors($viewInformation, $o->definedMeaningId, $definedMeaningMeaningName) as $propertyToColumnEditor)
777805 $availableEditors->addEditor($propertyToColumnEditor);
778806
779807 $availableEditors->addEditor(createObjectAttributesEditor($viewInformation, $o->definedMeaningAttributes, $wgPropertyAttributeName, $o->definedMeaningId, $definedMeaningMeaningName));
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -30,6 +30,7 @@
3131 protected $currentClass;
3232 protected $definedMeaningIdStack = array(); // Used to keep track of which defined meaning is being rendered
3333 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
3435
3536 public function __construct($prefix) {
3637 $this->keyStack = new RecordStack();
@@ -132,6 +133,23 @@
133134 throw new Exception("There is no annotation attribute in the current context");
134135 }
135136
 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+
136154 public function __tostring() {
137155 return "<object of class IdStack>";
138156 }
@@ -170,6 +188,7 @@
171189 $this->objectIdAttributeLevel = $objectIdAttributeLevel;
172190 $this->objectIdAttribute = $objectIdAttribute;
173191 }
 192+
174193 public function check(IdStack $idPath) {
175194 $objectId = $idPath->getKeyStack()->peek($this->objectIdAttributeLevel)->getAttributeValue($this->objectIdAttribute);
176195 return isClass($objectId);
@@ -2250,8 +2269,14 @@
22512270 }
22522271
22532272 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+
22552278 $result = $this->wrappedEditor->edit($idPath, $value);
 2279+
 2280+ $idPath->popClassAttributes();
22562281 $idPath->popDefinedMeaningId();
22572282
22582283 return $result;
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataTables.php
@@ -409,8 +409,8 @@
410410 $optionAttributeOptionsTable = new OptionAttributeOptionsTable("option_attribute_options");
411411 $optionAttributeValuesTable = new OptionAttributeValuesTable("option_attribute_values");
412412
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();
415415
416416 for ($i = 1; $i < count($expressions); $i++)
417417 $result .= ", " . $expressions[$i]->toExpression();
@@ -432,16 +432,45 @@
433433 return $result;
434434 }
435435
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) {
437445 foreach($tables as $table)
438446 if ($table->isVersioned)
439447 $restrictions[] = $table->removeTransactionId->toExpression() . " IS NULL";
440448
441 - return select($expressions, $tables, $restrictions);
 449+ return genericSelect($selectCommand, $expressions, $tables, $restrictions);
442450 }
443451
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);
446454 }
447455
 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+
448477 ?>
\ No newline at end of file

Status & tagging log