From c223e0bfb098d48fe438c20310c431665ee31072 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Tue, 10 Mar 2015 22:27:01 +0100 Subject: [PATCH] ApiParse: Support previewing section=new When live previewing a 'new' section, we want to automatically add the edit summary/sectiontitle as an H2 element, as the Edit Page and API do as well. Bug: T84877 Change-Id: I40925c16284bb97a4d491e12a8e7878b9d1b4810 --- includes/api/ApiParse.php | 15 ++++++++++++++- includes/api/i18n/en.json | 3 ++- includes/api/i18n/qqq.json | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 83e105bb49..20592ca290 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -70,6 +70,9 @@ class ApiParse extends ApiBase { 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; } @@ -203,7 +206,14 @@ class ApiParse extends ApiBase { } 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'] ) { @@ -706,6 +716,9 @@ class ApiParse extends ApiBase { 'onlypst' => false, 'effectivelanglinks' => false, 'section' => null, + 'sectiontitle' => array( + ApiBase::PARAM_TYPE => 'string', + ), 'disablepp' => false, 'disableeditsection' => false, 'generatexml' => array( diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 4237ff8ea5..1c6af662c4 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -274,7 +274,8 @@ "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 $1text.", "apihelp-parse-param-effectivelanglinks": "Includes language links supplied by extensions (for use with $1prop=langlinks).", - "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 new generate a new section.\n\nnew section is only honored when specifying text.", + "apihelp-parse-param-sectiontitle": "New section title when section is new.\n\nUnlike page editing, this does not fall back to summary 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 $1).", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 3f5084d6d7..3ecb7a5c36 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -253,6 +253,7 @@ "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}}", -- 2.20.1