jenkins-bot has submitted this change and it was merged. (
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(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index 7ece0ce..c0899cb 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->setText( 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..9a6ed9d 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..68187d1 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: merged
Gerrit-Change-Id: I3565868af824a08235ab5ce4a34145895ed0e74d
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Pmiazga <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits