r90359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90358‎ | r90359 | r90360 >
Date:19:57, 18 June 2011
Author:mgrabovsky
Status:resolved (Comments)
Tags:
Comment:
(bug 29443) Special:Undelete should invert checkboxes without reloading

Committed patch with code originally by [[b:User:Darklama]]
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.undelete.js (added) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -97,6 +97,8 @@
9898 enter an e-mail address.
9999 * (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds"
100100 * The class JpegOrTiffHandler was renamed ExifBitmapHandler.
 101+* (bug 29443) Special:Undelete should use JavaScript to invert all checkboxes
 102+ without reloading the page
101103
102104 === API changes in 1.19 ===
103105 * BREAKING CHANGE: action=watch now requires POST and token.
Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -1070,11 +1070,11 @@
10711071
10721072 $sk = $wgUser->getSkin();
10731073 if( $this->mAllowed ) {
 1074+ $wgOut->addModules( 'mediawiki.special.undelete' );
10741075 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
10751076 } else {
10761077 $wgOut->setPageTitle( wfMsg( 'viewdeletedpage' ) );
10771078 }
1078 -
10791079 $wgOut->wrapWikiMsg(
10801080 "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
10811081 array( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() )
Index: trunk/phase3/resources/Resources.php
@@ -518,6 +518,9 @@
519519 'mediawiki.special.block' => array(
520520 'scripts' => 'resources/mediawiki.special/mediawiki.special.block.js',
521521 ),
 522+ 'mediawiki.special.undelete' => array(
 523+ 'scripts' => 'resources/mediawiki.special/mediawiki.special.undelete.js',
 524+ ),
522525 'mediawiki.special.movePage' => array(
523526 'scripts' => 'resources/mediawiki.special/mediawiki.special.movePage.js',
524527 'dependencies' => 'jquery.byteLimit',
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.undelete.js
@@ -0,0 +1,15 @@
 2+/*
 3+ * JavaScript for Specical:Undelete
 4+ * @author: Code taken from [[b:MediaWiki:Gadget-EnhancedUndelete.js]] (originally written by [[b:User:Darklama]])
 5+ */
 6+( function( $ ) {
 7+ $(function() {
 8+ $('#mw-undelete-invert').click( function(e) {
 9+ e.stopImmediatePropagation();
 10+ $('input:checkbox').each( function() {
 11+ this.checked = !this.checked;
 12+ });
 13+ return false;
 14+ });
 15+ });
 16+} )( jQuery );
Property changes on: trunk/phase3/resources/mediawiki.special/mediawiki.special.undelete.js
___________________________________________________________________
Added: svn:eol-style
117 + native

Sign-offs

UserFlagDate
He7d3rtested19:45, 19 June 2011
Krinkletested16:52, 22 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r90587Follow-up r90359: modify code per Krinkle's commentsmgrabovsky14:51, 22 June 2011

Comments

#Comment by Hashar (talk | contribs)   15:40, 20 June 2011

This breaks Javascript tests: http://toolserver.org/~krinkle/testswarm/job/123/

Marking fixme :)


jquery.tabindex.js under Opera 11.0x:

http://toolserver.org/~krinkle/testswarm/?state=runresults&run_id=718&client_id=1824

mediawiki.Title.js under Opera 11.1x:

http://toolserver.org/~krinkle/testswarm/?state=runresults&run_id=719&client_id=1822


See Manual:JavaScript unit testing for help about running the test yourself :)


#Comment by Matěj Grabovský (talk | contribs)   19:15, 20 June 2011

Oh, sorry. I can't reproduce this on Windows, though. Nor have I any idea what is causing it or how to fix it.

#Comment by 😂 (talk | contribs)   19:49, 20 June 2011

When in doubt, back it out :)

#Comment by Brion VIBBER (talk | contribs)   20:05, 20 June 2011

Those tests don't look like they could be affected by this change in any way, as no file changed by this commit is loaded in the tests.

Removing fixme.

#Comment by Brion VIBBER (talk | contribs)   20:13, 20 June 2011

Can't repro errors on Opera 11.11/OS X either -- probably temporary problems from files not getting reloaded properly or something.

#Comment by Hashar (talk | contribs)   20:18, 20 June 2011

Thanks brion for testing this. I will poke Krinkle about this to check if it might be a bug in testswarm.

#Comment by Krinkle (talk | contribs)   23:48, 20 June 2011

Hi folks,

Just got an e-mail from Hashar. Looks like the Opera-client that was connected to the swarm had a short connection interruption half-way loading the page. This caused a few scripts to occasionally not be loaded. Not much TestSwarm can do about this.

TestSwarm has a setting for each "project" which controls how "certain" TestSwarm must be before marking a test as broken and continuing with the next test. For MediaWiki this setting is set to 3, this means if a client (say a browser with the Presto 2.7 engine) reports a test to be broken, TestSwarm will, if and when a similar browser is available again, re-send the test up to three times in attempt to get a "success". Only after three times it will continue to the next test job for that browser.

The reason the MediaWiki-project page kept showing the test as broken was likely because the Opera-client disconnected right after running that 1 test. I've reconnected two Opera-clients locally here and as expected they were first fed the broken tests and they are now showing up as succeeded without errors :-)

http://toolserver.org/~krinkle/testswarm/user/MediaWiki

As you can see the Opera 11.1 turned green. I don't have Opera 11.0 here though, if you do, simply reconnect it and it should fix itself.

#Comment by Krinkle (talk | contribs)   00:12, 21 June 2011

Aside from that, marking as fixme per the next few points:

  • Why is this callback function returning false ? It is therewith blocking any and all other events that may be bound, use e.preventDefault() instead.
  • Although the difference in this particular case is quite small (since SpecialUndelete pages are usually short), the selector is ineffecient right now. It uses "input:checkbox" which means all ‎<input> elements on the page are queried and one-by-one checked to see if it matches the checkbox-profile. On my localhost a gadget puts a checkbox next to the searchbar in Vector, this is wrongly toggled when I click the Invert button now! Instead make use of the context.
$('#mw-undelete-table') /* <= seperate find() call to speed up the ID-selector */.find('input:checkbox') /* <= only looks within the undelete-table */
  • Right now there are four anonymous functions. A closure to alias $ to jQuery, a shortcut to $(document).ready with $(fn), a function passed to click(), and another one passed to .each(). The former two can be merged by using the fact that the document-ready function is called with jQuery as first argument. This saves an additional function call and a little bandwidth as well. The latter each() is redundant as jQuery's internal methods automatically do each (ie. $('.foo').attr('title', 'Hello') sets the attribute for each of the selected elements, no need for an each() construction. The internal looping system is a light-weight for()-loop that optionally takes a function for non-static inputs, such as "!value" like is the case here.)
  • Attribution is done through Wikimedia-specific interwiki links. Aside from them obviously not working in a .js file (remember, this is not a Gadget), they are also Wikimedia-specific, please use full URLs where possible. Due to the simplicity of this function though and the convention of not listing authors for individual functions, perhaps it should be removed.
  • Check out the whitespace conventions there should be more spaces in function calls etc.

<source lang="javascript"> jQuery( document ).ready( function( $ ) {

 $( '#mw-undelete-invert' ).click( function( e ) {
   e.preventDefault();
   $( '#mw-undelete-table' ).find( 'input:checkbox' ).prop( 'checked', function( i, val ) { return !val; } );
 });

} );

#Comment by Matěj Grabovský (talk | contribs)   12:01, 21 June 2011

Firstly, I'm deeply sorry for committing the code so headlessly and thanks for all those valuable hints.

Additionally, regarding the second point: what is the difference between $('#mw-undelete-table input:checkbox') and $('#mw-undelete-table').find('input:checkbox') and how significant is the performance difference?

#Comment by He7d3r (talk | contribs)   11:54, 28 June 2011

Thank you for these explanations.

#Comment by Krinkle (talk | contribs)   13:54, 21 June 2011

I wrote down a few words regarding this at JSPERF. Check out Selector performance.

Status & tagging log