Prevent revisions with rev_page = 0 from being inserted into the DB
authorThis, that and the other <at.light@live.com.au>
Tue, 19 Jan 2016 23:30:32 +0000 (10:30 +1100)
committerThis, that and the other <at.light@live.com.au>
Tue, 19 Jan 2016 23:30:32 +0000 (10:30 +1100)
There's no good reason to ever do this, or to write code that lets it
happen. The revisions are just going to sit around in the DB, not
connected to anything (except maybe in some page's page_latest field,
if you're lucky). Any operations that do this should fail fast instead
of spamming the DB and appearing to "succeed".

Bug: T18674
Change-Id: I8219153a09adb1c556d0159a4fb0799895370a94

includes/Revision.php

index 1d7ac72..bce9781 100644 (file)
@@ -1366,6 +1366,17 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
+               // Not allowed to have rev_page equal to 0, false, etc.
+               if ( !$this->mPage ) {
+                       $title = $this->getTitle();
+                       if ( $title instanceof Title ) {
+                               $titleText = ' for page ' . $title->getPrefixedText();
+                       } else {
+                               $titleText = '';
+                       }
+                       throw new MWException( "Cannot insert revision$titleText: page ID must be nonzero" );
+               }
+
                $this->checkContentModel();
 
                $data = $this->mText;