[mediawiki.action.history.js] Provide cleaner handling of action=historysubmit hack.
authorKrinkle <krinkle@users.mediawiki.org>
Mon, 9 Jan 2012 02:08:35 +0000 (02:08 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Mon, 9 Jan 2012 02:08:35 +0000 (02:08 +0000)
* Follows-up r108341, r108370
* Doesn't remove it, server will still handle them properly (as provided by r57415) when JavaScript is off. This commit adds a progressive enhancement when possible so that submit will go to either of these:
* title= & diff= & oldid=
* action=revisiondelete & ids[..]=
instead of one of these
* action=historysubmit & title= & diff= & oldid= & ids[..]=
* action=historysubmit & revisiondelete=1 & ids[..]= diff= & oldid=
(removing redundant parameters and parameters from the other submission-type that don't belong in that url)
* Also re-adding support for action= revisiondelete in the query, as it was originally. Due to this hack it appears that support for the original action name (which is still returned as "revisiondelete" from MediaWiki::getAction() ) was removed or never existed in that place of the code at all. Fixed now.

includes/actions/HistoryAction.php
includes/specials/SpecialRevisiondelete.php
resources/mediawiki.action/mediawiki.action.history.js

index 2198572..c463eed 100644 (file)
@@ -434,7 +434,7 @@ class HistoryPager extends ReverseChronologicalPager {
                                'type' => 'submit',
                                'name' => $name,
                                'value' => '1',
-                               'class' => "mw-history-$name-button",
+                               'class' => "historysubmit mw-history-$name-button",
                        ),
                        $this->msg( $msg )->text()
                ) . "\n";
index cf06a2f..df60a26 100644 (file)
@@ -134,7 +134,7 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                // $this->ids = array_map( 'intval', $this->ids );
                $this->ids = array_unique( array_filter( $this->ids ) );
 
-               if ( $request->getVal( 'action' ) == 'historysubmit' ) {
+               if ( $request->getVal( 'action' ) == 'historysubmit' || $request->getVal( 'action' ) == 'revisiondelete' ) {
                        // For show/hide form submission from history page
                        // Since we are access through index.php?title=XXX&action=historysubmit
                        // getFullTitle() will contain the target title and not our title
index 04263c2..76b0e6c 100644 (file)
@@ -2,8 +2,9 @@
  * JavaScript for History action
  */
 jQuery( document ).ready( function ( $ ) {
-       var     $lis = $( '#pagehistory > li' ),
-               $radios;
+       var     $historyCompareForm = $( '#mw-history-compare' ),
+               $historySubmitter,
+               $lis = $( '#pagehistory > li' );
 
        /**
         * @context {Element} input
@@ -49,7 +50,7 @@ jQuery( document ).ready( function ( $ ) {
                                        $diffRadio.css( 'visibility', 'hidden' );
 
                                // We're between the selected radios
-                               } else if ( diffLi ) {
+                               } else if ( diffLi ) {
                                        $diffRadio.css( 'visibility', 'visible' );
                                        $oldidRadio.css( 'visibility', 'visible' );
 
@@ -64,8 +65,62 @@ jQuery( document ).ready( function ( $ ) {
                return true;
        }
 
-       $radios = $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( updateDiffRadios );
+       $lis.find( 'input[name="diff"], input[name="oldid"]' ).click( updateDiffRadios );
 
        // Set initial state
        updateDiffRadios();
+
+
+       // Prettify url output for HistoryAction submissions,
+       // to cover up action=historysubmit construction.
+
+       // Ideally we'd use e.target instead of $historySubmitter, but e.target points
+       // to the form element for submit actions, so.
+       $historyCompareForm.find( '.historysubmit' ).click( function () {
+               $historySubmitter = $(this);
+       } );
+
+       // On submit we clone the form element, remove unneeded fields in the clone
+       // that pollute the query parameter with stuff from the other "use case",
+       // and then submit the clone.
+       // Without the cloning we'd be changing the real form, which is slower, could make
+       // the page look broken for a second in slow browsers and might show the form broken
+       // again when coming back from a "next" page.
+       $historyCompareForm.submit( function ( e ) {
+               var     $copyForm, $copyRadios, $copyAction;
+
+               if ( $historySubmitter ) {
+                       $copyForm = $historyCompareForm.clone();
+                       $copyRadios = $copyForm.find( '#pagehistory > li' ).find( 'input[name="diff"], input[name="oldid"]' );
+                       $copyAction = $copyForm.find( '> [name="action"]');
+
+                       // Remove action=historysubmit and ids[..]=..
+                       if ( $historySubmitter.hasClass( 'mw-history-compareselectedversions-button' ) ) {
+                               $copyAction.remove();
+                               $copyForm.find( 'input[name^="ids["]:checked' ).prop( 'checked', false );
+
+                       // Remove diff=&oldid=, change action=historysubmit to revisiondelete, remove revisiondelete
+                       } else if ( $historySubmitter.hasClass( 'mw-history-revisiondelete-button' ) ) {
+                               $copyRadios.remove();
+                               $copyAction.val( $historySubmitter.attr( 'name' ) );
+                               $copyForm.find( ':submit' ).remove();
+                       }
+
+                       // IE7 doesn't do submission from an off-DOM clone, so insert hidden into document first
+                       // Also remove potentially conflicting id attributes that we don't need anyway
+                       $copyForm
+                               .css( 'display', 'none' )
+                               .find('[id]')
+                                       .removeAttr('id')
+                               .end()
+                               .insertAfter( $historyCompareForm )
+                               .submit();
+
+                       e.preventDefault();
+                       return false; // Because the submit is special, return false as well.
+               }
+               
+               // Continue natural browser handling other wise
+               return true;
+       } );
 } );