r16298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r16297‎ | r16298 | r16299 >
Date:13:53, 31 August 2006
Author:proes
Status:old
Tags:
Comment:
Also keep track of class in IdStack
Modified paths:
  • /trunk/extensions/Wikidata/WiktionaryZ/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/WiktionaryZ/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/WiktionaryZ/suggest.js
@@ -222,7 +222,7 @@
223223 }
224224
225225 function getTypeOf(element) {
226 - return getNameOf(element).replace(/\d+/g, "0");
 226+ return getNameOf(element).replace(/-\d+/g, "");
227227 }
228228
229229 function toggle(element, event) {
Index: trunk/extensions/Wikidata/WiktionaryZ/Editor.php
@@ -10,10 +10,13 @@
1111 protected $keyStack;
1212 protected $idStack = array();
1313 protected $currentId;
 14+ protected $classStack = array();
 15+ protected $currentClass;
1416
1517 public function __construct($prefix) {
1618 $this->keyStack = new RecordStack();
1719 $this->currentId = $prefix;
 20+ $this->currentClass = $prefix;
1821 }
1922
2023 protected function getKeyIds($record) {
@@ -34,6 +37,15 @@
3538 $this->currentId = array_pop($this->idStack);
3639 }
3740
 41+ protected function pushClass($class) {
 42+ $this->classStack[] = $this->currentClass;
 43+ $this->currentClass .= '-' . $class;
 44+ }
 45+
 46+ protected function popClass() {
 47+ $this->currentClass = array_pop($this->classStack);
 48+ }
 49+
3850 public function pushKey($record) {
3951 $this->keyStack->push($record);
4052 $this->pushId(implode("-", $this->getKeyIds($record)));
@@ -41,6 +53,7 @@
4254
4355 public function pushAttribute($attribute) {
4456 $this->pushId($attribute->id);
 57+ $this->pushClass($attribute->id);
4558 }
4659
4760 public function popKey() {
@@ -50,19 +63,20 @@
5164
5265 public function popAttribute() {
5366 $this->popId();
 67+ $this->popClass();
5468 }
5569
5670 public function getId() {
5771 return $this->currentId;
5872 }
5973
 74+ public function getClass() {
 75+ return $this->currentClass;
 76+ }
 77+
6078 public function getKeyStack() {
6179 return $this->keyStack;
6280 }
63 -
64 - public function getElementType() {
65 - return preg_replace("/\\d+/", "0", $this->getId());
66 - }
6781 }
6882
6983 interface PermissionController {
@@ -897,13 +911,13 @@
898912 foreach ($this->editors as $editor) {
899913 $attribute = $editor->getAttribute();
900914 $idPath->pushAttribute($attribute);
901 - $elementType = $idPath->getElementType();
902 - $expansionPrefix = $this->getExpansionPrefix($elementType);
903 - $this->setExpansionByEditor($editor, $elementType);
 915+ $class = $idPath->getClass();
 916+ $expansionPrefix = $this->getExpansionPrefix($class);
 917+ $this->setExpansionByEditor($editor, $class);
904918 $attributeId = $idPath->getId();
905919 $result .= '<li>'.
906920 '<h4 id="collapse-'. $attributeId .'" class="toggle" onclick="toggle(this, event);">' . $expansionPrefix . '&nbsp;' . $attribute->name . '</h4>' .
907 - '<div id="collapsable-'. $attributeId . '" class="expand-' . $elementType . '">' . $editor->view($idPath, $value->getAttributeValue($attribute)) . '</div>' .
 921+ '<div id="collapsable-'. $attributeId . '" class="expand-' . $class . '">' . $editor->view($idPath, $value->getAttributeValue($attribute)) . '</div>' .
908922 '</li>';
909923 $idPath->popAttribute();
910924 }
@@ -920,14 +934,14 @@
921935 $attribute = $editor->getAttribute();
922936
923937 $idPath->pushAttribute($attribute);
924 - $elementType = $idPath->getElementType();
925 - $this->setExpansionByEditor($editor, $elementType);
926 - $expansionPrefix = $this->getExpansionPrefix($elementType);
 938+ $class = $idPath->getClass();
 939+ $this->setExpansionByEditor($editor, $class);
 940+ $expansionPrefix = $this->getExpansionPrefix($class);
927941 $attributeId = $idPath->getId();
928942
929943 $result .= '<li>'.
930944 '<h4 id="collapse-'. $attributeId .'" class="toggle" onclick="toggle(this, event);">' . $expansionPrefix . '&nbsp;' . $attribute->name . '</h4>' .
931 - '<div id="collapsable-'. $attributeId . '" class="expand-' . $elementType . '">' . $editor->edit($idPath, $value->getAttributeValue($attribute)) . '</div>' .
 945+ '<div id="collapsable-'. $attributeId . '" class="expand-' . $class . '">' . $editor->edit($idPath, $value->getAttributeValue($attribute)) . '</div>' .
932946 '</li>';
933947 $idPath->popAttribute();
934948 }
@@ -944,14 +958,14 @@
945959 if ($attribute = $editor->getAddAttribute()) {
946960 $attribute = $editor->getAttribute();
947961 $idPath->pushAttribute($attribute);
948 - $elementType = $idPath->getElementType();
949 - $this->setExpansionByEditor($editor, $elementType);
950 - $expansionPrefix = $this->getExpansionPrefix($elementType);
 962+ $class = $idPath->getClass();
 963+ $this->setExpansionByEditor($editor, $class);
 964+ $expansionPrefix = $this->getExpansionPrefix($class);
951965 $attributeId = $idPath->getId();
952966
953967 $result .= '<li>'.
954968 '<h4 id="collapse-'. $attributeId .'" class="toggle" onclick="toggle(this, event);">' . $expansionPrefix . '&nbsp;' . $attribute->name . '</h4>' .
955 - '<div id="collapsable-'. $attributeId . '" class="expand-' . $elementType . '">' . $editor->add($idPath) . '</div>' .
 969+ '<div id="collapsable-'. $attributeId . '" class="expand-' . $class . '">' . $editor->add($idPath) . '</div>' .
956970 '</li>';
957971 $editor->add($idPath);
958972 $idPath->popAttribute();
@@ -1007,11 +1021,11 @@
10081022 $idPath->pushKey(project($record, $key));
10091023 $recordId = $idPath->getId();
10101024 if($i==0) {
1011 - $captionElementType = $idPath->getElementType();
1012 - $captionExpansionPrefix = $this->getExpansionPrefix($captionElementType);
1013 - $this->setExpansion($this->childrenExpanded, $captionElementType);
1014 - $valueElementType = $idPath->getElementType();
1015 - $this->setExpansion($this->childrenExpanded, $valueElementType);
 1025+ $captionClass = $idPath->getClass();
 1026+ $captionExpansionPrefix = $this->getExpansionPrefix($captionClass);
 1027+ $this->setExpansion($this->childrenExpanded, $captionClass);
 1028+ $valueClass = $idPath->getClass();
 1029+ $this->setExpansion($this->childrenExpanded, $valueClass);
10161030 }
10171031
10181032 $idPath->pushAttribute($captionAttribute);
@@ -1020,7 +1034,7 @@
10211035 $idPath->popAttribute();
10221036
10231037 $idPath->pushAttribute($valueAttribute);
1024 - $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $valueElementType . '">' . $this->valueEditor->view($idPath, $record->getAttributeValue($valueAttribute)) . '</div>' .
 1038+ $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $valueClass . '">' . $this->valueEditor->view($idPath, $record->getAttributeValue($valueAttribute)) . '</div>' .
10251039 '</li>';
10261040 $idPath->popAttribute();
10271041
@@ -1046,11 +1060,11 @@
10471061 $recordId = $idPath->getId();
10481062
10491063 if($i==0) {
1050 - $captionElementType = $idPath->getElementType();
1051 - $captionExpansionPrefix = $this->getExpansionPrefix($captionElementType);
1052 - $this->setExpansion($this->childrenExpanded, $captionElementType);
1053 - $valueElementType = $idPath->getElementType();
1054 - $this->setExpansion($this->childrenExpanded, $valueElementType);
 1064+ $captionClass = $idPath->getClass();
 1065+ $captionExpansionPrefix = $this->getExpansionPrefix($captionClass);
 1066+ $this->setExpansion($this->childrenExpanded, $captionClass);
 1067+ $valueClass = $idPath->getClass();
 1068+ $this->setExpansion($this->childrenExpanded, $valueClass);
10551069 }
10561070
10571071 $idPath->pushAttribute($captionAttribute);
@@ -1059,7 +1073,7 @@
10601074 $idPath->popAttribute();
10611075
10621076 $idPath->pushAttribute($valueAttribute);
1063 - $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $valueElementType . '">' . $this->valueEditor->edit($idPath, $record->getAttributeValue($valueAttribute)) . '</div>' .
 1077+ $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $valueClass . '">' . $this->valueEditor->edit($idPath, $record->getAttributeValue($valueAttribute)) . '</div>' .
10641078 '</li>';
10651079 $idPath->popAttribute();
10661080
@@ -1069,16 +1083,16 @@
10701084 if ($this->allowAdd) {
10711085 $recordId = 'add-' . $idPath->getId();
10721086 $idPath->pushAttribute($captionAttribute);
1073 - $elementType = $idPath->getElementType();
 1087+ $class = $idPath->getClass();
10741088
1075 - $this->setExpansion(true, $elementType);
 1089+ $this->setExpansion(true, $class);
10761090
10771091 $result .= '<li>'.
1078 - '<h' . $this->headerLevel .' id="collapse-'. $recordId .'" class="toggle" onclick="toggle(this, event);">' . $this->getExpansionPrefix($elementType) . ' <img src="extensions/Wikidata/Images/Add.png" title="Enter new list item to add" alt="Add"/> ' . $this->captionEditor->add($idPath) . '</h' . $this->headerLevel .'>';
 1092+ '<h' . $this->headerLevel .' id="collapse-'. $recordId .'" class="toggle" onclick="toggle(this, event);">' . $this->getExpansionPrefix($class) . ' <img src="extensions/Wikidata/Images/Add.png" title="Enter new list item to add" alt="Add"/> ' . $this->captionEditor->add($idPath) . '</h' . $this->headerLevel .'>';
10791093 $idPath->popAttribute();
10801094
10811095 $idPath->pushAttribute($valueAttribute);
1082 - $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $elementType . '">' . $this->valueEditor->add($idPath) . '</div>' .
 1096+ $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $class . '">' . $this->valueEditor->add($idPath) . '</div>' .
10831097 '</li>';
10841098 $idPath->popAttribute();
10851099 }
@@ -1096,16 +1110,16 @@
10971111 $recordId = 'add-' . $idPath->getId();
10981112
10991113 $idPath->pushAttribute($captionAttribute);
1100 - $elementType = $idPath->getElementType();
 1114+ $class = $idPath->getClass();
11011115
1102 - $this->setExpansion(true, $elementType);
 1116+ $this->setExpansion(true, $class);
11031117
11041118 $result .= '<li>'.
1105 - '<h' . $this->headerLevel .' id="collapse-'. $recordId .'" class="toggle" onclick="toggle(this, event);">' . $this->getExpansionPrefix($elementType) . '&nbsp;' . $this->captionEditor->add($idPath) . '</h' . $this->headerLevel .'>';
 1119+ '<h' . $this->headerLevel .' id="collapse-'. $recordId .'" class="toggle" onclick="toggle(this, event);">' . $this->getExpansionPrefix($class) . '&nbsp;' . $this->captionEditor->add($idPath) . '</h' . $this->headerLevel .'>';
11061120 $idPath->popAttribute();
11071121
11081122 $idPath->pushAttribute($valueAttribute);
1109 - $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $elementType . '">' . $this->valueEditor->add($idPath) . '</div>' .
 1123+ $result .= '<div id="collapsable-'. $recordId . '" class="expand-' . $class . '">' . $this->valueEditor->add($idPath) . '</div>' .
11101124 '</li>';
11111125 $idPath->popAttribute();
11121126