Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -315,6 +315,8 @@ |
316 | 316 | using Title::isCssJsSubpage() or checking Title::isWrongCaseCssJsPage(). |
317 | 317 | * (bug 24430) Remove number of column for edit field in preference page. |
318 | 318 | * Support for the deprecated hook MagicWordMagicWords was removed. |
| 319 | +* The Xml::namespaceSelector method has been deprecated, please use |
| 320 | + Html::namespaceSelector instead (note that the parameters have changed also). |
319 | 321 | |
320 | 322 | == Compatibility == |
321 | 323 | |
Index: trunk/phase3/includes/Xml.php |
— | — | @@ -117,42 +117,19 @@ |
118 | 118 | * @param $element_name String: value of the "name" attribute of the select tag |
119 | 119 | * @param $label String: optional label to add to the field |
120 | 120 | * @return string |
| 121 | + * @deprecated since 1.19 |
121 | 122 | */ |
122 | 123 | public static function namespaceSelector( $selected = '', $all = null, $element_name = 'namespace', $label = null ) { |
123 | | - global $wgContLang; |
124 | | - $namespaces = $wgContLang->getFormattedNamespaces(); |
125 | | - $options = array(); |
126 | | - |
127 | | - // Godawful hack... we'll be frequently passed selected namespaces |
128 | | - // as strings since PHP is such a shithole. |
129 | | - // But we also don't want blanks and nulls and "all"s matching 0, |
130 | | - // so let's convert *just* string ints to clean ints. |
131 | | - if( preg_match( '/^\d+$/', $selected ) ) { |
132 | | - $selected = intval( $selected ); |
133 | | - } |
134 | | - |
135 | | - if( !is_null( $all ) ) |
136 | | - $namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces; |
137 | | - foreach( $namespaces as $index => $name ) { |
138 | | - if( $index < NS_MAIN ) { |
139 | | - continue; |
140 | | - } |
141 | | - if( $index === 0 ) { |
142 | | - $name = wfMsg( 'blanknamespace' ); |
143 | | - } |
144 | | - $options[] = self::option( $name, $index, $index === $selected ); |
145 | | - } |
146 | | - |
147 | | - $ret = Xml::openElement( 'select', array( 'class' => 'namespaceselector', 'id' => 'namespace', |
148 | | - 'name' => $element_name ) ) |
149 | | - . "\n" |
150 | | - . implode( "\n", $options ) |
151 | | - . "\n" |
152 | | - . Xml::closeElement( 'select' ); |
153 | | - if ( !is_null( $label ) ) { |
154 | | - $ret = Xml::label( $label, $element_name ) . ' ' . $ret; |
155 | | - } |
156 | | - return $ret; |
| 124 | + wfDeprecated( __METHOD__, '1.19' ); |
| 125 | + return Html::namespaceSelector( array( |
| 126 | + 'selected' => $selected, |
| 127 | + 'all' => $all, |
| 128 | + 'label' => $label, |
| 129 | + ), array( |
| 130 | + 'name' => $element_name, |
| 131 | + 'id' => 'namespace', |
| 132 | + 'class' => 'namespaceselector', |
| 133 | + ) ); |
157 | 134 | } |
158 | 135 | |
159 | 136 | /** |
Index: trunk/phase3/includes/Html.php |
— | — | @@ -699,7 +699,61 @@ |
700 | 700 | } |
701 | 701 | return self::element( 'textarea', $attribs, $spacedValue ); |
702 | 702 | } |
| 703 | + /** |
| 704 | + * Build a drop-down box for selecting a namespace |
| 705 | + * |
| 706 | + * @param $params array: |
| 707 | + * - selected: [optional] Id of namespace which should be pre-selected |
| 708 | + * - all: [optional] Value of item for "all namespaces". If null or unset, <option> is omitted. |
| 709 | + * - label: text for label to add before the field |
| 710 | + * @param $selectAttribs array |
| 711 | + * @return string |
| 712 | + */ |
| 713 | + public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) { |
| 714 | + global $wgContLang; |
703 | 715 | |
| 716 | + $selectAttribs = $selectAttribs + array( |
| 717 | + 'id' => 'mw-namespaceselect', |
| 718 | + 'name' => 'namespace', |
| 719 | + ); |
| 720 | + ksort( $selectAttribs ); |
| 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'] ); |
| 728 | + } |
| 729 | + |
| 730 | + $options = array(); |
| 731 | + if ( isset( $params['all'] ) ) { |
| 732 | + $options[$params['all']] = wfMsg( 'namespacesall' ); |
| 733 | + } |
| 734 | + $options += $wgContLang->getFormattedNamespaces(); |
| 735 | + |
| 736 | + $optionsHtml = array(); |
| 737 | + foreach ( $options as $nsId => $nsName ) { |
| 738 | + if ( $nsId < NS_MAIN ) { |
| 739 | + continue; |
| 740 | + } |
| 741 | + if ( $nsId === 0 ) { |
| 742 | + $nsName = wfMsg( 'blanknamespace' ); |
| 743 | + } |
| 744 | + $optionsHtml[] = Xml::option( $nsName, $nsId, $nsId === $params['selected'] ); |
| 745 | + } |
| 746 | + |
| 747 | + $ret = Html::openElement( 'select', $selectAttribs ) |
| 748 | + . "\n" |
| 749 | + . implode( "\n", $optionsHtml ) |
| 750 | + . "\n" |
| 751 | + . Html::closeElement( 'select' ); |
| 752 | + if ( isset( $params['label'] ) ) { |
| 753 | + $ret = Xml::label( $params['label'], $selectAttribs['name'] ) . ' ' . $ret; |
| 754 | + } |
| 755 | + return $ret; |
| 756 | + } |
| 757 | + |
704 | 758 | /** |
705 | 759 | * Constructs the opening html-tag with necessary doctypes depending on |
706 | 760 | * global variables. |