diff options
author | Bartosz Dziewoński <matma.rex@gmail.com> | 2022-06-13 23:45:47 +0200 |
---|---|---|
committer | Bartosz Dziewoński <matma.rex@gmail.com> | 2022-06-13 22:57:25 +0000 |
commit | c5958b8d0a73a3f80df55e0090b08e9665ac8558 (patch) | |
tree | 4852b18900aca3fed84a3fc7434ff46491b2102e /includes/EditPage.php | |
parent | 144151b025e4c73479f98e05eecb1d239e4f9bbc (diff) | |
download | mediawikicore-c5958b8d0a73a3f80df55e0090b08e9665ac8558.tar.gz mediawikicore-c5958b8d0a73a3f80df55e0090b08e9665ac8558.zip |
Fix edit API using summary as section title incorrectly
'summary' must only be used as the section title when 'sectiontitle'
is not provided. Otherwise the provided section title must be used,
even if it is empty.
Bug: T54747
Change-Id: Id86d5cdd9e04cf1b2f3fbf243a4b250e2924cf87
Diffstat (limited to 'includes/EditPage.php')
-rw-r--r-- | includes/EditPage.php | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/includes/EditPage.php b/includes/EditPage.php index d1388146a592..852dfa62769d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -307,8 +307,8 @@ class EditPage implements IEditObject { /** @var string */ public $section = ''; - /** @var string */ - public $sectiontitle = ''; + /** @var string|null */ + public $sectiontitle = null; /** @var string|null * Timestamp from the first time the edit form was rendered. @@ -1146,13 +1146,17 @@ class EditPage implements IEditObject { # section titles. $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary ); - # Treat sectiontitle the same way as summary. + # Allow setting sectiontitle different from the edit summary. # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is # currently doing double duty as both edit summary and section title. Right now this # is just to allow API edits to work around this limitation, but this should be # incorporated into the actual edit form when EditPage is rewritten (T20654, T28312). - $this->sectiontitle = $request->getText( 'wpSectionTitle' ); - $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); + if ( $request->getCheck( 'wpSectionTitle' ) ) { + $this->sectiontitle = $request->getText( 'wpSectionTitle' ); + $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); + } else { + $this->sectiontitle = null; + } $this->edittime = $request->getVal( 'wpEdittime' ); $this->editRevId = $request->getIntOrNull( 'editRevId' ); @@ -1266,7 +1270,7 @@ class EditPage implements IEditObject { wfDebug( __METHOD__ . ": Not a posted form." ); $this->textbox1 = ''; $this->summary = ''; - $this->sectiontitle = ''; + $this->sectiontitle = null; $this->edittime = ''; $this->editRevId = null; $this->starttime = wfTimestampNow(); @@ -1284,7 +1288,7 @@ class EditPage implements IEditObject { // When creating a new section, we can preload a section title by passing it as the // preloadtitle parameter in the URL (T15100) - if ( $this->section === 'new' && $request->getVal( 'preloadtitle' ) ) { + if ( $this->section === 'new' && $request->getCheck( 'preloadtitle' ) ) { $this->sectiontitle = $request->getVal( 'preloadtitle' ); // Once wpSummary isn't being use for setting section titles, we should delete this. $this->summary = $request->getVal( 'preloadtitle' ); @@ -2082,23 +2086,27 @@ class EditPage implements IEditObject { $services->getContentLanguage()->getCode() ); - if ( $this->sectiontitle !== '' ) { - $newSectionAnchor = $this->guessSectionName( $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 === '' ) { + if ( $this->sectiontitle !== null ) { + if ( $this->sectiontitle !== '' ) { + $newSectionAnchor = $this->guessSectionName( $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 === '' ) { + $messageValue = MessageValue::new( 'newsectionsummary' ) + ->plaintextParams( $parser->stripSectionName( $this->sectiontitle ) ); + $newSectionSummary = $textFormatter->format( $messageValue ); + } + } + } else { + if ( $this->summary !== '' ) { + $newSectionAnchor = $this->guessSectionName( $this->summary ); + // This is a new section, so create a link to the new section + // in the revision summary. $messageValue = MessageValue::new( 'newsectionsummary' ) - ->plaintextParams( $parser->stripSectionName( $this->sectiontitle ) ); + ->plaintextParams( $parser->stripSectionName( $this->summary ) ); $newSectionSummary = $textFormatter->format( $messageValue ); } - } elseif ( $this->summary !== '' ) { - $newSectionAnchor = $this->guessSectionName( $this->summary ); - // This is a new section, so create a link to the new section - // in the revision summary. - $messageValue = MessageValue::new( 'newsectionsummary' ) - ->plaintextParams( $parser->stripSectionName( $this->summary ) ); - $newSectionSummary = $textFormatter->format( $messageValue ); } return [ $newSectionSummary, $newSectionAnchor ]; } @@ -2290,7 +2298,7 @@ class EditPage implements IEditObject { $result['sectionanchor'] = ''; if ( $this->section === 'new' ) { - if ( $this->sectiontitle !== '' ) { + if ( $this->sectiontitle !== null ) { // Insert the section title above the content. $content = $content->addSectionHeader( $this->sectiontitle ); } elseif ( $this->summary !== '' ) { @@ -2395,7 +2403,7 @@ class EditPage implements IEditObject { } } - if ( $this->sectiontitle !== '' ) { + if ( $this->sectiontitle !== null ) { $sectionTitle = $this->sectiontitle; } else { $sectionTitle = $this->summary; |