From: daniel Date: Thu, 1 Nov 2012 12:48:18 +0000 (+0100) Subject: (Bug 41574) Supply Title object to Revision if possible. X-Git-Tag: 1.31.0-rc.0~21775^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=b5b2b2f89860e85c75757007cce5324262b0473d;p=lhc%2Fweb%2Fwiklou.git (Bug 41574) Supply Title object to Revision if possible. The Revision object needs the Title to determine the default content model. Providing the Title explicitely wherever possible avoids an extra database lookup. Most importanlty, this fixes fatal errors that ocurr when the database lookup fails due to slave lag or transaction state. Change-Id: I516e82f7a893b274c513b128b8a46db491160b55 --- diff --git a/includes/ChangesList.php b/includes/ChangesList.php index e7395c0261..6b7e99c4d4 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -514,12 +514,12 @@ class ChangesList extends ContextSource { if ( $this->getUser()->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] ) { $rev = new Revision( array( + 'title' => $page, 'id' => $rc->mAttribs['rc_this_oldid'], 'user' => $rc->mAttribs['rc_user'], 'user_text' => $rc->mAttribs['rc_user_text'], 'deleted' => $rc->mAttribs['rc_deleted'] ) ); - $rev->setTitle( $page ); $s .= ' '.Linker::generateRollback( $rev, $this->getContext() ); } } diff --git a/includes/Import.php b/includes/Import.php index 71498ac72e..201746661b 100644 --- a/includes/Import.php +++ b/includes/Import.php @@ -1397,6 +1397,7 @@ class WikiRevision { # @todo FIXME: Use original rev_id optionally (better for backups) # Insert the row $revision = new Revision( array( + 'title' => $this->title, 'page' => $pageId, 'content_model' => $this->getModel(), 'content_format' => $this->getFormat(), diff --git a/includes/Revision.php b/includes/Revision.php index 431be69dc1..e841d33979 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -178,6 +178,13 @@ class Revision implements IDBAccessObject { unset( $attribs['content_format'] ); } + if ( !isset( $attribs['title'] ) + && isset( $row->ar_namespace ) + && isset( $row->ar_title ) ) { + + $attribs['title'] = Title::makeTitle( $row->ar_namespace, $row->ar_title ); + } + if ( isset( $row->ar_text ) && !$row->ar_text_id ) { // Pre-1.5 ar_text row $attribs['text'] = self::getRevisionText( $row, 'ar_' ); diff --git a/includes/Title.php b/includes/Title.php index 00fdc3a469..b484045b7d 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3816,6 +3816,7 @@ class Title { $newid = $redirectArticle->insertOn( $dbw ); if ( $newid ) { // sanity $redirectRevision = new Revision( array( + 'title' => $this, // for determining the default content model 'page' => $newid, 'comment' => $comment, 'content' => $redirectContent ) ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index b525ff1f1c..df3086a550 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2163,6 +2163,7 @@ class WikiPage extends Page implements IDBAccessObject { $dbw = wfGetDB( DB_MASTER ); $revision = new Revision( array( + 'title' => $this->getTitle(), // for determining the default content model 'page' => $this->getId(), 'text' => $serialized, 'length' => $content->getSize(), diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index 3d39e370c5..bdeb7fef95 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -135,7 +135,10 @@ class DeletedContribsPager extends IndexPager { function formatRow( $row ) { wfProfileIn( __METHOD__ ); + $page = Title::makeTitle( $row->ar_namespace, $row->ar_title ); + $rev = new Revision( array( + 'title' => $page, 'id' => $row->ar_rev_id, 'comment' => $row->ar_comment, 'user' => $row->ar_user, @@ -145,8 +148,6 @@ class DeletedContribsPager extends IndexPager { 'deleted' => $row->ar_deleted, ) ); - $page = Title::makeTitle( $row->ar_namespace, $row->ar_title ); - $undelete = SpecialPage::getTitleFor( 'Undelete' ); $logs = SpecialPage::getTitleFor( 'Log' ); diff --git a/includes/specials/SpecialMergeHistory.php b/includes/specials/SpecialMergeHistory.php index bc9a3d90f8..85e1d656cb 100644 --- a/includes/specials/SpecialMergeHistory.php +++ b/includes/specials/SpecialMergeHistory.php @@ -380,6 +380,7 @@ class SpecialMergeHistory extends SpecialPage { if ( $redirectContent ) { $redirectPage = WikiPage::factory( $targetTitle ); $redirectRevision = new Revision( array( + 'title' => $targetTitle, 'page' => $this->mTargetID, 'comment' => $comment, 'content' => $redirectContent ) ); diff --git a/tests/phpunit/includes/WikiPageTest.php b/tests/phpunit/includes/WikiPageTest.php index 6dc1568397..d7c4d56f12 100644 --- a/tests/phpunit/includes/WikiPageTest.php +++ b/tests/phpunit/includes/WikiPageTest.php @@ -60,7 +60,8 @@ class WikiPageTest extends MediaWikiLangTestCase { */ protected function newPage( $title, $model = null ) { if ( is_string( $title ) ) { - $title = Title::newFromText( $title ); + $ns = $this->getDefaultWikitextNS(); + $title = Title::newFromText( $title, $ns ); } $p = new WikiPage( $title ); @@ -79,11 +80,7 @@ class WikiPageTest extends MediaWikiLangTestCase { * @return WikiPage */ protected function createPage( $page, $text, $model = null ) { - if ( is_string( $page ) ) { - $page = Title::newFromText( $page ); - } - - if ( $page instanceof Title ) { + if ( is_string( $page ) || $page instanceof Title ) { $page = $this->newPage( $page, $model ); } @@ -94,9 +91,8 @@ class WikiPageTest extends MediaWikiLangTestCase { } public function testDoEditContent() { - $title = Title::newFromText( "WikiPageTest_testDoEditContent" ); - - $page = $this->newPage( $title ); + $page = $this->newPage( "WikiPageTest_testDoEditContent" ); + $title = $page->getTitle(); $content = ContentHandler::makeContent( "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam " . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.", @@ -543,10 +539,16 @@ class WikiPageTest extends MediaWikiLangTestCase { * @dataProvider provideIsCountable */ public function testIsCountable( $title, $model, $text, $mode, $expected ) { - global $wgArticleCountMethod; + global $wgContentHandlerUseDB; - $oldArticleCountMethod = $wgArticleCountMethod; - $wgArticleCountMethod = $mode; + $this->setMwGlobals( 'wgArticleCountMethod', $mode ); + + $title = Title::newFromText( $title ); + + if ( !$wgContentHandlerUseDB && ContentHandler::getDefaultModelFor( $title ) != $model ) { + $this->markTestSkipped( "Can not use non-default content model $model for " + . $title->getPrefixedDBkey() . " with \wgArticleCountMethod disabled." ); + } $page = $this->createPage( $title, $text, $model ); $hasLinks = wfGetDB( DB_SLAVE )->selectField( 'pagelinks', 1, @@ -557,8 +559,6 @@ class WikiPageTest extends MediaWikiLangTestCase { $v = $page->isCountable(); $w = $page->isCountable( $editInfo ); - $wgArticleCountMethod = $oldArticleCountMethod; - $this->assertEquals( $expected, $v, "isCountable( null ) returned unexpected value " . var_export( $v, true ) . " instead of " . var_export( $expected, true ) . " in mode `$mode` for text \"$text\"" );