Index: trunk/phase3/includes/Xml.php |
— | — | @@ -123,11 +123,11 @@ |
124 | 124 | wfDeprecated( __METHOD__, '1.19' ); |
125 | 125 | return Html::namespaceSelector( array( |
126 | 126 | 'selected' => $selected, |
127 | | - 'all' => $all, |
128 | | - 'label' => $label, |
| 127 | + 'all' => $all, |
| 128 | + 'label' => $label, |
129 | 129 | ), array( |
130 | | - 'name' => $element_name, |
131 | | - 'id' => 'namespace', |
| 130 | + 'name' => $element_name, |
| 131 | + 'id' => 'namespace', |
132 | 132 | 'class' => 'namespaceselector', |
133 | 133 | ) ); |
134 | 134 | } |
Index: trunk/phase3/includes/Html.php |
— | — | @@ -704,20 +704,24 @@ |
705 | 705 | * |
706 | 706 | * @param $params array: |
707 | 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. |
| 708 | + * - all: [optional] Value of item for "all namespaces". If null or unset, no <option> is generated to select all namespaces |
709 | 709 | * - label: text for label to add before the field |
710 | | - * @param $selectAttribs array |
711 | | - * @return string |
| 710 | + * @param $selectAttribs array HTML attributes for the generated select element. |
| 711 | + * - id: [optional], default: 'namespace' |
| 712 | + * - name: [optional], default: 'namespace' |
| 713 | + * @return string HTML code to select a namespace. |
712 | 714 | */ |
713 | 715 | public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) { |
714 | 716 | global $wgContLang; |
715 | 717 | |
| 718 | + // Default 'id' & 'name' <select> attributes |
716 | 719 | $selectAttribs = $selectAttribs + array( |
717 | | - 'id' => 'namespace', |
| 720 | + 'id' => 'namespace', |
718 | 721 | 'name' => 'namespace', |
719 | 722 | ); |
720 | 723 | ksort( $selectAttribs ); |
721 | 724 | |
| 725 | + // Is a namespace selected? |
722 | 726 | if ( isset( $params['selected'] ) ) { |
723 | 727 | // If string only contains digits, convert to clean int. Selected could also |
724 | 728 | // be "all" or "" etc. which needs to be left untouched. |
— | — | @@ -726,16 +730,23 @@ |
727 | 731 | if ( preg_match( '/^\d+$/', $params['selected'] ) ) { |
728 | 732 | $params['selected'] = intval( $params['selected'] ); |
729 | 733 | } |
| 734 | + // else: leaves it untouched for later processing |
730 | 735 | } else { |
731 | 736 | $params['selected'] = ''; |
732 | 737 | } |
733 | 738 | |
| 739 | + // Array holding the <option> elements |
734 | 740 | $options = array(); |
| 741 | + |
735 | 742 | if ( isset( $params['all'] ) ) { |
| 743 | + // add an <option> that would let the user select all namespaces. |
| 744 | + // Value is provided by user, the name shown is localized. |
736 | 745 | $options[$params['all']] = wfMsg( 'namespacesall' ); |
737 | 746 | } |
| 747 | + // Add defaults <option> according to content language |
738 | 748 | $options += $wgContLang->getFormattedNamespaces(); |
739 | 749 | |
| 750 | + // Convert $options to HTML |
740 | 751 | $optionsHtml = array(); |
741 | 752 | foreach ( $options as $nsId => $nsName ) { |
742 | 753 | if ( $nsId < NS_MAIN ) { |
— | — | @@ -747,14 +758,16 @@ |
748 | 759 | $optionsHtml[] = Xml::option( $nsName, $nsId, $nsId === $params['selected'] ); |
749 | 760 | } |
750 | 761 | |
751 | | - $ret = Html::openElement( 'select', $selectAttribs ) |
| 762 | + // Forge a <select> element and returns it |
| 763 | + $ret = ''; |
| 764 | + if ( isset( $params['label'] ) ) { |
| 765 | + $ret .= Xml::label( $params['label'], $selectAttribs['id'] ) . ' '; |
| 766 | + } |
| 767 | + $ret .= Html::openElement( 'select', $selectAttribs ) |
752 | 768 | . "\n" |
753 | 769 | . implode( "\n", $optionsHtml ) |
754 | 770 | . "\n" |
755 | 771 | . Html::closeElement( 'select' ); |
756 | | - if ( isset( $params['label'] ) ) { |
757 | | - $ret = Xml::label( $params['label'], $selectAttribs['id'] ) . ' ' . $ret; |
758 | | - } |
759 | 772 | return $ret; |
760 | 773 | } |
761 | 774 | |