r97886 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97885‎ | r97886 | r97887 >
Date:03:38, 23 September 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Made "under review" notices require the user's consent (bug 31093)
* Added 'cancel' button to review form
* Tweaked JS "back" links to fall through to the link when there is no prior url
* Toned down revreview-update-includes font (too much bold on the form)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/RejectConfirmationFormUI.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/language/RevisionReview.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/modules/review.js (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -388,7 +388,10 @@
389389 'revreview-submitedit', 'revreview-submitedit-title',
390390 'revreview-submit-review', 'revreview-submit-unreview',
391391 'revreview-submit-reviewed', 'revreview-submit-unreviewed',
392 - 'revreview-submitting', 'actioncomplete', 'actionfailed'
 392+ 'revreview-submitting', 'actioncomplete', 'actionfailed',
 393+ 'revreview-adv-reviewing-p', 'revreview-adv-reviewing-c',
 394+ 'revreview-sadv-reviewing-p', 'revreview-sadv-reviewing-c',
 395+ 'revreview-advertise-start', 'revreview-advertise-stop'
393396 ),
394397 'dependencies' => array( 'mediawiki.util' ),
395398 'localBasePath' => $localModulePath,
@@ -500,9 +503,6 @@
501504 # Implicit autoreview rights group
502505 $wgHooks['AutopromoteCondition'][] = 'FlaggedRevsHooks::checkAutoPromoteCond';
503506
504 -# Check if a page is currently being reviewed
505 -$wgHooks['MediaWikiPerformAction'][] = 'FlaggedRevsUIHooks::onMediaWikiPerformAction';
506 -
507507 # Actually register special pages
508508 $wgHooks['SpecialPage_initList'][] = 'FlaggedRevsUIHooks::defineSpecialPages';
509509
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php
@@ -119,30 +119,6 @@
120120 return true;
121121 }
122122
123 - public static function onMediaWikiPerformAction(
124 - $output, $article, Title $title, $user, $request
125 - ) {
126 - $fa = FlaggedPage::getTitleInstance( $title );
127 - self::maybeMarkUnderReview( $fa, $request );
128 - return true;
129 - }
130 -
131 - // Mark when an unreviewed page is being reviewed
132 - protected static function maybeMarkUnderReview( FlaggedPage $fa, WebRequest $request ) {
133 - global $wgUser;
134 - if ( !$request->getInt( 'reviewing' ) && !$request->getInt( 'rcid' ) ) {
135 - return true; // not implied by URL
136 - }
137 - # Set a key to note when someone is reviewing this.
138 - # NOTE: diff-to-stable views already handled elsewhere.
139 - if ( $fa->isReviewable() && !$fa->getStable() // not reviewed yet
140 - && $fa->getTitle()->userCan( 'review' ) )
141 - {
142 - FRUserActivity::setUserReviewingPage( $wgUser, $fa->getID() );
143 - }
144 - return true;
145 - }
146 -
147123 /** Add user preferences */
148124 public static function onGetPreferences( $user, array &$preferences ) {
149125 // Box or bar UI
Index: trunk/extensions/FlaggedRevs/presentation/language/RevisionReview.i18n.php
@@ -53,6 +53,7 @@
5454 See the [[Special:Unreviewedpages|list of unreviewed pages]].',
5555 'revreview-stable1' => 'You may want to view [{{fullurl:$1|stableid=$2}} this flagged version] and see if it is now the [{{fullurl:$1|stable=1}} stable version] of this page.',
5656 'revreview-stable2' => 'You may want to view the [{{fullurl:$1|stable=1}} stable version] of this page.',
 57+ 'revreview-cancel' => 'Cancel',
5758 'revreview-submit' => 'Submit',
5859 'revreview-submitting' => 'Submitting...',
5960 'revreview-submit-review' => 'Accept revision',
@@ -64,8 +65,12 @@
6566 'revreview-successful2' => '\'\'\'Revision of [[:$1|$1]] successfully unflagged.\'\'\'',
6667 'revreview-poss-conflict-p' => '\'\'\'Warning: [[User:$1|$1]] started reviewing this page on $2 at $3.\'\'\'',
6768 'revreview-poss-conflict-c' => '\'\'\'Warning: [[User:$1|$1]] started reviewing these changes on $2 at $3.\'\'\'',
68 - 'revreview-adv-reviewing-p' => '\'\'\'Notice: You are being advertised as having started reviewing this page on $1 at $2.\'\'\'',
69 - 'revreview-adv-reviewing-c' => '\'\'\'Notice: You are being advertised as having started reviewing these changes on $1 at $2.\'\'\'',
 69+ 'revreview-adv-reviewing-p' => 'Notice: Other reviewers can see that you are reviewing this page.',
 70+ 'revreview-adv-reviewing-c' => 'Notice: Other reviewers can see that you are reviewing these changes.',
 71+ 'revreview-sadv-reviewing-p' => 'Notice: Please advertise yourself as reviewing this page.',
 72+ 'revreview-sadv-reviewing-c' => 'Notice: Please advertise yourself as reviewing these changes.',
 73+ 'revreview-advertise-start' => 'Advertise',
 74+ 'revreview-advertise-stop' => 'De-advertise',
7075 'revreview-toolow' => '\'\'\'You must rate each of the attributes higher than "inadequate" in order for a revision to be considered reviewed.\'\'\'
7176
7277 To remove the review status of a revision, click "unaccept".
@@ -78,7 +83,7 @@
7984 'revreview-update-edited-prev' => '<span class="flaggedrevs_important">Your changes are not yet in the stable version. There are previous changes pending review.</span>
8085
8186 Please review all the changes shown below to make your edits appear in the stable version.',
82 - 'revreview-update-includes' => '\'\'\'Templates/files updated (unreviewed pages in bold):\'\'\'',
 87+ 'revreview-update-includes' => 'Templates/files updated (unreviewed pages in bold):',
8388
8489 'revreview-reject-header' => 'Reject changes for $1',
8590 'revreview-reject-text-list' => 'By completing this action you will be \'\'\'rejecting\'\'\' the source text changes from the following {{PLURAL:$1|revision|revisions}} of [[:$2|$2]]:',
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedPageView.php
@@ -1416,9 +1416,6 @@
14171417 $changeDiv = '';
14181418 # If the user can review then prompt them to review them...
14191419 if ( $wgUser->isAllowed( 'review' ) ) {
1420 - # Set a key to note that someone is viewing this
1421 - FRUserActivity::setUserReviewingDiff(
1422 - $wgUser, $oldRev->getId(), $newRev->getId() );
14231420 // Reviewer just edited...
14241421 if ( $wgRequest->getInt( 'shownotice' )
14251422 && $newRev->isCurrent()
Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php
@@ -124,15 +124,18 @@
125125 $form .= Xml::closeElement( 'legend' ) . "\n";
126126 # Show explanatory text
127127 $form .= $this->topNotice;
128 - # Show possible conflict warning msg...
 128+
 129+ # Check if anyone is reviewing this already and
 130+ # show a conflict warning message as needed...
129131 if ( $priorRevId ) {
130132 list( $u, $ts ) =
131133 FRUserActivity::getUserReviewingDiff( $priorRevId, $this->rev->getId() );
132134 } else {
133135 list( $u, $ts ) = FRUserActivity::getUserReviewingPage( $this->rev->getPage() );
134136 }
 137+ $form .= "<p>";
135138 if ( $u !== null ) { // page under review...
136 - $form .= '<p><span class="fr-under-review">';
 139+ $form .= '<span class="fr-under-review">';
137140 if ( $u != $this->user->getName() ) { // by another user...
138141 $msg = $priorRevId
139142 ? 'revreview-poss-conflict-c'
@@ -143,11 +146,19 @@
144147 $msg = $priorRevId
145148 ? 'revreview-adv-reviewing-c'
146149 : 'revreview-adv-reviewing-p';
147 - $form .= wfMsgExt( $msg, 'parseinline',
148 - $wgLang->date( $ts, true ), $wgLang->time( $ts, true ) );
 150+ $form .= wfMsgHtml( $msg );
149151 }
150 - $form .= "</span></p>\n";
 152+ $form .= "</span>";
 153+ } else { // page not under review; add JS button
 154+ $form .= '<span id="mw-fr-reviewing-status" style="display:none;"></span>';
151155 }
 156+ # Let user toggle advertising that they are reviewing this
 157+ if ( $u === null || $u === $this->user->getName() ) {
 158+ $form .= '<span id="mw-fr-reviewing-toggle" style="display:none;">';
 159+ $form .= ' (<a href="javascript:void()"></a>)'; // JS activated
 160+ $form .= '</span>';
 161+ }
 162+ $form .= "</p>\n";
152163
153164 if ( $disabled ) {
154165 $form .= Xml::openElement( 'div', array( 'class' => 'fr-rating-controls-disabled',
@@ -185,11 +196,14 @@
186197 }
187198 # Determine if there will be reject button
188199 $rejectId = $this->rejectRefRevId();
 200+
189201 # Add the submit buttons
190202 $form .= self::submitButtons( $rejectId, $frev, (bool)$disabled, $reviewIncludes );
191 - # Untoggle "reviewing" status on exit
192 - $form .= '<script type="text/javascript">var jsReviewingStatus = ' .
193 - (int)( $u == $this->user->getName() ) . "</script>\n";
 203+ # Add "cancel" link
 204+ $form .= Linker::link( $article->getTitle(),
 205+ wfMsg( 'revreview-cancel' ),
 206+ array( 'onClick' => 'history.back(); return !history.length;' ) );
 207+
194208 # Show stability log if there is anything interesting...
195209 if ( $article->isPageLocked() ) {
196210 $form .= ' ' . FlaggedRevsXML::logToggle( 'revreview-log-toggle-show' );
@@ -208,7 +222,9 @@
209223 $form .= Html::hidden( 'oldid', $revId, array( 'id' => 'mw-fr-input-oldid' ) ) . "\n";
210224 $form .= Html::hidden( 'wpEditToken', $this->user->editToken() ) . "\n";
211225 $form .= Html::hidden( 'changetime', $reviewTime,
212 - array( 'id' => 'mw-fr-input-changetime' ) ) . "\n";; // id for JS
 226+ array( 'id' => 'mw-fr-input-changetime' ) ) . "\n"; // id for JS
 227+ $form .= Html::hidden( 'userreviewing', (int)($u === $this->user->getName()),
 228+ array( 'id' => 'mw-fr-user-reviewing' ) ) . "\n"; // id for JS
213229 # Add review parameters
214230 $form .= Html::hidden( 'templateParams', $templateParams ) . "\n";
215231 $form .= Html::hidden( 'imageParams', $imageParams ) . "\n";
Index: trunk/extensions/FlaggedRevs/presentation/modules/review.js
@@ -5,6 +5,7 @@
66 */
77
88 window.FlaggedRevsReview = {
 9+ 'isUserReviewing': 0, // user reviewing this page?
910 /*
1011 * Updates for radios/checkboxes on patch by Daniel Arnold (bug 13744).
1112 * Visually update the revision rating form on change.
@@ -322,17 +323,79 @@
323324 },
324325
325326 /*
 327+ * Enable AJAX-based functionality to set that a user is reviewing a page/diff
 328+ */
 329+ 'enableAjaxReviewActivity': function() {
 330+ // User is already reviewing in another tab...
 331+ if ( $('#mw-fr-user-reviewing').val() == 1 ) {
 332+ var msgkey = $('#mw-fr-input-refid')
 333+ ? 'revreview-adv-reviewing-c'
 334+ : 'revreview-adv-reviewing-p';
 335+ $('#mw-fr-reviewing-status').html(
 336+ mw.msg( msgkey, [mw.config.get('wgUserName')] ) // advertised notice
 337+ );
 338+ $('#mw-fr-reviewing-toggle a').html(
 339+ mw.msg('revreview-advertise-stop')
 340+ ).click( FlaggedRevsReview.deadvertiseReviewing );
 341+ // User is not already reviewing this....
 342+ } else {
 343+ var msgkey = $('#mw-fr-input-refid')
 344+ ? 'revreview-sadv-reviewing-c'
 345+ : 'revreview-sadv-reviewing-p';
 346+ $('#mw-fr-reviewing-status').html(
 347+ mw.msg( msgkey, [mw.config.get('wgUserName')] ) // suggest to advertise
 348+ );
 349+
 350+ $('#mw-fr-reviewing-toggle a').html(
 351+ mw.msg('revreview-advertise-start')
 352+ ).click( FlaggedRevsReview.advertiseReviewing );
 353+ }
 354+ $('#mw-fr-reviewing-status').addClass('fr-under-review').show();
 355+ $('#mw-fr-reviewing-toggle').show();
 356+ },
 357+
 358+ /*
 359+ * Flag users as "now reviewing"
 360+ */
 361+ 'advertiseReviewing': function() {
 362+ FlaggedRevsReview.setReviewingStatus( 1 );
 363+ var msgkey = $('#mw-fr-input-refid')
 364+ ? 'revreview-adv-reviewing-c' // diff
 365+ : 'revreview-adv-reviewing-p' // page
 366+ $('#mw-fr-reviewing-status').html(
 367+ mw.msg( msgkey, [mw.config.get('wgUserName')] )
 368+ );
 369+ // Invert toggle text/function...
 370+ $('#mw-fr-reviewing-toggle a').html(
 371+ mw.msg('revreview-advertise-stop')
 372+ ).unbind('click').click( FlaggedRevsReview.deadvertiseReviewing );
 373+ },
 374+
 375+ /*
326376 * Flag users as "no longer reviewing"
327377 */
328378 'deadvertiseReviewing': function() {
329 - var form = document.getElementById('mw-fr-reviewform');
330 - if( form && jsReviewingStatus ) {
331 - var oRevId = document.getElementById('mw-fr-input-refid').value;
332 - var nRevId = document.getElementById('mw-fr-input-oldid').value;
333 - } else if( location.href.indexOf('&reviewing=1') != -1 ) {
334 - var oRevId = 0;
335 - var nRevId = mw.config.get('wgCurRevisionId');
336 - }
 379+ FlaggedRevsReview.setReviewingStatus( 0 );
 380+ var msgkey = $('#mw-fr-input-refid')
 381+ ? 'revreview-sadv-reviewing-c' // diff
 382+ : 'revreview-sadv-reviewing-p' // page
 383+ $('#mw-fr-reviewing-status').html(
 384+ mw.msg( msgkey, [mw.config.get('wgUserName')] )
 385+ );
 386+ // Invert toggle text/function...
 387+ $('#mw-fr-reviewing-toggle a').html(
 388+ mw.msg('revreview-advertise-start')
 389+ ).unbind('click').click( FlaggedRevsReview.advertiseReviewing );
 390+ },
 391+
 392+ /*
 393+ * Set reviewing status for this page/diff
 394+ */
 395+ 'setReviewingStatus': function( value ) {
 396+ // Get {previd,oldid} array for this page view.
 397+ // The previd value will be 0 if this is not a diff view.
 398+ var oRevId = $('#mw-fr-input-refid') ? $('#mw-fr-input-refid').val() : 0;
 399+ var nRevId = $('#mw-fr-input-oldid') ? $('#mw-fr-input-oldid').val() : 0;
337400 if ( nRevId > 0 ) {
338401 // Send GET request via AJAX!
339402 var call = jQuery.ajax({
@@ -341,15 +404,16 @@
342405 action : 'reviewactivity',
343406 previd : oRevId,
344407 oldid : nRevId,
345 - reviewing : 0
 408+ reviewing : value
346409 },
347410 type : "POST",
348411 dataType: "html", // response type
349 - timeout : 2000, // don't delay user exiting
 412+ timeout : 1700, // don't delay user exiting
350413 async : false
351414 });
352415 }
353 - return;
 416+ FlaggedRevsReview.isUserReviewing = value;
 417+ return ( call.status == 200 );
354418 }
355419 };
356420
@@ -357,6 +421,11 @@
358422 FlaggedRevsReview.maybeDisableAcceptButton();
359423 FlaggedRevsReview.updateRatingFormColors();
360424 FlaggedRevsReview.enableAjaxReview();
 425+FlaggedRevsReview.enableAjaxReviewActivity();
361426
362427 // Flag users as "no longer reviewing" on navigate-away
363 -window.onbeforeunload = FlaggedRevsReview.deadvertiseReviewing;
 428+window.onbeforeunload = function( e ) {
 429+ if ( FlaggedRevsReview.isUserReviewing == 1 ) {
 430+ FlaggedRevsReview.deadvertiseReviewing;
 431+ }
 432+};
Index: trunk/extensions/FlaggedRevs/presentation/RejectConfirmationFormUI.php
@@ -147,7 +147,7 @@
148148 $form .= Html::input( 'wpSubmit', wfMsg( 'revreview-reject-confirm' ), 'submit' );
149149 $form .= ' ';
150150 $form .= $skin->link( $this->form->getPage(), wfMsg( 'revreview-reject-cancel' ),
151 - array( 'onClick' => 'history.back(); return false;' ),
 151+ array( 'onClick' => 'history.back(); return !history.length;' ),
152152 array( 'oldid' => $this->form->getRefId(), 'diff' => $this->form->getOldId() ) );
153153 $form .= Xml::closeElement( 'form' );
154154

Follow-up revisions

RevisionCommit summaryAuthorDate
r97892FU r97886: fixed function callaaron07:17, 23 September 2011
r97899FU r97886: fix for JS back buttonaaron08:44, 23 September 2011
r97969FU r97886:...aaron22:45, 23 September 2011
r98179FU r97886:...aaron21:38, 26 September 2011
r98654Fix some things noticed in http://www.mediawiki.org/wiki/User:Krinkle/Extensi......aaron03:23, 2 October 2011
r98807MFT r97886,r97892,r97899,r97969,r98179,r98654: ajax reviewing status code cha...aaron20:55, 3 October 2011
r100383REL1_18 MFT r97886, r97899, r97969, r98179, r98497, r98654, r98773, r98801, r...reedy21:36, 20 October 2011

Comments

#Comment by Krinkle (talk | contribs)   19:56, 26 September 2011
+			var msgkey = $('#mw-fr-input-refid')
+				? 'revreview-adv-reviewing-c'
+				: 'revreview-adv-reviewing-p';

...

+		var oRevId = $('#mw-fr-input-refid') ? $('#mw-fr-input-refid').val() : 0;
+		var nRevId = $('#mw-fr-input-oldid') ? $('#mw-fr-input-oldid').val() : 0;

Object are always true-ish when casted to a boolean. You probably want to use $( ... ).length and cast that Number to a boolean, or use a strict $( .. ).length === 0. But the current code does not work as expected.

+window.onbeforeunload = function( e ) {
+	if ( FlaggedRevsReview.isUserReviewing == 1 ) {
+		FlaggedRevsReview.deadvertiseReviewing;
+	}
+};

This overwrites any previous bound functions and is potentially overwritten in the future by other functions. To allow using multiple functions use jQuery event binding instead like $( window ).bind( 'beforeunload', function( e ){ .. } );



+		} else { // page not under review; add JS button
+			$form .= '<span id="mw-fr-reviewing-status" style="display:none;"></span>';
 		}
+		# Let user toggle advertising that they are reviewing this
+		if ( $u === null || $u === $this->user->getName()  ) {
+			$form .= '<span id="mw-fr-reviewing-toggle" style="display:none;">';
+			$form .= ' (<a href="javascript:void()"></a>)'; // JS activated
+			$form .= '</span>';
...
+			array( 'onClick' => 'history.back(); return !history.length;' ) );

I'm not entirely sure what's going on here, but elements that can be expanded with JavaScript should also be hidden by javascript (either by litterly setting display none on it via javascript or by using .client-js .foobar { display: none; } in a stylesheet). Otherwise the content is invisible when javascript is disabled.

In case that's not what's going on here, never mind.

+			$( .. ).html(
+				mw.msg( ..

Html injection! Use .text() instead

Status & tagging log