* Renaming Xml::reasonDropDown to Xml::listDropDown to make sure it doesn't imply...
authorHuji <huji@users.mediawiki.org>
Mon, 28 Jan 2008 12:57:02 +0000 (12:57 +0000)
committerHuji <huji@users.mediawiki.org>
Mon, 28 Jan 2008 12:57:02 +0000 (12:57 +0000)
* 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.

includes/Article.php
includes/FileDeleteForm.php
includes/SpecialBlockip.php
includes/Xml.php

index 79b38e2..009bdcf 100644 (file)
@@ -2096,41 +2096,10 @@ class Article {
                $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'>
@@ -2139,14 +2108,12 @@ class Article {
                                $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\" />
index 229cba5..5f0b74c 100644 (file)
@@ -112,41 +112,10 @@ class FileDeleteForm {
        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>';
@@ -154,10 +123,8 @@ class FileDeleteForm {
                $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">';
index f059013..6b26a35 100644 (file)
@@ -82,7 +82,6 @@ class IPBlockForm {
                $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" );
@@ -111,38 +110,8 @@ class IPBlockForm {
                        $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();
 
@@ -182,17 +151,13 @@ class IPBlockForm {
                                        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>
index 3c209d0..2262df8 100644 (file)
@@ -330,14 +330,16 @@ class Xml {
        }
 
        /**
-        * 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;
                
@@ -366,8 +368,8 @@ class Xml {
                        }
                        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"