r101286 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101285‎ | r101286 | r101287 >
Date:21:36, 29 October 2011
Author:aaron
Status:resolved
Tags:
Comment:
* Cleanups to updateRecentChanges():
** Don't assume rc_this_oldid is chronologically ordered; use rc_timestamp.
** Removed broken and redundant code around updating rc_patrolled for $rcId. Only one caller passed in $rcId and it was for $rev, which gets its RC row updated already.
** Mark all pending revs "unpatrolled" on "un-accept" as it should. This aligns with the "accept" behavior. However, if $wgUseRCPatrol is off, only update new page RC rows as the other ones won't be used.
** Add function documentation.
* Added sanity exception to RevisionReviewForm::approveRevision().
* Removed unused $wgFlaggedRevsPatrolNamespaces var and obsolete comments.
Modified paths:
  • /trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.hooks.php
@@ -323,12 +323,9 @@
324324 } elseif ( $action === 'patrol' || $action === 'autopatrol' ) {
325325 $flaggedArticle = FlaggableWikiPage::getTitleInstance( $title );
326326 # For a page to be patrollable it must not be reviewable.
327 - # Note: normally, edits to non-reviewable, non-patrollable, pages are
328 - # silently marked patrolled automatically. With $wgUseNPPatrol on, the
329 - # first edit to those pages is left as being unpatrolled.
330327 if ( $flaggedArticle->isReviewable() ) {
331328 $result = false;
332 - return false;
 329+ return false; // patrol by "accepting"
333330 }
334331 # Enforce autoreview/review restrictions
335332 } elseif ( $action === 'autoreview' || $action === 'review' ) {
@@ -617,7 +614,7 @@
618615 $rc->mAttribs['rc_cur_id'], $revId, FR_MASTER );
619616 // Reviewed => patrolled
620617 if ( $quality !== false && $quality >= FR_CHECKED ) {
621 - RevisionReviewForm::updateRecentChanges( $rc->getTitle(), $revId );
 618+ RevisionReviewForm::updateRecentChanges( $rc, 'patrol', $fa->getStableRev() );
622619 $rc->mAttribs['rc_patrolled'] = 1; // make sure irc/email notifs know status
623620 }
624621 return true;
Index: trunk/extensions/FlaggedRevs/dataclasses/FlaggedRevs.class.php
@@ -109,7 +109,7 @@
110110 self::$restrictionLevels = array_unique( $wgFlaggedRevsRestrictionLevels );
111111 self::$restrictionLevels = array_filter( self::$restrictionLevels, 'strlen' );
112112 # Make sure no talk namespaces are in review namespace
113 - global $wgFlaggedRevsNamespaces, $wgFlaggedRevsPatrolNamespaces;
 113+ global $wgFlaggedRevsNamespaces;
114114 foreach ( $wgFlaggedRevsNamespaces as $ns ) {
115115 if ( MWNamespace::isTalk( $ns ) ) {
116116 die( 'FlaggedRevs given talk namespace in $wgFlaggedRevsNamespaces!' );
Index: trunk/extensions/FlaggedRevs/business/RevisionReviewForm.php
@@ -395,10 +395,10 @@
396396 $oldFrev->delete();
397397 }
398398 # Insert the new review entry...
399 - $flaggedRevision->insert();
400 - # Update recent changes...
401 - $rcId = $rev->isUnpatrolled(); // int
402 - self::updateRecentChanges( $this->page, $rev->getId(), $rcId, true );
 399+ if ( !$flaggedRevision->insert() ) {
 400+ throw new MWException(
 401+ "Flagged revision with ID {$rev->getId()} exists with unexpected fr_page_id" );
 402+ }
403403
404404 # Update the article review log...
405405 $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
@@ -406,7 +406,9 @@
407407 $this->comment, $this->oldid, $oldSvId, true );
408408
409409 # Get the new stable version as of now
410 - $sv = FlaggedRevision::determineStable( $this->page, FR_MASTER/*consistent*/ );
 410+ $sv = FlaggedRevision::determineStable( $this->page, FR_MASTER /*consistent*/ );
 411+ # Update recent changes...
 412+ self::updateRecentChanges( $rev, 'patrol', $sv );
411413 # Update page and tracking tables and clear cache
412414 $changed = FlaggedRevs::stableVersionUpdates( $this->page, $sv, $oldSv );
413415 if ( $changed ) {
@@ -432,8 +434,6 @@
433435
434436 # Delete from flaggedrevs table
435437 $frev->delete();
436 - # Update recent changes
437 - self::updateRecentChanges( $this->page, $frev->getRevId(), false, false );
438438
439439 # Update the article review log
440440 $oldSvId = $oldSv ? $oldSv->getRevId() : 0;
@@ -442,6 +442,8 @@
443443
444444 # Get the new stable version as of now
445445 $sv = FlaggedRevision::determineStable( $this->page, FR_MASTER /*consistent*/ );
 446+ # Update recent changes
 447+ self::updateRecentChanges( $frev->getRevision(), 'unpatrol', $sv );
446448 # Update page and tracking tables and clear cache
447449 $changed = FlaggedRevs::stableVersionUpdates( $this->page, $sv, $oldSv );
448450 if ( $changed ) {
@@ -470,32 +472,55 @@
471473 return $p;
472474 }
473475
474 - public static function updateRecentChanges(
475 - Title $title, $revId, $rcId = false, $patrol = true
476 - ) {
477 - wfProfileIn( __METHOD__ );
478 - $revId = intval( $revId );
 476+ /**
 477+ * Update rc_patrolled fields in recent changes after (un)accepting a rev.
 478+ * This maintains the patrolled <=> reviewed relationship for reviewable namespaces.
 479+ * @param $rev Revision|RecentChange
 480+ * @param $patrol string "patrol" or "unpatrol"
 481+ * @param $srev FlaggedRevsion|null The new stable version
 482+ * @return void
 483+ */
 484+ public static function updateRecentChanges( $rev, $patrol, $srev ) {
 485+ global $wgUseRCPatrol;
 486+
 487+ if ( $rev instanceof RecentChange ) {
 488+ $pageId = $rc->mAttribs['rc_cur_id'];
 489+ } else {
 490+ $pageId = $rev->getPage();
 491+ }
 492+ $sTimestamp = $srev ? $srev->getRevTimestamp() : null;
 493+
479494 $dbw = wfGetDB( DB_MASTER );
480 - # Olders edits be marked as patrolled now...
481 - $dbw->update( 'recentchanges',
482 - array( 'rc_patrolled' => $patrol ? 1 : 0 ),
483 - array( 'rc_cur_id' => $title->getArticleId(),
484 - $patrol ? "rc_this_oldid <= $revId" : "rc_this_oldid = $revId" ),
485 - __METHOD__,
486 - // Performance
487 - array( 'USE INDEX' => 'rc_cur_id', 'LIMIT' => 50 )
488 - );
489 - # New page patrol may be enabled. If so, the rc_id may be the first
490 - # edit and not this one. If it is different, mark it too.
491 - if ( $rcId && $rcId != $revId ) {
 495+ $limit = 100; // sanity limit to avoid slave lag (most useful when FR is first enabled)
 496+ $conds = array( 'rc_cur_id' => $pageId );
 497+ if ( !$wgUseRCPatrol ) {
 498+ # No sense in updating all the rows, only the new page one is used.
 499+ # If $wgUseNPPatrol is off, then not even those are used.
 500+ $conds['rc_type'] = RC_NEW; // reduce rows to UPDATE
 501+ }
 502+ # If we accepted this rev, then mark prior revs as patrolled...
 503+ if ( $patrol === 'patrol' ) {
 504+ if ( $sTimestamp ) { // sanity check; should always be set
 505+ $conds[] = 'rc_timestamp <= ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) );
 506+ $dbw->update( 'recentchanges',
 507+ array( 'rc_patrolled' => 1 ),
 508+ $conds,
 509+ __METHOD__,
 510+ array( 'USE INDEX' => 'rc_cur_id', 'LIMIT' => $limit ) // performance
 511+ );
 512+ }
 513+ # If we un-accepted this rev, then mark now-pending revs as unpatrolled...
 514+ } elseif ( $patrol === 'unpatrol' ) {
 515+ if ( $sTimestamp ) {
 516+ $conds[] = 'rc_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $sTimestamp ) );
 517+ }
492518 $dbw->update( 'recentchanges',
493 - array( 'rc_patrolled' => 1 ),
494 - array( 'rc_id' => $rcId,
495 - 'rc_type' => RC_NEW ),
496 - __METHOD__
 519+ array( 'rc_patrolled' => 0 ),
 520+ $conds,
 521+ __METHOD__,
 522+ array( 'USE INDEX' => 'rc_cur_id', 'LIMIT' => $limit ) // performance
497523 );
498524 }
499 - wfProfileOut( __METHOD__ );
500525 }
501526
502527 /**
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.setup.php
@@ -13,7 +13,7 @@
1414 public static function defineHookHandlers( &$hooks ) {
1515 global $wgFlaggedRevsProtection;
1616
17 - # Override current revision, add patrol links, set cache...
 17+ # Override current revision, set cache...
1818 $hooks['ArticleViewHeader'][] = 'FlaggedRevsUIHooks::onArticleViewHeader';
1919 $hooks['ImagePageFindFile'][] = 'FlaggedRevsUIHooks::onImagePageFindFile';
2020 # Override redirect behavior...

Sign-offs

UserFlagDate
😂inspected17:18, 6 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r101292* Fixed undefined $rc var from r101286...aaron00:11, 30 October 2011

Status & tagging log