From: Huji Date: Mon, 28 Jan 2008 12:57:02 +0000 (+0000) Subject: * Renaming Xml::reasonDropDown to Xml::listDropDown to make sure it doesn't imply... X-Git-Tag: 1.31.0-rc.0~49748 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=da4897cf6d36a5ea2a4c179b4694cef55d27ed6d;p=lhc%2Fweb%2Fwiklou.git * Renaming Xml::reasonDropDown to Xml::listDropDown to make sure it doesn't imply a special usage. * 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. --- diff --git a/includes/Article.php b/includes/Article.php index 79b38e2c7f..009bdcfd99 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 = ""; - $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 = ""; - } elseif ( substr( $value, 0, 2) == '**' ) { - // groupmember - $selected = ""; - $value = trim( substr( $value, 2 ) ); - if ( $this->DeleteReasonList === $value) - $selected = ' selected="selected"'; - $deleteReasonList .= ""; - } else { - // groupless delete reason - $selected = ""; - if ( $this->DeleteReasonList === $value) - $selected = ' selected="selected"'; - $deleteReasonList .= "$optgroup"; - $optgroup = ""; - } - } - $deleteReasonList .= $optgroup; - } + $deletereasonother = Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ); + $reasonDropDown = Xml::listDropDown( 'wpDeleteReasonList', wfMsgHtml( 'deletereason-dropdown' ), + wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ); + $wgOut->addHTML( "
@@ -2139,14 +2108,12 @@ class Article { $delcom:
- + $reasonDropDown
- $mDeletereasonother + $deletereasonother diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 229cba59b3..5f0b74c641 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -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 = ""; - $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 = ""; - } elseif ( substr( $value, 0, 2) == '**' ) { - // groupmember - $selected = ""; - $value = trim( substr( $value, 2 ) ); - if ( $mDeleteReasonList === $value) - $selected = ' selected="selected"'; - $deleteReasonList .= ""; - } else { - // groupless delete reason - $selected = ""; - if ( $this->DeleteReasonList === $value) - $selected = ' selected="selected"'; - $deleteReasonList .= "$optgroup"; - $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 .= '
' . wfMsgHtml( 'filedelete-legend' ) . ''; @@ -154,10 +123,8 @@ class FileDeleteForm { $form .= '"); - if ( $blockReasonList != '' ) { - $wgOut->addHTML(" - - - - "); - } + $wgOut->addHTML(" + + + + "); $wgOut->addHTML(" diff --git a/includes/Xml.php b/includes/Xml.php index 3c209d0a5f..2262df86c2 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -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"
'; $form .= $this->prepareMessage( 'filedelete-intro' ); $form .= "
$delcom "; - $form .= ""; - $form .= "
$mDeletereasonother "; + $form .= $reasonDropDown; + $form .= "
$deletereasonother "; $form .= "getText( 'wpReason' ) ) ."\" tabindex=\"1\" />"; $form .= '
'; diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index f059013eb6..6b26a358bf 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -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 .= ""; } - $scBlockReasonList = wfMsgForContent( 'ipbreason-dropdown' ); - $blockReasonList = ''; - if ( $scBlockReasonList != '' && $scBlockReasonList != '-' ) { - $blockReasonList = ""; - $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 = ""; - } elseif ( substr( $value, 0, 2) == '**' ) { - // groupmember - $selected = ""; - $value = trim( substr( $value, 2 ) ); - if ( $this->BlockReasonList === $value) - $selected = ' selected="selected"'; - $blockReasonList .= ""; - } else { - // groupless block reason - $selected = ""; - if ( $this->BlockReasonList === $value) - $selected = ' selected="selected"'; - $blockReasonList .= "$optgroup"; - $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' ) ) . "
{$mIpbreasonother} - -
{$mIpbreasonother} + $reasonDropDown +
{$mIpbreason}