TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/195695

Change subject: ApiParse: Support previewing section=new
......................................................................

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: T91167
Change-Id: I40925c16284bb97a4d491e12a8e7878b9d1b4810
---
M includes/api/ApiParse.php
1 file changed, 24 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/95/195695/1

diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php
index 83d2cbc..982a045 100644
--- a/includes/api/ApiParse.php
+++ b/includes/api/ApiParse.php
@@ -36,6 +36,9 @@
        /** @var Content $pstContent */
        private $pstContent = null;
 
+       /** @var string $summary */
+       private $summary = null;
+
        public function execute() {
                // The data is hot but user-dependent, like page views, so we 
set vary cookies
                $this->getMain()->setCacheMode( 'anon-public-user-private' );
@@ -70,8 +73,17 @@
 
                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 ( isset( $params['summary'] ) ) {
+                       $this->summary = $params['summary'];
+               } else {
+                       $this->summary = false;
                }
 
                // The parser needs $wgTitle to be set, apparently the
@@ -468,8 +480,18 @@
         * @return Content|bool
         */
        private function getSectionContent( Content $content, $what ) {
-               // Not cached (save or load)
-               $section = $content->getSection( $this->section );
+               if ( $this->section == 'new' ) {
+                       if ( $this->summary !== '' ) {
+                               // Insert the section title above the content.
+                               $section = $content->addSectionHeader( 
$this->summary );
+                       } else {
+                               $this->dieUsage( "A new section requires a 
summary" );
+                               $section = false;
+                       }
+               } else {
+                       // Not cached (save or load)
+                       $section = $content->getSection( $this->section );
+               }
                if ( $section === false ) {
                        $this->dieUsage( "There is no section {$this->section} 
in " . $what, 'nosuchsection' );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/195695
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I40925c16284bb97a4d491e12a8e7878b9d1b4810
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to