if ( isset( $params['section'] ) ) {
$this->section = $params['section'];
+ if ( !preg_match( '/^((T-)?\d+|new)$/', $this->section ) ) {
+ $this->dieUsage( "The section parameter must be a valid section id or 'new'", "invalidsection" );
+ }
} else {
$this->section = false;
}
}
if ( $this->section !== false ) {
- $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
+ if ( $this->section === 'new' ) {
+ // Insert the section title above the content.
+ if ( !is_null( $params['sectiontitle'] ) && $params['sectiontitle'] !== '' ) {
+ $this->content = $this->content->addSectionHeader( $params['sectiontitle'] );
+ }
+ } else {
+ $this->content = $this->getSectionContent( $this->content, $titleObj->getPrefixedText() );
+ }
}
if ( $params['pst'] || $params['onlypst'] ) {
'onlypst' => false,
'effectivelanglinks' => false,
'section' => null,
+ 'sectiontitle' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ),
'disablepp' => false,
'disableeditsection' => false,
'generatexml' => array(
"apihelp-parse-param-pst": "Do a pre-save transform on the input before parsing it. Only valid when used with text.",
"apihelp-parse-param-onlypst": "Do a pre-save transform (PST) on the input, but don't parse it. Returns the same wikitext, after a PST has been applied. Only valid when used with <var>$1text</var>.",
"apihelp-parse-param-effectivelanglinks": "Includes language links supplied by extensions (for use with <kbd>$1prop=langlinks</kbd>).",
- "apihelp-parse-param-section": "Only retrieve the content of this section number.",
+ "apihelp-parse-param-section": "Only retrieve the content of this section number or when <kbd>new</kbd> generate a new section.\n\n<kbd>new</kbd> section is only honored when specifying <var>text</var>.",
+ "apihelp-parse-param-sectiontitle": "New section title when <var>section</var> is <kbd>new</kbd>.\n\nUnlike page editing, this does not fall back to <var>summary</var> when omitted or empty.",
"apihelp-parse-param-disablepp": "Disable the PP Report from the parser output.",
"apihelp-parse-param-disableeditsection": "Disable edit section links from the parser output.",
"apihelp-parse-param-generatexml": "Generate XML parse tree (requires content model <code>$1</code>).",
"apihelp-parse-param-onlypst": "{{doc-apihelp-param|parse|onlypst}}",
"apihelp-parse-param-effectivelanglinks": "{{doc-apihelp-param|parse|effectivelanglinks}}",
"apihelp-parse-param-section": "{{doc-apihelp-param|parse|section}}",
+ "apihelp-parse-param-sectiontitle": "{{doc-apihelp-param|parse|sectiontitle}}",
"apihelp-parse-param-disablepp": "{{doc-apihelp-param|parse|disablepp}}",
"apihelp-parse-param-disableeditsection": "{{doc-apihelp-param|parse|disableeditsection}}",
"apihelp-parse-param-generatexml": "{{doc-apihelp-param|parse|generatexml|params=* $1 - Value of the constant CONTENT_MODEL_WIKITEXT|paramstart=2}}",