r114681 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114680‎ | r114681 | r114682 >
Date:06:45, 3 April 2012
Author:netbrain
Status:ok
Tags:
Comment:
styled code properly.
Modified paths:
  • /trunk/extensions/SideBarMenu/SideBarMenu.hooks.php (modified) (history)
  • /trunk/extensions/SideBarMenu/SideBarMenu.i18n.php (modified) (history)
  • /trunk/extensions/SideBarMenu/SideBarMenu.php (modified) (history)
  • /trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css (modified) (history)
  • /trunk/extensions/SideBarMenu/includes/MenuItem.php (modified) (history)
  • /trunk/extensions/SideBarMenu/includes/MenuParser.php (modified) (history)
  • /trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js (modified) (history)
  • /trunk/extensions/SideBarMenu/test/MenuItemTest.php (modified) (history)
  • /trunk/extensions/SideBarMenu/test/MenuParserTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SideBarMenu/test/MenuParserTest.php
@@ -1,213 +1,211 @@
22 <?php
33
4 -class MenuParserTest extends MediaWikiTestCase
5 -{
 4+class MenuParserTest extends MediaWikiTestCase {
65
7 - private $menuParser;
 6+ private $menuParser;
87
9 - protected function setUp()
10 - {
11 - $this->menuParser = new MenuParser(true);
12 - }
 8+ protected function setUp() {
 9+ $this->menuParser = new MenuParser(true);
 10+ }
1311
14 - public function testValidInputWhenNull(){
15 - $this->assertFalse($this->menuParser->isValidInput(null));
16 - }
 12+ public function testValidInputWhenNull() {
 13+ $this->assertFalse($this->menuParser->isValidInput(null));
 14+ }
1715
18 - public function testValidInputWhenEmpty(){
19 - $this->assertFalse($this->menuParser->isValidInput(""));
20 - }
 16+ public function testValidInputWhenEmpty() {
 17+ $this->assertFalse($this->menuParser->isValidInput(""));
 18+ }
2119
22 - public function testValidInput(){
23 - $this->assertTrue($this->menuParser->isValidInput("+MenuItem"));
24 - }
 20+ public function testValidInput() {
 21+ $this->assertTrue($this->menuParser->isValidInput("+MenuItem"));
 22+ }
2523
26 - public function testGetLevelWhenNull(){
27 - $this->assertEquals(0,$this->menuParser->getLevel(null));
28 - }
 24+ public function testGetLevelWhenNull() {
 25+ $this->assertEquals(0, $this->menuParser->getLevel(null));
 26+ }
2927
30 - public function testGetLevelWhenEmpty(){
31 - $this->assertEquals(0,$this->menuParser->getLevel(""));
32 - }
 28+ public function testGetLevelWhenEmpty() {
 29+ $this->assertEquals(0, $this->menuParser->getLevel(""));
 30+ }
3331
34 - public function testGetLevelWhenValidButNoStars(){
35 - $this->assertEquals(0,$this->menuParser->getLevel(""));
36 - }
 32+ public function testGetLevelWhenValidButNoStars() {
 33+ $this->assertEquals(0, $this->menuParser->getLevel(""));
 34+ }
3735
38 - public function testGetLevelWithValid(){
39 - $this->assertEquals(3,$this->menuParser->getLevel("***MenuItem"));
40 - }
 36+ public function testGetLevelWithValid() {
 37+ $this->assertEquals(3, $this->menuParser->getLevel("***MenuItem"));
 38+ }
4139
42 - public function testGetExpandedParameterWhenNoneSupplied(){
43 - $this->menuParser = new MenuParser(true);
44 - $this->assertTrue($this->menuParser->getExpandedParameter("MenuItem"));
45 - $this->menuParser = new MenuParser(false);
46 - $this->assertFalse($this->menuParser->getExpandedParameter("MenuItem"));
47 - }
 40+ public function testGetExpandedParameterWhenNoneSupplied() {
 41+ $this->menuParser = new MenuParser(true);
 42+ $this->assertTrue($this->menuParser->getExpandedParameter("MenuItem"));
 43+ $this->menuParser = new MenuParser(false);
 44+ $this->assertFalse($this->menuParser->getExpandedParameter("MenuItem"));
 45+ }
4846
49 - public function testGetExpandedParameterWhenNotExpanded(){
50 - $this->assertFalse($this->menuParser->getExpandedParameter("-MenuItem"));
51 - }
 47+ public function testGetExpandedParameterWhenNotExpanded() {
 48+ $this->assertFalse($this->menuParser->getExpandedParameter("-MenuItem"));
 49+ }
5250
53 - public function testGetExpandedParameterWhenExpanded(){
54 - $this->assertTrue($this->menuParser->getExpandedParameter("+MenuItem"));
55 - }
 51+ public function testGetExpandedParameterWhenExpanded() {
 52+ $this->assertTrue($this->menuParser->getExpandedParameter("+MenuItem"));
 53+ }
5654
57 - public function testGetTextParameter(){
58 - $this->assertEquals("MenuItem",$this->menuParser->getTextParameter("+***MenuItem"));
59 - $this->assertEquals("+MenuItem",$this->menuParser->getTextParameter("+***+MenuItem"));
60 - $this->assertEquals("MenuItem",$this->menuParser->getTextParameter("-MenuItem"));
61 - $this->assertEquals("MenuItem",$this->menuParser->getTextParameter("-*MenuItem"));
62 - $this->assertEquals("MenuItem",$this->menuParser->getTextParameter("MenuItem"));
63 - $this->assertEquals("+*MenuItem",$this->menuParser->getTextParameter("+***+*MenuItem"));
64 - }
 55+ public function testGetTextParameter() {
 56+ $this->assertEquals("MenuItem", $this->menuParser->getTextParameter("+***MenuItem"));
 57+ $this->assertEquals("+MenuItem", $this->menuParser->getTextParameter("+***+MenuItem"));
 58+ $this->assertEquals("MenuItem", $this->menuParser->getTextParameter("-MenuItem"));
 59+ $this->assertEquals("MenuItem", $this->menuParser->getTextParameter("-*MenuItem"));
 60+ $this->assertEquals("MenuItem", $this->menuParser->getTextParameter("MenuItem"));
 61+ $this->assertEquals("+*MenuItem", $this->menuParser->getTextParameter("+***+*MenuItem"));
 62+ }
6563
66 - public function testGetMenuItemWhenInputIsNull(){
67 - $this->setExpectedException('InvalidArgumentException');
68 - $this->assertNull($this->menuParser->getMenuItem(null));
69 - }
 64+ public function testGetMenuItemWhenInputIsNull() {
 65+ $this->setExpectedException('InvalidArgumentException');
 66+ $this->assertNull($this->menuParser->getMenuItem(null));
 67+ }
7068
71 - public function testGetMenuItemWhenInputIsEmpty(){
72 - $this->setExpectedException('InvalidArgumentException');
73 - $this->assertNull($this->menuParser->getMenuItem(""));
74 - }
 69+ public function testGetMenuItemWhenInputIsEmpty() {
 70+ $this->setExpectedException('InvalidArgumentException');
 71+ $this->assertNull($this->menuParser->getMenuItem(""));
 72+ }
7573
76 - public function testGetMenuItemWhenInputIsValid(){
77 - $data = "MenuItem";
78 - $menuItem = $this->menuParser->getMenuItem($data);
79 - $this->assertNotNull($menuItem);
80 - $this->assertEquals($data,$menuItem->getText());
81 - $this->assertTrue($menuItem->isExpanded());
82 - }
 74+ public function testGetMenuItemWhenInputIsValid() {
 75+ $data = "MenuItem";
 76+ $menuItem = $this->menuParser->getMenuItem($data);
 77+ $this->assertNotNull($menuItem);
 78+ $this->assertEquals($data, $menuItem->getText());
 79+ $this->assertTrue($menuItem->isExpanded());
 80+ }
8381
84 - public function testGetMenuItemWhenInputIsValidAndExpandIsSet(){
85 - $text = "MenuItem";
86 - $data = "+".$text;
87 - $menuItem = $this->menuParser->getMenuItem($data);
88 - $this->assertNotNull($menuItem);
89 - $this->assertEquals($text,$menuItem->getText());
90 - $this->assertTrue($menuItem->isExpanded());
91 - }
 82+ public function testGetMenuItemWhenInputIsValidAndExpandIsSet() {
 83+ $text = "MenuItem";
 84+ $data = "+" . $text;
 85+ $menuItem = $this->menuParser->getMenuItem($data);
 86+ $this->assertNotNull($menuItem);
 87+ $this->assertEquals($text, $menuItem->getText());
 88+ $this->assertTrue($menuItem->isExpanded());
 89+ }
9290
93 - public function testParseDataIntoHierarchicalArray(){
94 - $data = "MenuItem";
95 - $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
96 - $this->assertNotNull($array);
97 - $this->assertEquals($data,$array[0]);
98 - }
 91+ public function testParseDataIntoHierarchicalArray() {
 92+ $data = "MenuItem";
 93+ $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
 94+ $this->assertNotNull($array);
 95+ $this->assertEquals($data, $array[0]);
 96+ }
9997
100 - public function testParseDataIntoHierarchicalArrayWithSubLevel(){
101 - $lines = array("MenuItem","*SubMenuItem");
102 - $data = join("\n",$lines);
103 - $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
104 - $this->assertNotNull($array);
105 - $this->assertArrayHasKey($lines[0],$array);
106 - $this->assertEquals(
107 - array(
108 - 'MenuItem' => array(
109 - '*SubMenuItem'
110 - )
111 - ),$array
112 - );
113 - }
 98+ public function testParseDataIntoHierarchicalArrayWithSubLevel() {
 99+ $lines = array("MenuItem", "*SubMenuItem");
 100+ $data = join("\n", $lines);
 101+ $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
 102+ $this->assertNotNull($array);
 103+ $this->assertArrayHasKey($lines[0], $array);
 104+ $this->assertEquals(
 105+ array(
 106+ 'MenuItem' => array(
 107+ '*SubMenuItem'
 108+ )
 109+ ), $array
 110+ );
 111+ }
114112
115 - public function testParseDataIntoHierarchicalArrayWithSeveralSubLevels(){
116 - $lines = array("MenuItem","*SubMenuItem","*SubMenuItem2","**SubMenuItemOf2");
117 - $data = join("\n",$lines);
118 - $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
119 - $this->assertNotNull($array);
120 - $this->assertEquals(
121 - array(
122 - 'MenuItem' => array(
123 - '*SubMenuItem',
124 - '*SubMenuItem2' => array(
125 - '**SubMenuItemOf2'
126 - )
127 - )
128 - ),$array
129 - );
130 - }
 113+ public function testParseDataIntoHierarchicalArrayWithSeveralSubLevels() {
 114+ $lines = array("MenuItem", "*SubMenuItem", "*SubMenuItem2", "**SubMenuItemOf2");
 115+ $data = join("\n", $lines);
 116+ $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
 117+ $this->assertNotNull($array);
 118+ $this->assertEquals(
 119+ array(
 120+ 'MenuItem' => array(
 121+ '*SubMenuItem',
 122+ '*SubMenuItem2' => array(
 123+ '**SubMenuItemOf2'
 124+ )
 125+ )
 126+ ), $array
 127+ );
 128+ }
131129
132 - public function testParseDataIntoHierarchicalArrayWithSubLevelAndBack(){
133 - $lines = array("MenuItem","*SubMenuItem","MenuItem2");
134 - $data = join("\n",$lines);
135 - $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
136 - $this->assertNotNull($array);
137 - $this->assertEquals(
138 - array(
139 - 'MenuItem' => array(
140 - '*SubMenuItem'
141 - ),
142 - 'MenuItem2'
143 - ),$array
144 - );
145 - }
 130+ public function testParseDataIntoHierarchicalArrayWithSubLevelAndBack() {
 131+ $lines = array("MenuItem", "*SubMenuItem", "MenuItem2");
 132+ $data = join("\n", $lines);
 133+ $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
 134+ $this->assertNotNull($array);
 135+ $this->assertEquals(
 136+ array(
 137+ 'MenuItem' => array(
 138+ '*SubMenuItem'
 139+ ),
 140+ 'MenuItem2'
 141+ ), $array
 142+ );
 143+ }
146144
147 - public function testParseDataIntoHierarchicalArrayWithSubLevelAndBackSeveralLevels(){
148 - $lines = array("MenuItem","*SubMenuItem1","**SubMenuItem2","***SubMenuItem3","MenuItem2");
149 - $data = join("\n",$lines);
150 - $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
151 - $this->assertNotNull($array);
152 - $this->assertEquals(
153 - array(
154 - 'MenuItem' => array(
155 - '*SubMenuItem1' => array(
156 - '**SubMenuItem2' => array(
157 - '***SubMenuItem3'
158 - )
159 - )
160 - ),
161 - 'MenuItem2'
162 - ),$array
163 - );
164 - }
 145+ public function testParseDataIntoHierarchicalArrayWithSubLevelAndBackSeveralLevels() {
 146+ $lines = array("MenuItem", "*SubMenuItem1", "**SubMenuItem2", "***SubMenuItem3", "MenuItem2");
 147+ $data = join("\n", $lines);
 148+ $array = $this->menuParser->parseDataIntoHierarchicalArray($data);
 149+ $this->assertNotNull($array);
 150+ $this->assertEquals(
 151+ array(
 152+ 'MenuItem' => array(
 153+ '*SubMenuItem1' => array(
 154+ '**SubMenuItem2' => array(
 155+ '***SubMenuItem3'
 156+ )
 157+ )
 158+ ),
 159+ 'MenuItem2'
 160+ ), $array
 161+ );
 162+ }
165163
166164
167 - public function testGetMenuWithInvalidInput(){
168 - $this->assertNull($this->menuParser->getMenuTree(null));
169 - $this->assertNull($this->menuParser->getMenuTree(""));
170 - }
 165+ public function testGetMenuWithInvalidInput() {
 166+ $this->assertNull($this->menuParser->getMenuTree(null));
 167+ $this->assertNull($this->menuParser->getMenuTree(""));
 168+ }
171169
172 - public function testGetMenuWithValidInput(){
173 - $menu = $this->menuParser->getMenuTree("MenuItem");
174 - $this->assertNotNull($menu);
175 - $this->assertTrue($menu->isRoot());
176 - $this->assertEquals(1,sizeof($menu->getChildren()));
 170+ public function testGetMenuWithValidInput() {
 171+ $menu = $this->menuParser->getMenuTree("MenuItem");
 172+ $this->assertNotNull($menu);
 173+ $this->assertTrue($menu->isRoot());
 174+ $this->assertEquals(1, sizeof($menu->getChildren()));
177175
178 - $children = $menu->getChildren();
179 - $this->assertEquals("MenuItem",$children[0]->getText());
180 - }
 176+ $children = $menu->getChildren();
 177+ $this->assertEquals("MenuItem", $children[0]->getText());
 178+ }
181179
182 - public function testGetMenuWithValidComplexInput(){
183 - $data = array(
184 - 'MenuItem1',
185 - '*SubMenuItem1',
186 - '*SubMenuItem2',
187 - '*SubMenuItem3',
188 - '**SubMenuItem1Of1',
189 - '**SubMenuItem2Of1',
190 - 'MenuItem2',
191 - '*SubMenuItem1OfMenuItem2'
192 - );
193 - $menu = $this->menuParser->getMenuTree(join("\n",$data));
194 - $this->assertNotNull($menu);
195 - $this->assertEquals(2,sizeof($menu->getChildren()));
 180+ public function testGetMenuWithValidComplexInput() {
 181+ $data = array(
 182+ 'MenuItem1',
 183+ '*SubMenuItem1',
 184+ '*SubMenuItem2',
 185+ '*SubMenuItem3',
 186+ '**SubMenuItem1Of1',
 187+ '**SubMenuItem2Of1',
 188+ 'MenuItem2',
 189+ '*SubMenuItem1OfMenuItem2'
 190+ );
 191+ $menu = $this->menuParser->getMenuTree(join("\n", $data));
 192+ $this->assertNotNull($menu);
 193+ $this->assertEquals(2, sizeof($menu->getChildren()));
196194
197 - }
 195+ }
198196
199 - public function testGetMenuWithSeveralLineBreaks(){
200 - $data = array(
201 - '',
202 - 'MenuItem1',
203 - '',
204 - ''
205 - );
206 - $menu = $this->menuParser->getMenuTree(join("\n",$data));
207 - $this->assertNotNull($menu);
208 - $this->assertEquals(1,sizeof($menu->getChildren()));
 197+ public function testGetMenuWithSeveralLineBreaks() {
 198+ $data = array(
 199+ '',
 200+ 'MenuItem1',
 201+ '',
 202+ ''
 203+ );
 204+ $menu = $this->menuParser->getMenuTree(join("\n", $data));
 205+ $this->assertNotNull($menu);
 206+ $this->assertEquals(1, sizeof($menu->getChildren()));
209207
210 - $children = $menu->getChildren();
211 - $this->assertEquals("MenuItem1",$children[0]->getText());
 208+ $children = $menu->getChildren();
 209+ $this->assertEquals("MenuItem1", $children[0]->getText());
212210
213 - }
 211+ }
214212 }
Index: trunk/extensions/SideBarMenu/test/MenuItemTest.php
@@ -1,104 +1,102 @@
22 <?php
33
4 -class MenuItemTest extends MediaWikiTestCase
5 -{
6 - private $menuItem;
 4+class MenuItemTest extends MediaWikiTestCase {
 5+ private $menuItem;
76
8 - protected function setUp()
9 - {
10 - $this->menuItem = new MenuItem();
11 - }
 7+ protected function setUp() {
 8+ $this->menuItem = new MenuItem();
 9+ }
1210
13 - public function testIsRoot(){
14 - $this->assertTrue($this->menuItem->isRoot());
15 - }
 11+ public function testIsRoot() {
 12+ $this->assertTrue($this->menuItem->isRoot());
 13+ }
1614
17 - public function testIsNotRoot(){
18 - $this->menuItem->setParent(new MenuItem());
19 - $this->assertFalse($this->menuItem->isRoot());
20 - }
 15+ public function testIsNotRoot() {
 16+ $this->menuItem->setParent(new MenuItem());
 17+ $this->assertFalse($this->menuItem->isRoot());
 18+ }
2119
22 - public function testGetLevelWhenRoot(){
23 - $this->assertEquals(0,$this->menuItem->getLevel());
24 - }
 20+ public function testGetLevelWhenRoot() {
 21+ $this->assertEquals(0, $this->menuItem->getLevel());
 22+ }
2523
26 - public function testGetLevelWhenChild(){
27 - $this->menuItem->setParent(new MenuItem());
28 - $this->assertEquals(1,$this->menuItem->getLevel());
29 - }
 24+ public function testGetLevelWhenChild() {
 25+ $this->menuItem->setParent(new MenuItem());
 26+ $this->assertEquals(1, $this->menuItem->getLevel());
 27+ }
3028
31 - public function testGetLevelWhenSeveralChildren(){
32 - $prev = $this->menuItem;
33 - for($x = 0; $x < 10; $x++){
34 - $child = new MenuItem();
35 - $child->setParent($prev);
36 - $prev = $child;
 29+ public function testGetLevelWhenSeveralChildren() {
 30+ $prev = $this->menuItem;
 31+ for ($x = 0; $x < 10; $x++) {
 32+ $child = new MenuItem();
 33+ $child->setParent($prev);
 34+ $prev = $child;
3735
38 - }
39 - $this->assertEquals(10,$prev->getLevel());
40 - }
 36+ }
 37+ $this->assertEquals(10, $prev->getLevel());
 38+ }
4139
42 - public function testAddChildAlsoAddsParent(){
43 - $child = new MenuItem();
44 - $this->menuItem->addChild($child);
45 - $this->assertContains($child,$this->menuItem->getChildren());
46 - $this->assertEquals($child->getParent(),$this->menuItem);
47 - }
 40+ public function testAddChildAlsoAddsParent() {
 41+ $child = new MenuItem();
 42+ $this->menuItem->addChild($child);
 43+ $this->assertContains($child, $this->menuItem->getChildren());
 44+ $this->assertEquals($child->getParent(), $this->menuItem);
 45+ }
4846
49 - public function testAddSameChildSeveralTimes(){
50 - $child = new MenuItem();
51 - for($x = 0; $x < 3; $x++){
52 - $this->menuItem->addChild($child);
53 - }
54 - $this->assertEquals(1,sizeof($this->menuItem->getChildren()));
55 - }
 47+ public function testAddSameChildSeveralTimes() {
 48+ $child = new MenuItem();
 49+ for ($x = 0; $x < 3; $x++) {
 50+ $this->menuItem->addChild($child);
 51+ }
 52+ $this->assertEquals(1, sizeof($this->menuItem->getChildren()));
 53+ }
5654
57 - public function testAddParentAlsoAddsChild(){
58 - $parent = new MenuItem();
59 - $this->menuItem->setParent($parent);
60 - $this->assertContains($this->menuItem,$parent->getChildren());
61 - }
 55+ public function testAddParentAlsoAddsChild() {
 56+ $parent = new MenuItem();
 57+ $this->menuItem->setParent($parent);
 58+ $this->assertContains($this->menuItem, $parent->getChildren());
 59+ }
6260
63 - public function testToHTMLOnRootMenuItem(){
64 - $html = $this->menuItem->toHTML();
65 - $this->assertEquals("",$html);
66 - }
 61+ public function testToHTMLOnRootMenuItem() {
 62+ $html = $this->menuItem->toHTML();
 63+ $this->assertEquals("", $html);
 64+ }
6765
68 - public function testToHTMLOnProperMenuItem(){
69 - $menuItemChild = new MenuItem();
70 - $menuItemChild->setText("MenuItem1");
71 - $this->menuItem->addChild($menuItemChild);
72 - $html = $this->menuItem->toHTML();
73 - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li></ul>',$html);
74 - }
 66+ public function testToHTMLOnProperMenuItem() {
 67+ $menuItemChild = new MenuItem();
 68+ $menuItemChild->setText("MenuItem1");
 69+ $this->menuItem->addChild($menuItemChild);
 70+ $html = $this->menuItem->toHTML();
 71+ $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li></ul>', $html);
 72+ }
7573
76 - public function testToHTMLOnSeveralMenuItems(){
77 - $menuItemChild1 = new MenuItem();
78 - $menuItemChild1->setText("MenuItem1");
79 - $menuItemChild2 = new MenuItem();
80 - $menuItemChild2->setText("MenuItem2");
 74+ public function testToHTMLOnSeveralMenuItems() {
 75+ $menuItemChild1 = new MenuItem();
 76+ $menuItemChild1->setText("MenuItem1");
 77+ $menuItemChild2 = new MenuItem();
 78+ $menuItemChild2->setText("MenuItem2");
8179
82 - $this->menuItem->addChild($menuItemChild1);
83 - $this->menuItem->addChild($menuItemChild2);
 80+ $this->menuItem->addChild($menuItemChild1);
 81+ $this->menuItem->addChild($menuItemChild2);
8482
85 - $html = $this->menuItem->toHTML();
86 - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span></div></li></ul>',$html);
87 - }
 83+ $html = $this->menuItem->toHTML();
 84+ $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span></div></li></ul>', $html);
 85+ }
8886
89 - public function testToHTMLOnSeveralMenuItemsWithSublevels(){
90 - $menuItemChild1 = new MenuItem();
91 - $menuItemChild1->setText("MenuItem1");
92 - $menuItemChild2 = new MenuItem();
93 - $menuItemChild2->setText("MenuItem2");
 87+ public function testToHTMLOnSeveralMenuItemsWithSublevels() {
 88+ $menuItemChild1 = new MenuItem();
 89+ $menuItemChild1->setText("MenuItem1");
 90+ $menuItemChild2 = new MenuItem();
 91+ $menuItemChild2->setText("MenuItem2");
9492
95 - $this->menuItem->addChild($menuItemChild1);
96 - $this->menuItem->addChild($menuItemChild2);
 93+ $this->menuItem->addChild($menuItemChild1);
 94+ $this->menuItem->addChild($menuItemChild2);
9795
98 - $subLevel1 = new MenuItem();
99 - $subLevel1->setText("SubMenuItem1");
100 - $subLevel1->setParent($menuItemChild2);
 96+ $subLevel1 = new MenuItem();
 97+ $subLevel1->setText("SubMenuItem1");
 98+ $subLevel1->setParent($menuItemChild2);
10199
102 - $html = $this->menuItem->toHTML();
103 - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span><span class="sidebar-menu-item-controls"></span></div><ul class="sidebar-menu sidebar-menu-1"><li class="sidebar-menu-item sidebar-menu-item-2"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-2">SubMenuItem1</span></div></li></ul></li></ul>',$html);
104 - }
 100+ $html = $this->menuItem->toHTML();
 101+ $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span><span class="sidebar-menu-item-controls"></span></div><ul class="sidebar-menu sidebar-menu-1"><li class="sidebar-menu-item sidebar-menu-item-2"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-2">SubMenuItem1</span></div></li></ul></li></ul>', $html);
 102+ }
105103 }
Index: trunk/extensions/SideBarMenu/SideBarMenu.i18n.php
@@ -9,15 +9,15 @@
1010 $messages = array();
1111
1212 /** English
13 - * @author Kim Eik
 13+ * @author Kim Eik
1414 */
1515 $messages['en'] = array(
16 - 'sidebarmenu-desc' => 'A simple sidebar menu parser which creates collapsable/expandable menus and sub-menus',
17 - 'sidebarmenu-parser-input-error' => 'Parser returned with error: $1',
18 - 'sidebarmenu-parser-syntax-error' => 'Could not parse "$1", make sure the syntax is correct.',
19 - 'sidebarmenu-js-init-error' => 'Failed loading JavaScript resources.',
20 - 'sidebarmenu-parser-menuitem-expanded-null' => '"parser.menuitem.expanded" should be true or false, instead it is null.',
21 - 'sidebarmenu-edit' => 'Edit'
 16+ 'sidebarmenu-desc' => 'A simple sidebar menu parser which creates collapsable/expandable menus and sub-menus',
 17+ 'sidebarmenu-parser-input-error' => 'Parser returned with error: $1',
 18+ 'sidebarmenu-parser-syntax-error' => 'Could not parse "$1", make sure the syntax is correct.',
 19+ 'sidebarmenu-js-init-error' => 'Failed loading JavaScript resources.',
 20+ 'sidebarmenu-parser-menuitem-expanded-null' => '"parser.menuitem.expanded" should be true or false, instead it is null.',
 21+ 'sidebarmenu-edit' => 'Edit'
2222 );
2323
2424 /** Message documentation (Message documentation)
Index: trunk/extensions/SideBarMenu/SideBarMenu.php
@@ -1,7 +1,7 @@
22 <?php
33
44 if (!defined('MEDIAWIKI')) {
5 - die('Not an entry point.');
 5+ die('Not an entry point.');
66 }
77
88 //SideBarMenu constants
@@ -14,18 +14,18 @@
1515
1616 //default settings
1717 $wgSideBarMenuConfig[SBM_CONTROLS_SHOW] = null;
18 -$wgSideBarMenuConfig[SBM_CONTROLS_HIDE]= null;
 18+$wgSideBarMenuConfig[SBM_CONTROLS_HIDE] = null;
1919 $wgSideBarMenuConfig[SBM_JS_ANIMATE] = true;
2020 $wgSideBarMenuConfig[SBM_EXPANDED] = true;
2121 $wgSideBarMenuConfig[SBM_EDIT_LINK] = true;
2222
2323 $wgExtensionCredits['parserhook'][] = array(
24 - 'path' => __FILE__,
25 - 'name' => 'SideBarMenu',
26 - 'version' => 0.1,
27 - 'author' => 'Kim Eik',
28 - 'url' => 'https://www.mediawiki.org/wiki/Extension:SideBarMenu',
29 - 'descriptionmsg' => 'sidebarmenu-desc'
 24+ 'path' => __FILE__,
 25+ 'name' => 'SideBarMenu',
 26+ 'version' => 0.1,
 27+ 'author' => 'Kim Eik',
 28+ 'url' => 'https://www.mediawiki.org/wiki/Extension:SideBarMenu',
 29+ 'descriptionmsg' => 'sidebarmenu-desc'
3030 );
3131
3232
@@ -39,7 +39,7 @@
4040 $wgHooks['UnitTestsList'][] = 'SideBarMenuHooks::registerUnitTests';
4141
4242 //Autoload hooks
43 -$wgAutoloadClasses['SideBarMenuHooks'] = dirname( __FILE__ ) . '/SideBarMenu.hooks.php';
 43+$wgAutoloadClasses['SideBarMenuHooks'] = dirname(__FILE__) . '/SideBarMenu.hooks.php';
4444
4545 //Autoload classes
4646 $wgMyExtensionIncludes = dirname(__FILE__) . '/includes';
@@ -48,25 +48,25 @@
4949 $wgAutoloadClasses['MenuItem'] = $wgMyExtensionIncludes . '/MenuItem.php';
5050
5151 //i18n
52 -$wgExtensionMessagesFiles['SideBarMenu'] = dirname( __FILE__ ) . '/SideBarMenu.i18n.php';
 52+$wgExtensionMessagesFiles['SideBarMenu'] = dirname(__FILE__) . '/SideBarMenu.i18n.php';
5353
5454 //Resources
5555 $wgResourceModules['ext.sidebarmenu.core'] = array(
56 - 'scripts' => array(
57 - 'js/ext.sidebarmenu.js'
58 - ),
59 - 'styles' => array(
60 - 'css/ext.sidebarmenu.css'
61 - ),
62 - 'dependencies' => array (
63 - 'jquery.ui.core',
64 - 'jquery.effects.core',
 56+ 'scripts' => array(
 57+ 'js/ext.sidebarmenu.js'
 58+ ),
 59+ 'styles' => array(
 60+ 'css/ext.sidebarmenu.css'
 61+ ),
 62+ 'dependencies' => array(
 63+ 'jquery.ui.core',
 64+ 'jquery.effects.core',
6565
66 - ),
67 - 'messages' => array(
68 - 'sidebarmenu-js-init-error'
69 - ),
70 - 'group' => 'ext.sidebarmenu',
71 - 'localBasePath' => dirname( __FILE__ ),
72 - 'remoteExtPath' => 'SideBarMenu'
 66+ ),
 67+ 'messages' => array(
 68+ 'sidebarmenu-js-init-error'
 69+ ),
 70+ 'group' => 'ext.sidebarmenu',
 71+ 'localBasePath' => dirname(__FILE__),
 72+ 'remoteExtPath' => 'SideBarMenu'
7373 );
Index: trunk/extensions/SideBarMenu/SideBarMenu.hooks.php
@@ -1,70 +1,67 @@
22 <?php
33
4 -class SideBarMenuHooks
5 -{
 4+class SideBarMenuHooks {
65
7 - public static function init(Parser &$parser){
8 - $parser->setHook('sidebarmenu','SideBarMenuHooks::renderFromTag');
9 - return true;
10 - }
 6+ public static function init(Parser &$parser) {
 7+ $parser->setHook('sidebarmenu', 'SideBarMenuHooks::renderFromTag');
 8+ return true;
 9+ }
1110
12 - public static function renderFromTag( $input, array $args, Parser $parser, PPFrame $frame ){
13 - $parser->getOutput()->addModules('ext.sidebarmenu.core');
 11+ public static function renderFromTag($input, array $args, Parser $parser, PPFrame $frame) {
 12+ $parser->getOutput()->addModules('ext.sidebarmenu.core');
1413
15 - //default settings
16 - $config = self::getTagConfig($args);
 14+ //default settings
 15+ $config = self::getTagConfig($args);
1716
18 - $output = '<div class="sidebar-menu-container">';
19 - try{
20 - $menuParser = new MenuParser($config[SBM_EXPANDED]);
21 - $output .= $parser->recursiveTagParse($menuParser->getMenuTree($input)->toHTML(),$frame);
22 - }catch(Exception $x){
23 - wfDebug("An error occured during parsing of: '$input' caught exception: $x");
24 - return wfMsg('sidebarmenu-parser-input-error',$x->getMessage());
25 - }
26 - if($config[SBM_EDIT_LINK]){
27 - $output .= Linker::link($frame->getTitle(),wfMsg('sidebarmenu-edit'),array('title' => wfMsg('sidebarmenu-edit')),array('action' => 'edit'));
 17+ $output = '<div class="sidebar-menu-container">';
 18+ try {
 19+ $menuParser = new MenuParser($config[SBM_EXPANDED]);
 20+ $output .= $parser->recursiveTagParse($menuParser->getMenuTree($input)->toHTML(), $frame);
 21+ } catch (Exception $x) {
 22+ wfDebug("An error occured during parsing of: '$input' caught exception: $x");
 23+ return wfMsg('sidebarmenu-parser-input-error', $x->getMessage());
2824 }
29 - $output .= '</div>';
 25+ if ($config[SBM_EDIT_LINK]) {
 26+ $output .= Linker::link($frame->getTitle(), wfMsg('sidebarmenu-edit'), array('title' => wfMsg('sidebarmenu-edit')), array('action' => 'edit'));
 27+ }
 28+ $output .= '</div>';
3029
31 - $jsOutput = self::getJSConfig($config);
 30+ $jsOutput = self::getJSConfig($config);
3231
33 - return array( $jsOutput.$output, 'noparse' => true, 'isHTML' => true );
34 - }
 32+ return array($jsOutput . $output, 'noparse' => true, 'isHTML' => true);
 33+ }
3534
36 - public static function registerUnitTests( &$files ) {
37 - $testDir = dirname( __FILE__ ) . '/test/';
38 - $testFiles = scandir($testDir);
39 - foreach($testFiles as $testFile){
40 - $absoluteFile = $testDir . $testFile;
41 - if(is_file($absoluteFile)){
42 - $files[] = $absoluteFile;
43 - }
44 - }
45 - return true;
46 - }
 35+ public static function registerUnitTests(&$files) {
 36+ $testDir = dirname(__FILE__) . '/test/';
 37+ $testFiles = scandir($testDir);
 38+ foreach ($testFiles as $testFile) {
 39+ $absoluteFile = $testDir . $testFile;
 40+ if (is_file($absoluteFile)) {
 41+ $files[] = $absoluteFile;
 42+ }
 43+ }
 44+ return true;
 45+ }
4746
48 - public static function registerMagicWords(&$magicWords, $langCode){
49 - $magicWords['sidebarmenu'] = array(0,'sidebarmenu');
50 - return true;
51 - }
 47+ public static function registerMagicWords(&$magicWords, $langCode) {
 48+ $magicWords['sidebarmenu'] = array(0, 'sidebarmenu');
 49+ return true;
 50+ }
5251
53 - private static function minifyJavascript($js)
54 - {
55 - $js = preg_replace("/[\n\r]/", "", $js); //remove newlines
56 - $js = preg_replace("/[\s]{2,}/", " ", $js); //remove spaces
 52+ private static function minifyJavascript($js) {
 53+ $js = preg_replace("/[\n\r]/", "", $js); //remove newlines
 54+ $js = preg_replace("/[\s]{2,}/", " ", $js); //remove spaces
5755
58 - return $js;
59 - }
 56+ return $js;
 57+ }
6058
61 - private static function getAsJSEncodedString($s)
62 - {
63 - return "'$s'";
64 - }
 59+ private static function getAsJSEncodedString($s) {
 60+ return "'$s'";
 61+ }
6562
66 - private static function getJSConfig($config){
67 - //javascript config output
68 - $jsOutput = Html::inlineScript("
 63+ private static function getJSConfig($config) {
 64+ //javascript config output
 65+ $jsOutput = Html::inlineScript("
6966 var sidebarmenu = {
7067 config: {
7168 controls: {
@@ -77,18 +74,17 @@
7875 }
7976 };
8077 ");
81 - //minify js to prevent <p> tags to be rendered
82 - return self::minifyJavascript($jsOutput);
83 - }
 78+ //minify js to prevent <p> tags to be rendered
 79+ return self::minifyJavascript($jsOutput);
 80+ }
8481
85 - private static function getTagConfig($args)
86 - {
87 - global $wgSideBarMenuConfig;
88 - $config[SBM_EXPANDED] = array_key_exists(SBM_EXPANDED, $args) ? filter_var($args[SBM_EXPANDED], FILTER_VALIDATE_BOOLEAN) : $wgSideBarMenuConfig[SBM_EXPANDED];
89 - $config[SBM_CONTROLS_SHOW] = array_key_exists(SBM_CONTROLS_SHOW, $args) ? $args[SBM_CONTROLS_SHOW] : (isset($wgSideBarMenuConfig[SBM_CONTROLS_SHOW]) ? $wgSideBarMenuConfig[SBM_CONTROLS_SHOW] : '['.wfMsg('showtoc').']');
90 - $config[SBM_CONTROLS_HIDE] = array_key_exists(SBM_CONTROLS_HIDE, $args) ? $args[SBM_CONTROLS_HIDE] : (isset($wgSideBarMenuConfig[SBM_CONTROLS_HIDE]) ? $wgSideBarMenuConfig[SBM_CONTROLS_HIDE] : '['.wfMsg('hidetoc').']');
91 - $config[SBM_JS_ANIMATE] = array_key_exists(SBM_JS_ANIMATE, $args) ? $args[SBM_JS_ANIMATE] : $wgSideBarMenuConfig[SBM_JS_ANIMATE];
92 - $config[SBM_EDIT_LINK] = array_key_exists(SBM_EDIT_LINK, $args) ? filter_var($args[SBM_EDIT_LINK], FILTER_VALIDATE_BOOLEAN) : $wgSideBarMenuConfig[SBM_EDIT_LINK];
93 - return $config;
94 - }
 82+ private static function getTagConfig($args) {
 83+ global $wgSideBarMenuConfig;
 84+ $config[SBM_EXPANDED] = array_key_exists(SBM_EXPANDED, $args) ? filter_var($args[SBM_EXPANDED], FILTER_VALIDATE_BOOLEAN) : $wgSideBarMenuConfig[SBM_EXPANDED];
 85+ $config[SBM_CONTROLS_SHOW] = array_key_exists(SBM_CONTROLS_SHOW, $args) ? $args[SBM_CONTROLS_SHOW] : (isset($wgSideBarMenuConfig[SBM_CONTROLS_SHOW]) ? $wgSideBarMenuConfig[SBM_CONTROLS_SHOW] : '[' . wfMsg('showtoc') . ']');
 86+ $config[SBM_CONTROLS_HIDE] = array_key_exists(SBM_CONTROLS_HIDE, $args) ? $args[SBM_CONTROLS_HIDE] : (isset($wgSideBarMenuConfig[SBM_CONTROLS_HIDE]) ? $wgSideBarMenuConfig[SBM_CONTROLS_HIDE] : '[' . wfMsg('hidetoc') . ']');
 87+ $config[SBM_JS_ANIMATE] = array_key_exists(SBM_JS_ANIMATE, $args) ? $args[SBM_JS_ANIMATE] : $wgSideBarMenuConfig[SBM_JS_ANIMATE];
 88+ $config[SBM_EDIT_LINK] = array_key_exists(SBM_EDIT_LINK, $args) ? filter_var($args[SBM_EDIT_LINK], FILTER_VALIDATE_BOOLEAN) : $wgSideBarMenuConfig[SBM_EDIT_LINK];
 89+ return $config;
 90+ }
9591 }
Index: trunk/extensions/SideBarMenu/includes/MenuParser.php
@@ -1,123 +1,119 @@
22 <?php
33 class MenuParser {
44
5 - private $expandedByDefault;
 5+ private $expandedByDefault;
66
7 - function __construct($expandedByDefault)
8 - {
9 - $this->expandedByDefault = $expandedByDefault;
10 - }
 7+ function __construct($expandedByDefault) {
 8+ $this->expandedByDefault = $expandedByDefault;
 9+ }
1110
1211
13 - public function isValidInput($data)
14 - {
15 - return !(is_null($data) || strlen($data) == 0);
16 - }
 12+ public function isValidInput($data) {
 13+ return !(is_null($data) || strlen($data) == 0);
 14+ }
1715
1816
19 - public function getLevel($line)
20 - {
21 - return substr_count($line, '*');
22 - }
 17+ public function getLevel($line) {
 18+ return substr_count($line, '*');
 19+ }
2320
24 - public function getExpandedParameter($line)
25 - {
26 - if ($this->startsWith($line, '+')) {
27 - return true;
28 - } else if($this->startsWith($line, '-')) {
29 - return false;
30 - }
31 - return $this->expandedByDefault;
32 - }
 21+ public function getExpandedParameter($line) {
 22+ if ($this->startsWith($line, '+')) {
 23+ return true;
 24+ } else {
 25+ if ($this->startsWith($line, '-')) {
 26+ return false;
 27+ }
 28+ }
 29+ return $this->expandedByDefault;
 30+ }
3331
34 - public function getTextParameter($line)
35 - {
36 - return preg_filter("/\+|\-?\**(.*)/", "$1", $line);
37 - }
 32+ public function getTextParameter($line) {
 33+ return preg_filter("/\+|\-?\**(.*)/", "$1", $line);
 34+ }
3835
3936
40 - public function getMenuTree($data){
41 - if($this->isValidInput($data)){
42 - $data = $this->cleanupData($data);
43 - $root = new MenuItem();
44 - $root->setExpanded(true);
45 - $arrayData = $this->parseDataIntoHierarchicalArray($data);
46 - $this->addChildrenToMenuItemFromArrayData($root,$arrayData);
47 - return $root;
48 - }
49 - return null;
50 - }
 37+ public function getMenuTree($data) {
 38+ if ($this->isValidInput($data)) {
 39+ $data = $this->cleanupData($data);
 40+ $root = new MenuItem();
 41+ $root->setExpanded(true);
 42+ $arrayData = $this->parseDataIntoHierarchicalArray($data);
 43+ $this->addChildrenToMenuItemFromArrayData($root, $arrayData);
 44+ return $root;
 45+ }
 46+ return null;
 47+ }
5148
5249
53 - public function getMenuItem($line)
54 - {
55 - $line = trim($line);
56 - if($this->isValidInput($line)){
57 - $menuItem = new MenuItem();
58 - $menuItem->setExpanded($this->getExpandedParameter($line));
59 - $menuItem->setText($this->getTextParameter($line));
60 - return $menuItem;
61 - }else{
62 - throw new InvalidArgumentException();
63 - }
64 - }
 50+ public function getMenuItem($line) {
 51+ $line = trim($line);
 52+ if ($this->isValidInput($line)) {
 53+ $menuItem = new MenuItem();
 54+ $menuItem->setExpanded($this->getExpandedParameter($line));
 55+ $menuItem->setText($this->getTextParameter($line));
 56+ return $menuItem;
 57+ } else {
 58+ throw new InvalidArgumentException();
 59+ }
 60+ }
6561
66 - public function parseDataIntoHierarchicalArray($data)
67 - {
68 - $rootArray = array();
69 - $prevLevel = 0;
70 - $levelArray[0] = &$rootArray;
71 - foreach(preg_split("/\n/",$data) as $line){
72 - $level = $this->getLevel($line);
73 - if($level == $prevLevel){
74 - $levelArray[$level][] = $line;
75 - }else if($level-1 == $prevLevel){
76 - //child of previous line
77 - $parent = array_pop($levelArray[$level-1]);
78 - $levelArray[$level-1][$parent][] = $line;
79 - $levelArray[$level] = &$levelArray[$level-1][$parent];
80 - }else if($level < $prevLevel){
81 - //back some levels
82 - $levelArray[$level][] = $line;
83 - }else{
84 - //syntax error
85 - throw new InvalidArgumentException(wfMsg('sidebarmenu-parser-syntax-error',$line));
86 - }
87 - $prevLevel = $level;
88 - }
89 - return $rootArray;
90 - }
 62+ public function parseDataIntoHierarchicalArray($data) {
 63+ $rootArray = array();
 64+ $prevLevel = 0;
 65+ $levelArray[0] = &$rootArray;
 66+ foreach (preg_split("/\n/", $data) as $line) {
 67+ $level = $this->getLevel($line);
 68+ if ($level == $prevLevel) {
 69+ $levelArray[$level][] = $line;
 70+ } else {
 71+ if ($level - 1 == $prevLevel) {
 72+ //child of previous line
 73+ $parent = array_pop($levelArray[$level - 1]);
 74+ $levelArray[$level - 1][$parent][] = $line;
 75+ $levelArray[$level] = &$levelArray[$level - 1][$parent];
 76+ } else {
 77+ if ($level < $prevLevel) {
 78+ //back some levels
 79+ $levelArray[$level][] = $line;
 80+ } else {
 81+ //syntax error
 82+ throw new InvalidArgumentException(wfMsg('sidebarmenu-parser-syntax-error', $line));
 83+ }
 84+ }
 85+ }
 86+ $prevLevel = $level;
 87+ }
 88+ return $rootArray;
 89+ }
9190
92 - public function addChildrenToMenuItemFromArrayData(MenuItem &$rootMenuItem,$arrayData)
93 - {
94 - foreach ($arrayData as $key => $val) {
95 - if (is_string($key)) {
96 - $menuItem = $this->getMenuItem($key);
97 - $rootMenuItem->addChild($menuItem);
98 - $this->addChildrenToMenuItemFromArrayData($menuItem,$val);
99 - } else {
100 - $menuItem = $this->getMenuItem($val);
101 - $rootMenuItem->addChild($menuItem);
102 - }
103 - }
104 - }
 91+ public function addChildrenToMenuItemFromArrayData(MenuItem &$rootMenuItem, $arrayData) {
 92+ foreach ($arrayData as $key => $val) {
 93+ if (is_string($key)) {
 94+ $menuItem = $this->getMenuItem($key);
 95+ $rootMenuItem->addChild($menuItem);
 96+ $this->addChildrenToMenuItemFromArrayData($menuItem, $val);
 97+ } else {
 98+ $menuItem = $this->getMenuItem($val);
 99+ $rootMenuItem->addChild($menuItem);
 100+ }
 101+ }
 102+ }
105103
106 - private static function startsWith($haystack, $needle)
107 - {
108 - $length = strlen($needle);
109 - return (substr($haystack, 0, $length) === $needle);
110 - }
 104+ private static function startsWith($haystack, $needle) {
 105+ $length = strlen($needle);
 106+ return (substr($haystack, 0, $length) === $needle);
 107+ }
111108
112 - private static function cleanupData($data){
113 - return trim($data,"\n ");
114 - }
 109+ private static function cleanupData($data) {
 110+ return trim($data, "\n ");
 111+ }
115112
116 - private static function removeLineBreaksFromStartOfString($data)
117 - {
118 - while (self::startsWith($data, "\n")) {
119 - $data = substr($data, 1);
120 - }
121 - return $data;
122 - }
 113+ private static function removeLineBreaksFromStartOfString($data) {
 114+ while (self::startsWith($data, "\n")) {
 115+ $data = substr($data, 1);
 116+ }
 117+ return $data;
 118+ }
123119
124120 }
Index: trunk/extensions/SideBarMenu/includes/MenuItem.php
@@ -1,125 +1,113 @@
22 <?php
33
4 -class MenuItem
5 -{
6 - private $expanded = false;
7 - private $children = array();
8 - private $parent = null;
9 - private $text;
 4+class MenuItem {
 5+ private $expanded = false;
 6+ private $children = array();
 7+ private $parent = null;
 8+ private $text;
109
1110
12 - public function setExpanded($expanded)
13 - {
14 - if(is_null($expanded)){
15 - throw new InvalidArgumentException(wfMsg('sidebarmenu-parser-menuitem-expanded-null'));
16 - }else{
17 - $this->expanded = $expanded;
18 - }
19 - }
 11+ public function setExpanded($expanded) {
 12+ if (is_null($expanded)) {
 13+ throw new InvalidArgumentException(wfMsg('sidebarmenu-parser-menuitem-expanded-null'));
 14+ } else {
 15+ $this->expanded = $expanded;
 16+ }
 17+ }
2018
21 - public function isExpanded()
22 - {
23 - return $this->expanded;
24 - }
 19+ public function isExpanded() {
 20+ return $this->expanded;
 21+ }
2522
26 - public function setText($link)
27 - {
28 - $this->text = $link;
29 - }
 23+ public function setText($link) {
 24+ $this->text = $link;
 25+ }
3026
31 - public function getText()
32 - {
33 - return $this->text;
34 - }
 27+ public function getText() {
 28+ return $this->text;
 29+ }
3530
36 - public function addChild(MenuItem $child)
37 - {
38 - if(!in_array($child,$this->children)){
39 - $this->children[] = $child;
40 - $child->setParent($this);
41 - }
42 - }
 31+ public function addChild(MenuItem $child) {
 32+ if (!in_array($child, $this->children)) {
 33+ $this->children[] = $child;
 34+ $child->setParent($this);
 35+ }
 36+ }
4337
44 - public function getChildren()
45 - {
46 - return $this->children;
47 - }
 38+ public function getChildren() {
 39+ return $this->children;
 40+ }
4841
49 - public function hasChildren()
50 - {
51 - return sizeof($this->children) > 0;
52 - }
 42+ public function hasChildren() {
 43+ return sizeof($this->children) > 0;
 44+ }
5345
54 - public function setParent(MenuItem $parent)
55 - {
56 - if($this->parent !== $parent){
57 - $this->parent = $parent;
58 - $parent->addChild($this);
59 - }
60 - }
 46+ public function setParent(MenuItem $parent) {
 47+ if ($this->parent !== $parent) {
 48+ $this->parent = $parent;
 49+ $parent->addChild($this);
 50+ }
 51+ }
6152
62 - public function getParent()
63 - {
64 - return $this->parent;
65 - }
66 -
67 - public function isRoot(){
68 - return is_null($this->parent);
69 - }
 53+ public function getParent() {
 54+ return $this->parent;
 55+ }
7056
71 - public function getLevel(){
72 - if($this->isRoot()){
73 - return 0;
74 - }else{
75 - return 1+$this->getParent()->getLevel();
76 - }
77 - }
 57+ public function isRoot() {
 58+ return is_null($this->parent);
 59+ }
7860
79 - public function toHTML()
80 - {
81 - $output = "";
82 - if($this->isRoot()){
83 - $output .= $this->childrenToHTML();
84 - }else{
85 - $itemClasses[] = 'sidebar-menu-item';
86 - $itemClasses[] = 'sidebar-menu-item-'.$this->getLevel();
 61+ public function getLevel() {
 62+ if ($this->isRoot()) {
 63+ return 0;
 64+ } else {
 65+ return 1 + $this->getParent()->getLevel();
 66+ }
 67+ }
8768
88 - if($this->hasChildren()){
89 - $itemClasses[] = $this->isExpanded() ? 'sidebar-menu-item-expanded' : 'sidebar-menu-item-collapsed';
90 - }
 69+ public function toHTML() {
 70+ $output = "";
 71+ if ($this->isRoot()) {
 72+ $output .= $this->childrenToHTML();
 73+ } else {
 74+ $itemClasses[] = 'sidebar-menu-item';
 75+ $itemClasses[] = 'sidebar-menu-item-' . $this->getLevel();
9176
92 - $textClasses[] = 'sidebar-menu-item-text';
93 - $textClasses[] = 'sidebar-menu-item-text-'.$this->getLevel();
 77+ if ($this->hasChildren()) {
 78+ $itemClasses[] = $this->isExpanded() ? 'sidebar-menu-item-expanded' : 'sidebar-menu-item-collapsed';
 79+ }
9480
95 - $output .= "<li class=\"".join(' ',$itemClasses)."\">";
96 - $output .= "<div class=\"sidebar-menu-item-text-container\">";
97 - $output .= "<span class=\"".join(' ',$textClasses)."\">".$this->getText()."</span>";
 81+ $textClasses[] = 'sidebar-menu-item-text';
 82+ $textClasses[] = 'sidebar-menu-item-text-' . $this->getLevel();
9883
99 - if($this->hasChildren()){
100 - $output .= "<span class=\"sidebar-menu-item-controls\"></span>";
101 - }
 84+ $output .= "<li class=\"" . join(' ', $itemClasses) . "\">";
 85+ $output .= "<div class=\"sidebar-menu-item-text-container\">";
 86+ $output .= "<span class=\"" . join(' ', $textClasses) . "\">" . $this->getText() . "</span>";
10287
103 - $output .= "</div>";
104 - $output .= $this->childrenToHTML();
105 - $output .= "</li>";
106 - }
 88+ if ($this->hasChildren()) {
 89+ $output .= "<span class=\"sidebar-menu-item-controls\"></span>";
 90+ }
10791
108 - return $output;
109 - }
 92+ $output .= "</div>";
 93+ $output .= $this->childrenToHTML();
 94+ $output .= "</li>";
 95+ }
11096
111 - private function childrenToHTML()
112 - {
113 - if($this->hasChildren()){
114 - $menuClasses[] = 'sidebar-menu';
115 - $menuClasses[] = 'sidebar-menu-'.$this->getLevel();
 97+ return $output;
 98+ }
11699
117 - $output = "<ul class=\"".join(' ',$menuClasses)."\">";
118 - foreach ($this->getChildren() as $child) {
119 - $output .= $child->toHTML();
120 - }
121 - $output .= "</ul>";
122 - return $output;
123 - }
124 - }
 100+ private function childrenToHTML() {
 101+ if ($this->hasChildren()) {
 102+ $menuClasses[] = 'sidebar-menu';
 103+ $menuClasses[] = 'sidebar-menu-' . $this->getLevel();
125104
 105+ $output = "<ul class=\"" . join(' ', $menuClasses) . "\">";
 106+ foreach ($this->getChildren() as $child) {
 107+ $output .= $child->toHTML();
 108+ }
 109+ $output .= "</ul>";
 110+ return $output;
 111+ }
 112+ }
 113+
126114 }
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css
@@ -1,38 +1,38 @@
22 /* default SideBarMenu extension styling */
33
4 -.sidebar-menu-container{
 4+.sidebar-menu-container {
55 padding: 5px;
66 float: left;
77 clear: left;
88 margin: 5px;
99 }
1010
11 -.sidebar-menu-item-collapsed .sidebar-menu{
 11+.sidebar-menu-item-collapsed .sidebar-menu {
1212 display: none;
1313 }
 14+
1415 .sidebar-menu-item-expanded {
1516 display: list-item;
1617 }
1718
18 -.sidebar-menu-0,.sidebar-menu-1{
 19+.sidebar-menu-0, .sidebar-menu-1 {
1920 margin: 0px !important;
2021 padding: 0px !important;
2122 list-style: none;
2223 }
2324
24 -
25 -.sidebar-menu-item-1{
 25+.sidebar-menu-item-1 {
2626 margin: 10px 0px;
2727 background-color: #f2f2f2;
2828 }
2929
30 -.sidebar-menu-item-1 > .sidebar-menu-item-text-container{
 30+.sidebar-menu-item-1 > .sidebar-menu-item-text-container {
3131 border: 1px solid #aaa;
3232 border-bottom: 0px;
3333 padding: 3px;
3434 }
3535
36 -.sidebar-menu-item-2{
 36+.sidebar-menu-item-2 {
3737 background-color: #f9f9f9;
3838 border: 1px solid #aaa;
3939 border-bottom: 0px;
@@ -40,11 +40,11 @@
4141 margin-bottom: 0px !important;
4242 }
4343
44 -.sidebar-menu-item-text-container{
 44+.sidebar-menu-item-text-container {
4545 position: relative;
4646 }
4747
48 -.sidebar-menu-item-controls{
 48+.sidebar-menu-item-controls {
4949 float: right;
5050 color: #0645AD;
5151 cursor: pointer;
@@ -55,7 +55,7 @@
5656 user-select: none;
5757 }
5858
59 -.sidebar-menu-item-1{
 59+.sidebar-menu-item-1 {
6060 border-bottom: 1px solid #aaa;
6161 }
6262
Index: trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js
@@ -1,5 +1,5 @@
2 -$(document).ready(function(){
3 - if(typeof(sidebarmenu) !== 'undefined'){
 2+$(document).ready(function () {
 3+ if (typeof(sidebarmenu) !== 'undefined') {
44 var showText = sidebarmenu.config.controls.show;
55 var hideText = sidebarmenu.config.controls.hide;
66 var useAnimations = sidebarmenu.config.js.animate;
@@ -10,28 +10,28 @@
1111 }
1212
1313 initControls();
14 - $('.sidebar-menu-item-controls').click(function(){
 14+ $('.sidebar-menu-item-controls').click(function () {
1515 var currentText = $(this).text();
1616
17 - if(currentText == showText){
 17+ if (currentText == showText) {
1818 $(this).text(hideText);
19 - }else if(currentText == hideText){
 19+ } else if (currentText == hideText) {
2020 $(this).text(showText);
2121 }
2222
23 - if(useAnimations){
24 - //A little "ugly" hack to prevent some gui glitches.
25 - $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded',250).children('.sidebar-menu').show(0,function(){
 23+ if (useAnimations) {
 24+ //A little "ugly" hack to prevent some gui glitches.
 25+ $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded', 250).children('.sidebar-menu').show(0, function () {
2626 var _this = $(this);
27 - setTimeout(function(){
28 - _this.css('display','')
29 - },250);
 27+ setTimeout(function () {
 28+ _this.css('display', '')
 29+ }, 250);
3030 });
31 - }else{
 31+ } else {
3232 $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded');
3333 }
3434 });
35 - }else{
 35+ } else {
3636 $('.sidebar-menu-container').prepend(mw.msg('sidebar-js-init-error'));
3737 }
3838 });
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114595added edit parameter. Wheter to display a edit link for sidebarmenu.netbrain08:56, 29 March 2012

Status & tagging log