r25731 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25730‎ | r25731 | r25732 >
Date:15:48, 10 September 2007
Author:proes
Status:old
Tags:
Comment:
Hide first column of a filtered property to column section when there is only one attribute option configured in the filter.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/PropertyToColumnFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/PropertyToColumnFilter.php
@@ -4,6 +4,7 @@
55
66 interface AttributeIDFilter {
77 public function filter(array $attributeIDs);
 8+ public function leavesOnlyOneOption();
89 }
910
1011 class IncludeAttributeIDsFilter implements AttributeIDFilter {
@@ -22,6 +23,10 @@
2324
2425 return $result;
2526 }
 27+
 28+ public function leavesOnlyOneOption() {
 29+ return count($this->attributeIDsToInclude) == 1;
 30+ }
2631 }
2732
2833 class ExcludeAttributeIDsFilter implements AttributeIDFilter {
@@ -40,6 +45,10 @@
4146
4247 return $result;
4348 }
 49+
 50+ public function leavesOnlyOneOption() {
 51+ return false;
 52+ }
4453 }
4554
4655 /**
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -24,12 +24,14 @@
2525 protected $valueAttribute;
2626 protected $attributeIDFilter;
2727 protected $levelName;
 28+ protected $showPropertyColumn;
2829
2930 public function __construct(Attribute $attribute, $propertyCaption, $valueCaption, ViewInformation $viewInformation, $levelName, AttributeIDFilter $attributeIDFilter) {
3031 parent::__construct(new RecordUnorderedListEditor($attribute, 5));
3132
3233 $this->levelName = $levelName;
3334 $this->attributeIDFilter = $attributeIDFilter;
 35+ $this->showPropertyColumn = !$attributeIDFilter->leavesOnlyOneOption();
3436
3537 $this->recordSetTableEditor = new RecordSetTableEditor(
3638 $attribute,
@@ -153,24 +155,28 @@
154156 $this->wrappedEditor->addEditor($editor);
155157 }
156158
157 - protected function getVisibleStructureForEditor(Editor $editor, array &$suffixAttributes) {
 159+ protected function getVisibleStructureForEditor(Editor $editor, $showPropertyColumn, array &$suffixAttributes) {
158160 $leadingAttributes = array();
159161 $childEditors = $editor->getEditors();
160162
161 - for ($i = 0; $i < 2; $i++)
 163+ for ($i = $showPropertyColumn ? 0 : 1; $i < 2; $i++)
162164 $leadingAttributes[] = $childEditors[$i]->getAttribute();
163165
164166 return new Structure(array_merge($leadingAttributes, $suffixAttributes));
165167 }
166168
167169 public function view(IdStack $idPath, $value) {
 170+ $visibleAttributes = array();
 171+
 172+ if ($this->showPropertyColumn)
 173+ $visibleAttributes[] = $this->propertyAttribute;
 174+
 175+ $visibleAttributes[] = $this->valueAttribute;
 176+
168177 $idPath->pushAnnotationAttribute($this->getAttribute());
169178 $visibleSuffixAttributes = $this->determineVisibleSuffixAttributes($idPath, $value);
170179
171 - $visibleStructure = new Structure(array_merge(
172 - array($this->propertyAttribute, $this->valueAttribute),
173 - $visibleSuffixAttributes
174 - ));
 180+ $visibleStructure = new Structure(array_merge($visibleAttributes, $visibleSuffixAttributes));
175181
176182 $result = $this->recordSetTableEditor->viewHeader($idPath, $visibleStructure);
177183
@@ -180,7 +186,7 @@
181187 $result .= $editor->viewRows(
182188 $idPath,
183189 $value->getAttributeValue($attribute),
184 - $this->getVisibleStructureForEditor($editor, $visibleSuffixAttributes)
 190+ $this->getVisibleStructureForEditor($editor, $this->showPropertyColumn, $visibleSuffixAttributes)
185191 );
186192 $idPath->popAttribute();
187193 }
@@ -214,12 +220,16 @@
215221 $idPath->popAnnotationAttribute();
216222 }
217223
218 - public function showEditField(IdStack $idPath) {
 224+ protected function getAttributeOptionCount(IdStack $idPath) {
219225 $classAttributes = $idPath->getClassAttributes()->filterClassAttributesOnLevel($this->getLevelName());
220226 $classAttributes = $this->getAttributeIDFilter()->filter($classAttributes);
221227
222 - return count($classAttributes) > 0;
 228+ return count($classAttributes);
223229 }
 230+
 231+ public function showEditField(IdStack $idPath) {
 232+ return $this->getAttributeOptionCount($idPath) > 0;
 233+ }
224234 }
225235
226236 class ShowEditFieldForAttributeValuesChecker extends ShowEditFieldChecker {
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -2333,8 +2333,14 @@
23342334
23352335 class DefinedMeaningContextEditor extends WrappingEditor {
23362336 public function view(IdStack $idPath, $value) {
2337 - $idPath->pushDefinedMeaningId($value->definedMeaningId);
 2337+ $definedMeaningId = (int) $value->definedMeaningId;
 2338+
 2339+ $idPath->pushDefinedMeaningId($definedMeaningId);
 2340+ $idPath->pushClassAttributes(new ClassAttributes($definedMeaningId));
 2341+
23382342 $result = $this->wrappedEditor->view($idPath, $value);
 2343+
 2344+ $idPath->popClassAttributes();
23392345 $idPath->popDefinedMeaningId();
23402346
23412347 return $result;

Status & tagging log