Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/258723

Change subject: Prevent edits from having timestamps older that the last one
......................................................................

Prevent edits from having timestamps older that the last one

* This presents such errors as edit conflicts.
* Also removed pointless  variable.

Change-Id: I6e875faa93ceed25bda1225a49f0471e85c186eb
---
M includes/page/WikiPage.php
1 file changed, 16 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/23/258723/1

diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index f290db8..fb30914 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -1773,18 +1773,24 @@
                // Update article, but only if changed.
                $status = Status::newGood( array( 'new' => false, 'revision' => 
null ) );
 
-               // Convenience variables
+               // Use one consistent time value
                $now = wfTimestampNow();
+
+               // Convenience variables
                $oldid = $meta['oldId'];
+               /** @var $oldRevision Revision|null */
+               $oldRevision = $meta['oldRevision'];
                /** @var $oldContent Content|null */
                $oldContent = $meta['oldContent'];
-               $newsize = $content->getSize();
 
-               if ( !$oldid ) {
+               if ( !$oldid || !$oldRevision ) {
                        // Article gone missing
                        $status->fatal( 'edit-gone-missing' );
 
                        return $status;
+               } elseif ( $oldRevision->getTimestamp() >= $now ) {
+                       // Sanity check to stop edits from going into the past 
and breaking history
+                       $status->fatal( 'edit-conflict' );
                } elseif ( !$oldContent ) {
                        // Sanity check for bug 37225
                        throw new MWException( "Could not find text for current 
revision {$oldid}." );
@@ -1797,7 +1803,7 @@
                        'comment'    => $summary,
                        'minor_edit' => $meta['minor'],
                        'text'       => $meta['serialized'],
-                       'len'        => $newsize,
+                       'len'        => $content->getSize(),
                        'parent_id'  => $oldid,
                        'user'       => $user->getId(),
                        'user_text'  => $user->getName(),
@@ -1862,7 +1868,7 @@
                                        $meta['bot'],
                                        '',
                                        $oldContent ? $oldContent->getSize() : 
0,
-                                       $newsize,
+                                       $content->getSize(),
                                        $revisionId,
                                        $patrolled
                                );
@@ -1885,7 +1891,7 @@
                        array(
                                'changed' => $changed,
                                'oldcountable' => $meta['oldCountable'],
-                               'oldrevision' => $meta['oldRevision']
+                               'oldrevision' => $oldRevision
                        )
                );
 
@@ -1921,8 +1927,9 @@
 
                $status = Status::newGood( array( 'new' => true, 'revision' => 
null ) );
 
+               // Use one consistent time value
                $now = wfTimestampNow();
-               $newsize = $content->getSize();
+
                $prepStatus = $content->prepareSave( $this, $flags, 
$meta['oldId'], $user );
                $status->merge( $prepStatus );
                if ( !$status->isOK() ) {
@@ -1953,7 +1960,7 @@
                        'comment'    => $summary,
                        'minor_edit' => $meta['minor'],
                        'text'       => $meta['serialized'],
-                       'len'        => $newsize,
+                       'len'        => $content->getSize(),
                        'user'       => $user->getId(),
                        'user_text'  => $user->getName(),
                        'timestamp'  => $now,
@@ -1985,7 +1992,7 @@
                                $summary,
                                $meta['bot'],
                                '',
-                               $newsize,
+                               $content->getSize(),
                                $revisionId,
                                $patrolled
                        );

-- 
To view, visit https://gerrit.wikimedia.org/r/258723
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e875faa93ceed25bda1225a49f0471e85c186eb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to