Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php |
— | — | @@ -1394,7 +1394,23 @@ |
1395 | 1395 | return $result; |
1396 | 1396 | } |
1397 | 1397 | |
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) { |
1399 | 1415 | $result = ''; |
1400 | 1416 | |
1401 | 1417 | foreach ($editors as $editor) { |
— | — | @@ -1404,12 +1420,17 @@ |
1405 | 1421 | $attributeId = $idPath->getId(); |
1406 | 1422 | $attributeValue = $value->getAttributeValue($attribute); |
1407 | 1423 | |
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 | + } |
1414 | 1435 | |
1415 | 1436 | $idPath->popAttribute(); |
1416 | 1437 | } |
— | — | @@ -1418,14 +1439,31 @@ |
1419 | 1440 | } |
1420 | 1441 | |
1421 | 1442 | 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)); |
1423 | 1445 | } |
1424 | 1446 | |
1425 | 1447 | public function showEditField(IdStack $idPath) { |
1426 | 1448 | return true; |
1427 | 1449 | } |
1428 | 1450 | |
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) { |
1430 | 1468 | $result = ''; |
1431 | 1469 | |
1432 | 1470 | foreach ($editors as $editor) { |
— | — | @@ -1435,13 +1473,18 @@ |
1436 | 1474 | if ($editor->showEditField($idPath)) { |
1437 | 1475 | $class = $idPath->getClass(); |
1438 | 1476 | $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 . '>'; |
1445 | 1487 | } |
| 1488 | + |
1446 | 1489 | $idPath->popAttribute(); |
1447 | 1490 | } |
1448 | 1491 | |
— | — | @@ -1449,7 +1492,8 @@ |
1450 | 1493 | } |
1451 | 1494 | |
1452 | 1495 | 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)); |
1454 | 1498 | } |
1455 | 1499 | |
1456 | 1500 | protected function addEditors(IdStack $idPath, $editors, $htmlTag) { |
— | — | @@ -1520,11 +1564,25 @@ |
1521 | 1565 | } |
1522 | 1566 | |
1523 | 1567 | 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; |
1525 | 1576 | } |
1526 | 1577 | |
1527 | 1578 | 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; |
1529 | 1587 | } |
1530 | 1588 | |
1531 | 1589 | public function add(IdStack $idPath) { |