r25583 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25582‎ | r25583 | r25584 >
Date:13:03, 6 September 2007
Author:proes
Status:old
Tags:
Comment:
Compress RecordListEditors when there is only one option to expand/collapse
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -1394,7 +1394,23 @@
13951395 return $result;
13961396 }
13971397
1398 - protected function viewEditors(IdStack $idPath, $value, $editors, $htmlTag) {
 1398+ protected function shouldCompressOnView($idPath, $value, $editors) {
 1399+ $visibleEditorCount = 0;
 1400+
 1401+ foreach ($editors as $editor) {
 1402+ $attribute = $editor->getAttribute();
 1403+ $idPath->pushAttribute($attribute);
 1404+
 1405+ if ($editor->showsData($value->getAttributeValue($attribute)))
 1406+ $visibleEditorCount++;
 1407+
 1408+ $idPath->popAttribute();
 1409+ }
 1410+
 1411+ return $visibleEditorCount <= 1;
 1412+ }
 1413+
 1414+ protected function viewEditors(IdStack $idPath, $value, $editors, $htmlTag, $compress) {
13991415 $result = '';
14001416
14011417 foreach ($editors as $editor) {
@@ -1404,12 +1420,17 @@
14051421 $attributeId = $idPath->getId();
14061422 $attributeValue = $value->getAttributeValue($attribute);
14071423
1408 - if ($editor->showsData($attributeValue))
1409 - $result .=
1410 - '<' . $htmlTag . '>' .
1411 - $this->childHeader($editor, $attribute, $class, $attributeId) .
1412 - $this->viewChild($editor, $idPath, $value, $attribute, $class, $attributeId) .
1413 - '</' . $htmlTag . '>';
 1424+ if ($editor->showsData($attributeValue)) {
 1425+ if (!$compress)
 1426+ $result .=
 1427+ '<' . $htmlTag . '>' .
 1428+ $this->childHeader($editor, $attribute, $class, $attributeId);
 1429+
 1430+ $result .= $this->viewChild($editor, $idPath, $value, $attribute, $class, $attributeId);
 1431+
 1432+ if (!$compress)
 1433+ $result .= '</' . $htmlTag . '>';
 1434+ }
14141435
14151436 $idPath->popAttribute();
14161437 }
@@ -1418,14 +1439,31 @@
14191440 }
14201441
14211442 public function view(IdStack $idPath, $value) {
1422 - return $this->viewEditors($idPath, $value, $this->getEditors(), $this->htmlTag);
 1443+ $editors = $this->getEditors();
 1444+ return $this->viewEditors($idPath, $value, $editors, $this->htmlTag, $this->shouldCompressOnView($idPath, $value, $editors));
14231445 }
14241446
14251447 public function showEditField(IdStack $idPath) {
14261448 return true;
14271449 }
14281450
1429 - protected function editEditors(IdStack $idPath, $value, $editors, $htmlTag) {
 1451+ protected function shouldCompressOnEdit($idPath, $value, $editors) {
 1452+ $visibleEditorCount = 0;
 1453+
 1454+ foreach ($editors as $editor) {
 1455+ $attribute = $editor->getAttribute();
 1456+ $idPath->pushAttribute($attribute);
 1457+
 1458+ if ($editor->showEditField($idPath))
 1459+ $visibleEditorCount++;
 1460+
 1461+ $idPath->popAttribute();
 1462+ }
 1463+
 1464+ return $visibleEditorCount <= 1;
 1465+ }
 1466+
 1467+ protected function editEditors(IdStack $idPath, $value, $editors, $htmlTag, $compress) {
14301468 $result = '';
14311469
14321470 foreach ($editors as $editor) {
@@ -1435,13 +1473,18 @@
14361474 if ($editor->showEditField($idPath)) {
14371475 $class = $idPath->getClass();
14381476 $attributeId = $idPath->getId();
1439 -
1440 - $result .=
1441 - '<' . $htmlTag . '>'.
1442 - $this->childHeader($editor, $attribute, $class, $attributeId) .
1443 - $this->editChild($editor, $idPath, $value, $attribute, $class, $attributeId) .
1444 - '</' . $htmlTag . '>';
 1477+
 1478+ if (!$compress)
 1479+ $result .=
 1480+ '<' . $htmlTag . '>'.
 1481+ $this->childHeader($editor, $attribute, $class, $attributeId);
 1482+
 1483+ $result .= $this->editChild($editor, $idPath, $value, $attribute, $class, $attributeId);
 1484+
 1485+ if (!$compress)
 1486+ $result .= '</' . $htmlTag . '>';
14451487 }
 1488+
14461489 $idPath->popAttribute();
14471490 }
14481491
@@ -1449,7 +1492,8 @@
14501493 }
14511494
14521495 public function edit(IdStack $idPath, $value) {
1453 - return $this->editEditors($idPath, $value, $this->getEditors(), $this->htmlTag);
 1496+ $editors = $this->getEditors();
 1497+ return $this->editEditors($idPath, $value, $editors, $this->htmlTag, $this->shouldCompressOnEdit($idPath, $value, $editors));
14541498 }
14551499
14561500 protected function addEditors(IdStack $idPath, $editors, $htmlTag) {
@@ -1520,11 +1564,25 @@
15211565 }
15221566
15231567 public function view(IdStack $idPath, $value) {
1524 - return $this->wrapInList(parent::view($idPath, $value));
 1568+ $editors = $this->getEditors();
 1569+ $compress = $this->shouldCompressOnView($idPath, $value, $editors);
 1570+ $result = $this->viewEditors($idPath, $value, $editors, $this->htmlTag, $compress);
 1571+
 1572+ if (!$compress)
 1573+ return $this->wrapInList($result);
 1574+ else
 1575+ return $result;
15251576 }
15261577
15271578 public function edit(IdStack $idPath, $value) {
1528 - return $this->wrapInList(parent::edit($idPath, $value));
 1579+ $editors = $this->getEditors();
 1580+ $compress = $this->shouldCompressOnEdit($idPath, $value, $editors);
 1581+ $result = $this->editEditors($idPath, $value, $editors, $this->htmlTag, $compress);
 1582+
 1583+ if (!$compress)
 1584+ return $this->wrapInList($result);
 1585+ else
 1586+ return $result;
15291587 }
15301588
15311589 public function add(IdStack $idPath) {

Status & tagging log