From d4e61f4e83e3ba2de5025a9c9bf7af094907113c Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Tue, 28 Apr 2009 01:00:35 +0000 Subject: [PATCH] * Fix silly PHP annoyance where eauth message was shown on all saves. * Disable email-related checkboxes when email address is not confirmed --- includes/HTMLForm.php | 53 +++++++++++++++++++++++++++++++++------- includes/Preferences.php | 2 +- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index 89ef72a79a..c06bd9e6ed 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -306,7 +306,11 @@ class HTMLForm { foreach( $this->mFlatFields as $fieldname => $field ) { if ( !empty($field->mParams['nodata']) ) continue; - $fieldData[$fieldname] = $field->loadDataFromRequest( $wgRequest ); + if ( !empty($field->mParams['disabled']) ) { + $fieldData[$fieldname] = $field->getDefault(); + } else { + $fieldData[$fieldname] = $field->loadDataFromRequest( $wgRequest ); + } } // Filter data. @@ -492,10 +496,14 @@ class HTMLTextField extends HTMLFormField { $attribs['maxlength'] = $this->mParams['maxlength']; } + if (!empty($this->mParams['disabled'])) { + $attribs['disabled'] = 'disabled'; + } + return Xml::input( $this->mName, $this->getSize(), $value, - $attribs ); + $attribs ) ; } } @@ -537,7 +545,12 @@ class HTMLCheckField extends HTMLFormField { if ( !empty( $this->mParams['invert'] ) ) $value = !$value; - return Xml::check( $this->mName, $value, array( 'id' => $this->mID ) ) . ' ' . + $attr = array( 'id' => $this->mID ); + if (!empty($this->mParams['disabled'])) { + $attr['disabled'] = 'disabled'; + } + + return Xml::check( $this->mName, $value, $attr ) . ' ' . Xml::tags( 'label', array( 'for' => $this->mID ), $this->mLabel ); } @@ -579,9 +592,13 @@ class HTMLSelectField extends HTMLFormField { return wfMsgExt( 'htmlform-select-badoption', 'parseinline' ); } - function getInputHTML( $value ) { + function getInputHTML( $value ) { $select = new XmlSelect( $this->mName, $this->mID, $value ); + if (!empty($this->mParams['disabled'])) { + $select->setAttribute( 'disabled', 'disabled' ); + } + $select->addOptions( $this->mParams['options'] ); return $select->getHTML(); @@ -600,8 +617,8 @@ class HTMLSelectOrOtherField extends HTMLTextField { } function getInputHTML( $value ) { - $valInSelect = false; + if ($value !== false) $valInSelect = in_array( $value, HTMLFormField::flattenOptions($this->mParams['options']) ); @@ -613,9 +630,13 @@ class HTMLSelectOrOtherField extends HTMLTextField { $select->setAttribute( 'class', 'mw-htmlform-select-or-other' ); - $select = $select->getHTML(); - $tbAttribs = array( 'id' => $this->mID.'-other' ); + if (!empty($this->mParams['disabled'])) { + $select->setAttribute( 'disabled', 'disabled' ); + $tbAttribs['disabled'] = 'disabled'; + } + + $select = $select->getHTML(); if ( isset($this->mParams['maxlength']) ) { $tbAttribs['maxlength'] = $this->mParams['maxlength']; @@ -670,13 +691,21 @@ class HTMLMultiSelectField extends HTMLFormField { function formatOptions( $options, $value ) { $html = ''; + + $attribs = array(); + if ( !empty( $this->mParams['disabled'] ) ) { + $attribs['disabled'] = 'disabled'; + } + foreach( $options as $label => $info ) { if (is_array($info)) { $html .= Xml::tags( 'h1', null, $label ) . "\n"; $html .= $this->formatOptions( $info, $value ); } else { + $thisAttribs = array( 'id' => $this->mID."-$info", 'value' => $info ); + $checkbox = Xml::check( $this->mName.'[]', in_array( $info, $value ), - array( 'id' => $this->mID."-$info", 'value' => $info ) ); + $attribs + $thisAttribs ); $checkbox .= ' ' . Xml::tags( 'label', array( 'for' => $this->mID."-$info" ), $label ); $html .= $checkbox . '
'; @@ -733,13 +762,19 @@ class HTMLRadioField extends HTMLFormField { function formatOptions( $options, $value ) { $html = ''; + + $attribs = array(); + if ( !empty( $this->mParams['disabled'] ) ) { + $attribs['disabled'] = 'disabled'; + } + foreach( $options as $label => $info ) { if (is_array($info)) { $html .= Xml::tags( 'h1', null, $label ) . "\n"; $html .= $this->formatOptions( $info, $value ); } else { $html .= Xml::radio( $this->mName, $info, $info == $value, - array( 'id' => $this->mID."-$info" ) ); + $attribs + array( 'id' => $this->mID."-$info" ) ); $html .= ' ' . Xml::tags( 'label', array( 'for' => $this->mID."-$info" ), $label ); diff --git a/includes/Preferences.php b/includes/Preferences.php index 2303c06c67..fec3a74d82 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1165,7 +1165,7 @@ class Preferences { if ($res) { $urlOptions = array( 'success' ); - if ($res) + if ($res === 'eauth') $urlOptions[] = 'eauth'; $queryString = implode( '&', $urlOptions ); -- 2.20.1