Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | var $save = false, $preview = false, $diff = false; |
93 | 93 | var $minoredit = false, $watchthis = false, $recreate = false; |
94 | 94 | var $textbox1 = '', $textbox2 = '', $summary = '', $nosummary = false; |
95 | | - var $edittime = '', $section = '', $starttime = ''; |
| 95 | + var $edittime = '', $section = '', $sectiontitle = '', $starttime = ''; |
96 | 96 | var $oldid = 0, $editintro = '', $scrolltop = null, $bot = true; |
97 | 97 | |
98 | 98 | # Placeholders for text injection by hooks (must be HTML) |
— | — | @@ -480,7 +480,7 @@ |
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
484 | | - * @todo document |
| 484 | + * This function collects the form data and uses it to populate various member variables. |
485 | 485 | * @param $request WebRequest |
486 | 486 | */ |
487 | 487 | function importFormData( &$request ) { |
— | — | @@ -510,15 +510,25 @@ |
511 | 511 | # Truncate for whole multibyte characters. +5 bytes for ellipsis |
512 | 512 | $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 ); |
513 | 513 | |
514 | | - # Remove extra headings from summaries and new sections. |
515 | | - $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary); |
| 514 | + # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the |
| 515 | + # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for |
| 516 | + # section titles. |
| 517 | + $this->summary = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary ); |
| 518 | + |
| 519 | + # Treat sectiontitle the same way as summary. |
| 520 | + # Note that wpSectionTitle is not yet a part of the actual edit form, as wpSummary is |
| 521 | + # currently doing double duty as both edit summary and section title. Right now this |
| 522 | + # is just to allow API edits to work around this limitation, but this should be |
| 523 | + # incorporated into the actual edit form when EditPage is rewritten (Bugs 18654, 26312). |
| 524 | + $this->sectiontitle = $wgLang->truncate( $request->getText( 'wpSectionTitle' ), 250 ); |
| 525 | + $this->sectiontitle = preg_replace( '/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->sectiontitle ); |
516 | 526 | |
517 | 527 | $this->edittime = $request->getVal( 'wpEdittime' ); |
518 | 528 | $this->starttime = $request->getVal( 'wpStarttime' ); |
519 | 529 | |
520 | 530 | $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' ); |
521 | 531 | |
522 | | - if ($this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null) { |
| 532 | + if ( $this->textbox1 === '' && $request->getVal( 'wpTextbox1' ) === null ) { |
523 | 533 | // wpTextbox1 field is missing, possibly due to being "too big" |
524 | 534 | // according to some filter rules such as Suhosin's setting for |
525 | 535 | // suhosin.request.max_value_length (d'oh) |
— | — | @@ -585,19 +595,24 @@ |
586 | 596 | } else { |
587 | 597 | # Not a posted form? Start with nothing. |
588 | 598 | wfDebug( __METHOD__ . ": Not a posted form.\n" ); |
589 | | - $this->textbox1 = ''; |
590 | | - $this->summary = ''; |
591 | | - $this->edittime = ''; |
592 | | - $this->starttime = wfTimestampNow(); |
593 | | - $this->edit = false; |
594 | | - $this->preview = false; |
595 | | - $this->save = false; |
596 | | - $this->diff = false; |
597 | | - $this->minoredit = false; |
598 | | - $this->watchthis = $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters |
599 | | - $this->recreate = false; |
600 | | - |
| 599 | + $this->textbox1 = ''; |
| 600 | + $this->summary = ''; |
| 601 | + $this->sectiontitle = ''; |
| 602 | + $this->edittime = ''; |
| 603 | + $this->starttime = wfTimestampNow(); |
| 604 | + $this->edit = false; |
| 605 | + $this->preview = false; |
| 606 | + $this->save = false; |
| 607 | + $this->diff = false; |
| 608 | + $this->minoredit = false; |
| 609 | + $this->watchthis = $request->getBool( 'watchthis', false ); // Watch may be overriden by request parameters |
| 610 | + $this->recreate = false; |
| 611 | + |
| 612 | + // When creating a new section, we can preload a section title by passing it as the |
| 613 | + // preloadtitle parameter in the URL (Bug 13100) |
601 | 614 | if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) { |
| 615 | + $this->sectiontitle = $request->getVal( 'preloadtitle' ); |
| 616 | + // Once wpSummary isn't being use for setting section titles, we should delete this. |
602 | 617 | $this->summary = $request->getVal( 'preloadtitle' ); |
603 | 618 | } |
604 | 619 | elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) { |
— | — | @@ -1116,16 +1131,32 @@ |
1117 | 1132 | |
1118 | 1133 | $text = $this->textbox1; |
1119 | 1134 | $result['sectionanchor'] == ''; |
1120 | | - if ( $this->section == 'new' && $this->summary != '' ) { |
1121 | | - $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text; |
1122 | | - |
1123 | | - # Jump to the new section |
1124 | | - $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); |
| 1135 | + if ( $this->section == 'new' ) { |
| 1136 | + if ( $this->sectiontitle != '' ) { |
| 1137 | + // Insert the section title above the content. |
| 1138 | + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->sectiontitle ) . "\n\n" . $text; |
| 1139 | + |
| 1140 | + // Jump to the new section |
| 1141 | + $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->sectiontitle ); |
| 1142 | + |
| 1143 | + // If no edit summary was specified, create one automatically from the section |
| 1144 | + // title and have it link to the new section. Otherwise, respect the summary as |
| 1145 | + // passed. |
| 1146 | + if ( $this->summary == '' ) { |
| 1147 | + $cleanSectionTitle = $wgParser->stripSectionName( $this->sectiontitle ); |
| 1148 | + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSectionTitle ); |
| 1149 | + } |
| 1150 | + } elseif ( $this->summary != '' ) { |
| 1151 | + // Insert the section title above the content. |
| 1152 | + $text = wfMsgForContent( 'newsectionheaderdefaultlevel', $this->summary ) . "\n\n" . $text; |
| 1153 | + |
| 1154 | + // Jump to the new section |
| 1155 | + $result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText( $this->summary ); |
1125 | 1156 | |
1126 | | - # This is a new section, so create a link to the new section |
1127 | | - # in the revision summary. |
1128 | | - $cleanSummary = $wgParser->stripSectionName( $this->summary ); |
1129 | | - $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); |
| 1157 | + // Create a link to the new section from the edit summary. |
| 1158 | + $cleanSummary = $wgParser->stripSectionName( $this->summary ); |
| 1159 | + $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary ); |
| 1160 | + } |
1130 | 1161 | } |
1131 | 1162 | |
1132 | 1163 | $status->value = self::AS_SUCCESS_NEW_ARTICLE; |
Index: trunk/phase3/includes/api/ApiEditPage.php |
— | — | @@ -181,6 +181,10 @@ |
182 | 182 | if ( !is_null( $params['summary'] ) ) { |
183 | 183 | $reqArr['wpSummary'] = $params['summary']; |
184 | 184 | } |
| 185 | + |
| 186 | + if ( !is_null( $params['sectiontitle'] ) ) { |
| 187 | + $reqArr['wpSectionTitle'] = $params['sectiontitle']; |
| 188 | + } |
185 | 189 | |
186 | 190 | // Watch out for basetimestamp == '' |
187 | 191 | // wfTimestamp() treats it as NOW, almost certainly causing an edit conflict |
— | — | @@ -404,6 +408,10 @@ |
405 | 409 | ApiBase::PARAM_REQUIRED => true |
406 | 410 | ), |
407 | 411 | 'section' => null, |
| 412 | + 'sectiontitle' => array( |
| 413 | + ApiBase::PARAM_TYPE => 'string', |
| 414 | + ApiBase::PARAM_REQUIRED => false, |
| 415 | + ), |
408 | 416 | 'text' => null, |
409 | 417 | 'token' => null, |
410 | 418 | 'summary' => null, |
— | — | @@ -453,6 +461,7 @@ |
454 | 462 | return array( |
455 | 463 | 'title' => 'Page title', |
456 | 464 | 'section' => 'Section number. 0 for the top section, \'new\' for a new section', |
| 465 | + 'sectiontitle' => 'The title for a new section', |
457 | 466 | 'text' => 'Page content', |
458 | 467 | 'token' => array( 'Edit token. You can get one of these through prop=info.', |
459 | 468 | 'The token should always be sent as the last parameter, or at least, after the text parameter' |