r49408 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49407‎ | r49408 | r49409 >
Date:17:38, 11 April 2009
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
(bug 16607) Added convenience checkboxes for revisiondelete to history pages
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/PageHistory.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/skins/common/history.js (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -726,6 +726,7 @@
727727 'difference',
728728 'lineno',
729729 'compareselectedversions',
 730+ 'showhideselectedversions',
730731 'visualcomparison',
731732 'wikicodecomparison',
732733 'editundo',
Index: trunk/phase3/skins/common/wikibits.js
@@ -431,6 +431,7 @@
432432 }
433433 for (var i = start; i <= finish; ++i ) {
434434 checkboxes[i].checked = endState;
 435+ if( i > start ) checkboxes[i].onchange(); // fire triggers
435436 }
436437 lastCheckbox = this.index;
437438 return true;
Index: trunk/phase3/skins/common/history.js
@@ -9,6 +9,16 @@
1010 return radios;
1111 }
1212
 13+function deleteCheck(parent) {
 14+ var inputs = parent.getElementsByTagName('input');
 15+ for (var i = 0; i < inputs.length; i++) {
 16+ if (inputs[i].name == "showhiderevisions") {
 17+ return inputs[i];
 18+ }
 19+ }
 20+ return null;
 21+}
 22+
1323 // check selection and tweak visibility/class onclick
1424 function diffcheck() {
1525 var dli = false; // the li where the diff radio is checked
@@ -74,13 +84,14 @@
7585 return true;
7686 }
7787
78 -// page history stuff
79 -// attach event handlers to the input elements on history page
 88+// Attach event handlers to the input elements on history page
8089 function histrowinit() {
8190 var hf = document.getElementById('pagehistory');
8291 if (!hf) {
8392 return;
8493 }
 94+ var df = document.getElementById('mw-history-revdeleteform');
 95+ if( df ) df.style.visibility = 'visible'; // Enable JS form
8596 var lis = hf.getElementsByTagName('li');
8697 for (var i = 0; i < lis.length; i++) {
8798 var inputs = historyRadios(lis[i]);
@@ -88,8 +99,28 @@
89100 inputs[0].onclick = diffcheck;
90101 inputs[1].onclick = diffcheck;
91102 }
 103+ var check = deleteCheck(lis[i]);
 104+ if( df && check ) {
 105+ check.style.visibility = 'visible'; // Enable JS form
 106+ }
92107 }
93108 diffcheck();
94109 }
95110
 111+// Multi-item revision delete. 'checked' is the *previous* state.
 112+function updateShowHideForm( oldid, checked ) {
 113+ var formOldids = document.getElementById('revdel-oldid');
 114+ if( !formOldids ) return;
 115+ if( checked ) { // add on oldid if checked
 116+ if( formOldids.value ) {
 117+ formOldids.value += ',' + oldid;
 118+ } else {
 119+ formOldids.value = oldid;
 120+ }
 121+ } else if( formOldids.value ) { // remove oldid if unchecked
 122+ var reg = new RegExp( '(^|,)'+oldid+'($|,)' );
 123+ formOldids.value = formOldids.value.replace( reg, '' );
 124+ }
 125+}
 126+
96127 hookEvent("load", histrowinit);
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1477,7 +1477,7 @@
14781478 * to ensure that client-side caches don't keep obsolete copies of global
14791479 * styles.
14801480 */
1481 -$wgStyleVersion = '209';
 1481+$wgStyleVersion = '210';
14821482
14831483
14841484 # Server-side caching:
Index: trunk/phase3/includes/PageHistory.php
@@ -153,33 +153,48 @@
154154 * @return string HTML output
155155 */
156156 function beginHistoryList() {
157 - global $wgTitle, $wgScript, $wgEnableHtmlDiff;
 157+ global $wgTitle, $wgUser, $wgScript, $wgEnableHtmlDiff;
158158 $this->lastdate = '';
159159 $s = wfMsgExt( 'histlegend', array( 'parse') );
160 - $s .= Xml::openElement( 'form', array( 'action' => $wgScript, 'id' => 'mw-history-compare' ) );
 160+ if( $wgUser->isAllowed('deleterevision') ) {
 161+ $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
 162+ $s .= Xml::openElement( 'form',
 163+ array(
 164+ 'action' => $revdel->getFullUrl(),
 165+ 'method' => 'get', 'id' => 'mw-history-revdeleteform',
 166+ 'style' => 'visibility:hidden;float:right;'
 167+ )
 168+ );
 169+ $s .= Xml::hidden( 'target', $wgTitle->getPrefixedDbKey() );
 170+ $s .= Xml::hidden( 'oldid', '', array('id'=>'revdel-oldid') );
 171+ $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) );
 172+ $s .= Xml::closeElement( 'form' );
 173+ }
 174+ $s .= Xml::openElement( 'form', array( 'action' => $wgScript,
 175+ 'id' => 'mw-history-compare' ) );
161176 $s .= Xml::hidden( 'title', $wgTitle->getPrefixedDbKey() );
162177 if( $wgEnableHtmlDiff ) {
163178 $s .= $this->submitButton( wfMsg( 'visualcomparison'),
164179 array(
165 - 'name' => 'htmldiff',
166 - 'class' => 'historysubmit',
167 - 'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
168 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 180+ 'name' => 'htmldiff',
 181+ 'class' => 'historysubmit',
 182+ 'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
 183+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
169184 )
170185 );
171186 $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
172187 array(
173 - 'class' => 'historysubmit',
174 - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
175 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 188+ 'class' => 'historysubmit',
 189+ 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
 190+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
176191 )
177192 );
178193 } else {
179194 $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
180195 array(
181 - 'class' => 'historysubmit',
182 - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
183 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 196+ 'class' => 'historysubmit',
 197+ 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
 198+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
184199 )
185200 );
186201 }
@@ -198,25 +213,25 @@
199214 if( $wgEnableHtmlDiff ) {
200215 $s .= $this->submitButton( wfMsg( 'visualcomparison'),
201216 array(
202 - 'name' => 'htmldiff',
203 - 'class' => 'historysubmit',
204 - 'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
205 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 217+ 'name' => 'htmldiff',
 218+ 'class' => 'historysubmit',
 219+ 'accesskey' => wfMsg( 'accesskey-visualcomparison' ),
 220+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
206221 )
207222 );
208223 $s .= $this->submitButton( wfMsg( 'wikicodecomparison'),
209224 array(
210 - 'class' => 'historysubmit',
211 - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
212 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 225+ 'class' => 'historysubmit',
 226+ 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
 227+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
213228 )
214229 );
215230 } else {
216231 $s .= $this->submitButton( wfMsg( 'compareselectedversions'),
217232 array(
218 - 'class' => 'historysubmit',
219 - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
220 - 'title' => wfMsg( 'tooltip-compareselectedversions' ),
 233+ 'class' => 'historysubmit',
 234+ 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ),
 235+ 'title' => wfMsg( 'tooltip-compareselectedversions' ),
221236 )
222237 );
223238 }
@@ -268,15 +283,23 @@
269284 $s = "($curlink) ($lastlink) $arbitrary";
270285
271286 if( $wgUser->isAllowed( 'deleterevision' ) ) {
 287+ // Hide JS by default for non-JS browsing
 288+ $hidden = array( 'style' => 'visibility:hidden' );
 289+ // If revision was hidden from sysops
272290 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
273 - // If revision was hidden from sysops
274 - $del = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.
275 - $this->message['rev-delundel'].')' );
 291+ $del = Xml::check( 'deleterevisions', false,
 292+ $hidden + array('disabled' => 'disabled') );
 293+ $del .= Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
 294+ '(' . $this->message['rev-delundel'] . ')' );
 295+ // Otherwise, show the link...
276296 } else {
 297+ $jsCall = 'updateShowHideForm('.$rev->getId().',this.checked)';
 298+ $del = Xml::check( 'showhiderevisions', false,
 299+ $hidden + array('onchange' => $jsCall) );
277300 $query = array( 'target' => $this->mTitle->getPrefixedDbkey(),
278 - 'oldid' => $rev->getId()
279 - );
280 - $del = $this->mSkin->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
 301+ 'oldid' => $rev->getId() );
 302+ $del .= $this->mSkin->revDeleteLink( $query,
 303+ $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
281304 }
282305 $s .= " $del ";
283306 }
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1396,6 +1396,7 @@
13971397 'difference' => '(Difference between revisions)',
13981398 'lineno' => 'Line $1:',
13991399 'compareselectedversions' => 'Compare selected versions',
 1400+'showhideselectedversions' => 'Show/hide selected versions',
14001401 'visualcomparison' => 'Visual comparison',
14011402 'wikicodecomparison' => 'Wikitext comparison',
14021403 'editundo' => 'undo',

Follow-up revisions

RevisionCommit summaryAuthorDate
r49424Minor JS fix for r49408aaron14:55, 12 April 2009
r49554Tweaked r49408: Improved hiding and changed 1 revision case handlingaaron04:51, 16 April 2009
r55741* Fixed CR r48837. Although using ids[]=x in the query string is wrong and br...tstarling01:59, 2 September 2009

Comments

#Comment by Raymond (talk | contribs)   20:26, 13 April 2009

I think it does not make sense to show the new button for history pages with 1 revision only.

#Comment by Tim Starling (talk | contribs)   08:18, 8 May 2009

This style of UI easily be done without any JavaScript dependency. For instance, look at the Special:Undelete code. This is not acceptable as it is.

#Comment by Aaron Schulz (talk | contribs)   14:34, 8 May 2009

I would have used normal checkboxes except the the entire page is already a form for diffs, wish makes it hard to submit to two differing locations (article url and revisiondelete url)

#Comment by Tim Starling (talk | contribs)   09:42, 26 May 2009

You can submit to a common point, such as action=history, and distribute to the appropriate code based on which button was clicked.

#Comment by Aaron Schulz (talk | contribs)   11:31, 26 May 2009

Already thought of that but didn't like; a revert would be better even.

#Comment by Tim Starling (talk | contribs)   11:37, 26 May 2009

Any particular reason?

#Comment by Tim Starling (talk | contribs)   14:22, 16 August 2009

I'll take that as a no.

#Comment by Tim Starling (talk | contribs)   02:00, 2 September 2009

Fixed in r55741.

Status & tagging log