r30150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r30149‎ | r30150 | r30151 >
Date:11:28, 25 January 2008
Author:huji
Status:old
Tags:
Comment:
Introducing Xml::reasonDropDown
* Generates a drop-down box given the required information
* Supports marking the approrpiate option as pre-selected
* Shall be used on deletion and protection pages, where a dropdown is used to select the appropriate reason for the action
Modified paths:
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -309,7 +309,7 @@
310310 'type' => 'hidden',
311311 'value' => $value ) + $attribs );
312312 }
313 -
 313+
314314 /**
315315 * Convenience function to build an HTML drop-down list item.
316316 * @param $text String: text for this item
@@ -330,6 +330,51 @@
331331 }
332332
333333 /**
 334+ * Build a drop-down box for selecting a reason for an action
 335+ *
 336+ * @param mixed $other Text for the "Other reasons" option
 337+ * @param mixed $list Correctly formatted text to be used to generate the options
 338+ * @param mixed $selected Option which should be pre-selected
 339+ * @return string
 340+ */
 341+ public static function reasonDropDown( $other = '', $list = '', $selected = '' ) {
 342+ $options = '';
 343+ $optgroup = false;
 344+
 345+ $options = self::option( $other, 'other', $selected === 'other' );
 346+
 347+ foreach ( explode( "\n", $list ) as $option) {
 348+ $value = trim( htmlspecialchars($option) );
 349+ if ( $value == '' ) {
 350+ continue;
 351+ } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
 352+ // A new group is starting ...
 353+ $value = trim( substr( $value, 1 ) );
 354+ if( $optgroup ) $options .= self::closeElement('optgroup');
 355+ $options .= self::openElement( 'optgroup', array( 'label' => $value ) );
 356+ $optgroup = true;
 357+ } elseif ( substr( $value, 0, 2) == '**' ) {
 358+ // groupmember
 359+ $value = trim( substr( $value, 2 ) );
 360+ $options .= self::option( $value, $value, $selected === $value );
 361+ } else {
 362+ // groupless reason list
 363+ if( $optgroup ) $options .= self::closeElement('optgroup');
 364+ $options .= self::option( $value, $value, $selected === $value );
 365+ $optgroup = false;
 366+ }
 367+ }
 368+ if( $optgroup ) $options .= self::closeElement('optgroup');
 369+
 370+ return Xml::openElement( 'select', array( 'id' => 'wpReasonDropDown', 'name' => 'wpReasonDropDown',
 371+ 'class' => 'wpReasonDropDown' ) )
 372+ . "\n"
 373+ . $options
 374+ . "\n"
 375+ . Xml::closeElement( 'select' );
 376+ }
 377+
 378+ /**
334379 * Returns an escaped string suitable for inclusion in a string literal
335380 * for JavaScript source code.
336381 * Illegal control characters are assumed not to be present.

Status & tagging log