From 69bf90f2bce761b787d99673fb10456347f35f81 Mon Sep 17 00:00:00 2001 From: Adam Roses Wight Date: Wed, 4 Jun 2014 17:34:42 -0700 Subject: [PATCH] WikiPage: Allow replaceSection on an nonexistent page This corrects a regression, where replaceSection would require that the page have at least one revision in the database. If the page does not exist, continue with the replacement, using a null baseRevId. Also: clean up a few comments in the replaceSection functions. Bug: 66141 Change-Id: Ieb2cb05aee07a1d8bbdc3bdfe9536dfa8bee529e --- includes/WikiPage.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 676d8d5d84..1c66ef53f0 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -1479,7 +1479,7 @@ class WikiPage implements Page, IDBAccessObject { * @throws MWException * @return string New complete article text, or null if error. * - * @deprecated since 1.21, use replaceSectionContent() instead + * @deprecated since 1.21, use replaceSectionAtRev() instead */ public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null @@ -1540,13 +1540,9 @@ class WikiPage implements Page, IDBAccessObject { if ( $edittime && $section !== 'new' ) { $dbw = wfGetDB( DB_MASTER ); $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); - if ( !$rev ) { - wfDebug( __METHOD__ . " given bad revision time for page " . - $this->getId() . "; edittime: $edittime)\n" ); - wfProfileOut( __METHOD__ ); - return null; + if ( $rev ) { + $baseRevId = $rev->getId(); } - $baseRevId = $rev->getId(); } wfProfileOut( __METHOD__ ); @@ -1583,12 +1579,12 @@ class WikiPage implements Page, IDBAccessObject { if ( is_null( $baseRevId ) || $section == 'new' ) { $oldContent = $this->getContent(); } else { - // TODO: try DB_READ first + // TODO: try DB_SLAVE first $dbw = wfGetDB( DB_MASTER ); $rev = Revision::loadFromId( $dbw, $baseRevId ); if ( !$rev ) { - wfDebug( "WikiPage::replaceSection asked for bogus section (page: " . + wfDebug( __METHOD__ . " asked for bogus section (page: " . $this->getId() . "; section: $section; edittime: $edittime)\n" ); wfProfileOut( __METHOD__ ); return null; @@ -1603,7 +1599,6 @@ class WikiPage implements Page, IDBAccessObject { return null; } - // FIXME: $oldContent might be null? $newContent = $oldContent->replaceSection( $section, $sectionContent, $sectionTitle ); } -- 2.20.1