Anomie has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/347445 )
Change subject: ApiMobileView: Handle embedded stylesheets
......................................................................
ApiMobileView: Handle embedded stylesheets
If the page contains deduplicated embedded stylesheets as added in
Ibc3fc372, action=mobileview needs to reduplicate them into each section
that it chops the article into.
This should be useless but harmless without Ibc3fc372.
Bug: T160563
Change-Id: Ie4b788af41ece5d5f12c798bacd91818367cc211
---
M includes/api/ApiMobileView.php
1 file changed, 23 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/45/347445/1
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index b7ea0ec..420674b 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -11,7 +11,7 @@
/**
* Increment this when changing the format of cached data
*/
- const CACHE_VERSION = 8;
+ const CACHE_VERSION = 9;
/** @var boolean Saves whether redirects has to be followed or not */
private $followRedirects;
@@ -486,6 +486,17 @@
protected function parseSectionsData( $html, Title $title, ParserOutput
$parserOutput,
$useTidy = false, $revId = null
) {
+ $pattern =
'!(<(?i:style)(?:\s[^>]*)?\sdata-mw-embedded-module="([^>"]+)"(?:\s[^>]*)?>)'
+ . '(.+?)(</(?i:style)>)!s';
+ $embeddedStyles = [];
+ if ( preg_match_all( $pattern, $html, $matches, PREG_SET_ORDER
) ) {
+ foreach ( $matches as $m ) {
+ if ( trim( $m[3] ) !== '' ) {
+ $embeddedStyles[$m[2]] = $m[3];
+ }
+ }
+ }
+
$data = [];
$data['sections'] = $parserOutput->getSections();
$sectionCount = count( $data['sections'] );
@@ -504,6 +515,17 @@
$data['text'] = [];
$data['refsections'] = [];
foreach ( $chunks as $chunk ) {
+ if ( $embeddedStyles ) {
+ $seen = [];
+ $chunk = preg_replace_callback( $pattern,
function ( $m ) use ( &$seen, $embeddedStyles ) {
+ if ( !isset( $seen[$m[2]] ) ) {
+ $seen[$m[2]] = true;
+ return $m[1] .
$embeddedStyles[$m[2]] . $m[4];
+ } else {
+ return $m[1] . $m[4];
+ }
+ }, $chunk );
+ }
if ( count( $data['text'] ) ) {
$chunk = "<h$chunk";
}
--
To view, visit https://gerrit.wikimedia.org/r/347445
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie4b788af41ece5d5f12c798bacd91818367cc211
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