Fix OutputPage::parseInternal() by stripping <div> wrapper
[lhc/web/wiklou.git] / includes / OutputPage.php
index d3a8d0c..97d9d83 100644 (file)
@@ -1758,6 +1758,7 @@ class OutputPage extends ContextSource {
         *    or else addWikiTextAsContent() if $interface is false.
         */
        public function addWikiText( $text, $linestart = true, $interface = true ) {
+               wfDeprecated( __METHOD__, '1.32' );
                $title = $this->getTitle();
                if ( !$title ) {
                        throw new MWException( 'Title is null' );
@@ -1936,6 +1937,10 @@ class OutputPage extends ContextSource {
        ) {
                global $wgParser;
 
+               if ( !$tidy ) {
+                       wfDeprecated( 'disabling tidy', '1.32' );
+               }
+
                $popts = $this->parserOptions();
                $oldTidy = $popts->setTidy( $tidy );
                $popts->setInterfaceMessage( (bool)$interface );
@@ -2086,6 +2091,9 @@ class OutputPage extends ContextSource {
        /**
         * Parse wikitext and return the HTML.
         *
+        * @todo The output is wrapped in a <div> iff $interface is false; it's
+        * probably best to always strip the wrapper.
+        *
         * @param string $text
         * @param bool $linestart Is this the start of a line?
         * @param bool $interface Use interface language (instead of content language) while parsing
@@ -2096,6 +2104,45 @@ class OutputPage extends ContextSource {
         * @return string HTML
         */
        public function parse( $text, $linestart = true, $interface = false, $language = null ) {
+               return $this->parseInternal(
+                       $text, $linestart, $interface, $language
+               )->getText( [
+                       'enableSectionEditLinks' => false,
+               ] );
+       }
+
+       /**
+        * Parse wikitext, strip paragraph wrapper, and return the HTML.
+        *
+        * @param string $text
+        * @param bool $linestart Is this the start of a line?
+        * @param bool $interface Use interface language (instead of content language) while parsing
+        *   language sensitive magic words like GRAMMAR and PLURAL
+        * @return string HTML
+        */
+       public function parseInline( $text, $linestart = true, $interface = false ) {
+               $parsed = $this->parseInternal(
+                       $text, $linestart, $interface, /*language*/null
+               )->getText( [
+                       'enableSectionEditLinks' => false,
+                       'wrapperDivClass' => '', /* no wrapper div */
+               ] );
+               return Parser::stripOuterParagraph( $parsed );
+       }
+
+       /**
+        * Parse wikitext and return the HTML (internal implementation helper)
+        *
+        * @param string $text
+        * @param bool $linestart Is this the start of a line?
+        * @param bool $interface Use interface language (instead of content language) while parsing
+        *   language sensitive magic words like GRAMMAR and PLURAL.  This also disables
+        *   LanguageConverter.
+        * @param Language|null $language Target language object, will override $interface
+        * @throws MWException
+        * @return ParserOutput
+        */
+       private function parseInternal( $text, $linestart, $interface, $language ) {
                global $wgParser;
 
                if ( is_null( $this->getTitle() ) ) {
@@ -2122,26 +2169,7 @@ class OutputPage extends ContextSource {
                        $popts->setTargetLanguage( $oldLang );
                }
 
-               return $parserOutput->getText( [
-                       'enableSectionEditLinks' => false,
-               ] );
-       }
-
-       /**
-        * Parse wikitext, strip paragraphs, and return the HTML.
-        *
-        * @todo This doesn't work as expected at all.  If $interface is false, there's always a
-        * wrapping <div>, so stripOuterParagraph() does nothing.
-        *
-        * @param string $text
-        * @param bool $linestart Is this the start of a line?
-        * @param bool $interface Use interface language (instead of content language) while parsing
-        *   language sensitive magic words like GRAMMAR and PLURAL
-        * @return string HTML
-        */
-       public function parseInline( $text, $linestart = true, $interface = false ) {
-               $parsed = $this->parse( $text, $linestart, $interface );
-               return Parser::stripOuterParagraph( $parsed );
+               return $parserOutput;
        }
 
        /**
@@ -2460,6 +2488,7 @@ class OutputPage extends ContextSource {
                                !$this->haveCacheVaryCookies()
                        ) {
                                if ( $config->get( 'UseESI' ) ) {
+                                       wfDeprecated( '$wgUseESI = true', '1.33' );
                                        # We'll purge the proxy cache explicitly, but require end user agents
                                        # to revalidate against the proxy on each visit.
                                        # Surrogate-Control controls our CDN, Cache-Control downstream caches
@@ -4109,8 +4138,8 @@ class OutputPage extends ContextSource {
         * Helper function to setup the PHP implementation of OOUI to use in this request.
         *
         * @since 1.26
-        * @param String $skinName The Skin name to determine the correct OOUI theme
-        * @param String $dir Language direction
+        * @param string $skinName The Skin name to determine the correct OOUI theme
+        * @param string $dir Language direction
         */
        public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) {
                $themes = ResourceLoaderOOUIModule::getSkinThemeMap();