Index: trunk/extensions/SideBarMenu/test/MenuParserTest.php |
— | — | @@ -1,213 +1,211 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class MenuParserTest extends MediaWikiTestCase |
5 | | -{ |
| 4 | +class MenuParserTest extends MediaWikiTestCase { |
6 | 5 | |
7 | | - private $menuParser; |
| 6 | + private $menuParser; |
8 | 7 | |
9 | | - protected function setUp() |
10 | | - { |
11 | | - $this->menuParser = new MenuParser(true); |
12 | | - } |
| 8 | + protected function setUp() { |
| 9 | + $this->menuParser = new MenuParser(true); |
| 10 | + } |
13 | 11 | |
14 | | - public function testValidInputWhenNull(){ |
15 | | - $this->assertFalse($this->menuParser->isValidInput(null)); |
16 | | - } |
| 12 | + public function testValidInputWhenNull() { |
| 13 | + $this->assertFalse($this->menuParser->isValidInput(null)); |
| 14 | + } |
17 | 15 | |
18 | | - public function testValidInputWhenEmpty(){ |
19 | | - $this->assertFalse($this->menuParser->isValidInput("")); |
20 | | - } |
| 16 | + public function testValidInputWhenEmpty() { |
| 17 | + $this->assertFalse($this->menuParser->isValidInput("")); |
| 18 | + } |
21 | 19 | |
22 | | - public function testValidInput(){ |
23 | | - $this->assertTrue($this->menuParser->isValidInput("+MenuItem")); |
24 | | - } |
| 20 | + public function testValidInput() { |
| 21 | + $this->assertTrue($this->menuParser->isValidInput("+MenuItem")); |
| 22 | + } |
25 | 23 | |
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 | + } |
29 | 27 | |
30 | | - public function testGetLevelWhenEmpty(){ |
31 | | - $this->assertEquals(0,$this->menuParser->getLevel("")); |
32 | | - } |
| 28 | + public function testGetLevelWhenEmpty() { |
| 29 | + $this->assertEquals(0, $this->menuParser->getLevel("")); |
| 30 | + } |
33 | 31 | |
34 | | - public function testGetLevelWhenValidButNoStars(){ |
35 | | - $this->assertEquals(0,$this->menuParser->getLevel("")); |
36 | | - } |
| 32 | + public function testGetLevelWhenValidButNoStars() { |
| 33 | + $this->assertEquals(0, $this->menuParser->getLevel("")); |
| 34 | + } |
37 | 35 | |
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 | + } |
41 | 39 | |
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 | + } |
48 | 46 | |
49 | | - public function testGetExpandedParameterWhenNotExpanded(){ |
50 | | - $this->assertFalse($this->menuParser->getExpandedParameter("-MenuItem")); |
51 | | - } |
| 47 | + public function testGetExpandedParameterWhenNotExpanded() { |
| 48 | + $this->assertFalse($this->menuParser->getExpandedParameter("-MenuItem")); |
| 49 | + } |
52 | 50 | |
53 | | - public function testGetExpandedParameterWhenExpanded(){ |
54 | | - $this->assertTrue($this->menuParser->getExpandedParameter("+MenuItem")); |
55 | | - } |
| 51 | + public function testGetExpandedParameterWhenExpanded() { |
| 52 | + $this->assertTrue($this->menuParser->getExpandedParameter("+MenuItem")); |
| 53 | + } |
56 | 54 | |
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 | + } |
65 | 63 | |
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 | + } |
70 | 68 | |
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 | + } |
75 | 73 | |
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 | + } |
83 | 81 | |
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 | + } |
92 | 90 | |
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 | + } |
99 | 97 | |
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 | + } |
114 | 112 | |
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 | + } |
131 | 129 | |
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 | + } |
146 | 144 | |
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 | + } |
165 | 163 | |
166 | 164 | |
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 | + } |
171 | 169 | |
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())); |
177 | 175 | |
178 | | - $children = $menu->getChildren(); |
179 | | - $this->assertEquals("MenuItem",$children[0]->getText()); |
180 | | - } |
| 176 | + $children = $menu->getChildren(); |
| 177 | + $this->assertEquals("MenuItem", $children[0]->getText()); |
| 178 | + } |
181 | 179 | |
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())); |
196 | 194 | |
197 | | - } |
| 195 | + } |
198 | 196 | |
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())); |
209 | 207 | |
210 | | - $children = $menu->getChildren(); |
211 | | - $this->assertEquals("MenuItem1",$children[0]->getText()); |
| 208 | + $children = $menu->getChildren(); |
| 209 | + $this->assertEquals("MenuItem1", $children[0]->getText()); |
212 | 210 | |
213 | | - } |
| 211 | + } |
214 | 212 | } |
Index: trunk/extensions/SideBarMenu/test/MenuItemTest.php |
— | — | @@ -1,104 +1,102 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class MenuItemTest extends MediaWikiTestCase |
5 | | -{ |
6 | | - private $menuItem; |
| 4 | +class MenuItemTest extends MediaWikiTestCase { |
| 5 | + private $menuItem; |
7 | 6 | |
8 | | - protected function setUp() |
9 | | - { |
10 | | - $this->menuItem = new MenuItem(); |
11 | | - } |
| 7 | + protected function setUp() { |
| 8 | + $this->menuItem = new MenuItem(); |
| 9 | + } |
12 | 10 | |
13 | | - public function testIsRoot(){ |
14 | | - $this->assertTrue($this->menuItem->isRoot()); |
15 | | - } |
| 11 | + public function testIsRoot() { |
| 12 | + $this->assertTrue($this->menuItem->isRoot()); |
| 13 | + } |
16 | 14 | |
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 | + } |
21 | 19 | |
22 | | - public function testGetLevelWhenRoot(){ |
23 | | - $this->assertEquals(0,$this->menuItem->getLevel()); |
24 | | - } |
| 20 | + public function testGetLevelWhenRoot() { |
| 21 | + $this->assertEquals(0, $this->menuItem->getLevel()); |
| 22 | + } |
25 | 23 | |
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 | + } |
30 | 28 | |
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; |
37 | 35 | |
38 | | - } |
39 | | - $this->assertEquals(10,$prev->getLevel()); |
40 | | - } |
| 36 | + } |
| 37 | + $this->assertEquals(10, $prev->getLevel()); |
| 38 | + } |
41 | 39 | |
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 | + } |
48 | 46 | |
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 | + } |
56 | 54 | |
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 | + } |
62 | 60 | |
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 | + } |
67 | 65 | |
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 | + } |
75 | 73 | |
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"); |
81 | 79 | |
82 | | - $this->menuItem->addChild($menuItemChild1); |
83 | | - $this->menuItem->addChild($menuItemChild2); |
| 80 | + $this->menuItem->addChild($menuItemChild1); |
| 81 | + $this->menuItem->addChild($menuItemChild2); |
84 | 82 | |
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 | + } |
88 | 86 | |
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"); |
94 | 92 | |
95 | | - $this->menuItem->addChild($menuItemChild1); |
96 | | - $this->menuItem->addChild($menuItemChild2); |
| 93 | + $this->menuItem->addChild($menuItemChild1); |
| 94 | + $this->menuItem->addChild($menuItemChild2); |
97 | 95 | |
98 | | - $subLevel1 = new MenuItem(); |
99 | | - $subLevel1->setText("SubMenuItem1"); |
100 | | - $subLevel1->setParent($menuItemChild2); |
| 96 | + $subLevel1 = new MenuItem(); |
| 97 | + $subLevel1->setText("SubMenuItem1"); |
| 98 | + $subLevel1->setParent($menuItemChild2); |
101 | 99 | |
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 | + } |
105 | 103 | } |
Index: trunk/extensions/SideBarMenu/SideBarMenu.i18n.php |
— | — | @@ -9,15 +9,15 @@ |
10 | 10 | $messages = array(); |
11 | 11 | |
12 | 12 | /** English |
13 | | - * @author Kim Eik |
| 13 | + * @author Kim Eik |
14 | 14 | */ |
15 | 15 | $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' |
22 | 22 | ); |
23 | 23 | |
24 | 24 | /** Message documentation (Message documentation) |
Index: trunk/extensions/SideBarMenu/SideBarMenu.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | if (!defined('MEDIAWIKI')) { |
5 | | - die('Not an entry point.'); |
| 5 | + die('Not an entry point.'); |
6 | 6 | } |
7 | 7 | |
8 | 8 | //SideBarMenu constants |
— | — | @@ -14,18 +14,18 @@ |
15 | 15 | |
16 | 16 | //default settings |
17 | 17 | $wgSideBarMenuConfig[SBM_CONTROLS_SHOW] = null; |
18 | | -$wgSideBarMenuConfig[SBM_CONTROLS_HIDE]= null; |
| 18 | +$wgSideBarMenuConfig[SBM_CONTROLS_HIDE] = null; |
19 | 19 | $wgSideBarMenuConfig[SBM_JS_ANIMATE] = true; |
20 | 20 | $wgSideBarMenuConfig[SBM_EXPANDED] = true; |
21 | 21 | $wgSideBarMenuConfig[SBM_EDIT_LINK] = true; |
22 | 22 | |
23 | 23 | $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' |
30 | 30 | ); |
31 | 31 | |
32 | 32 | |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | $wgHooks['UnitTestsList'][] = 'SideBarMenuHooks::registerUnitTests'; |
41 | 41 | |
42 | 42 | //Autoload hooks |
43 | | -$wgAutoloadClasses['SideBarMenuHooks'] = dirname( __FILE__ ) . '/SideBarMenu.hooks.php'; |
| 43 | +$wgAutoloadClasses['SideBarMenuHooks'] = dirname(__FILE__) . '/SideBarMenu.hooks.php'; |
44 | 44 | |
45 | 45 | //Autoload classes |
46 | 46 | $wgMyExtensionIncludes = dirname(__FILE__) . '/includes'; |
— | — | @@ -48,25 +48,25 @@ |
49 | 49 | $wgAutoloadClasses['MenuItem'] = $wgMyExtensionIncludes . '/MenuItem.php'; |
50 | 50 | |
51 | 51 | //i18n |
52 | | -$wgExtensionMessagesFiles['SideBarMenu'] = dirname( __FILE__ ) . '/SideBarMenu.i18n.php'; |
| 52 | +$wgExtensionMessagesFiles['SideBarMenu'] = dirname(__FILE__) . '/SideBarMenu.i18n.php'; |
53 | 53 | |
54 | 54 | //Resources |
55 | 55 | $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', |
65 | 65 | |
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' |
73 | 73 | ); |
Index: trunk/extensions/SideBarMenu/SideBarMenu.hooks.php |
— | — | @@ -1,70 +1,67 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class SideBarMenuHooks |
5 | | -{ |
| 4 | +class SideBarMenuHooks { |
6 | 5 | |
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 | + } |
11 | 10 | |
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'); |
14 | 13 | |
15 | | - //default settings |
16 | | - $config = self::getTagConfig($args); |
| 14 | + //default settings |
| 15 | + $config = self::getTagConfig($args); |
17 | 16 | |
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()); |
28 | 24 | } |
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>'; |
30 | 29 | |
31 | | - $jsOutput = self::getJSConfig($config); |
| 30 | + $jsOutput = self::getJSConfig($config); |
32 | 31 | |
33 | | - return array( $jsOutput.$output, 'noparse' => true, 'isHTML' => true ); |
34 | | - } |
| 32 | + return array($jsOutput . $output, 'noparse' => true, 'isHTML' => true); |
| 33 | + } |
35 | 34 | |
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 | + } |
47 | 46 | |
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 | + } |
52 | 51 | |
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 |
57 | 55 | |
58 | | - return $js; |
59 | | - } |
| 56 | + return $js; |
| 57 | + } |
60 | 58 | |
61 | | - private static function getAsJSEncodedString($s) |
62 | | - { |
63 | | - return "'$s'"; |
64 | | - } |
| 59 | + private static function getAsJSEncodedString($s) { |
| 60 | + return "'$s'"; |
| 61 | + } |
65 | 62 | |
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(" |
69 | 66 | var sidebarmenu = { |
70 | 67 | config: { |
71 | 68 | controls: { |
— | — | @@ -77,18 +74,17 @@ |
78 | 75 | } |
79 | 76 | }; |
80 | 77 | "); |
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 | + } |
84 | 81 | |
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 | + } |
95 | 91 | } |
Index: trunk/extensions/SideBarMenu/includes/MenuParser.php |
— | — | @@ -1,123 +1,119 @@ |
2 | 2 | <?php |
3 | 3 | class MenuParser { |
4 | 4 | |
5 | | - private $expandedByDefault; |
| 5 | + private $expandedByDefault; |
6 | 6 | |
7 | | - function __construct($expandedByDefault) |
8 | | - { |
9 | | - $this->expandedByDefault = $expandedByDefault; |
10 | | - } |
| 7 | + function __construct($expandedByDefault) { |
| 8 | + $this->expandedByDefault = $expandedByDefault; |
| 9 | + } |
11 | 10 | |
12 | 11 | |
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 | + } |
17 | 15 | |
18 | 16 | |
19 | | - public function getLevel($line) |
20 | | - { |
21 | | - return substr_count($line, '*'); |
22 | | - } |
| 17 | + public function getLevel($line) { |
| 18 | + return substr_count($line, '*'); |
| 19 | + } |
23 | 20 | |
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 | + } |
33 | 31 | |
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 | + } |
38 | 35 | |
39 | 36 | |
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 | + } |
51 | 48 | |
52 | 49 | |
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 | + } |
65 | 61 | |
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 | + } |
91 | 90 | |
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 | + } |
105 | 103 | |
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 | + } |
111 | 108 | |
112 | | - private static function cleanupData($data){ |
113 | | - return trim($data,"\n "); |
114 | | - } |
| 109 | + private static function cleanupData($data) { |
| 110 | + return trim($data, "\n "); |
| 111 | + } |
115 | 112 | |
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 | + } |
123 | 119 | |
124 | 120 | } |
Index: trunk/extensions/SideBarMenu/includes/MenuItem.php |
— | — | @@ -1,125 +1,113 @@ |
2 | 2 | <?php |
3 | 3 | |
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; |
10 | 9 | |
11 | 10 | |
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 | + } |
20 | 18 | |
21 | | - public function isExpanded() |
22 | | - { |
23 | | - return $this->expanded; |
24 | | - } |
| 19 | + public function isExpanded() { |
| 20 | + return $this->expanded; |
| 21 | + } |
25 | 22 | |
26 | | - public function setText($link) |
27 | | - { |
28 | | - $this->text = $link; |
29 | | - } |
| 23 | + public function setText($link) { |
| 24 | + $this->text = $link; |
| 25 | + } |
30 | 26 | |
31 | | - public function getText() |
32 | | - { |
33 | | - return $this->text; |
34 | | - } |
| 27 | + public function getText() { |
| 28 | + return $this->text; |
| 29 | + } |
35 | 30 | |
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 | + } |
43 | 37 | |
44 | | - public function getChildren() |
45 | | - { |
46 | | - return $this->children; |
47 | | - } |
| 38 | + public function getChildren() { |
| 39 | + return $this->children; |
| 40 | + } |
48 | 41 | |
49 | | - public function hasChildren() |
50 | | - { |
51 | | - return sizeof($this->children) > 0; |
52 | | - } |
| 42 | + public function hasChildren() { |
| 43 | + return sizeof($this->children) > 0; |
| 44 | + } |
53 | 45 | |
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 | + } |
61 | 52 | |
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 | + } |
70 | 56 | |
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 | + } |
78 | 60 | |
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 | + } |
87 | 68 | |
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(); |
91 | 76 | |
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 | + } |
94 | 80 | |
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(); |
98 | 83 | |
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>"; |
102 | 87 | |
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 | + } |
107 | 91 | |
108 | | - return $output; |
109 | | - } |
| 92 | + $output .= "</div>"; |
| 93 | + $output .= $this->childrenToHTML(); |
| 94 | + $output .= "</li>"; |
| 95 | + } |
110 | 96 | |
111 | | - private function childrenToHTML() |
112 | | - { |
113 | | - if($this->hasChildren()){ |
114 | | - $menuClasses[] = 'sidebar-menu'; |
115 | | - $menuClasses[] = 'sidebar-menu-'.$this->getLevel(); |
| 97 | + return $output; |
| 98 | + } |
116 | 99 | |
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(); |
125 | 104 | |
| 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 | + |
126 | 114 | } |
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css |
— | — | @@ -1,38 +1,38 @@ |
2 | 2 | /* default SideBarMenu extension styling */ |
3 | 3 | |
4 | | -.sidebar-menu-container{ |
| 4 | +.sidebar-menu-container { |
5 | 5 | padding: 5px; |
6 | 6 | float: left; |
7 | 7 | clear: left; |
8 | 8 | margin: 5px; |
9 | 9 | } |
10 | 10 | |
11 | | -.sidebar-menu-item-collapsed .sidebar-menu{ |
| 11 | +.sidebar-menu-item-collapsed .sidebar-menu { |
12 | 12 | display: none; |
13 | 13 | } |
| 14 | + |
14 | 15 | .sidebar-menu-item-expanded { |
15 | 16 | display: list-item; |
16 | 17 | } |
17 | 18 | |
18 | | -.sidebar-menu-0,.sidebar-menu-1{ |
| 19 | +.sidebar-menu-0, .sidebar-menu-1 { |
19 | 20 | margin: 0px !important; |
20 | 21 | padding: 0px !important; |
21 | 22 | list-style: none; |
22 | 23 | } |
23 | 24 | |
24 | | - |
25 | | -.sidebar-menu-item-1{ |
| 25 | +.sidebar-menu-item-1 { |
26 | 26 | margin: 10px 0px; |
27 | 27 | background-color: #f2f2f2; |
28 | 28 | } |
29 | 29 | |
30 | | -.sidebar-menu-item-1 > .sidebar-menu-item-text-container{ |
| 30 | +.sidebar-menu-item-1 > .sidebar-menu-item-text-container { |
31 | 31 | border: 1px solid #aaa; |
32 | 32 | border-bottom: 0px; |
33 | 33 | padding: 3px; |
34 | 34 | } |
35 | 35 | |
36 | | -.sidebar-menu-item-2{ |
| 36 | +.sidebar-menu-item-2 { |
37 | 37 | background-color: #f9f9f9; |
38 | 38 | border: 1px solid #aaa; |
39 | 39 | border-bottom: 0px; |
— | — | @@ -40,11 +40,11 @@ |
41 | 41 | margin-bottom: 0px !important; |
42 | 42 | } |
43 | 43 | |
44 | | -.sidebar-menu-item-text-container{ |
| 44 | +.sidebar-menu-item-text-container { |
45 | 45 | position: relative; |
46 | 46 | } |
47 | 47 | |
48 | | -.sidebar-menu-item-controls{ |
| 48 | +.sidebar-menu-item-controls { |
49 | 49 | float: right; |
50 | 50 | color: #0645AD; |
51 | 51 | cursor: pointer; |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | user-select: none; |
57 | 57 | } |
58 | 58 | |
59 | | -.sidebar-menu-item-1{ |
| 59 | +.sidebar-menu-item-1 { |
60 | 60 | border-bottom: 1px solid #aaa; |
61 | 61 | } |
62 | 62 | |
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') { |
4 | 4 | var showText = sidebarmenu.config.controls.show; |
5 | 5 | var hideText = sidebarmenu.config.controls.hide; |
6 | 6 | var useAnimations = sidebarmenu.config.js.animate; |
— | — | @@ -10,28 +10,28 @@ |
11 | 11 | } |
12 | 12 | |
13 | 13 | initControls(); |
14 | | - $('.sidebar-menu-item-controls').click(function(){ |
| 14 | + $('.sidebar-menu-item-controls').click(function () { |
15 | 15 | var currentText = $(this).text(); |
16 | 16 | |
17 | | - if(currentText == showText){ |
| 17 | + if (currentText == showText) { |
18 | 18 | $(this).text(hideText); |
19 | | - }else if(currentText == hideText){ |
| 19 | + } else if (currentText == hideText) { |
20 | 20 | $(this).text(showText); |
21 | 21 | } |
22 | 22 | |
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 () { |
26 | 26 | var _this = $(this); |
27 | | - setTimeout(function(){ |
28 | | - _this.css('display','') |
29 | | - },250); |
| 27 | + setTimeout(function () { |
| 28 | + _this.css('display', '') |
| 29 | + }, 250); |
30 | 30 | }); |
31 | | - }else{ |
| 31 | + } else { |
32 | 32 | $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded'); |
33 | 33 | } |
34 | 34 | }); |
35 | | - }else{ |
| 35 | + } else { |
36 | 36 | $('.sidebar-menu-container').prepend(mw.msg('sidebar-js-init-error')); |
37 | 37 | } |
38 | 38 | }); |
\ No newline at end of file |