Index: trunk/phase3/tests/phpunit/includes/HtmlTest.php |
— | — | @@ -215,7 +215,7 @@ |
216 | 216 | |
217 | 217 | function testNamespaceSelector() { |
218 | 218 | $this->assertEquals( |
219 | | - '<select id="namespace" name="namespace">' . "\n" . |
| 219 | + '<select>' . "\n" . |
220 | 220 | '<option value="0">(Main)</option>' . "\n" . |
221 | 221 | '<option value="1">Talk</option>' . "\n" . |
222 | 222 | '<option value="2">User</option>' . "\n" . |
— | — | @@ -236,6 +236,7 @@ |
237 | 237 | Html::namespaceSelector(), |
238 | 238 | 'Basic namespace selector without custom options' |
239 | 239 | ); |
| 240 | + |
240 | 241 | $this->assertEquals( |
241 | 242 | '<label for="mw-test-namespace">Select a namespace:</label> ' . |
242 | 243 | '<select id="mw-test-namespace" name="wpNamespace">' . "\n" . |
— | — | @@ -263,12 +264,14 @@ |
264 | 265 | ), |
265 | 266 | 'Basic namespace selector with custom values' |
266 | 267 | ); |
267 | | - } |
268 | 268 | |
269 | | - function testCanFilterOutNamespaces() { |
270 | | - $this->assertEquals( |
271 | | -'<select id="namespace" name="namespace">' . "\n" . |
| 269 | + $this->assertEquals( |
| 270 | + '<label>Select a namespace:</label> ' . |
| 271 | +'<select>' . "\n" . |
| 272 | +'<option value="0">(Main)</option>' . "\n" . |
| 273 | +'<option value="1">Talk</option>' . "\n" . |
272 | 274 | '<option value="2">User</option>' . "\n" . |
| 275 | +'<option value="3">User talk</option>' . "\n" . |
273 | 276 | '<option value="4">MyWiki</option>' . "\n" . |
274 | 277 | '<option value="5">MyWiki Talk</option>' . "\n" . |
275 | 278 | '<option value="6">File</option>' . "\n" . |
— | — | @@ -279,17 +282,41 @@ |
280 | 283 | '<option value="11">Template talk</option>' . "\n" . |
281 | 284 | '<option value="14">Category</option>' . "\n" . |
282 | 285 | '<option value="15">Category talk</option>' . "\n" . |
| 286 | +'<option value="100">Custom</option>' . "\n" . |
| 287 | +'<option value="101">Custom talk</option>' . "\n" . |
283 | 288 | '</select>', |
284 | 289 | Html::namespaceSelector( |
| 290 | + array( 'label' => 'Select a namespace:' ) |
| 291 | + ), |
| 292 | + 'Basic namespace selector with a custom label but no id attribtue for the <select>' |
| 293 | + ); |
| 294 | + } |
| 295 | + |
| 296 | + function testCanFilterOutNamespaces() { |
| 297 | + $this->assertEquals( |
| 298 | +'<select>' . "\n" . |
| 299 | +'<option value="2">User</option>' . "\n" . |
| 300 | +'<option value="4">MyWiki</option>' . "\n" . |
| 301 | +'<option value="5">MyWiki Talk</option>' . "\n" . |
| 302 | +'<option value="6">File</option>' . "\n" . |
| 303 | +'<option value="7">File talk</option>' . "\n" . |
| 304 | +'<option value="8">MediaWiki</option>' . "\n" . |
| 305 | +'<option value="9">MediaWiki talk</option>' . "\n" . |
| 306 | +'<option value="10">Template</option>' . "\n" . |
| 307 | +'<option value="11">Template talk</option>' . "\n" . |
| 308 | +'<option value="14">Category</option>' . "\n" . |
| 309 | +'<option value="15">Category talk</option>' . "\n" . |
| 310 | +'</select>', |
| 311 | + Html::namespaceSelector( |
285 | 312 | array( 'exclude' => array( 0, 1, 3, 100, 101 ) ) |
286 | 313 | ), |
287 | 314 | 'Namespace selector namespace filtering.' |
288 | 315 | ); |
289 | | - } |
| 316 | + } |
290 | 317 | |
291 | | - function testCanDisableANamespaces() { |
292 | | - $this->assertEquals( |
293 | | -'<select id="namespace" name="namespace">' . "\n" . |
| 318 | + function testCanDisableANamespaces() { |
| 319 | + $this->assertEquals( |
| 320 | +'<select>' . "\n" . |
294 | 321 | '<option disabled="" value="0">(Main)</option>' . "\n" . |
295 | 322 | '<option disabled="" value="1">Talk</option>' . "\n" . |
296 | 323 | '<option disabled="" value="2">User</option>' . "\n" . |
— | — | @@ -314,75 +341,4 @@ |
315 | 342 | ); |
316 | 343 | } |
317 | 344 | |
318 | | - function testNamespaceSelectorIdAndNameDefaultsAttributes() { |
319 | | - |
320 | | - $this->assertNsSelectorIdAndName( |
321 | | - 'namespace', 'namespace', |
322 | | - Html::namespaceSelector( array(), array( |
323 | | - # neither 'id' nor 'name' key given |
324 | | - )), |
325 | | - "Neither 'id' nor 'name' key given" |
326 | | - ); |
327 | | - |
328 | | - $this->assertNsSelectorIdAndName( |
329 | | - 'namespace', 'select_name', |
330 | | - Html::namespaceSelector( array(), array( |
331 | | - 'name' => 'select_name', |
332 | | - # no 'id' key given |
333 | | - )), |
334 | | - "No 'id' key given, 'name' given" |
335 | | - ); |
336 | | - |
337 | | - $this->assertNsSelectorIdAndName( |
338 | | - 'select_id', 'namespace', |
339 | | - Html::namespaceSelector( array(), array( |
340 | | - 'id' => 'select_id', |
341 | | - # no 'name' key given |
342 | | - )), |
343 | | - "'id' given, no 'name' key given" |
344 | | - ); |
345 | | - |
346 | | - $this->assertNsSelectorIdAndName( |
347 | | - 'select_id', 'select_name', |
348 | | - Html::namespaceSelector( array(), array( |
349 | | - 'id' => 'select_id', |
350 | | - 'name' => 'select_name', |
351 | | - )), |
352 | | - "Both 'id' and 'name' given" |
353 | | - ); |
354 | | - } |
355 | | - |
356 | | - /** |
357 | | - * Helper to verify <select> attributes generated by Html::namespaceSelector() |
358 | | - * This helper expect the Html method to use 'namespace' as a default value for |
359 | | - * both 'id' and 'name' attributes. |
360 | | - * |
361 | | - * @param String $expectedId <select> id attribute value |
362 | | - * @param String $expectedName <select> name attribute value |
363 | | - * @param String $html Output of a call to Html::namespaceSelector() |
364 | | - * @param String $msg Optional message (default: '') |
365 | | - */ |
366 | | - function assertNsSelectorIdAndName( $expectedId, $expectedName, $html, $msg = '' ) { |
367 | | - $actualId = 'namespace'; |
368 | | - if( 1 === preg_match( '/id="(.+?)"/', $html, $m ) ) { |
369 | | - $actualId = $m[1]; |
370 | | - } |
371 | | - |
372 | | - $actualName = 'namespace'; |
373 | | - if( 1 === preg_match( '/name="(.+?)"/', $html, $m ) ) { |
374 | | - $actualName = $m[1]; |
375 | | - } |
376 | | - $this->assertEquals( |
377 | | - array( #expected |
378 | | - 'id' => $expectedId, |
379 | | - 'name' => $expectedName, |
380 | | - ), |
381 | | - array( #actual |
382 | | - 'id' => $actualId, |
383 | | - 'name' => $actualName, |
384 | | - ), |
385 | | - 'Html::namespaceSelector() got wrong id and/or name attribute(s). ' . $msg |
386 | | - ); |
387 | | - } |
388 | | - |
389 | 345 | } |
Index: trunk/phase3/includes/Html.php |
— | — | @@ -718,11 +718,6 @@ |
719 | 719 | public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) { |
720 | 720 | global $wgContLang; |
721 | 721 | |
722 | | - // Default 'id' & 'name' <select> attributes |
723 | | - $selectAttribs = $selectAttribs + array( |
724 | | - 'id' => 'namespace', |
725 | | - 'name' => 'namespace', |
726 | | - ); |
727 | 722 | ksort( $selectAttribs ); |
728 | 723 | |
729 | 724 | // Is a namespace selected? |
— | — | @@ -768,14 +763,22 @@ |
769 | 764 | // main we don't use "" but the user message descripting it (e.g. "(Main)" or "(Article)") |
770 | 765 | $nsName = wfMsg( 'blanknamespace' ); |
771 | 766 | } |
772 | | - $optionsHtml[] = Xml::option( $nsName, $nsId, $nsId === $params['selected'], array( |
773 | | - 'disabled' => in_array( $nsId, $params['disable'] ), |
774 | | - ) ); |
| 767 | + $optionsHtml[] = Html::element( |
| 768 | + 'option', array( |
| 769 | + 'disabled' => in_array( $nsId, $params['disable'] ), |
| 770 | + 'value' => $nsId, |
| 771 | + 'selected' => $nsId === $params['selected'], |
| 772 | + ), $nsName |
| 773 | + ); |
775 | 774 | } |
776 | 775 | |
777 | 776 | $ret = ''; |
778 | 777 | if ( isset( $params['label'] ) ) { |
779 | | - $ret .= Xml::label( $params['label'], $selectAttribs['id'] ) . ' '; |
| 778 | + $ret .= Html::element( |
| 779 | + 'label', array( |
| 780 | + 'for' => isset( $selectAttribs['id'] ) ? $selectAttribs['id'] : null, |
| 781 | + ), $params['label'] |
| 782 | + ) . ' '; |
780 | 783 | } |
781 | 784 | |
782 | 785 | // Wrap options in a <select> |
Index: trunk/phase3/includes/specials/SpecialPrefixindex.php |
— | — | @@ -109,8 +109,6 @@ |
110 | 110 | <td class='mw-input'>" . |
111 | 111 | Html::namespaceSelector( array( |
112 | 112 | 'selected' => $namespace, |
113 | | - 'all' => null, |
114 | | - 'label' => null, |
115 | 113 | ), array( |
116 | 114 | 'name' => 'namespace', |
117 | 115 | 'id' => 'namespace', |
Index: trunk/phase3/includes/specials/SpecialContributions.php |
— | — | @@ -447,7 +447,6 @@ |
448 | 448 | Html::namespaceSelector( array( |
449 | 449 | 'selected' => $this->opts['namespace'], |
450 | 450 | 'all' => '', |
451 | | - 'label' => null, |
452 | 451 | ), array( |
453 | 452 | 'name' => 'namespace', |
454 | 453 | 'id' => 'namespace', |