if ( !$class ) {
throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
}
-
+
$descriptor['fieldname'] = $fieldname;
$obj = new $class( $descriptor );
/**
* Try submitting, with edit token check first
- * @return Status|boolean
+ * @return Status|boolean
*/
function tryAuthorizedSubmit() {
global $wgUser, $wgRequest;
# For good measure (it is the default)
$wgOut->preventClickjacking();
+ $wgOut->addModules( 'mediawiki.htmlform' );
$html = ''
. $this->getErrors( $submitResult )
global $wgUser;
$html = '';
-
if( $this->getMethod() == 'post' ){
$html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
$html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
function getTitle() {
return $this->mTitle;
}
-
+
/**
* Set the method used to submit the form
* @param $method String
public function setMethod( $method='post' ){
$this->mMethod = $method;
}
-
+
public function getMethod(){
return $this->mMethod;
}
if ( isset( $params['name'] ) ) {
$this->mName = $params['name'];
}
-
+
$validName = Sanitizer::escapeId( $this->mName );
if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
}
-
+
$this->mID = "mw-input-{$this->mName}";
if ( isset( $params['default'] ) ) {
global $wgRequest;
$errors = $this->validate( $value, $this->mParent->mFieldData );
-
+
$cellAttributes = array();
$verticalLabel = false;
-
+
if ( !empty($this->mParams['vertical-label']) ) {
$cellAttributes['colspan'] = 2;
$verticalLabel = true;
array( 'class' => 'mw-input' ) + $cellAttributes,
$this->getInputHTML( $value ) . "\n$errors"
);
-
+
$fieldType = get_class( $this );
-
+
if ($verticalLabel) {
$html = Html::rawElement( 'tr',
array( 'class' => 'mw-htmlform-vertical-label' ), $label );
if ( $p !== true ) {
return $p;
}
-
+
$value = trim( $value );
# http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
- # with the addition that a leading '+' sign is ok.
+ # with the addition that a leading '+' sign is ok.
if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
return wfMsgExt( 'htmlform-float-invalid', 'parse' );
}
}
# http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
- # with the addition that a leading '+' sign is ok. Note that leading zeros
- # are fine, and will be left in the input, which is useful for things like
+ # with the addition that a leading '+' sign is ok. Note that leading zeros
+ # are fine, and will be left in the input, which is useful for things like
# phone numbers when you know that they are integers (the HTML5 type=tel
# input does not require its value to be numeric). If you want a tidier
# value to, eg, save in the DB, clean it up with intval().
} else {
$thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
- $checkbox = Xml::check(
- $this->mName . '[]',
+ $checkbox = Xml::check(
+ $this->mName . '[]',
in_array( $info, $value, true ),
$attribs + $thisAttribs );
$checkbox .= ' ' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
class HTMLHiddenField extends HTMLFormField {
public function __construct( $params ) {
parent::__construct( $params );
-
+
# Per HTML5 spec, hidden fields cannot be 'required'
# http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
unset( $this->mParams['required'] );
protected function needsLabel() {
return false;
}
-
+
/**
* Button cannot be invalid
*/
wfMsgForContent( 'ipbreason-dropdown' ),
wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
- $wgOut->addModules( 'mediawiki.special.block' );
+ # FIXME: this should actually use HTMLForm, not just some of its JavaScript
+ $wgOut->addModules( array( 'mediawiki.special.block', 'mediawiki.htmlform' ) );
+
$wgOut->addHTML(
Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
Xml::openElement( 'fieldset' ) .
) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). "
</td>
</tr>
- <tr>"
- );
- if( $showblockoptions ) {
- $wgOut->addHTML("
+ <tr>
<td class='mw-label'>
{$mIpbexpiry}
</td>
- <td class='mw-input'>" .
+ <td class='mw-input'>"
+ );
+ if( $showblockoptions ) {
+ $wgOut->addHTML(
Xml::tags( 'select',
array(
'id' => 'wpBlockExpiry',
'name' => 'wpBlockExpiry',
+ 'class' => 'mw-htmlform-select-or-other', # FIXME: actually make this use HTMLForm
'tabindex' => '2' ),
- $blockExpiryFormOptions ) .
- "</td>"
+ $blockExpiryFormOptions
+ ) . "<br/>\n"
);
}
- $wgOut->addHTML("
- </tr>
- <tr id='wpBlockOther'>
- <td class='mw-label'>
- {$mIpbother}
- </td>
- <td class='mw-input'>" .
- Xml::input( 'wpBlockOther', 45, $this->BlockOther,
- array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
+ $wgOut->addHTML(
+ Xml::input(
+ 'wpBlockOther',
+ 45,
+ $this->BlockOther,
+ array(
+ 'tabindex' => '3',
+ 'id' => 'wpBlockExpiry-other'
+ )
+ ) . "
</td>
</tr>
<tr>
'debugScripts' => 'resources/mediawiki/mediawiki.log.js',
'debugRaw' => false,
),
+ 'mediawiki.htmlform' => array(
+ 'scripts' => 'resources/mediawiki/mediawiki.htmlform.js',
+ ),
'mediawiki.util' => array(
'scripts' => 'resources/mediawiki.util/mediawiki.util.js',
'dependencies' => array(
/* JavaScript for Special:Block */
-// Fade or snap depending on argument
-jQuery.fn.goIn = function( instantToggle ) {
- if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
- return jQuery(this).show();
- }
- return jQuery(this).stop( true, true ).fadeIn();
-};
-jQuery.fn.goOut = function( instantToggle ) {
- if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
- return jQuery(this).hide();
- }
- return jQuery(this).stop( true, true ).fadeOut();
-};
-
jQuery( function( $ ) {
var DO_INSTANT = true,
- $blockExpiry = $( '#wpBlockExpiry' ), $blockOther = $( '#wpBlockOther' ),
$blockTarget = $( '#mw-bi-target' ), $anonOnlyRow = $( '#wpAnonOnlyRow' ),
$enableAutoblockRow = $( '#wpEnableAutoblockRow' ),
$hideUser = $( '#wpEnableHideUser' ), $watchUser = $( '#wpEnableWatchUser' );
- var considerChangingExpiryFocus = function( instant ) {
- if ( $blockExpiry.val() == 'other' ) {
- $blockOther.goIn( instant );
- } else {
- $blockOther.goOut( instant );
- }
- };
var updateBlockOptions = function( instant ) {
if ( !$blockTarget.length ) {
return;
};
// Bind functions so they're checked whenever stuff changes
- $blockExpiry.change( considerChangingExpiryFocus );
$blockTarget.keyup( updateBlockOptions );
// Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
- considerChangingExpiryFocus( DO_INSTANT );
updateBlockOptions( DO_INSTANT );
});
\ No newline at end of file
--- /dev/null
+/**
+ * Utility functions for jazzing up HTMLForm elements
+ */
+
+// Fade or snap depending on argument
+jQuery.fn.goIn = function( instantToggle ) {
+ if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
+ return $(this).show();
+ }
+ return jQuery(this).stop( true, true ).fadeIn();
+};
+jQuery.fn.goOut = function( instantToggle ) {
+ if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
+ return $(this).hide();
+ }
+ return jQuery(this).stop( true, true ).fadeOut();
+};
+
+/**
+ * Bind a function to the jQuery object via live(), and also immediately trigger
+ * the function on the objects with an 'instant' paramter set to true
+ * @param callback function taking one paramter, which is Bool true when the event
+ * is called immediately, and the EventArgs object when triggered from an event
+ */
+jQuery.fn.liveAndTestAtStart = function( callback ){
+ $(this)
+ .live( 'change', callback )
+ .each( function( index, element ){
+ callback.call( this, true );
+ } );
+}
+
+jQuery( function( $ ) {
+
+ // animate the SelectOrOther fields, to only show the text field when
+ // 'other' is selected
+ $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ){
+ var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
+ if ( $(this).val() == 'other' ) {
+ $other.goIn( instant );
+ } else {
+ $other.goOut( instant );
+ }
+ });
+
+});
\ No newline at end of file