r23641 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23640‎ | r23641 | r23642 >
Date:14:01, 2 July 2007
Author:proes
Status:old
Tags:
Comment:
* Hide table columns that contain no data for easier viewing
* Fixed bug: typo in Wikidata.php
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -412,21 +412,82 @@
413413 $this->rowHTMLAttributes = $rowHTMLAttributes;
414414 }
415415
 416+ protected function columnShowsData($columnEditor, $value, $attributePath) {
 417+ $result = false;
 418+ $recordCount = $value->getRecordCount();
 419+ $i = 0;
 420+
 421+ while (!$result && $i < $recordCount) {
 422+ $recordOrScalar = $value->getRecord($i);
 423+
 424+ foreach ($attributePath as $attribute)
 425+ $recordOrScalar = $recordOrScalar->getAttributeValue($attribute);
 426+
 427+ $result = $columnEditor->showsData($recordOrScalar);
 428+ $i++;
 429+ }
 430+
 431+ return $result;
 432+ }
 433+
 434+ protected function getColumnEditorsShowingData($editor, $value, $attributePath = array()) {
 435+ $result = array();
 436+
 437+ foreach ($editor->getEditors() as $childEditor) {
 438+ array_push($attributePath, $childEditor->getAttribute());
 439+
 440+ if ($childEditor instanceof RecordTableCellEditor) {
 441+ $visibleChildColumnEditors = $this->getColumnEditorsShowingData($childEditor, $value, $attributePath);
 442+
 443+ if (count($visibleChildColumnEditors) > 0) {
 444+ $result[] = $childEditor;
 445+ $result = array_merge($result, $visibleChildColumnEditors);
 446+ }
 447+ }
 448+ else if ($this->columnShowsData($childEditor, $value, $attributePath))
 449+ $result[] = $childEditor;
 450+
 451+ array_pop($attributePath);
 452+ }
 453+
 454+ return $result;
 455+ }
 456+
 457+ protected function getAllColumnEditors($editor, $value) {
 458+ $result = array();
 459+
 460+ foreach ($editor->getEditors() as $childEditor) {
 461+ if ($childEditor instanceof RecordTableCellEditor) {
 462+ $result[] = $childEditor;
 463+ $result = array_merge($result, $this->getAllColumnEditors($childEditor, $value));
 464+ }
 465+ else
 466+ $result[] = $childEditor;
 467+ }
 468+
 469+ return $result;
 470+ }
 471+
416472 public function view($idPath, $value) {
417473 $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">';
418474 $structure = $value->getStructure();
419475 $key = $value->getKey();
420476 $rowAttributes = $this->getRowAttributesText();
 477+ $visibleColumnEditors = $this->getColumnEditorsShowingData($this, $value);
421478
422 - foreach(getStructureAsTableHeaderRows($this->getTableStructure($this), 0, $idPath) as $headerRow)
 479+ foreach (getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), 0, $idPath) as $headerRow)
423480 $result .= '<tr>' . $headerRow . '</tr>'.EOL;
424481
425482 $recordCount = $value->getRecordCount();
426483
427 - for($i = 0; $i < $recordCount; $i++) {
 484+ for ($i = 0; $i < $recordCount; $i++) {
428485 $record = $value->getRecord($i);
429486 $idPath->pushKey(project($record, $key));
430 - $result .= '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' . getRecordAsTableCells($idPath, $this, $record) .'</tr>'.EOL;
 487+ $result .=
 488+ '<tr id="'. $idPath->getId() .'" '. $rowAttributes . '>' .
 489+ getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record) .
 490+ '</tr>'.EOL;
 491+
431492 $idPath->popKey();
432493 }
433494
@@ -442,15 +503,11 @@
443504 $result = '<table id="'. $idPath->getId() .'" class="wiki-data-table">';
444505 $key = $value->getKey();
445506 $rowAttributes = $this->getRowAttributesText();
 507+ $visibleColumnEditors = $this->getAllColumnEditors($this, $value);
 508+ $columnOffset = $this->allowRemove ? 1 : 0;
 509+ $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this, $visibleColumnEditors), $columnOffset, $idPath);
446510
447511 if ($this->allowRemove)
448 - $columnOffset = 1;
449 - else
450 - $columnOffset = 0;
451 -
452 - $headerRows = getStructureAsTableHeaderRows($this->getTableStructure($this), $columnOffset, $idPath);
453 -
454 - if ($this->allowRemove)
455512 $headerRows[0] = '<th class="remove" rowspan="' . count($headerRows) . '"><img src="'.$wgStylePath.'/amethyst/delete.png" title="Mark rows to remove" alt="Remove"/></th>' . $headerRows[0];
456513
457514 if ($this->repeatInput)
@@ -478,7 +535,7 @@
479536 if ($this->permissionController->allowUpdateOfValue($idPath, $record))
480537 $result .= getRecordAsEditTableCells($record, $idPath, $this);
481538 else
482 - $result .= getRecordAsTableCells($idPath, $this, $record);
 539+ $result .= getRecordAsTableCells($idPath, $this, $visibleColumnEditors, $record);
483540
484541 $idPath->popKey();
485542
@@ -539,18 +596,20 @@
540597 return $result . '</tr>' . EOL;
541598 }
542599
543 - public function getTableStructure($editor) {
 600+ public function getTableStructure($editor, $visibleColumnEditors) {
544601 $attributes = array();
545602
546603 foreach($editor->getEditors() as $childEditor) {
547 - $childAttribute = $childEditor->getAttribute();
548 -
549 - if ($childEditor instanceof RecordTableCellEditor)
550 - $type = $this->getTableStructure($childEditor);
551 - else
552 - $type = 'short-text';
553 -
554 - $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type);
 604+ if (in_array($childEditor, $visibleColumnEditors, true)) {
 605+ $childAttribute = $childEditor->getAttribute();
 606+
 607+ if ($childEditor instanceof RecordTableCellEditor)
 608+ $type = $this->getTableStructure($childEditor, $visibleColumnEditors);
 609+ else
 610+ $type = 'short-text';
 611+
 612+ $attributes[] = new Attribute($childAttribute->id, $childAttribute->name, $type);
 613+ }
555614 }
556615
557616 return new Structure($attributes);
@@ -632,7 +691,16 @@
633692 }
634693
635694 public function showsData($value) {
636 - return true;
 695+ $result = true;
 696+ $i = 0;
 697+
 698+ while ($result && $i < count($this->editors)) {
 699+ $editor = $this->editors[$i];
 700+ $result = $editor->showsData($value->getAttributeValue($editor->getAttribute()));
 701+ $i++;
 702+ }
 703+
 704+ return $result;
637705 }
638706
639707 public function showEditField($idPath) {
@@ -715,7 +783,7 @@
716784 }
717785
718786 public function showsData($value) {
719 - return true;
 787+ return ($value != null) && (trim($value) != "");
720788 }
721789
722790 public function showEditField($idPath) {
@@ -725,7 +793,7 @@
726794
727795 class LanguageEditor extends ScalarEditor {
728796 public function getViewHTML($idPath, $value) {
729 - return languageIdAsText($value);
 797+ return languageIdAsText($value);
730798 }
731799
732800 public function getEditHTML($idPath, $value) {
@@ -742,6 +810,10 @@
743811
744812 return $wgRequest->getInt($id);
745813 }
 814+
 815+ public function showsData($value) {
 816+ return ($value != null) && ($value != 0);
 817+ }
746818 }
747819
748820 class SpellingEditor extends ScalarEditor {
@@ -1161,16 +1233,18 @@
11621234 }
11631235
11641236 public function showsData($value) {
1165 - $index = 0;
1166 - $showsData = false;
1167 - while($index < count($this->editors) && !$showsData) {
1168 - $editor = $this->editors[$index];
 1237+ $i = 0;
 1238+ $result = false;
 1239+
 1240+ while(!$result && $i < count($this->editors)) {
 1241+ $editor = $this->editors[$i];
11691242 $attribute = $editor->getAttribute();
11701243 $attributeValue = $value->getAttributeValue($attribute);
1171 - $showsData = $editor->showsData($attributeValue);
1172 - $index += 1;
 1244+ $result = $editor->showsData($attributeValue);
 1245+ $i++;
11731246 }
1174 - return $showsData;
 1247+
 1248+ return $result;
11751249 }
11761250
11771251 public function view($idPath, $value) {
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -593,8 +593,8 @@
594594 return $this->dataset;
595595 }
596596
597 - public function setLanguageId($langaugeId) {
598 - $this->langaugeId=$languageId;
 597+ public function setLanguageId($languageId) {
 598+ $this->languageId = $languageId;
599599 }
600600
601601 public function getLanguageId() {
Index: trunk/extensions/Wikidata/OmegaWiki/HTMLtable.php
@@ -113,28 +113,27 @@
114114 return $type;
115115 }
116116
117 -function getRecordAsTableCells($idPath, $editor, $record, &$startColumn = 0) {
 117+function getRecordAsTableCells($idPath, $editor, $visibleColumnEditors, $record, &$startColumn = 0) {
118118 $result = '';
119119
120 - foreach($editor->getEditors() as $childEditor) {
121 - $attribute = $childEditor->getAttribute();
122 - $type = $attribute->type;
123 - $value = $record->getAttributeValue($attribute);
124 - $idPath->pushAttribute($attribute);
125 - $attributeId = $idPath->getId();
126 -
127 - if ($childEditor instanceof RecordTableCellEditor)
128 - $result .= getRecordAsTableCells($idPath, $childEditor, $value, $startColumn);
129 - else {
130 - if($childEditor->showsData($value))
131 - $displayValue = $childEditor->view($idPath, $value);
132 - else
133 - $displayValue = "";
134 - $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>';
135 - $startColumn++;
 120+ foreach ($editor->getEditors() as $childEditor) {
 121+ if (in_array($childEditor, $visibleColumnEditors, true)) {
 122+ $attribute = $childEditor->getAttribute();
 123+ $type = $attribute->type;
 124+ $value = $record->getAttributeValue($attribute);
 125+ $idPath->pushAttribute($attribute);
 126+ $attributeId = $idPath->getId();
 127+
 128+ if ($childEditor instanceof RecordTableCellEditor)
 129+ $result .= getRecordAsTableCells($idPath, $childEditor, $visibleColumnEditors, $value, $startColumn);
 130+ else {
 131+ $displayValue = $childEditor->showsData($value) ? $childEditor->view($idPath, $value) : "";
 132+ $result .= '<td class="'. getHTMLClassForType($type,$attribute) .' column-'. parityClass($startColumn) . '">'. $displayValue . '</td>';
 133+ $startColumn++;
 134+ }
 135+
 136+ $idPath->popAttribute();
136137 }
137 -
138 - $idPath->popAttribute();
139138 }
140139
141140 return $result;

Status & tagging log