From 8fc9222c7ea2f7df12e4c67564058050364a6ea7 Mon Sep 17 00:00:00 2001 From: "This, that and the other" Date: Wed, 20 Jan 2016 10:30:32 +1100 Subject: [PATCH] Prevent revisions with rev_page = 0 from being inserted into the DB 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/Revision.php b/includes/Revision.php index 1d7ac72542..bce9781173 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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; -- 2.20.1