From: Ryan Kaldari Date: Tue, 20 Dec 2011 23:50:15 +0000 (+0000) Subject: follow-up to r106754 - using strict comparison, adding logic for editing existing... X-Git-Tag: 1.31.0-rc.0~25841 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=9f5877af5c82c29f777566f4de7f888bc0cf9d85;p=lhc%2Fweb%2Fwiklou.git follow-up to r106754 - using strict comparison, adding logic for editing existing pages, changing parameter name in WikiPage::replaceSection from $summary to $sectionTitle as it only used for section titling --- diff --git a/includes/EditPage.php b/includes/EditPage.php index eeabe0328b..2097329df2 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -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. diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 1e67cfc60b..333eaf0549 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -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}"