Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393271 )

Change subject: Use ParserOutput stateless transforms when available
......................................................................

Use ParserOutput stateless transforms when available

See MediaWiki core changes Ied5fe1a61 and I78b62ec3.

There's no need to feature-flag the extra parameter in calls to
ParserOutput::getText(), they'll just be ignored if this is merged
first.

This also changes the TOC-removing logic in MobileFrontendHooks to
actually remove the TOC from the HTML instead of relying on the stateful
ParserOutput::setTOCEnabled().

Change-Id: I3565868af824a08235ab5ce4a34145895ed0e74d
---
M includes/MobileFrontend.hooks.php
M includes/api/ApiMobileView.php
M tests/phpunit/api/ApiMobileViewTest.php
3 files changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/71/393271/1

diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 7ece0ce..52a51d6 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -1073,7 +1073,12 @@
                $context = MobileContext::singleton();
 
                if ( $context->shouldDisplayMobileView() ) {
-                       $po->setTOCEnabled( false );
+                       // Remove TOC from the ParserOutput HTML
+                       $po->setRawText( preg_replace(
+                               '#' . preg_quote( Parser::TOC_START, '#' ) . 
'.*?' . preg_quote( Parser::TOC_END, '#' ) . '#s',
+                               '',
+                               $po->getRawText()
+                       ) );
                        $outputPage->setProperty( 'MFTOC', $po->getTOCHTML() 
!== '' );
 
                        if ( $context->shouldShowWikibaseDescriptions( 
'tagline' ) ) {
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index dd0591d..ccda585 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -452,7 +452,7 @@
         */
        protected function getParserOutput( WikiPage $wp, ParserOptions 
$parserOptions, $oldid = null ) {
                $parserOutput = $wp->getParserOutput( $parserOptions, $oldid );
-               if ( $parserOutput ) {
+               if ( $parserOutput && !defined( 
ParserOutput::SUPPORTS_STATELESS_TRANSFORMS ) ) {
                        $parserOutput->setTOCEnabled( false );
                }
 
@@ -615,7 +615,7 @@
                                $this->dieWithError( 
'apierror-mobilefrontend-badidtitle', 'invalidparams' );
                                return;
                        }
-                       $html = $parserOutput->getText();
+                       $html = $parserOutput->getText( [ 'allowTOC' => false ] 
);
                        $cacheExpiry = $parserOutput->getCacheExpiry();
                }
 
diff --git a/tests/phpunit/api/ApiMobileViewTest.php 
b/tests/phpunit/api/ApiMobileViewTest.php
index 91cb2fd..5211cd8 100644
--- a/tests/phpunit/api/ApiMobileViewTest.php
+++ b/tests/phpunit/api/ApiMobileViewTest.php
@@ -22,8 +22,10 @@
                }
                $parser = new Parser();
                $po = $parser->parse( $params['text'], $wp->getTitle(), 
$parserOptions );
-               $po->setTOCEnabled( false );
-               $po->setText( str_replace( [ "\r", "\n" ], '', $po->getText() ) 
);
+               if ( !defined( ParserOutput::SUPPORTS_STATELESS_TRANSFORMS ) ) {
+                       $po->setTOCEnabled( false );
+               }
+               $po->setText( str_replace( [ "\r", "\n" ], '', $po->getText( [ 
'allowTOC' => false ] ) ) );
 
                return $po;
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3565868af824a08235ab5ce4a34145895ed0e74d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to