(Big 41436) Make sure Revision knows page Title.
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 29 Oct 2012 15:21:27 +0000 (16:21 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 29 Oct 2012 15:31:16 +0000 (16:31 +0100)
With $wgContentHandlerUseDB, Revision needs access to the page's Title
object to determin the page's default content model. This apparently
failed in production for newly created pages (supposedly because of
some complication with database transactions or master/client setup).

This change makes WikiPage::doEditContent pass the Title object
directly to the Revision to avoid any database issues. This also
gets rid of a pointless database read.

Change-Id: I9db228c3fcda0f8dfe52be1659014a6e4b4775af

includes/Revision.php
includes/WikiPage.php

index 984da69..431be69 100644 (file)
@@ -600,15 +600,18 @@ class Revision implements IDBAccessObject {
                                $this->mContent = $handler->unserializeContent( $this->mText );
                        }
 
-                       // if we have a Title object, override mPage. Useful for testing and convenience.
-                       if ( isset( $row['title'] ) ) {
-                               $this->mTitle     = $row['title'];
-                               $this->mPage      = $this->mTitle->getArticleID();
-                       } else {
-                               $this->mTitle     = null; // Load on demand if needed
+                       // If we have a Title object, make sure it is consistent with mPage.
+                       if ( $this->mTitle && $this->mTitle->exists() ) {
+                               if ( $this->mPage === null ) {
+                                       // if the page ID wasn't known, set it now
+                                       $this->mPage = $this->mTitle->getArticleID();
+                               } elseif ( $this->mTitle->getArticleID() !== $this->mPage ) {
+                                       // got different page IDs, something is wrong.
+                                       throw new MWException( "Page ID " . $this->mPage . " mismatches the ID "
+                                                       . $this->mTitle->getArticleID() . " provided by the Title object." );
+                               }
                        }
 
-                       // @todo: XXX: really? we are about to create a revision. it will usually then be the current one.
                        $this->mCurrent   = false;
 
                        // If we still have no length, see it we have the text to figure it out
index c148a5f..b525ff1 100644 (file)
@@ -1708,6 +1708,7 @@ class WikiPage extends Page implements IDBAccessObject {
 
                        $revision = new Revision( array(
                                'page'       => $this->getId(),
+                               'title'      => $this->getTitle(), // for determining the default content model
                                'comment'    => $summary,
                                'minor_edit' => $isminor,
                                'text'       => $serialized,
@@ -1835,6 +1836,7 @@ class WikiPage extends Page implements IDBAccessObject {
                        # Save the revision text...
                        $revision = new Revision( array(
                                'page'       => $newid,
+                               'title'      => $this->getTitle(), // for determining the default content model
                                'comment'    => $summary,
                                'minor_edit' => $isminor,
                                'text'       => $serialized,