r110275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110274‎ | r110275 | r110276 >
Date:11:02, 30 January 2012
Author:hashar
Status:resolved
Tags:
Comment:
comment / style for Html::namespaceSelector()

Xml.php:
* align array values. Easier to the eyes.

Html.php:
* Various comments
* Switched the way the HTML is forged

Ping r109990
Modified paths:
  • /trunk/phase3/includes/Html.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -123,11 +123,11 @@
124124 wfDeprecated( __METHOD__, '1.19' );
125125 return Html::namespaceSelector( array(
126126 'selected' => $selected,
127 - 'all' => $all,
128 - 'label' => $label,
 127+ 'all' => $all,
 128+ 'label' => $label,
129129 ), array(
130 - 'name' => $element_name,
131 - 'id' => 'namespace',
 130+ 'name' => $element_name,
 131+ 'id' => 'namespace',
132132 'class' => 'namespaceselector',
133133 ) );
134134 }
Index: trunk/phase3/includes/Html.php
@@ -704,20 +704,24 @@
705705 *
706706 * @param $params array:
707707 * - 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
709709 * - 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.
712714 */
713715 public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) {
714716 global $wgContLang;
715717
 718+ // Default 'id' & 'name' <select> attributes
716719 $selectAttribs = $selectAttribs + array(
717 - 'id' => 'namespace',
 720+ 'id' => 'namespace',
718721 'name' => 'namespace',
719722 );
720723 ksort( $selectAttribs );
721724
 725+ // Is a namespace selected?
722726 if ( isset( $params['selected'] ) ) {
723727 // If string only contains digits, convert to clean int. Selected could also
724728 // be "all" or "" etc. which needs to be left untouched.
@@ -726,16 +730,23 @@
727731 if ( preg_match( '/^\d+$/', $params['selected'] ) ) {
728732 $params['selected'] = intval( $params['selected'] );
729733 }
 734+ // else: leaves it untouched for later processing
730735 } else {
731736 $params['selected'] = '';
732737 }
733738
 739+ // Array holding the <option> elements
734740 $options = array();
 741+
735742 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.
736745 $options[$params['all']] = wfMsg( 'namespacesall' );
737746 }
 747+ // Add defaults <option> according to content language
738748 $options += $wgContLang->getFormattedNamespaces();
739749
 750+ // Convert $options to HTML
740751 $optionsHtml = array();
741752 foreach ( $options as $nsId => $nsName ) {
742753 if ( $nsId < NS_MAIN ) {
@@ -747,14 +758,16 @@
748759 $optionsHtml[] = Xml::option( $nsName, $nsId, $nsId === $params['selected'] );
749760 }
750761
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'] ) . '&#160;';
 766+ }
 767+ $ret .= Html::openElement( 'select', $selectAttribs )
752768 . "\n"
753769 . implode( "\n", $optionsHtml )
754770 . "\n"
755771 . Html::closeElement( 'select' );
756 - if ( isset( $params['label'] ) ) {
757 - $ret = Xml::label( $params['label'], $selectAttribs['id'] ) . '&#160;' . $ret;
758 - }
759772 return $ret;
760773 }
761774

Follow-up revisions

RevisionCommit summaryAuthorDate
r111315[Html.php] Follow-up r110275, comment fixes....krinkle18:58, 12 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109990[Xml/Html] new method Html::namespaceSelector...krinkle03:01, 25 January 2012

Status & tagging log