follow-up to r106754 - using strict comparison, adding logic for editing existing...
authorRyan Kaldari <kaldari@users.mediawiki.org>
Tue, 20 Dec 2011 23:50:15 +0000 (23:50 +0000)
committerRyan Kaldari <kaldari@users.mediawiki.org>
Tue, 20 Dec 2011 23:50:15 +0000 (23:50 +0000)
includes/EditPage.php
includes/WikiPage.php

index eeabe03..2097329 100644 (file)
@@ -1132,7 +1132,7 @@ class EditPage {
                        $text = $this->textbox1;
                        $result['sectionanchor'] = '';
                        if ( $this->section == 'new' ) {
-                               if ( $this->sectiontitle != '' ) {
+                               if ( $this->sectiontitle !== '' ) {
                                        // Insert the section title above the content.
                                        $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $text;
                                        
@@ -1142,11 +1142,11 @@ class EditPage {
                                        // If no edit summary was specified, create one automatically from the section
                                        // title and have it link to the new section. Otherwise, respect the summary as
                                        // passed.
-                                       if ( $this->summary == '' ) {
+                                       if ( $this->summary === '' ) {
                                                $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
                                                $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle );
                                        }
-                               } elseif ( $this->summary != '' ) {
+                               } elseif ( $this->summary !== '' ) {
                                        // Insert the section title above the content.
                                        $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text;
                                        
@@ -1189,14 +1189,22 @@ class EditPage {
                                        $this->isConflict = false;
                                }
                        }
-
+                       
+                       // If sectiontitle is set, use it, otherwise use the summary as the section title (for
+                       // backwards compatibility with old forms/bots).
+                       if ( $this->sectiontitle !== '' ) {
+                               $sectionTitle = $this->sectiontitle;
+                       } else {
+                               $sectionTitle = $this->summary;
+                       }
+                       
                        if ( $this->isConflict ) {
                                wfDebug( __METHOD__ . ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
                                        $this->mArticle->getTimestamp() . "')\n" );
-                               $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
+                               $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle, $this->edittime );
                        } else {
                                wfDebug( __METHOD__ . ": getting section '$this->section'\n" );
-                               $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
+                               $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle );
                        }
                        if ( is_null( $text ) ) {
                                wfDebug( __METHOD__ . ": activating conflict; section replace failed.\n" );
@@ -1273,7 +1281,16 @@ class EditPage {
                                        wfProfileOut( __METHOD__ );
                                        return $status;
                                }
-                               if ( $this->summary != '' ) {
+                               if ( $this->sectiontitle !== '' ) {
+                                       $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
+                                       // If no edit summary was specified, create one automatically from the section
+                                       // title and have it link to the new section. Otherwise, respect the summary as
+                                       // passed.
+                                       if ( $this->summary === '' ) {
+                                               $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
+                                               $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle );
+                                       }
+                               } elseif ( $this->summary !== '' ) {
                                        $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
                                        # This is a new section, so create a link to the new section
                                        # in the revision summary.
index 1e67cfc..333eaf0 100644 (file)
@@ -978,11 +978,11 @@ class WikiPage extends Page {
        /**
         * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
         * @param $text String: new text of the section
-        * @param $summary String: new section's subject, only if $section is 'new'
+        * @param $sectionTitle String: new section's subject, only if $section is 'new'
         * @param $edittime String: revision timestamp or null to use the current revision
         * @return string Complete article text, or null if error
         */
-       public function replaceSection( $section, $text, $summary = '', $edittime = null ) {
+       public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) {
                wfProfileIn( __METHOD__ );
 
                if ( strval( $section ) == '' ) {
@@ -1006,7 +1006,7 @@ class WikiPage extends Page {
 
                        if ( $section == 'new' ) {
                                # Inserting a new section
-                               $subject = $summary ? wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" : '';
+                               $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
                                if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
                                        $text = strlen( trim( $oldtext ) ) > 0
                                                ? "{$oldtext}\n\n{$subject}{$text}"