From: Krinkle Date: Mon, 9 Jan 2012 02:08:35 +0000 (+0000) Subject: [mediawiki.action.history.js] Provide cleaner handling of action=historysubmit hack. X-Git-Tag: 1.31.0-rc.0~25410 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=c538f96a2d0adc4976d62de577e2395ceea6d0a9;p=lhc%2Fweb%2Fwiklou.git [mediawiki.action.history.js] Provide cleaner handling of action=historysubmit hack. * 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. --- diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index 21985721ab..c463eed248 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -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"; diff --git a/includes/specials/SpecialRevisiondelete.php b/includes/specials/SpecialRevisiondelete.php index cf06a2f780..df60a26ad2 100644 --- a/includes/specials/SpecialRevisiondelete.php +++ b/includes/specials/SpecialRevisiondelete.php @@ -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 diff --git a/resources/mediawiki.action/mediawiki.action.history.js b/resources/mediawiki.action/mediawiki.action.history.js index 04263c262d..76b0e6cde0 100644 --- a/resources/mediawiki.action/mediawiki.action.history.js +++ b/resources/mediawiki.action/mediawiki.action.history.js @@ -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; + } ); } );