* Fixed CR r48837. Although using ids[]=x in the query string is wrong and broken...
authorTim Starling <tstarling@users.mediawiki.org>
Wed, 2 Sep 2009 01:59:36 +0000 (01:59 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Wed, 2 Sep 2009 01:59:36 +0000 (01:59 +0000)
* Fixed CR r49408: removed JS dependency for multiple revision delete/undelete. Using <button type=submit> we can submit the parameter "action=revisiondelete". The custom action is then distributed to Special:Revisiondelete, which can understand this kind of entry point with only minor changes.
* Also used <button type=submit> to avoid submitting the htmldiff button caption back to the server
* Show the same buttons at the top and bottom of the history page, refactored duplicated code

includes/Article.php
includes/HistoryPage.php
includes/Wiki.php
includes/specials/SpecialRevisiondelete.php
skins/common/history.js

index 7436f60..819dbc5 100644 (file)
@@ -937,7 +937,7 @@ class Article {
                $rcid = $wgRequest->getVal( 'rcid' );
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
                $purge = $wgRequest->getVal( 'action' ) == 'purge';
-               $htmldiff = $wgRequest->getVal( 'htmldiff' , false);
+               $htmldiff = $wgRequest->getBool( 'htmldiff' );
                $unhide = $wgRequest->getInt('unhide') == 1;
                $oldid = $this->getOldID();
 
index 5cd0b0d..6f6cfab 100644 (file)
@@ -260,7 +260,7 @@ class HistoryPage {
  * @ingroup Pager
  */
 class HistoryPager extends ReverseChronologicalPager {
-       public $lastRow = false, $counter, $historyPage, $title;
+       public $lastRow = false, $counter, $historyPage, $title, $buttons;
        protected $oldIdChecked;
 
        function __construct( $historyPage, $year='', $month='', $tagFilter = '' ) {
@@ -323,58 +323,56 @@ class HistoryPager extends ReverseChronologicalPager {
                $this->oldIdChecked = 0;
 
                $wgOut->wrapWikiMsg( "<div class='mw-history-legend'>\n$1</div>", 'histlegend' );
-               $s = '';
-               if( $this->getNumRows() > 1 && $wgUser->isAllowed('deleterevision') ) {
-                       $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
-                       $s .= Xml::openElement( 'form',
+               $s = Xml::openElement( 'form', array( 'action' => $wgScript,
+                       'id' => 'mw-history-compare' ) ) . "\n";
+               $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() ) . "\n";
+
+               $this->buttons = '<div>';
+               if( $wgUser->isAllowed('deleterevision') ) {
+                       $this->buttons .= Xml::element( 'button', 
                                array(
-                                       'action' => $revdel->getLocalURL( array( 
-                                               'type' => 'revision',
-                                               'target' => $this->title->getPrefixedDbKey()
-                                       ) ),
-                                       'method' => 'post', 
-                                       'id' => 'mw-history-revdeleteform',
-                                       'style'  => 'visibility:hidden;float:right;'
-                               )
-                       );
-                       $s .= Xml::hidden( 'ids', '', array('id'=>'revdel-oldid') );
-                       $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) );
-                       $s .= Xml::closeElement( 'form' );
+                                       'type' => 'submit',
+                                       'name' => 'action',
+                                       'value' => 'revisiondelete',
+                                       'style' => 'float: right',
+                               ),
+                               wfMsg( 'showhideselectedversions' )
+                       ) . "\n";
                }
-               $s .= Xml::openElement( 'form', array( 'action' => $wgScript,
-                       'id' => 'mw-history-compare' ) );
-               $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() );
                if( $wgEnableHtmlDiff ) {
-                       $s .= $this->submitButton( wfMsg( 'visualcomparison'),
+                       $this->buttons .= Xml::element( 'button',
                                array(
-                                       'name' => 'htmldiff',
+                                       'type'      => 'submit',
+                                       'name'      => 'htmldiff',
+                                       'value'     => '1',
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-                       $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
+                               ),
+                               wfMsg( 'visualcomparison')
+                       ) . "\n";
+                       $this->buttons .= $this->submitButton( wfMsg( 'wikicodecomparison'),
                                array(
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
                                )
-                       );
+                       ) . "\n";
                } else {
-                       $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
+                       $this->buttons .= $this->submitButton( wfMsg( 'compareselectedversions'),
                                array(
                                        'class'     => 'historysubmit',
                                        'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
                                        'title'     => wfMsg( 'tooltip-compareselectedversions' ),
                                )
-                       );
+                       ) . "\n";
                }
-               $s .= '<ul id="pagehistory">' . "\n";
+               $this->buttons .= '</div>';
+               $s .= $this->buttons . '<ul id="pagehistory">' . "\n";
                return $s;
        }
 
        function getEndBody() {
-
                if( $this->lastRow ) {
                        $latest = $this->counter == 1 && $this->mIsFirst;
                        $firstInList = $this->counter == 1;
@@ -394,34 +392,8 @@ class HistoryPager extends ReverseChronologicalPager {
                } else {
                        $s = '';
                }
-
-               global $wgEnableHtmlDiff;
-               $s .= '</ul>';
-               if( $wgEnableHtmlDiff ) {
-                       $s .= $this->submitButton( wfMsg( 'visualcomparison'),
-                               array(
-                                       'name' => 'htmldiff',
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-                       $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
-                               array(
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-               } else {
-                       $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
-                               array(
-                                       'class'     => 'historysubmit',
-                                       'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
-                                       'title'     => wfMsg( 'tooltip-compareselectedversions' ),
-                               )
-                       );
-               }
+               $s .= "</ul>\n";
+               $s .= $this->buttons;
                $s .= '</form>';
                return $s;
        }
@@ -470,26 +442,19 @@ class HistoryPager extends ReverseChronologicalPager {
                $s = "($curlink) ($lastlink) $diffButtons";
 
                if( $wgUser->isAllowed( 'deleterevision' ) ) {
-                       // Hide JS by default for non-JS browsing
-                       $hidden = array( 'style' => 'display:none' );
                        // If revision was hidden from sysops
                        if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
-                               $del = Xml::check( 'deleterevisions', false,
-                                       $hidden + array('disabled' => 'disabled') );
+                               $del = Xml::check( 'deleterevisions', false, array('disabled' => 'disabled') );
                                $del .= Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
                                        '(' . $this->historyPage->message['rev-delundel'] . ')' );
                        // Otherwise, show the link...
                        } else {
                                $id = $rev->getId();
-                               $jsCall = "updateShowHideForm($id,this.checked)";
-                               $del = Xml::check( 'showhiderevisions', false,
-                                       $hidden + array(
-                                               'onchange' => $jsCall,
-                                               'id' => "mw-revdel-$id" ) );
+                               $del = Xml::check( 'showhiderevisions', false, array( 'name' => "ids[$id]" ) );
                                $query = array(
                                        'type' => 'revision',
                                        'target' => $this->title->getPrefixedDbkey(),
-                                       'ids' => $rev->getId() );
+                                       'ids' => $id );
                                $del .= $this->getSkin()->revDeleteLink( $query,
                                        $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
                        }
index bad7af9..8c391e6 100644 (file)
@@ -535,6 +535,11 @@ class MediaWiki {
                                $history = new HistoryPage( $article );
                                $history->history();
                                break;
+                       case 'revisiondelete':
+                               # For show/hide submission from history page
+                               $special = SpecialPage::getPage( 'Revisiondelete' );
+                               $special->execute( '' );
+                               break;
                        default:
                                if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
                                        $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
index 3445893..917a166 100644 (file)
@@ -107,10 +107,25 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                $this->outputHeader();
                $this->submitClicked = $wgRequest->wasPosted() && $wgRequest->getBool( 'wpSubmit' );
                # Handle our many different possible input types.
-               # Use CSV, since the cgi handling will break on arrays.
-               $this->ids = explode( ',', $wgRequest->getVal('ids') );
+               $ids = $wgRequest->getVal( 'ids' );
+               if ( !is_null( $ids ) ) {
+                       # Allow CSV, for backwards compatibility, or a single ID for show/hide links
+                       $this->ids = explode( ',', $ids );
+               } else {
+                       # Array input
+                       $this->ids = array_keys( $wgRequest->getArray( 'ids' ) );
+               }
+               $this->ids = array_map( 'intval', $this->ids );
                $this->ids = array_unique( array_filter( $this->ids ) );
-               $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
+
+               if ( $wgRequest->getVal( 'action' ) == 'revisiondelete' ) {
+                       # For show/hide form submission from history page
+                       $this->targetObj = $GLOBALS['wgTitle'];
+                       $this->typeName = 'revision';
+               } else {
+                       $this->typeName = $wgRequest->getVal( 'type' );
+                       $this->targetObj = Title::newFromText( $wgRequest->getText( 'target' ) );
+               }
 
                # For reviewing deleted files...
                $this->archiveName = $wgRequest->getVal( 'file' );
@@ -120,7 +135,6 @@ class SpecialRevisionDelete extends UnlistedSpecialPage {
                        return;
                }
 
-               $this->typeName = $wgRequest->getVal( 'type' );
                if ( isset( self::$deprecatedTypeMap[$this->typeName] ) ) {
                        $this->typeName = self::$deprecatedTypeMap[$this->typeName];
                }
index 75e0d05..0265122 100644 (file)
@@ -9,16 +9,6 @@ function historyRadios(parent) {
        return radios;
 }
 
-function deleteCheck(parent) {
-       var inputs = parent.getElementsByTagName('input');
-       for (var i = 0; i < inputs.length; i++) {
-               if (inputs[i].name == "showhiderevisions") {
-                       return inputs[i];
-               }
-       }
-       return null;
-}
-
 // check selection and tweak visibility/class onclick
 function diffcheck() {
        var dli = false; // the li where the diff radio is checked
@@ -90,8 +80,6 @@ function diffcheck() {
 function histrowinit() {
        var hf = document.getElementById('pagehistory');
        if (!hf) return;
-       var df = document.getElementById('mw-history-revdeleteform');
-       if( df ) df.style.visibility = 'visible'; // Enable JS form
        var lis = hf.getElementsByTagName('li');
        for (var i = 0; i < lis.length; i++) {
                var inputs = historyRadios(lis[i]);
@@ -99,28 +87,8 @@ function histrowinit() {
                        inputs[0].onclick = diffcheck;
                        inputs[1].onclick = diffcheck;
                }
-               var check = deleteCheck(lis[i]);
-               if( df && check ) {
-                       check.style.display = 'inline'; // Enable JS form
-               }
        }
        diffcheck();
 }
 
-// Multi-item revision delete. 'checked' is the *previous* state.
-function updateShowHideForm( oldid, checked ) {
-       var formOldids = document.getElementById('revdel-oldid');
-       if( !formOldids ) return;
-       if( checked ) { // add on oldid if checked
-               if( formOldids.value ) {
-                       formOldids.value += ',' + oldid;
-               } else {
-                       formOldids.value = oldid;
-               }
-       } else if( formOldids.value ) { // remove oldid if unchecked
-               var reg = new RegExp( '(^|,)'+oldid+'($|,)' );
-               formOldids.value = formOldids.value.replace( reg, '' );
-       }
-}
-
 hookEvent("load", histrowinit);