From 6d10567e62f58f2ee61cc843369e211168aa3122 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 26 Dec 2011 14:45:58 +0000 Subject: [PATCH] * (bug 30711) WikiPage::replaceSection() now always the current text when adding a new section * Made WikiPage::replaceSection() use getRawText() to get the current text * Made EditPage::showDiff() also use the current text when diffing for adding a new section * Removed the "You are editing an old version" when section=new since the oldid parameter has no effect new due to the above --- includes/EditPage.php | 8 ++++++-- includes/WikiPage.php | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 558c6cd6c3..8358cc56bc 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1823,7 +1823,7 @@ HTML $wgOut->addWikiMsg( 'nonunicodebrowser' ); } - if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) { + if ( $this->section != 'new' && isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) { // Let sysop know that this will make private content public if saved if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) { @@ -2165,7 +2165,11 @@ HTML function showDiff() { global $wgUser, $wgContLang, $wgParser; - $oldtext = $this->mArticle->fetchContent(); + if ( $this->section == 'new' ) { + $oldtext = $this->mArticle->getRawText(); + } else { + $oldtext = $this->mArticle->fetchContent(); + } $newtext = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 3dd3e106ab..c61efe5375 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -988,21 +988,26 @@ class WikiPage extends Page { if ( strval( $section ) == '' ) { // Whole-page edit; let the whole text through } else { - if ( is_null( $edittime ) ) { - $rev = Revision::newFromTitle( $this->mTitle ); + // Bug 30711: always use current version when adding a new section + if ( is_null( $edittime ) || $section == 'new' ) { + $oldtext = $this->getRawText(); + if ( $oldtext === false ) { + wfDebug( __METHOD__ . ": no page text\n" ); + return null; + } } else { $dbw = wfGetDB( DB_MASTER ); $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); - } - if ( !$rev ) { - wfDebug( "WikiPage::replaceSection asked for bogus section (page: " . - $this->getId() . "; section: $section; edittime: $edittime)\n" ); - wfProfileOut( __METHOD__ ); - return null; - } + if ( !$rev ) { + wfDebug( "WikiPage::replaceSection asked for bogus section (page: " . + $this->getId() . "; section: $section; edittime: $edittime)\n" ); + wfProfileOut( __METHOD__ ); + return null; + } - $oldtext = $rev->getText(); + $oldtext = $rev->getText(); + } if ( $section == 'new' ) { # Inserting a new section -- 2.20.1