Index: trunk/phase3/tests/phpunit/includes/XmlTest.php |
— | — | @@ -214,7 +214,7 @@ |
215 | 215 | 'Basic namespace selector without custom options' |
216 | 216 | ); |
217 | 217 | $this->assertEquals( |
218 | | - '<label for="myname">Select a namespace:</label> <select class="namespaceselector" id="namespace" name="myname"> |
| 218 | + '<label for="namespace">Select a namespace:</label> <select class="namespaceselector" id="namespace" name="myname"> |
219 | 219 | <option value="all">all</option> |
220 | 220 | <option value="0">(Main)</option> |
221 | 221 | <option value="1">Talk</option> |
Index: trunk/phase3/tests/phpunit/includes/HtmlTest.php |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | class HtmlTest extends MediaWikiTestCase { |
6 | 6 | private static $oldLang; |
7 | 7 | private static $oldContLang; |
| 8 | + private static $oldNamespaces; |
8 | 9 | |
9 | 10 | public function setUp() { |
10 | 11 | global $wgLang, $wgContLang, $wgLanguageCode; |
— | — | @@ -13,6 +14,29 @@ |
14 | 15 | |
15 | 16 | $wgLanguageCode = 'en'; |
16 | 17 | $wgContLang = $wgLang = Language::factory( $wgLanguageCode ); |
| 18 | + |
| 19 | + // Hardcode namespaces during test runs, |
| 20 | + // so that html output based on existing namespaces |
| 21 | + // can be properly evaluated. |
| 22 | + self::$oldNamespaces = $wgContLang->namespaceNames; |
| 23 | + $wgContLang->namespaceNames = array( |
| 24 | + -2 => 'Media', |
| 25 | + -1 => 'Special', |
| 26 | + 0 => '', |
| 27 | + 1 => 'Talk', |
| 28 | + 2 => 'User', |
| 29 | + 3 => 'User_talk', |
| 30 | + 4 => 'MyWiki', |
| 31 | + 5 => 'MyWiki_Talk', |
| 32 | + 6 => 'File', |
| 33 | + 7 => 'File_talk', |
| 34 | + 8 => 'MediaWiki', |
| 35 | + 9 => 'MediaWiki_talk', |
| 36 | + 10 => 'Template', |
| 37 | + 11 => 'Template_talk', |
| 38 | + 100 => 'Custom', |
| 39 | + 101 => 'Custom_talk', |
| 40 | + ); |
17 | 41 | } |
18 | 42 | |
19 | 43 | public function tearDown() { |
— | — | @@ -20,6 +44,7 @@ |
21 | 45 | $wgLang = self::$oldLang; |
22 | 46 | $wgContLang = self::$oldContLang; |
23 | 47 | $wgLanguageCode = $wgContLang->getCode(); |
| 48 | + $wgContLang->namespaceNames = self::$oldNamespaces; |
24 | 49 | } |
25 | 50 | |
26 | 51 | public function testExpandAttributesSkipsNullAndFalse() { |
— | — | @@ -182,4 +207,51 @@ |
183 | 208 | ))) |
184 | 209 | ); |
185 | 210 | } |
| 211 | + |
| 212 | + function testNamespaceSelector() { |
| 213 | + $this->assertEquals( |
| 214 | + '<select id="namespace" name="namespace"> |
| 215 | +<option value="0">(Main)</option> |
| 216 | +<option value="1">Talk</option> |
| 217 | +<option value="2">User</option> |
| 218 | +<option value="3">User talk</option> |
| 219 | +<option value="4">MyWiki</option> |
| 220 | +<option value="5">MyWiki Talk</option> |
| 221 | +<option value="6">File</option> |
| 222 | +<option value="7">File talk</option> |
| 223 | +<option value="8">MediaWiki</option> |
| 224 | +<option value="9">MediaWiki talk</option> |
| 225 | +<option value="10">Template</option> |
| 226 | +<option value="11">Template talk</option> |
| 227 | +<option value="100">Custom</option> |
| 228 | +<option value="101">Custom talk</option> |
| 229 | +</select>', |
| 230 | + Html::namespaceSelector(), |
| 231 | + 'Basic namespace selector without custom options' |
| 232 | + ); |
| 233 | + $this->assertEquals( |
| 234 | + '<label for="mw-test-namespace">Select a namespace:</label> <select id="mw-test-namespace" name="wpNamespace"> |
| 235 | +<option value="all">all</option> |
| 236 | +<option value="0">(Main)</option> |
| 237 | +<option value="1">Talk</option> |
| 238 | +<option value="2" selected="">User</option> |
| 239 | +<option value="3">User talk</option> |
| 240 | +<option value="4">MyWiki</option> |
| 241 | +<option value="5">MyWiki Talk</option> |
| 242 | +<option value="6">File</option> |
| 243 | +<option value="7">File talk</option> |
| 244 | +<option value="8">MediaWiki</option> |
| 245 | +<option value="9">MediaWiki talk</option> |
| 246 | +<option value="10">Template</option> |
| 247 | +<option value="11">Template talk</option> |
| 248 | +<option value="100">Custom</option> |
| 249 | +<option value="101">Custom talk</option> |
| 250 | +</select>', |
| 251 | + Html::namespaceSelector( |
| 252 | + array( 'selected' => '2', 'all' => 'all', 'label' => 'Select a namespace:' ), |
| 253 | + array( 'name' => 'wpNamespace', 'id' => 'mw-test-namespace' ) |
| 254 | + ), |
| 255 | + 'Basic namespace selector with custom values' |
| 256 | + ); |
| 257 | + } |
186 | 258 | } |
Index: trunk/phase3/includes/Html.php |
— | — | @@ -713,17 +713,21 @@ |
714 | 714 | global $wgContLang; |
715 | 715 | |
716 | 716 | $selectAttribs = $selectAttribs + array( |
717 | | - 'id' => 'mw-namespaceselect', |
| 717 | + 'id' => 'namespace', |
718 | 718 | 'name' => 'namespace', |
719 | 719 | ); |
720 | 720 | ksort( $selectAttribs ); |
721 | 721 | |
722 | | - // If string only contains digits, convert to clean int. Selected could also |
723 | | - // be "all" or "" etc. which needs to be left untouched. |
724 | | - // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues |
725 | | - // and returns false for already clean ints. Use regex instead.. |
726 | | - if ( preg_match( '/^\d+$/', $params['selected'] ) ) { |
727 | | - $params['selected'] = intval( $params['selected'] ); |
| 722 | + if ( isset( $params['selected'] ) ) { |
| 723 | + // If string only contains digits, convert to clean int. Selected could also |
| 724 | + // be "all" or "" etc. which needs to be left untouched. |
| 725 | + // PHP is_numeric() has issues with large strings, PHP ctype_digit has other issues |
| 726 | + // and returns false for already clean ints. Use regex instead.. |
| 727 | + if ( preg_match( '/^\d+$/', $params['selected'] ) ) { |
| 728 | + $params['selected'] = intval( $params['selected'] ); |
| 729 | + } |
| 730 | + } else { |
| 731 | + $params['selected'] = ''; |
728 | 732 | } |
729 | 733 | |
730 | 734 | $options = array(); |
— | — | @@ -749,7 +753,7 @@ |
750 | 754 | . "\n" |
751 | 755 | . Html::closeElement( 'select' ); |
752 | 756 | if ( isset( $params['label'] ) ) { |
753 | | - $ret = Xml::label( $params['label'], $selectAttribs['name'] ) . ' ' . $ret; |
| 757 | + $ret = Xml::label( $params['label'], $selectAttribs['id'] ) . ' ' . $ret; |
754 | 758 | } |
755 | 759 | return $ret; |
756 | 760 | } |