From 8498a4f575412e8a75139b036627e4dc39c659f8 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 29 Oct 2012 16:21:27 +0100 Subject: [PATCH] (Big 41436) Make sure Revision knows page Title. 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 | 17 ++++++++++------- includes/WikiPage.php | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index 984da69206..431be69dc1 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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 diff --git a/includes/WikiPage.php b/includes/WikiPage.php index c148a5f14d..b525ff1f1c 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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, -- 2.20.1