* If the given revision is newer than the currently set page_latest,
* update the page record. Otherwise, do nothing.
*
+ * @deprecated since 1.24, use updateRevisionOn instead
+ *
* @param DatabaseBase $dbw
* @param Revision $revision
* @return bool
* @return Content New complete article content, or null if error.
*
* @since 1.21
+ * @deprecated since 1.24, use replaceSectionAtRev instead
*/
public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '',
$edittime = null ) {
wfProfileIn( __METHOD__ );
+ $baseRevId = null;
+ 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;
+ }
+ $baseRevId = $rev->getId();
+ }
+
+ wfProfileOut( __METHOD__ );
+ return $this->replaceSectionAtRev( $section, $sectionContent, $sectionTitle, $baseRevId );
+ }
+
+ /**
+ * @param string|null|bool $section Null/false, a section number (0, 1, 2, T1, T2, ...) or "new".
+ * @param Content $sectionContent New content of the section.
+ * @param string $sectionTitle New section's subject, only if $section is "new".
+ * @param string $baseRevId integer|null
+ *
+ * @throws MWException
+ * @return Content New complete article content, or null if error.
+ *
+ * @since 1.24
+ */
+ public function replaceSectionAtRev( $section, Content $sectionContent,
+ $sectionTitle = '', $baseRevId = null
+ ) {
+ wfProfileIn( __METHOD__ );
+
if ( strval( $section ) == '' ) {
// Whole-page edit; let the whole text through
$newContent = $sectionContent;
}
// Bug 30711: always use current version when adding a new section
- if ( is_null( $edittime ) || $section == 'new' ) {
+ if ( is_null( $baseRevId ) || $section == 'new' ) {
$oldContent = $this->getContent();
} else {
+ // TODO: try DB_READ first
$dbw = wfGetDB( DB_MASTER );
- $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+ $rev = Revision::loadFromId( $dbw, $baseRevId );
if ( !$rev ) {
wfDebug( "WikiPage::replaceSection asked for bogus section (page: " .
$this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
}
+ /**
+ * @dataProvider dataReplaceSection
+ * @covers WikiPage::replaceSectionAtRev
+ */
+ public function testReplaceSectionAtRev( $title, $model, $text, $section,
+ $with, $sectionTitle, $expected
+ ) {
+ $page = $this->createPage( $title, $text, $model );
+ $baseRevId = $page->getLatest();
+
+ $content = ContentHandler::makeContent( $with, $page->getTitle(), $page->getContentModel() );
+ $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
+
+ $this->assertEquals( $expected, is_null( $c ) ? null : trim( $c->getNativeData() ) );
+ }
+
/* @todo FIXME: fix this!
public function testGetUndoText() {
$this->checkHasDiff3();