r106895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106894‎ | r106895 | r106896 >
Date:23:50, 20 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -1132,7 +1132,7 @@
11331133 $text = $this->textbox1;
11341134 $result['sectionanchor'] = '';
11351135 if ( $this->section == 'new' ) {
1136 - if ( $this->sectiontitle != '' ) {
 1136+ if ( $this->sectiontitle !== '' ) {
11371137 // Insert the section title above the content.
11381138 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $text;
11391139
@@ -1142,11 +1142,11 @@
11431143 // If no edit summary was specified, create one automatically from the section
11441144 // title and have it link to the new section. Otherwise, respect the summary as
11451145 // passed.
1146 - if ( $this->summary == '' ) {
 1146+ if ( $this->summary === '' ) {
11471147 $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
11481148 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle );
11491149 }
1150 - } elseif ( $this->summary != '' ) {
 1150+ } elseif ( $this->summary !== '' ) {
11511151 // Insert the section title above the content.
11521152 $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text;
11531153
@@ -1189,14 +1189,22 @@
11901190 $this->isConflict = false;
11911191 }
11921192 }
1193 -
 1193+
 1194+ // If sectiontitle is set, use it, otherwise use the summary as the section title (for
 1195+ // backwards compatibility with old forms/bots).
 1196+ if ( $this->sectiontitle !== '' ) {
 1197+ $sectionTitle = $this->sectiontitle;
 1198+ } else {
 1199+ $sectionTitle = $this->summary;
 1200+ }
 1201+
11941202 if ( $this->isConflict ) {
11951203 wfDebug( __METHOD__ . ": conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
11961204 $this->mArticle->getTimestamp() . "')\n" );
1197 - $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
 1205+ $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle, $this->edittime );
11981206 } else {
11991207 wfDebug( __METHOD__ . ": getting section '$this->section'\n" );
1200 - $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
 1208+ $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $sectionTitle );
12011209 }
12021210 if ( is_null( $text ) ) {
12031211 wfDebug( __METHOD__ . ": activating conflict; section replace failed.\n" );
@@ -1273,7 +1281,16 @@
12741282 wfProfileOut( __METHOD__ );
12751283 return $status;
12761284 }
1277 - if ( $this->summary != '' ) {
 1285+ if ( $this->sectiontitle !== '' ) {
 1286+ $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle );
 1287+ // If no edit summary was specified, create one automatically from the section
 1288+ // title and have it link to the new section. Otherwise, respect the summary as
 1289+ // passed.
 1290+ if ( $this->summary === '' ) {
 1291+ $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle );
 1292+ $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle );
 1293+ }
 1294+ } elseif ( $this->summary !== '' ) {
12781295 $sectionanchor = $wgParser->guessLegacySectionNameFromWikiText( $this->summary );
12791296 # This is a new section, so create a link to the new section
12801297 # in the revision summary.
Index: trunk/phase3/includes/WikiPage.php
@@ -978,11 +978,11 @@
979979 /**
980980 * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
981981 * @param $text String: new text of the section
982 - * @param $summary String: new section's subject, only if $section is 'new'
 982+ * @param $sectionTitle String: new section's subject, only if $section is 'new'
983983 * @param $edittime String: revision timestamp or null to use the current revision
984984 * @return string Complete article text, or null if error
985985 */
986 - public function replaceSection( $section, $text, $summary = '', $edittime = null ) {
 986+ public function replaceSection( $section, $text, $sectionTitle = '', $edittime = null ) {
987987 wfProfileIn( __METHOD__ );
988988
989989 if ( strval( $section ) == '' ) {
@@ -1006,7 +1006,7 @@
10071007
10081008 if ( $section == 'new' ) {
10091009 # Inserting a new section
1010 - $subject = $summary ? wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" : '';
 1010+ $subject = $sectionTitle ? wfMsgForContent( 'newsectionheaderdefaultlevel', $sectionTitle ) . "\n\n" : '';
10111011 if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
10121012 $text = strlen( trim( $oldtext ) ) > 0
10131013 ? "{$oldtext}\n\n{$subject}{$text}"

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106754adding sectiontitle/wgSectionTitle as a new parameter for page editing (so th...kaldari04:15, 20 December 2011

Status & tagging log