Demon has submitted this change and it was merged.
Change subject: Made auto-review base rev ID handling smarter.
......................................................................
Made auto-review base rev ID handling smarter.
* This adds an altBaseRevId hidden param and uses it to deal
with autoreview for rollback/undo of the latest revision(s)
to an unreviewed one, where the latest was reviewed. We can
trust that the user did not make the page worse in this case.
Bug: 43966
Change-Id: Ibd36b60df6cff0d04e035b81855b2789b22a9240
---
M backend/FlaggedRevs.hooks.php
M frontend/FlaggablePageView.php
2 files changed, 47 insertions(+), 17 deletions(-)
Approvals:
Demon: Verified; Looks good to me, approved
diff --git a/backend/FlaggedRevs.hooks.php b/backend/FlaggedRevs.hooks.php
index 448451b..6977b42 100644
--- a/backend/FlaggedRevs.hooks.php
+++ b/backend/FlaggedRevs.hooks.php
@@ -353,7 +353,7 @@
/**
* When an edit is made by a user, review it if either:
- * (a) The user can 'autoreview' and the edit's base revision is a
checked
+ * (a) The user can 'autoreview' and the edit's base revision was
checked
* (b) The edit is a self-revert to the stable version (by anyone)
* (c) The user can 'autoreview' new pages and this edit is a new page
* (d) The user can 'review' and the "review pending edits" checkbox
was checked
@@ -415,6 +415,9 @@
# (a) this new revision creates a new page and new page
autoreview is enabled
# (b) this new revision is based on an old, reviewed, revision
if ( $title->getUserPermissionsErrors( 'autoreview', $user )
=== array() ) {
+ // For rollback/null edits, use the previous ID as the
alternate base ID.
+ // Otherwise, use the 'altBaseRevId' parameter passed
in by the request.
+ $altBaseRevId = $isOldRevCopy ? $prevRevId :
$wgRequest->getInt( 'altBaseRevId' );
if ( !$prevRevId ) { // New pages
$reviewableNewPage =
FlaggedRevs::autoReviewNewPages();
$reviewableChange = false;
@@ -423,6 +426,9 @@
# Check if the base revision was reviewed...
if ( FlaggedRevs::autoReviewEdits() ) {
$frev = FlaggedRevision::newFromTitle(
$title, $baseRevId, FR_MASTER );
+ if ( !$frev && $altBaseRevId ) {
+ $frev =
FlaggedRevision::newFromTitle( $title, $altBaseRevId, FR_MASTER );
+ }
}
$reviewableChange = (bool)$frev;
}
diff --git a/frontend/FlaggablePageView.php b/frontend/FlaggablePageView.php
index a09053e..d143b4b 100644
--- a/frontend/FlaggablePageView.php
+++ b/frontend/FlaggablePageView.php
@@ -1794,7 +1794,11 @@
}
if ( !isset( $editPage->fr_baseFRev ) ) {
$baseRevId = self::getBaseRevId( $editPage,
$this->getRequest() );
+ $baseRevId2 = self::getAltBaseRevId( $editPage,
$this->getRequest() );
$editPage->fr_baseFRev =
FlaggedRevision::newFromTitle( $title, $baseRevId );
+ if ( !$editPage->fr_baseFRev && $baseRevId2 ) {
+ $editPage->fr_baseFRev =
FlaggedRevision::newFromTitle( $title, $baseRevId2 );
+ }
}
if ( $editPage->fr_baseFRev ) {
return true; // edit will be autoreviewed
@@ -1857,8 +1861,10 @@
* Note: baseRevId trusted for Reviewers - text checked for others.
*/
public function addRevisionIDField( EditPage $editPage, OutputPage $out
) {
- $revId = self::getBaseRevId( $editPage, $this->getRequest() );
- $out->addHTML( "\n" . Html::hidden( 'baseRevId', $revId ) );
+ $out->addHTML( "\n" . Html::hidden( 'baseRevId',
+ self::getBaseRevId( $editPage, $this->getRequest() ) )
);
+ $out->addHTML( "\n" . Html::hidden( 'altBaseRevId',
+ self::getAltBaseRevId( $editPage, $this->getRequest() )
) );
$out->addHTML( "\n" . Html::hidden( 'undidRev',
empty( $editPage->undidRev ) ? 0 : $editPage->undidRev )
);
@@ -1875,16 +1881,8 @@
if ( !isset( $editPage->fr_baseRevId ) ) {
$article = $editPage->getArticle(); // convenience
$latestId = $article->getLatest(); // current rev
- $undo = $request->getIntOrNull( 'undo' );
- # Undoing consecutive top edits...
- if ( $undo && $undo === $latestId ) {
- # Treat this like a revert to a base revision.
- # We are undoing all edits *after* some rev ID
(undoafter).
- # If undoafter is not given, then it is the
previous rev ID.
- $revId = $request->getInt( 'undoafter',
-
$article->getTitle()->getPreviousRevisionID( $latestId, Title::GAID_FOR_UPDATE
) );
- # Undoing other edits...
- } elseif ( $undo ) {
+ # Undoing edits...
+ if ( $request->getIntOrNull( 'undo' ) ) {
$revId = $latestId; // current rev is the base
rev
# Other edits...
} else {
@@ -1895,11 +1893,37 @@
: $request->getInt( 'baseRevId' ); //
e.g. "show changes"/"preview"
}
# Zero oldid => draft revision
- if ( !$revId ) {
- $revId = $latestId;
- }
- $editPage->fr_baseRevId = $revId;
+ $editPage->fr_baseRevId = $revId ?: $latestId;
}
return $editPage->fr_baseRevId;
}
+
+ /**
+ * Guess the alternative rev ID the text of this form is based off.
+ * When undoing the top X edits, the base can be though of as either
+ * the current or the edit X edits prior to the latest.
+ * Note: baseRevId trusted for Reviewers - check text for others.
+ * @param EditPage $editPage
+ * @param WebRequest $request
+ * @return int
+ */
+ protected static function getAltBaseRevId( EditPage $editPage,
WebRequest $request ) {
+ if ( !isset( $editPage->fr_altBaseRevId ) ) {
+ $article = $editPage->getArticle(); // convenience
+ $latestId = $article->getLatest(); // current rev
+ $undo = $request->getIntOrNull( 'undo' );
+ # Undoing consecutive top edits...
+ if ( $undo && $undo === $latestId ) {
+ # Treat this like a revert to a base revision.
+ # We are undoing all edits *after* some rev ID
(undoafter).
+ # If undoafter is not given, then it is the
previous rev ID.
+ $revId = $request->getInt( 'undoafter',
+
$article->getTitle()->getPreviousRevisionID( $latestId, Title::GAID_FOR_UPDATE
) );
+ } else {
+ $revId = $request->getInt( 'altBaseRevId' );
+ }
+ $editPage->fr_altBaseRevId = $revId;
+ }
+ return $editPage->fr_altBaseRevId;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/60909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibd36b60df6cff0d04e035b81855b2789b22a9240
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FlaggedRevs
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Demon <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits