* (bug 30711) WikiPage::replaceSection() now always the current text when adding...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 26 Dec 2011 14:45:58 +0000 (14:45 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 26 Dec 2011 14:45:58 +0000 (14:45 +0000)
* 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
includes/WikiPage.php

index 558c6cd..8358cc5 100644 (file)
@@ -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 );
 
index 3dd3e10..c61efe5 100644 (file)
@@ -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