r24031 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24030‎ | r24031 | r24032 >
Date:13:36, 12 July 2007
Author:proes
Status:old
Tags:
Comment:
* Sharpened ObjectAttributeValuesEditor functionality
* Showing annotation of annotation is pending
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
@@ -23,7 +23,7 @@
2424 public $childNodes = array();
2525 }
2626
27 -function getTableHeaderNode($structure, &$currentColumn=0) {
 27+function getTableHeaderNode(Structure $structure, &$currentColumn=0) {
2828 $tableHeaderNode = new TableHeaderNode();
2929
3030 foreach($structure->getAttributes() as $attribute) {
@@ -50,7 +50,7 @@
5151 return $tableHeaderNode;
5252 }
5353
54 -function addChildNodesToRows($headerNode, &$rows, $currentDepth, $columnOffset, $idPath, $leftmost=True) {
 54+function addChildNodesToRows(TableHeaderNode $headerNode, &$rows, $currentDepth, $columnOffset, IdStack $idPath, $leftmost=True) {
5555 $height = $headerNode->height;
5656 foreach($headerNode->childNodes as $childNode) {
5757 $attribute = $childNode->attribute;
@@ -91,7 +91,7 @@
9292 }
9393 }
9494
95 -function getStructureAsTableHeaderRows($structure, $columnOffset, $idPath) {
 95+function getStructureAsTableHeaderRows(Structure $structure, $columnOffset, IdStack $idPath) {
9696 $rootNode = getTableHeaderNode($structure);
9797 $result = array();
9898
@@ -103,18 +103,21 @@
104104 return $result;
105105 }
106106
107 -function getHTMLClassForType($type,$attribute) {
 107+function getHTMLClassForType($type, Attribute $attribute) {
108108 if ($type instanceof Structure)
109109 return $attribute->id;
110110 else
111111 return $type;
112112 }
113113
114 -function getRecordAsTableCells($idPath, $editor, $visibleColumnEditors, $record, &$startColumn = 0) {
 114+function getRecordAsTableCells(IdStack $idPath, Editor $editor, Structure $visibleStructure, Record $record, &$startColumn = 0) {
115115 $result = '';
 116+ $childEditorMap = $editor->getAttributeEditorMap();
116117
117 - foreach ($editor->getEditors() as $childEditor) {
118 - if (in_array($childEditor, $visibleColumnEditors, true)) {
 118+ foreach ($visibleStructure->getAttributes() as $visibleAttribute) {
 119+ $childEditor = $childEditorMap->getEditorForAttribute($visibleAttribute);
 120+
 121+ if ($childEditor != null) {
119122 $attribute = $childEditor->getAttribute();
120123 $type = $attribute->type;
121124 $value = $record->getAttributeValue($attribute);
@@ -122,7 +125,7 @@
123126 $attributeId = $idPath->getId();
124127
125128 if ($childEditor instanceof RecordTableCellEditor)
126 - $result .= getRecordAsTableCells($idPath, $childEditor, $visibleColumnEditors, $value, $startColumn);
 129+ $result .= getRecordAsTableCells($idPath, $childEditor, $visibleAttribute->type, $value, $startColumn);
127130 else {
128131 $displayValue = $childEditor->showsData($value) ? $childEditor->view($idPath, $value) : "";
129132 $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>';
@@ -131,12 +134,14 @@
132135
133136 $idPath->popAttribute();
134137 }
 138+ else
 139+ $result .= '<td/>';
135140 }
136141
137142 return $result;
138143 }
139144
140 -function getRecordAsEditTableCells($record, $idPath, $editor, &$startColumn = 0) {
 145+function getRecordAsEditTableCells(Record $record, IdStack $idPath, Editor $editor, &$startColumn = 0) {
141146 $result = '';
142147
143148 foreach($editor->getEditors() as $childEditor) {
@@ -164,7 +169,7 @@
165170 return $result;
166171 }
167172
168 -function getStructureAsAddCells($idPath, $editor, &$startColumn = 0) {
 173+function getStructureAsAddCells(IdStack $idPath, Editor $editor, &$startColumn = 0) {
169174 $result = '';
170175
171176 foreach($editor->getEditors() as $childEditor) {
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -8,6 +8,165 @@
99 require_once('GotoSourceTemplate.php');
1010 require_once('ViewInformation.php');
1111
 12+class ObjectAttributeValuesEditor extends WrappingEditor {
 13+ protected $recordSetTableEditor;
 14+ protected $propertyAttribute;
 15+ protected $valueAttribute;
 16+ protected $suffixAttributes;
 17+
 18+ public function __construct(Attribute $attribute, ViewInformation $viewInformation) {
 19+ parent::__construct(new RecordUnorderedListEditor($attribute, 5));
 20+
 21+ $this->recordSetTableEditor = new RecordSetTableEditor(
 22+ $attribute,
 23+ new SimplePermissionController(false),
 24+ new ShowEditFieldChecker(true),
 25+ new AllowAddController(false),
 26+ false,
 27+ false,
 28+ null
 29+ );
 30+
 31+ $this->propertyAttribute = new Attribute("property", "Property", "short-text");
 32+ $this->valueAttribute = new Attribute("value", "Value", "short-text");
 33+
 34+ $this->suffixAttributes = array();
 35+
 36+// foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter)
 37+// $this->suffixAttributes[] = $propertyToColumnFilter->getAttribute();
 38+
 39+ global
 40+ $wgRequest, $objectAttributesAttribute, $recordLifeSpanAttribute;
 41+
 42+// $this->suffixAttributes[] = $objectAttributesAttribute;
 43+
 44+ if ($wgRequest->getText('action') == 'history' && $viewInformation->showRecordLifeSpan)
 45+ $this->suffixAttributes[] = $recordLifeSpanAttribute;
 46+ }
 47+
 48+ protected function attributeInStructure(Attribute $attribute, Structure $structure) {
 49+ $result = false;
 50+ $attributes = $structure->getAttributes();
 51+ $i = 0;
 52+
 53+ while (!$result && $i < count($attributes)) {
 54+ $result = $attribute->id == $attributes[$i]->id;
 55+ $i++;
 56+ }
 57+
 58+
 59+ return $result;
 60+ }
 61+
 62+ protected function attributeInStructures(Attribute $attribute, array &$structures) {
 63+ $result = false;
 64+ $i = 0;
 65+
 66+ while (!$result && $i < count($structures)) {
 67+ $result = $this->attributeInStructure($attribute, $structures[$i]);
 68+ $i++;
 69+ }
 70+
 71+ return $result;
 72+ }
 73+
 74+ protected function getSubStructureForAttribute(Structure $structure, Attribute $attribute) {
 75+ $attributes = $structure->getAttributes();
 76+ $result = null;
 77+ $i = 0;
 78+
 79+ while ($result == null && $i < count($attributes))
 80+ if ($attribute->id == $attributes[$i]->id)
 81+ $result = $attributes[$i]->type;
 82+ else
 83+ $i++;
 84+
 85+ return $result;
 86+ }
 87+
 88+ protected function filterStructuresOnAttribute(array &$structures, Attribute $attribute) {
 89+ $result = array();
 90+
 91+ foreach ($structures as $structure) {
 92+ $subStructure = $this->getSubStructureForAttribute($structure, $attribute);
 93+
 94+ if ($subStructure != null)
 95+ $result[] = $subStructure;
 96+ }
 97+
 98+ return $result;
 99+ }
 100+
 101+ protected function filterAttributesByStructures(array &$attributes, array &$structures) {
 102+ $result = array();
 103+
 104+ foreach ($attributes as $attribute) {
 105+ if ($attribute->type instanceof Structure) {
 106+ $filteredAttributes = $this->filterAttributesByStructures(
 107+ $attribute->type->getAttributes(),
 108+ $this->filterStructuresOnAttribute($structures, $attribute)
 109+ );
 110+
 111+ if (count($filteredAttributes) > 0)
 112+ $result[] = new Attribute($attribute->id, $attribute->name, new Structure($filteredAttributes));
 113+ }
 114+ else if ($this->attributeInStructures($attribute, $structures))
 115+ $result[] = $attribute;
 116+ }
 117+
 118+ return $result;
 119+ }
 120+
 121+ public function determineVisibleSuffixAttributes($value) {
 122+ $visibleStructures = array();
 123+
 124+ foreach ($this->getEditors() as $editor)
 125+ $visibleStructures[] = $editor->getTableStructureForView($value->getAttributeValue($editor->getAttribute()));
 126+
 127+ return $this->filterAttributesByStructures($this->suffixAttributes, $visibleStructures);
 128+ }
 129+
 130+ public function addEditor(Editor $editor) {
 131+ $this->wrappedEditor->addEditor($editor);
 132+ }
 133+
 134+ protected function getVisibleStructureForEditor(Editor $editor, array &$suffixAttributes) {
 135+ $leadingAttributes = array();
 136+ $childEditors = $editor->getEditors();
 137+
 138+ for ($i = 0; $i < 2; $i++)
 139+ $leadingAttributes[] = $childEditors[$i]->getAttribute();
 140+
 141+ return new Structure(array_merge($leadingAttributes, $suffixAttributes));
 142+ }
 143+
 144+ public function view(IdStack $idPath, $value) {
 145+ $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($value);
 146+
 147+ $visibleStructure = new Structure(array_merge(
 148+ array($this->propertyAttribute, $this->valueAttribute),
 149+ $visibleSuffixAttributes
 150+ ));
 151+
 152+ $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleStructure);
 153+
 154+ foreach ($this->getEditors() as $editor) {
 155+ $attribute = $editor->getAttribute();
 156+ $idPath->pushAttribute($attribute);
 157+ $result .= $editor->viewRows(
 158+ $idPath,
 159+ $value->getAttributeValue($attribute),
 160+ $this->getVisibleStructureForEditor($editor, $visibleSuffixAttributes)
 161+ );
 162+ $idPath->popAttribute();
 163+ }
 164+
 165+ $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleStructure);
 166+
 167+ return $result;
 168+ }
 169+}
 170+
12171 function initializeObjectAttributeEditors(ViewInformation $viewInformation) {
13172 global
14173 $objectAttributesAttribute, $definedMeaningIdAttribute,
@@ -49,16 +208,27 @@
50209 return $result;
51210 }
52211
53 -function addTableLifeSpanEditor(Editor $editor, $showRecordLifeSpan) {
 212+function getTableLifeSpanEditor($showRecordLifeSpan) {
54213 global
55214 $recordLifeSpanAttribute, $addTransactionAttribute, $removeTransactionAttribute, $wgRequest;
56215
 216+ $result = array();
 217+
57218 if ($wgRequest->getText('action') == 'history' && $showRecordLifeSpan)
58 - $editor->addEditor(createTableLifeSpanEditor($recordLifeSpanAttribute));
 219+ $result[] = createTableLifeSpanEditor($recordLifeSpanAttribute);
 220+
 221+ return $result;
59222 }
60223
 224+function getTableMetadataEditors(ViewInformation $viewInformation) {
 225+ return getTableLifeSpanEditor($viewInformation->showRecordLifeSpan);
 226+}
 227+
61228 function addTableMetadataEditors($editor, ViewInformation $viewInformation) {
62 - addTableLifeSpanEditor($editor, $viewInformation->showRecordLifeSpan);
 229+ $metadataEditors = getTableMetadataEditors($viewInformation);
 230+
 231+ foreach ($metadataEditors as $metadataEditor)
 232+ $editor->addEditor($metadataEditor);
63233 }
64234
65235 function getDefinitionEditor(ViewInformation $viewInformation) {
@@ -137,7 +307,7 @@
138308 global
139309 $objectAttributesAttribute, $definedMeaningIdAttribute;
140310
141 - $result = new ObjectAttributeValuesEditor($attribute);
 311+ $result = new ObjectAttributeValuesEditor($attribute, $viewInformation);
142312
143313 addObjectAttributesEditors(
144314 $result,
@@ -154,7 +324,7 @@
155325 global
156326 $objectAttributesAttribute, $definedMeaningIdAttribute;
157327
158 - $result = new ObjectAttributeValuesEditor($attribute);
 328+ $result = new ObjectAttributeValuesEditor($attribute, $viewInformation);
159329
160330 addObjectAttributesEditors(
161331 $result,
@@ -502,20 +672,6 @@
503673 return $expressionsEditor;
504674 }
505675
506 -class AttributeEditorMap {
507 - protected $attributeEditorMap = array();
508 -
509 - public function addEditor($editor) {
510 - $attributeId = $editor->getAttribute()->id;
511 - $this->attributeEditorMap[$attributeId] = $editor;
512 - }
513 -
514 - public function getEditorForAttributeId($attributeId) {
515 - # FIXME: check if this actually exists
516 - return @$this->attributeEditorMap[$attributeId];
517 - }
518 -}
519 -
520676 function getDefinedMeaningEditor(ViewInformation $viewInformation) {
521677 global
522678 $wdDefinedMeaningAttributesOrder, $definedMeaningIdAttribute, $definedMeaningMeaningName,
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -659,21 +659,19 @@
660660 $translatedContentTable,
661661 $translatedTextStructure, $omegaWikiAttributes;
662662
663 - $o=$omegaWikiAttributes;
664 -
665663 $recordSet = queryRecordSet(
666664 $translatedTextStructure->getStructureType(),
667665 $viewInformation->queryTransactionInformation,
668 - $o->language,
 666+ $omegaWikiAttributes->language,
669667 new TableColumnsToAttributesMapping(
670 - new TableColumnsToAttribute(array('language_id'), $o->language),
671 - new TableColumnsToAttribute(array('text_id'), $o->text)
 668+ new TableColumnsToAttribute(array('language_id'), $omegaWikiAttributes->language),
 669+ new TableColumnsToAttribute(array('text_id'), $omegaWikiAttributes->text)
672670 ),
673671 $translatedContentTable,
674672 array("translated_content_id=$translatedContentId")
675673 );
676674
677 - expandTextReferencesInRecordSet($recordSet, array($o->text));
 675+ expandTextReferencesInRecordSet($recordSet, array($omegaWikiAttributes->text));
678676
679677 return $recordSet;
680678 }
@@ -682,15 +680,13 @@
683681 global
684682 $translatedContentTable, $omegaWikiAttributes ;
685683
686 - $o=$omegaWikiAttributes;
687 -
688684 $recordSet = queryRecordSet(
689685 null,
690686 $viewInformation->queryTransactionInformation,
691687 $o->language,
692688 new TableColumnsToAttributesMapping(
693 - new TableColumnsToAttribute(array('language_id'), $o->language),
694 - new TableColumnsToAttribute(array('text_id'), $o->text)
 689+ new TableColumnsToAttribute(array('language_id'), $omegaWikiAttributes->language),
 690+ new TableColumnsToAttribute(array('text_id'), $omegaWikiAttributes->text)
695691 ),
696692 $translatedContentTable,
697693 array(
@@ -699,7 +695,7 @@
700696 )
701697 );
702698
703 - expandTextReferencesInRecordSet($recordSet, array($textAttribute));
 699+ expandTextReferencesInRecordSet($recordSet, array($omegaWikiAttributes->textAttribute));
704700
705701 return $recordSet;
706702 }
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -145,19 +145,44 @@
146146 public function getAddValue(IdStack $idPath);
147147
148148 public function getEditors();
 149+ public function getAttributeEditorMap();
149150 }
150151
 152+class AttributeEditorMap {
 153+ protected $attributeEditorMap = array();
 154+
 155+ public function addEditor($editor) {
 156+ $attributeId = $editor->getAttribute()->id;
 157+ $this->attributeEditorMap[$attributeId] = $editor;
 158+ }
 159+
 160+ public function getEditorForAttributeId($attributeId) {
 161+ if (isset($this->attributeEditorMap[$attributeId]))
 162+ return $this->attributeEditorMap[$attributeId];
 163+ else
 164+ return null;
 165+ }
 166+
 167+ public function getEditorForAttribute(Attribute $attribute) {
 168+ return $this->getEditorForAttributeId($attribute->id);
 169+ }
 170+}
 171+
151172 /* XXX: Basic Editor class. */
152173 abstract class DefaultEditor implements Editor {
153 - protected $editors = array();
 174+ protected $editors;
 175+ protected $attributeEditorMap;
154176 protected $attribute;
155177
156178 public function __construct(Attribute $attribute = null) {
157179 $this->attribute = $attribute;
 180+ $this->editors = array();
 181+ $this->attributeEditorMap = new AttributeEditorMap();
158182 }
159183
160184 public function addEditor(Editor $editor) {
161185 $this->editors[] = $editor;
 186+ $this->attributeEditorMap->addEditor($editor);
162187 }
163188
164189 public function getAttribute() {
@@ -167,6 +192,10 @@
168193 public function getEditors() {
169194 return $this->editors;
170195 }
 196+
 197+ public function getAttributeEditorMap() {
 198+ return $this->attributeEditorMap;
 199+ }
171200
172201 public function getExpansionPrefix($class, $elementId) {
173202 return '<span id="prefix-collapsed-' . $elementId . '" class="collapse-' . $class . '">+</span><span id="prefix-expanded-' . $elementId . '" class="expand-' . $class . '">&ndash;</span>' . EOL;
@@ -255,7 +284,7 @@
256285 $relation = new ArrayRecordSet($addStructure, $addStructure); // TODO Determine real key
257286 $values = array();
258287
259 - foreach($this->editors as $editor)
 288+ foreach($this->getEditors() as $editor)
260289 if ($attribute = $editor->getAddAttribute()) {
261290 $idPath->pushAttribute($attribute);
262291 $values[] = $editor->getAddValue($idPath);
@@ -271,7 +300,7 @@
272301 }
273302
274303 protected function saveRecord(IdStack $idPath, Record $record) {
275 - foreach($this->editors as $editor) {
 304+ foreach($this->getEditors() as $editor) {
276305 $attribute = $editor->getAttribute();
277306 $value = $record->getAttributeValue($attribute);
278307 $idPath->pushAttribute($attribute);
@@ -304,7 +333,7 @@
305334 public function getStructure() {
306335 $attributes = array();
307336
308 - foreach($this->editors as $editor)
 337+ foreach($this->getEditors() as $editor)
309338 $attributes[] = $editor->getAttribute();
310339
311340 return new Structure($attributes);
@@ -317,7 +346,7 @@
318347 protected function getUpdateStructure() {
319348 $attributes = array();
320349
321 - foreach($this->editors as $editor)
 350+ foreach($this->getEditors() as $editor)
322351 if ($updateAttribute = $editor->getUpdateAttribute())
323352 $attributes[] = $updateAttribute;
324353
@@ -327,7 +356,7 @@
328357 protected function getAddStructure() {
329358 $attributes = array();
330359
331 - foreach($this->editors as $editor)
 360+ foreach($this->getEditors() as $editor)
332361 if ($addAttribute = $editor->getAddAttribute())
333362 $attributes[] = $addAttribute;
334363
@@ -337,7 +366,7 @@
338367 protected function getUpdateEditors() {
339368 $updateEditors = array();
340369
341 - foreach($this->editors as $editor)
 370+ foreach($this->getEditors() as $editor)
342371 if ($editor->getUpdateAttribute())
343372 $updateEditors[] = $editor;
344373
@@ -347,7 +376,7 @@
348377 protected function getAddEditors() {
349378 $addEditors = array();
350379
351 - foreach($this->editors as $editor)
 380+ foreach($this->getEditors() as $editor)
352381 if ($editor->getAddAttribute())
353382 $addEditors[] = $editor;
354383
@@ -470,55 +499,56 @@
471500
472501 return $result;
473502 }
 503+
 504+ public function getTableStructure(Editor $editor) {
 505+ $attributes = array();
474506
475 - protected function getColumnEditorsShowingData(Editor $editor, $value, $attributePath = array()) {
476 - $result = array();
477 -
 507+ foreach($editor->getEditors() as $childEditor) {
 508+ $childAttribute = $childEditor->getAttribute();
 509+
 510+ if ($childEditor instanceof RecordTableCellEditor)
 511+ $type = $this->getTableStructure($childEditor);
 512+ else
 513+ $type = 'short-text';
 514+
 515+ $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type);
 516+ }
 517+
 518+ return new Structure($attributes);
 519+ }
 520+
 521+ protected function getTableStructureShowingData(Editor $editor, $value, $attributePath = array()) {
 522+ $attributes = array();
 523+
478524 foreach ($editor->getEditors() as $childEditor) {
479 - array_push($attributePath, $childEditor->getAttribute());
 525+ $childAttribute = $childEditor->getAttribute();
 526+ array_push($attributePath, $childAttribute);
480527
481 - if ($childEditor instanceof RecordTableCellEditor) {
482 - $visibleChildColumnEditors = $this->getColumnEditorsShowingData($childEditor, $value, $attributePath);
 528+ if ($childEditor instanceof RecordTableCellEditor) {
 529+ $type = $this->getTableStructureShowingData($childEditor, $value, $attributePath);
483530
484 - if (count($visibleChildColumnEditors) > 0) {
485 - $result[] = $childEditor;
486 - $result = array_merge($result, $visibleChildColumnEditors);
487 - }
 531+ if (count($type->getAttributes()) > 0)
 532+ $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type);
488533 }
489534 else if ($this->columnShowsData($childEditor, $value, $attributePath))
490 - $result[] = $childEditor;
491 -
 535+ $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, 'short-text');
 536+
492537 array_pop($attributePath);
493 - }
494 -
495 - return $result;
 538+ }
 539+
 540+ return new Structure($attributes);
496541 }
497 -
498 - public function getAllColumnEditors(Editor $editor) {
499 - $result = array();
500 -
501 - foreach ($editor->getEditors() as $childEditor) {
502 - if ($childEditor instanceof RecordTableCellEditor) {
503 - $result[] = $childEditor;
504 - $result = array_merge($result, $this->getAllColumnEditors($childEditor));
505 - }
506 - else
507 - $result[] = $childEditor;
508 - }
509 -
510 - return $result;
511 - }
512542
513 - public function viewHeader(IdStack $idPath, array $visibleColumnEditors) {
 543+ public function viewHeader(IdStack $idPath, Structure $visibleStructure) {
514544 $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">';
515545
516 - foreach (getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), 0, $idPath) as $headerRow)
 546+ foreach (getStructureAsTableHeaderRows($visibleStructure, 0, $idPath) as $headerRow)
517547 $result .= '<tr>' . $headerRow . '</tr>'.EOL;
518548
519549 return $result;
520550 }
521551
522 - public function viewRows(IdStack $idPath, $value, array $visibleColumnEditors) {
 552+ public function viewRows(IdStack $idPath, $value, Structure $visibleStructure) {
523553 $result = "";
524554 $rowAttributes = $this->getRowAttributesText();
525555 $key = $value->getKey();
@@ -529,7 +559,7 @@
530560 $idPath->pushKey(project($record, $key));
531561 $result .=
532562 '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' .
533 - getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record) .
 563+ getRecordAsTableCells($idPath, $this, $visibleStructure, $record) .
534564 '</tr>'.EOL;
535565
536566 $idPath->popKey();
@@ -538,24 +568,24 @@
539569 return $result;
540570 }
541571
542 - public function viewFooter(IdStack $idPath, array $visibleColumnEditors) {
 572+ public function viewFooter(IdStack $idPath, Structure $visibleStructure) {
543573 return '</table>' . EOL;
544574 }
545575
546 - public function getVisibleColumnEditorsForView($value) {
 576+ public function getTableStructureForView($value) {
547577 if ($this->hideEmptyColumns)
548 - return $this->getColumnEditorsShowingData($this, $value);
 578+ return $this->getTableStructureShowingData($this, $value);
549579 else
550 - return $this->getAllColumnEditors($this);
 580+ return $this->getTableStructure($this);
551581 }
552582
553583 public function view(IdStack $idPath, $value) {
554 - $visibleColumnEditors = $this->getVisibleColumnEditorsForView($value);
 584+ $visibleStructure = $this->getTableStructureForView($value);
555585
556586 $result =
557 - $this->viewHeader($idPath, $visibleColumnEditors) .
558 - $this->viewRows($idPath, $value, $visibleColumnEditors) .
559 - $this->viewFooter($idPath, $visibleColumnEditors);
 587+ $this->viewHeader($idPath, $visibleStructure) .
 588+ $this->viewRows($idPath, $value, $visibleStructure) .
 589+ $this->viewFooter($idPath, $visibleStructure);
560590
561591 return $result;
562592 }
@@ -567,9 +597,9 @@
568598 $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">';
569599 $key = $value->getKey();
570600 $rowAttributes = $this->getRowAttributesText();
571 - $visibleColumnEditors = $this->getAllColumnEditors($this);
 601+ $visibleStructure = $this->getTableStructure($this);
572602 $columnOffset = $this->allowRemove ? 1 : 0;
573 - $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), $columnOffset, $idPath);
 603+ $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this), $columnOffset, $idPath);
574604
575605 if ($this->allowRemove)
576606 $headerRows[0] = '<th class="remove" rowspan="' . count($headerRows) . '"><img src="'.$wgStylePath.'/amethyst/delete.png" title="Mark rows to remove" alt="Remove"/></th>' . $headerRows[0];
@@ -599,7 +629,7 @@
600630 if ($this->permissionController->allowUpdateOfValue($idPath, $record))
601631 $result .= getRecordAsEditTableCells($record, $idPath, $this);
602632 else
603 - $result .= getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record);
 633+ $result .= getRecordAsTableCells($idPath, $this, $visibleStructure, $record);
604634
605635 $idPath->popKey();
606636
@@ -660,25 +690,6 @@
661691 return $result . '</tr>' . EOL;
662692 }
663693
664 - public function getTableStructure(Editor $editor, $visibleColumnEditors) {
665 - $attributes = array();
666 -
667 - foreach($editor->getEditors() as $childEditor) {
668 - if (in_array($childEditor, $visibleColumnEditors, true)) {
669 - $childAttribute = $childEditor->getAttribute();
670 -
671 - if ($childEditor instanceof RecordTableCellEditor)
672 - $type = $this->getTableStructure($childEditor, $visibleColumnEditors);
673 - else
674 - $type = 'short-text';
675 -
676 - $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type);
677 - }
678 - }
679 -
680 - return new Structure($attributes);
681 - }
682 -
683694 public function setHideEmptyColumns($hideEmptyColumns) {
684695 $this->hideEmptyColumns = $hideEmptyColumns;
685696 }
@@ -688,7 +699,7 @@
689700 protected function getUpdateStructure() {
690701 $attributes = array();
691702
692 - foreach($this->editors as $editor)
 703+ foreach($this->getEditors() as $editor)
693704 if ($updateAttribute = $editor->getUpdateAttribute())
694705 $attributes[] = $updateAttribute;
695706
@@ -698,7 +709,7 @@
699710 protected function getAddStructure() {
700711 $attributes = array();
701712
702 - foreach($this->editors as $editor)
 713+ foreach($this->getEditors() as $editor)
703714 if ($addAttribute = $editor->getAddAttribute())
704715 $attributes[] = $addAttribute;
705716
@@ -708,7 +719,7 @@
709720 public function getUpdateValue(IdStack $idPath) {
710721 $result = new ArrayRecord($this->getUpdateStructure());
711722
712 - foreach($this->editors as $editor)
 723+ foreach($this->getEditors() as $editor)
713724 if ($attribute = $editor->getUpdateAttribute()) {
714725 $idPath->pushAttribute($attribute);
715726 $result->setAttributeValue($attribute, $editor->getUpdateValue($idPath));
@@ -721,7 +732,7 @@
722733 public function getAddValue(IdStack $idPath) {
723734 $result = new ArrayRecord($this->getAddStructure());
724735
725 - foreach($this->editors as $editor)
 736+ foreach($this->getEditors() as $editor)
726737 if ($attribute = $editor->getAddAttribute()) {
727738 $idPath->pushAttribute($attribute);
728739 $result->setAttributeValue($attribute, $editor->getAddValue($idPath));
@@ -750,7 +761,7 @@
751762 }
752763
753764 public function save(IdStack $idPath, $value) {
754 - foreach($this->editors as $editor) {
 765+ foreach($this->getEditors() as $editor) {
755766 $attribute = $editor->getAttribute();
756767 $idPath->pushAttribute($attribute);
757768 $editor->save($idPath, $value->getAttributeValue($attribute));
@@ -761,9 +772,10 @@
762773 public function showsData($value) {
763774 $result = true;
764775 $i = 0;
 776+ $childEditors = $this->getEditors();
765777
766 - while ($result && $i < count($this->editors)) {
767 - $editor = $this->editors[$i];
 778+ while ($result && $i < count($childEditors)) {
 779+ $editor = $childEditors[$i];
768780 $result = $editor->showsData($value->getAttributeValue($editor->getAttribute()));
769781 $i++;
770782 }
@@ -1316,9 +1328,10 @@
13171329 public function showsData($value) {
13181330 $i = 0;
13191331 $result = false;
 1332+ $childEditors = $this->getEditors();
13201333
1321 - while(!$result && $i < count($this->editors)) {
1322 - $editor = $this->editors[$i];
 1334+ while(!$result && $i < count($childEditors)) {
 1335+ $editor = $childEditors[$i];
13231336 $attribute = $editor->getAttribute();
13241337 $attributeValue = $value->getAttributeValue($attribute);
13251338 $result = $editor->showsData($attributeValue);
@@ -1330,7 +1343,8 @@
13311344
13321345 public function view(IdStack $idPath, $value) {
13331346 $result = '';
1334 - foreach ($this->editors as $editor) {
 1347+
 1348+ foreach ($this->getEditors() as $editor) {
13351349 $attribute = $editor->getAttribute();
13361350 $idPath->pushAttribute($attribute);
13371351 $class = $idPath->getClass();
@@ -1353,7 +1367,7 @@
13541368
13551369 public function edit(IdStack $idPath, $value) {
13561370 $result = '';
1357 - foreach ($this->editors as $editor) {
 1371+ foreach ($this->getEditors() as $editor) {
13581372 $attribute = $editor->getAttribute();
13591373 $idPath->pushAttribute($attribute);
13601374
@@ -1373,7 +1387,7 @@
13741388
13751389 public function add(IdStack $idPath) {
13761390 $result = '';
1377 - foreach($this->editors as $editor) {
 1391+ foreach($this->getEditors() as $editor) {
13781392 if ($attribute = $editor->getAddAttribute()) {
13791393 $idPath->pushAttribute($attribute);
13801394 $class = $idPath->getClass();
@@ -1524,6 +1538,10 @@
15251539 public function getEditors() {
15261540 return $this->wrappedEditor->getEditors();
15271541 }
 1542+
 1543+ public function getAttributeEditorMap() {
 1544+ return $this->wrappedEditor->getAttributeEditorMap();
 1545+ }
15281546 }
15291547
15301548 class PopUpEditor extends WrappingEditor {
@@ -1746,7 +1764,7 @@
17471765 public function view(IdStack $idPath, $value) {
17481766 $fields = array();
17491767
1750 - foreach($this->editors as $editor) {
 1768+ foreach($this->getEditors() as $editor) {
17511769 $attribute = $editor->getAttribute();
17521770 $idPath->pushAttribute($attribute);
17531771 $attributeValue = $editor->view($idPath, $value->getAttributeValue($attribute));
@@ -1768,7 +1786,7 @@
17691787 public function add(IdStack $idPath) {
17701788 $fields = array();
17711789
1772 - foreach($this->editors as $editor) {
 1790+ foreach($this->getEditors() as $editor) {
17731791 if ($attribute = $editor->getAddAttribute()) {
17741792 $attribute = $editor->getAttribute();
17751793 $idPath->pushAttribute($attribute);
@@ -1785,7 +1803,7 @@
17861804 public function edit(IdStack $idPath, $value) {
17871805 $fields = array();
17881806
1789 - foreach($this->editors as $editor) {
 1807+ foreach($this->getEditors() as $editor) {
17901808 $attribute = $editor->getAttribute();
17911809 $idPath->pushAttribute($attribute);
17921810 $fields[] = $attribute->name . $this->valueSeparator. $editor->view($idPath, $value->getAttributeValue($attribute));
@@ -2169,75 +2187,4 @@
21702188 public function showsData($value) {
21712189 return true;
21722190 }
2173 -}
2174 -
2175 -class ObjectAttributeValuesEditor extends WrappingEditor {
2176 - protected $recordSetTableEditor;
2177 - protected $propertyEditor;
2178 - protected $vslueEditor;
2179 -
2180 - public function __construct(Attribute $attribute = null) {
2181 - parent::__construct(new RecordUnorderedListEditor($attribute, 5));
2182 -
2183 - $this->recordSetTableEditor = new RecordSetTableEditor(
2184 - $attribute,
2185 - new SimplePermissionController(false),
2186 - new ShowEditFieldChecker(true),
2187 - new AllowAddController(false),
2188 - false,
2189 - false,
2190 - null
2191 - );
2192 -
2193 - $propertyAttribute = new Attribute("property", "Property", "short-text");
2194 - $valueAttribute = new Attribute("value", "Value", "short-text");
2195 -
2196 - $this->propertyEditor = new ShortTextEditor($propertyAttribute, new SimplePermissionController(false), false);
2197 - $this->valueEditor = new ShortTextEditor($valueAttribute, new SimplePermissionController(false), false);
2198 -
2199 - $this->recordSetTableEditor->addEditor($this->propertyEditor);
2200 - $this->recordSetTableEditor->addEditor($this->valueEditor);
2201 - }
2202 -
2203 - public function addEditor(Editor $editor) {
2204 - $this->wrappedEditor->addEditor($editor);
2205 - $childEditors = $editor->getEditors();
2206 -
2207 - for ($i = count($this->recordSetTableEditor->getEditors()); $i < count($childEditors); $i++)
2208 - $this->recordSetTableEditor->addEditor($childEditors[$i]);
2209 - }
2210 -
2211 - public function determineVisibleHeaders($value) {
2212 - $result = array($this->propertyEditor, $this->valueEditor);
2213 -
2214 - foreach ($this->wrappedEditor->getEditors() as $editor) {
2215 - $visibleEditors = $editor->getVisibleColumnEditorsForView($value->getAttributeValue($editor->getAttribute()));
2216 -
2217 - foreach ($visibleEditors as $visibleEditor)
2218 - if (!in_array($visibleEditor, $result, true))
2219 - $result[] = $visibleEditor;
2220 - }
2221 -
2222 - return $result;
2223 - }
2224 -
2225 - public function view(IdStack $idPath, $value) {
2226 - $visibleColumnEditors = $this->determineVisibleHeaders($value);
2227 - $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleColumnEditors);
2228 -
2229 - foreach ($this->wrappedEditor->getEditors() as $editor) {
2230 - $attribute = $editor->getAttribute();
2231 - $idPath->pushAttribute($attribute);
2232 - $result .= $editor->viewRows(
2233 - $idPath,
2234 - $value->getAttributeValue($attribute),
2235 - $visibleColumnEditors
2236 - );
2237 - $idPath->popAttribute();
2238 - }
2239 -
2240 - $result .= $this->recordSetTableEditor->viewFooter($idPath, $visibleColumnEditors);
2241 -
2242 - return $result;
2243 - }
2244 -}
 2191+}
\ No newline at end of file

Status & tagging log