r83280 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83279‎ | r83280 | r83281 >
Date:12:48, 5 March 2011
Author:happy-melon
Status:ok (Comments)
Tags:
Comment:
Follow-up r83183, r83202:
* Update SpecialCheckUser.php to new location of IP functions
* Spin out the 'hide-other-field-if-select-box-not-on-other' function as one which should apply to all such fields, especially those created via HTMLForm. SpecialBlockip and SpecialGlobalBlock should ultimately be converted to use HTMLForm anyway.
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/checkuser.js (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php (modified) (history)
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.block.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.htmlform.js (added) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -184,7 +184,7 @@
185185 if ( !$class ) {
186186 throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
187187 }
188 -
 188+
189189 $descriptor['fieldname'] = $fieldname;
190190
191191 $obj = new $class( $descriptor );
@@ -210,7 +210,7 @@
211211
212212 /**
213213 * Try submitting, with edit token check first
214 - * @return Status|boolean
 214+ * @return Status|boolean
215215 */
216216 function tryAuthorizedSubmit() {
217217 global $wgUser, $wgRequest;
@@ -368,6 +368,7 @@
369369
370370 # For good measure (it is the default)
371371 $wgOut->preventClickjacking();
 372+ $wgOut->addModules( 'mediawiki.htmlform' );
372373
373374 $html = ''
374375 . $this->getErrors( $submitResult )
@@ -424,7 +425,6 @@
425426 global $wgUser;
426427
427428 $html = '';
428 -
429429 if( $this->getMethod() == 'post' ){
430430 $html .= Html::hidden( 'wpEditToken', $wgUser->editToken(), array( 'id' => 'wpEditToken' ) ) . "\n";
431431 $html .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n";
@@ -623,7 +623,7 @@
624624 function getTitle() {
625625 return $this->mTitle;
626626 }
627 -
 627+
628628 /**
629629 * Set the method used to submit the form
630630 * @param $method String
@@ -631,7 +631,7 @@
632632 public function setMethod( $method='post' ){
633633 $this->mMethod = $method;
634634 }
635 -
 635+
636636 public function getMethod(){
637637 return $this->mMethod;
638638 }
@@ -840,12 +840,12 @@
841841 if ( isset( $params['name'] ) ) {
842842 $this->mName = $params['name'];
843843 }
844 -
 844+
845845 $validName = Sanitizer::escapeId( $this->mName );
846846 if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
847847 throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
848848 }
849 -
 849+
850850 $this->mID = "mw-input-{$this->mName}";
851851
852852 if ( isset( $params['default'] ) ) {
@@ -887,10 +887,10 @@
888888 global $wgRequest;
889889
890890 $errors = $this->validate( $value, $this->mParent->mFieldData );
891 -
 891+
892892 $cellAttributes = array();
893893 $verticalLabel = false;
894 -
 894+
895895 if ( !empty($this->mParams['vertical-label']) ) {
896896 $cellAttributes['colspan'] = 2;
897897 $verticalLabel = true;
@@ -908,9 +908,9 @@
909909 array( 'class' => 'mw-input' ) + $cellAttributes,
910910 $this->getInputHTML( $value ) . "\n$errors"
911911 );
912 -
 912+
913913 $fieldType = get_class( $this );
914 -
 914+
915915 if ($verticalLabel) {
916916 $html = Html::rawElement( 'tr',
917917 array( 'class' => 'mw-htmlform-vertical-label' ), $label );
@@ -1139,11 +1139,11 @@
11401140 if ( $p !== true ) {
11411141 return $p;
11421142 }
1143 -
 1143+
11441144 $value = trim( $value );
11451145
11461146 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
1147 - # with the addition that a leading '+' sign is ok.
 1147+ # with the addition that a leading '+' sign is ok.
11481148 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
11491149 return wfMsgExt( 'htmlform-float-invalid', 'parse' );
11501150 }
@@ -1182,8 +1182,8 @@
11831183 }
11841184
11851185 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
1186 - # with the addition that a leading '+' sign is ok. Note that leading zeros
1187 - # are fine, and will be left in the input, which is useful for things like
 1186+ # with the addition that a leading '+' sign is ok. Note that leading zeros
 1187+ # are fine, and will be left in the input, which is useful for things like
11881188 # phone numbers when you know that they are integers (the HTML5 type=tel
11891189 # input does not require its value to be numeric). If you want a tidier
11901190 # value to, eg, save in the DB, clean it up with intval().
@@ -1415,8 +1415,8 @@
14161416 } else {
14171417 $thisAttribs = array( 'id' => "{$this->mID}-$info", 'value' => $info );
14181418
1419 - $checkbox = Xml::check(
1420 - $this->mName . '[]',
 1419+ $checkbox = Xml::check(
 1420+ $this->mName . '[]',
14211421 in_array( $info, $value, true ),
14221422 $attribs + $thisAttribs );
14231423 $checkbox .= ' ' . Html::rawElement( 'label', array( 'for' => "{$this->mID}-$info" ), $label );
@@ -1556,7 +1556,7 @@
15571557 class HTMLHiddenField extends HTMLFormField {
15581558 public function __construct( $params ) {
15591559 parent::__construct( $params );
1560 -
 1560+
15611561 # Per HTML5 spec, hidden fields cannot be 'required'
15621562 # http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
15631563 unset( $this->mParams['required'] );
@@ -1605,7 +1605,7 @@
16061606 protected function needsLabel() {
16071607 return false;
16081608 }
1609 -
 1609+
16101610 /**
16111611 * Button cannot be invalid
16121612 */
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -199,7 +199,9 @@
200200 wfMsgForContent( 'ipbreason-dropdown' ),
201201 wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
202202
203 - $wgOut->addModules( 'mediawiki.special.block' );
 203+ # FIXME: this should actually use HTMLForm, not just some of its JavaScript
 204+ $wgOut->addModules( array( 'mediawiki.special.block', 'mediawiki.htmlform' ) );
 205+
204206 $wgOut->addHTML(
205207 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
206208 Xml::openElement( 'fieldset' ) .
@@ -218,33 +220,35 @@
219221 ) + ( $this->BlockAddress ? array() : array( 'autofocus' ) ) ). "
220222 </td>
221223 </tr>
222 - <tr>"
223 - );
224 - if( $showblockoptions ) {
225 - $wgOut->addHTML("
 224+ <tr>
226225 <td class='mw-label'>
227226 {$mIpbexpiry}
228227 </td>
229 - <td class='mw-input'>" .
 228+ <td class='mw-input'>"
 229+ );
 230+ if( $showblockoptions ) {
 231+ $wgOut->addHTML(
230232 Xml::tags( 'select',
231233 array(
232234 'id' => 'wpBlockExpiry',
233235 'name' => 'wpBlockExpiry',
 236+ 'class' => 'mw-htmlform-select-or-other', # FIXME: actually make this use HTMLForm
234237 'tabindex' => '2' ),
235 - $blockExpiryFormOptions ) .
236 - "</td>"
 238+ $blockExpiryFormOptions
 239+ ) . "<br/>\n"
237240 );
238241 }
239 - $wgOut->addHTML("
240 - </tr>
241 - <tr id='wpBlockOther'>
242 - <td class='mw-label'>
243 - {$mIpbother}
 242+ $wgOut->addHTML(
 243+ Xml::input(
 244+ 'wpBlockOther',
 245+ 45,
 246+ $this->BlockOther,
 247+ array(
 248+ 'tabindex' => '3',
 249+ 'id' => 'wpBlockExpiry-other'
 250+ )
 251+ ) . "
244252 </td>
245 - <td class='mw-input'>" .
246 - Xml::input( 'wpBlockOther', 45, $this->BlockOther,
247 - array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
248 - </td>
249253 </tr>
250254 <tr>
251255 <td class='mw-label'>
Index: trunk/phase3/resources/Resources.php
@@ -382,6 +382,9 @@
383383 'debugScripts' => 'resources/mediawiki/mediawiki.log.js',
384384 'debugRaw' => false,
385385 ),
 386+ 'mediawiki.htmlform' => array(
 387+ 'scripts' => 'resources/mediawiki/mediawiki.htmlform.js',
 388+ ),
386389 'mediawiki.util' => array(
387390 'scripts' => 'resources/mediawiki.util/mediawiki.util.js',
388391 'dependencies' => array(
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.block.js
@@ -1,34 +1,12 @@
22 /* JavaScript for Special:Block */
33
4 -// Fade or snap depending on argument
5 -jQuery.fn.goIn = function( instantToggle ) {
6 - if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
7 - return jQuery(this).show();
8 - }
9 - return jQuery(this).stop( true, true ).fadeIn();
10 -};
11 -jQuery.fn.goOut = function( instantToggle ) {
12 - if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
13 - return jQuery(this).hide();
14 - }
15 - return jQuery(this).stop( true, true ).fadeOut();
16 -};
17 -
184 jQuery( function( $ ) {
195
206 var DO_INSTANT = true,
21 - $blockExpiry = $( '#wpBlockExpiry' ), $blockOther = $( '#wpBlockOther' ),
227 $blockTarget = $( '#mw-bi-target' ), $anonOnlyRow = $( '#wpAnonOnlyRow' ),
238 $enableAutoblockRow = $( '#wpEnableAutoblockRow' ),
249 $hideUser = $( '#wpEnableHideUser' ), $watchUser = $( '#wpEnableWatchUser' );
2510
26 - var considerChangingExpiryFocus = function( instant ) {
27 - if ( $blockExpiry.val() == 'other' ) {
28 - $blockOther.goIn( instant );
29 - } else {
30 - $blockOther.goOut( instant );
31 - }
32 - };
3311 var updateBlockOptions = function( instant ) {
3412 if ( !$blockTarget.length ) {
3513 return;
@@ -59,10 +37,8 @@
6038 };
6139
6240 // Bind functions so they're checked whenever stuff changes
63 - $blockExpiry.change( considerChangingExpiryFocus );
6441 $blockTarget.keyup( updateBlockOptions );
6542
6643 // Call them now to set initial state (ie. Special:Block/Foobar?wpBlockExpiry=2+hours)
67 - considerChangingExpiryFocus( DO_INSTANT );
6844 updateBlockOptions( DO_INSTANT );
6945 });
\ No newline at end of file
Index: trunk/phase3/resources/mediawiki/mediawiki.htmlform.js
@@ -0,0 +1,46 @@
 2+/**
 3+ * Utility functions for jazzing up HTMLForm elements
 4+ */
 5+
 6+// Fade or snap depending on argument
 7+jQuery.fn.goIn = function( instantToggle ) {
 8+ if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
 9+ return $(this).show();
 10+ }
 11+ return jQuery(this).stop( true, true ).fadeIn();
 12+};
 13+jQuery.fn.goOut = function( instantToggle ) {
 14+ if ( typeof instantToggle != 'undefined' && instantToggle === true ) {
 15+ return $(this).hide();
 16+ }
 17+ return jQuery(this).stop( true, true ).fadeOut();
 18+};
 19+
 20+/**
 21+ * Bind a function to the jQuery object via live(), and also immediately trigger
 22+ * the function on the objects with an 'instant' paramter set to true
 23+ * @param callback function taking one paramter, which is Bool true when the event
 24+ * is called immediately, and the EventArgs object when triggered from an event
 25+ */
 26+jQuery.fn.liveAndTestAtStart = function( callback ){
 27+ $(this)
 28+ .live( 'change', callback )
 29+ .each( function( index, element ){
 30+ callback.call( this, true );
 31+ } );
 32+}
 33+
 34+jQuery( function( $ ) {
 35+
 36+ // animate the SelectOrOther fields, to only show the text field when
 37+ // 'other' is selected
 38+ $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ){
 39+ var $other = $( '#' + $(this).attr( 'id' ) + '-other' );
 40+ if ( $(this).val() == 'other' ) {
 41+ $other.goIn( instant );
 42+ } else {
 43+ $other.goOut( instant );
 44+ }
 45+ });
 46+
 47+});
\ No newline at end of file
Property changes on: trunk/phase3/resources/mediawiki/mediawiki.htmlform.js
___________________________________________________________________
Added: svn:eol-style
148 + native
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlock.php
@@ -221,7 +221,7 @@
222222 'wpExpiryOther',
223223 45,
224224 $this->mExpiry == $this->mExpirySelection ? '' : $this->mExpiry,
225 - array( 'id' => 'mw-globalblock-expiry-other' )
 225+ array( 'id' => 'mw-globalblock-expiry-selector-other' )
226226 );
227227 }
228228
@@ -264,6 +264,9 @@
265265 $form .= Xml::closeElement( 'form' );
266266 $form .= Xml::closeElement( 'fieldset' );
267267
 268+ #FIXME: make this actually use HTMLForm, instead of just its JavaScript
 269+ $wgOut->addModules( 'mediawiki.htmlform' );
 270+
268271 $wgOut->addHTML( $form );
269272
270273 // Show loglist of previous blocks
@@ -289,7 +292,10 @@
290293 if ($id == null) { $id = $name; }
291294 if ($selected == null) { $selected = 'other'; }
292295
293 - $attribs = array( 'id' => $id, 'name' => $name, 'onchange' => 'considerChangingExpiryFocus()' );
 296+ $attribs = array(
 297+ 'id' => $id,
 298+ 'name' => $name,
 299+ 'class' => 'mw-htmlform-select-or-other' ); # FIXME: make this actually use HTMLForm
294300
295301 $selector .= Xml::openElement( 'select', $attribs );
296302
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -71,8 +71,8 @@
7272 $wgHooks['ContributionsToolLinks'][] = 'efLoadCheckUserLink';
7373
7474 $wgResourceModules['ext.checkUser'] = array(
75 - 'scripts' => 'checkuser.js',
76 - 'dependencies' => array( 'mediawiki.legacy.block' ), // IP stuff
 75+ 'scripts' => 'checkuser.js',
 76+ 'dependencies' => array( 'mediawiki.util' ), // IP stuff
7777 'localBasePath' => dirname( __FILE__ ),
7878 'remoteExtPath' => 'CheckUser',
7979 );
Index: trunk/extensions/CheckUser/checkuser.js
@@ -40,11 +40,11 @@
4141 // Go through each IP in the list, get its binary form, and
4242 // track the largest binary prefix among them...
4343 for( var i = 0; i < ips.length; i++ ) {
44 - // ...in the spirit of block.js, call this "addy"
 44+ // ...in the spirit of mediawiki.special.block.js, call this "addy"
4545 var addy = ips[i].replace(/^\s*|\s*$/, '' ); // trim
4646 // Match the first IP in each list (ignore other garbage)
47 - var ipV4 = isIPv4Address( addy, true ); // from block.js
48 - var ipV6 = isIPv6Address( addy, true ); // from block.js
 47+ var ipV4 = mw.util.isIPv4Address( addy, true );
 48+ var ipV6 = mw.util.isIPv6Address( addy, true );
4949 var ip_cidr = addy.match(/^(.*)(?:\/(\d+))?$/);
5050 // Binary form
5151 var bin = new String( '' );

Sign-offs

UserFlagDate
Krinkleinspected23:35, 10 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r83300Follow-up r83280; looks like I accidentally deprecated a piece of legacy JS :Dhappy-melon17:06, 5 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83183Convert Special:BlockIP JS to jQuery/ResourceLoader. Change the order of the...happy-melon23:54, 3 March 2011
r83202Moving IP-check to mw.util & some enhancements to and applying code conventio...krinkle01:48, 4 March 2011

Comments

#Comment by Happy-melon (talk | contribs)   12:49, 5 March 2011

Hmm, seem to be quite a few random whitespace changes in HTMLForm.php...

#Comment by Aaron Schulz (talk | contribs)   16:07, 16 June 2011

- if( $showblockoptions ) {

Why was that check shifted down?

#Comment by Aaron Schulz (talk | contribs)   23:00, 11 July 2011

Nevermind.

Status & tagging log