Merge "Test ApiUserrights"
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index ec015da..099d278 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 /**
- * Created on Dec 01, 2007
- *
  * Copyright © 2007 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
@@ -245,12 +243,6 @@ class ApiParse extends ApiBase {
                        if ( $params['onlypst'] ) {
                                // Build a result and bail out
                                $result_array = [];
-                               if ( $this->contentIsDeleted ) {
-                                       $result_array['textdeleted'] = true;
-                               }
-                               if ( $this->contentIsSuppressed ) {
-                                       $result_array['textsuppressed'] = true;
-                               }
                                $result_array['text'] = $this->pstContent->serialize( $format );
                                $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
                                if ( isset( $prop['wikitext'] ) ) {
@@ -346,6 +338,8 @@ class ApiParse extends ApiBase {
                        $result_array['text'] = $p_result->getText( [
                                'allowTOC' => !$params['disabletoc'],
                                'enableSectionEditLinks' => !$params['disableeditsection'],
+                               'unwrap' => $params['wrapoutputclass'] === '',
+                               'deduplicateStyles' => !$params['disablestylededuplication'],
                        ] );
                        $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'text';
                }
@@ -400,8 +394,8 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['displaytitle'] ) ) {
-                       $result_array['displaytitle'] = $p_result->getDisplayTitle() ?:
-                               $titleObj->getPrefixedText();
+                       $result_array['displaytitle'] = $p_result->getDisplayTitle() !== false
+                               ? $p_result->getDisplayTitle() : $titleObj->getPrefixedText();
                }
 
                if ( isset( $prop['headitems'] ) ) {
@@ -490,12 +484,7 @@ class ApiParse extends ApiBase {
                        }
 
                        $wgParser->startExternalParse( $titleObj, $popts, Parser::OT_PREPROCESS );
-                       $dom = $wgParser->preprocessToDom( $this->content->getNativeData() );
-                       if ( is_callable( [ $dom, 'saveXML' ] ) ) {
-                               $xml = $dom->saveXML();
-                       } else {
-                               $xml = $dom->__toString();
-                       }
+                       $xml = $wgParser->preprocessToDom( $this->content->getNativeData() )->__toString();
                        $result_array['parsetree'] = $xml;
                        $result_array[ApiResult::META_BC_SUBELEMENTS][] = 'parsetree';
                }
@@ -536,13 +525,12 @@ class ApiParse extends ApiBase {
                $popts->enableLimitReport( !$params['disablepp'] && !$params['disablelimitreport'] );
                $popts->setIsPreview( $params['preview'] || $params['sectionpreview'] );
                $popts->setIsSectionPreview( $params['sectionpreview'] );
-               $popts->setEditSection( !$params['disableeditsection'] );
                if ( $params['disabletidy'] ) {
                        $popts->setTidy( false );
                }
-               $popts->setWrapOutputClass(
-                       $params['wrapoutputclass'] === '' ? false : $params['wrapoutputclass']
-               );
+               if ( $params['wrapoutputclass'] !== '' ) {
+                       $popts->setWrapOutputClass( $params['wrapoutputclass'] );
+               }
 
                $reset = null;
                $suppressCache = false;
@@ -579,7 +567,7 @@ class ApiParse extends ApiBase {
                        } else {
                                $this->content = $page->getContent( Revision::FOR_THIS_USER, $this->getUser() );
                                if ( !$this->content ) {
-                                       $this->dieWithError( [ 'apierror-missingcontent-pageid', $pageId ] );
+                                       $this->dieWithError( [ 'apierror-missingcontent-pageid', $page->getId() ] );
                                }
                        }
                        $this->contentIsDeleted = $isDeleted;
@@ -603,7 +591,7 @@ class ApiParse extends ApiBase {
                        $pout = $page->getParserOutput( $popts, $revId, $suppressCache );
                }
                if ( !$pout ) {
-                       $this->dieWithError( [ 'apierror-nosuchrevid', $revId ?: $page->getLatest() ] );
+                       $this->dieWithError( [ 'apierror-nosuchrevid', $revId ?: $page->getLatest() ] ); // @codeCoverageIgnore
                }
 
                return $pout;
@@ -878,6 +866,7 @@ class ApiParse extends ApiBase {
                        'disablelimitreport' => false,
                        'disableeditsection' => false,
                        'disabletidy' => false,
+                       'disablestylededuplication' => false,
                        'generatexml' => [
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_HELP_MSG => [