* Adding support for custom name and id, custom class, and custom tabindex to Xml::listDropDown
* Changing the order of parameters Xml::listDropDown accepts.
* Updating ipblock, file deletion and page deletion forms so they all use this new Xml element rather than holding three copies of similar code.
* Removing variables which are no more used in the three above forms.
* Renaming a few variables to follow the coding style of MediaWiki.
$token = htmlspecialchars( $wgUser->editToken() );
$watch = Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '2' ) );
- $mDeletereasonother = Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' );
- $mDeletereasonotherlist = wfMsgHtml( 'deletereasonotherlist' );
- $scDeleteReasonList = wfMsgForContent( 'deletereason-dropdown' );
-
- $deleteReasonList = '';
- if ( $scDeleteReasonList != '' && $scDeleteReasonList != '-' ) {
- $deleteReasonList = "<option value=\"other\">$mDeletereasonotherlist</option>";
- $optgroup = "";
- foreach ( explode( "\n", $scDeleteReasonList ) as $option) {
- $value = trim( htmlspecialchars($option) );
- if ( $value == '' ) {
- continue;
- } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
- // A new group is starting ...
- $value = trim( substr( $value, 1 ) );
- $deleteReasonList .= "$optgroup<optgroup label=\"$value\">";
- $optgroup = "</optgroup>";
- } elseif ( substr( $value, 0, 2) == '**' ) {
- // groupmember
- $selected = "";
- $value = trim( substr( $value, 2 ) );
- if ( $this->DeleteReasonList === $value)
- $selected = ' selected="selected"';
- $deleteReasonList .= "<option value=\"$value\"$selected>$value</option>";
- } else {
- // groupless delete reason
- $selected = "";
- if ( $this->DeleteReasonList === $value)
- $selected = ' selected="selected"';
- $deleteReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
- $optgroup = "";
- }
- }
- $deleteReasonList .= $optgroup;
- }
+ $deletereasonother = Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' );
+ $reasonDropDown = Xml::listDropDown( 'wpDeleteReasonList', wfMsgHtml( 'deletereason-dropdown' ),
+ wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 );
+
$wgOut->addHTML( "
<form id='deleteconfirm' method='post' action=\"{$formaction}\">
<table border='0'>
$delcom:
</td>
<td align='left'>
- <select tabindex='1' id='wpDeleteReasonList' name=\"wpDeleteReasonList\">
- $deleteReasonList
- </select>
+ $reasonDropDown
</td>
</tr>
<tr id=\"wpDeleteReasonRow\" name=\"wpDeleteReasonRow\">
<td>
- $mDeletereasonother
+ $deletereasonother
</td>
<td align='left'>
<input type='text' maxlength='255' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" tabindex=\"2\" />
private function showForm() {
global $wgOut, $wgUser, $wgRequest;
- $mDeletereasonother = Xml::label( wfMsg( 'filedelete-otherreason' ), 'wpReason' );
- $mDeletereasonotherlist = wfMsgHtml( 'filedelete-reason-otherlist' );
- $scDeleteReasonList = wfMsgForContent( 'filedelete-reason-dropdown' );
- $mDeleteReasonList = '';
+ $deletereasonother = Xml::label( wfMsg( 'filedelete-otherreason' ), 'wpReason' );
$delcom = Xml::label( wfMsg( 'filedelete-comment' ), 'wpDeleteReasonList' );
- if ( $scDeleteReasonList != '' && $scDeleteReasonList != '-' ) {
- $deleteReasonList = "<option value=\"other\">$mDeletereasonotherlist</option>";
- $optgroup = "";
- foreach ( explode( "\n", $scDeleteReasonList ) as $option) {
- $value = trim( htmlspecialchars($option) );
- if ( $value == '' ) {
- continue;
- } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
- // A new group is starting ...
- $value = trim( substr( $value, 1 ) );
- $deleteReasonList .= "$optgroup<optgroup label=\"$value\">";
- $optgroup = "</optgroup>";
- } elseif ( substr( $value, 0, 2) == '**' ) {
- // groupmember
- $selected = "";
- $value = trim( substr( $value, 2 ) );
- if ( $mDeleteReasonList === $value)
- $selected = ' selected="selected"';
- $deleteReasonList .= "<option value=\"$value\"$selected>$value</option>";
- } else {
- // groupless delete reason
- $selected = "";
- if ( $this->DeleteReasonList === $value)
- $selected = ' selected="selected"';
- $deleteReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
- $optgroup = "";
- }
- }
- $deleteReasonList .= $optgroup;
- }
+ $reasonDropDown = Xml::listDropDown( 'wpDeleteReasonList', wfMsgHtml( 'filedelete-reason-dropdown' ),
+ wfMsgForContent( 'filedelete-reason-otherlist' ), '', 'wpReasonDropDown', 1 );
$form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction() ) );
$form .= '<fieldset><legend>' . wfMsgHtml( 'filedelete-legend' ) . '</legend>';
$form .= '<table><tr><td colspan="2">';
$form .= $this->prepareMessage( 'filedelete-intro' );
$form .= "</td></tr><tr><td align=\"right\"> $delcom </td><td align=\"left\">";
- $form .= "<select tabindex='2' id='wpDeleteReasonList' name=\"wpDeleteReasonList\">
- $deleteReasonList
-</select>";
- $form .= "</td></tr><tr><td align=\"right\"> $mDeletereasonother </td><td align=\"left\">";
+ $form .= $reasonDropDown;
+ $form .= "</td></tr><tr><td align=\"right\"> $deletereasonother </td><td align=\"left\">";
$form .= "<input type='text' maxlength='255' size='60' name='wpReason' id='wpReason' ";
$form .= "value=\"". htmlspecialchars( $wgRequest->getText( 'wpReason' ) ) ."\" tabindex=\"1\" />";
$form .= '</td></tr><tr><td colspan="2">';
$mIpbothertime = wfMsgHtml( 'ipbotheroption' );
$mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
$mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
- $mIpbreasonotherlist = wfMsgHtml( 'ipbreasonotherlist' );
$titleObj = SpecialPage::getTitleFor( 'Blockip' );
$action = $titleObj->escapeLocalURL( "action=submit" );
$blockExpiryFormOptions .= "<option value=\"$value\"$selected>$show</option>";
}
- $scBlockReasonList = wfMsgForContent( 'ipbreason-dropdown' );
- $blockReasonList = '';
- if ( $scBlockReasonList != '' && $scBlockReasonList != '-' ) {
- $blockReasonList = "<option value=\"other\">$mIpbreasonotherlist</option>";
- $optgroup = "";
- foreach ( explode( "\n", $scBlockReasonList ) as $option) {
- $value = trim( htmlspecialchars($option) );
- if ( $value == '' ) {
- continue;
- } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
- // A new group is starting ...
- $value = trim( substr( $value, 1 ) );
- $blockReasonList .= "$optgroup<optgroup label=\"$value\">";
- $optgroup = "</optgroup>";
- } elseif ( substr( $value, 0, 2) == '**' ) {
- // groupmember
- $selected = "";
- $value = trim( substr( $value, 2 ) );
- if ( $this->BlockReasonList === $value)
- $selected = ' selected="selected"';
- $blockReasonList .= "<option value=\"$value\"$selected>$value</option>";
- } else {
- // groupless block reason
- $selected = "";
- if ( $this->BlockReasonList === $value)
- $selected = ' selected="selected"';
- $blockReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
- $optgroup = "";
- }
- }
- $blockReasonList .= $optgroup;
- }
+ $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList', wfMsgHtml( 'ipbreason-dropdown' ),
+ wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 );
$token = $wgUser->editToken();
array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
</td>
</tr>");
- if ( $blockReasonList != '' ) {
- $wgOut->addHTML("
- <tr>
- <td align=\"$alignRight\">{$mIpbreasonother}</td>
- <td>
- <select tabindex='4' id=\"wpBlockReasonList\" name=\"wpBlockReasonList\">
- $blockReasonList
- </select>
- </td>
- </tr>");
- }
+ $wgOut->addHTML("
+ <tr>
+ <td align=\"$alignRight\">{$mIpbreasonother}</td>
+ <td>
+ $reasonDropDown
+ </td>
+ </tr>");
$wgOut->addHTML("
<tr id=\"wpBlockReason\">
<td align=\"$alignRight\">{$mIpbreason}</td>
}
/**
- * Build a drop-down box for selecting a reason for an action
+ * Build a drop-down box from a textual list.
*
+ * @param mixed $name Name and id for the drop-down
+ * @param mixed $class CSS classes for the drop-down
* @param mixed $other Text for the "Other reasons" option
* @param mixed $list Correctly formatted text to be used to generate the options
* @param mixed $selected Option which should be pre-selected
* @return string
*/
- public static function reasonDropDown( $other = '', $list = '', $selected = '' ) {
+ public static function listDropDown( $name= '', $list = '', $other = '', $selected = '', $class = '', $tabindex = Null ) {
$options = '';
$optgroup = false;
}
if( $optgroup ) $options .= self::closeElement('optgroup');
- return Xml::openElement( 'select', array( 'id' => 'wpReasonDropDown', 'name' => 'wpReasonDropDown',
- 'class' => 'wpReasonDropDown' ) )
+ return Xml::openElement( 'select', array( 'id' => $name, 'name' => $name,
+ 'class' => $class, 'tabindex' => $tabindex ) )
. "\n"
. $options
. "\n"