From: Brad Jorsch Date: Mon, 7 Jul 2014 22:42:02 +0000 (-0400) Subject: Actually detect duplicate section=new submissions X-Git-Tag: 1.31.0-rc.0~14955^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=355cbd2e3e19eef455383e398cbeb636757c379f;p=lhc%2Fweb%2Fwiklou.git Actually detect duplicate section=new submissions The current check will basically never pass, since it's looking for the submitted section title to match the section title inserted into the 'newsectionsummary' message. So let's factor out the code for applying 'newsectionsummary' and use that for the conflict check. We can't just update $this->summary earlier, since later checks depend on looking at the submitted summary rather than the mangled one. Bug: 67634 Change-Id: I72890c0641f991696ec98b50a6a42b2be7f46f63 --- diff --git a/includes/EditPage.php b/includes/EditPage.php index 3d57e95895..88c49a7732 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1523,6 +1523,37 @@ class EditPage { return true; } + /** + * Return the summary to be used for a new section. + * + * @param string $sectionanchor Set to the section anchor text + * @return string + */ + private function newSectionSummary( &$sectionanchor = null ) { + global $wgParser; + + 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 ); + return wfMessage( 'newsectionsummary' ) + ->rawParams( $cleanSectionTitle )->inContentLanguage()->text(); + } + } 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. + $cleanSummary = $wgParser->stripSectionName( $this->summary ); + return wfMessage( 'newsectionsummary' ) + ->rawParams( $cleanSummary )->inContentLanguage()->text(); + } else { + return $this->summary; + } + } + /** * Attempt submission (no UI) * @@ -1764,31 +1795,11 @@ class EditPage { if ( $this->sectiontitle !== '' ) { // Insert the section title above the content. $content = $content->addSectionHeader( $this->sectiontitle ); - - // Jump to the new section - $result['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 = wfMessage( 'newsectionsummary' ) - ->rawParams( $cleanSectionTitle )->inContentLanguage()->text(); - } } elseif ( $this->summary !== '' ) { // Insert the section title above the content. $content = $content->addSectionHeader( $this->summary ); - - // Jump to the new section - $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); - - // Create a link to the new section from the edit summary. - $cleanSummary = $wgParser->stripSectionName( $this->summary ); - $this->summary = wfMessage( 'newsectionsummary' ) - ->rawParams( $cleanSummary )->inContentLanguage()->text(); } + $this->summary = $this->newSectionSummary( $result['sectionanchor'] ); } $status->value = self::AS_SUCCESS_NEW_ARTICLE; @@ -1806,7 +1817,8 @@ class EditPage { $this->isConflict = true; if ( $this->section == 'new' ) { if ( $this->mArticle->getUserText() == $wgUser->getName() && - $this->mArticle->getComment() == $this->summary ) { + $this->mArticle->getComment() == $this->newSectionSummary() + ) { // Probably a duplicate submission of a new comment. // This can happen when squid resends a request after // a timeout but the first one actually went through. @@ -1920,24 +1932,7 @@ class EditPage { wfProfileIn( __METHOD__ . '-sectionanchor' ); $sectionanchor = ''; if ( $this->section == 'new' ) { - 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 = wfMessage( 'newsectionsummary' ) - ->rawParams( $cleanSectionTitle )->inContentLanguage()->text(); - } - } 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. - $cleanSummary = $wgParser->stripSectionName( $this->summary ); - $this->summary = wfMessage( 'newsectionsummary' ) - ->rawParams( $cleanSummary )->inContentLanguage()->text(); - } + $this->summary = $this->newSectionSummary( $sectionanchor ); } elseif ( $this->section != '' ) { # Try to get a section anchor from the section source, redirect # to edited section if header found.