https://www.mediawiki.org/wiki/Special:Code/MediaWiki/108380
Revision: 108380
Author: krinkle
Date: 2012-01-09 02:08:35 +0000 (Mon, 09 Jan 2012)
Log Message:
-----------
[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.
Modified Paths:
--------------
trunk/phase3/includes/actions/HistoryAction.php
trunk/phase3/includes/specials/SpecialRevisiondelete.php
trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
Modified: trunk/phase3/includes/actions/HistoryAction.php
===================================================================
--- trunk/phase3/includes/actions/HistoryAction.php 2012-01-09 02:06:38 UTC
(rev 108379)
+++ trunk/phase3/includes/actions/HistoryAction.php 2012-01-09 02:08:35 UTC
(rev 108380)
@@ -434,7 +434,7 @@
'type' => 'submit',
'name' => $name,
'value' => '1',
- 'class' => "mw-history-$name-button",
+ 'class' => "historysubmit
mw-history-$name-button",
),
$this->msg( $msg )->text()
) . "\n";
Modified: trunk/phase3/includes/specials/SpecialRevisiondelete.php
===================================================================
--- trunk/phase3/includes/specials/SpecialRevisiondelete.php 2012-01-09
02:06:38 UTC (rev 108379)
+++ trunk/phase3/includes/specials/SpecialRevisiondelete.php 2012-01-09
02:08:35 UTC (rev 108380)
@@ -134,7 +134,7 @@
// $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
Modified: trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
===================================================================
--- trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
2012-01-09 02:06:38 UTC (rev 108379)
+++ trunk/phase3/resources/mediawiki.action/mediawiki.action.history.js
2012-01-09 02:08:35 UTC (rev 108380)
@@ -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 @@
$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 @@
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;
+ } );
} );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs