jenkins-bot has submitted this change and it was merged.

Change subject: Do not impact API with lazy loading changes
......................................................................


Do not impact API with lazy loading changes

API usage should not be impacted by our changes, so ensure
the config only impacts the mobile view. We can add API parameters
later if deemed useful.

Correctly pass beta flag again (broken in
I2b2aa15bee73454b1abc238c3413d30cdaa49f2c)

Bug: T129167
Change-Id: I999650e0b301ab27ec4d54d9f2ce75c052a4995e
---
M includes/MobileFormatter.php
M includes/MobileFrontend.body.php
M includes/MobileFrontend.hooks.php
3 files changed, 24 insertions(+), 20 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MobileFormatter.php b/includes/MobileFormatter.php
index c9ff2dd..c7c5b3a 100644
--- a/includes/MobileFormatter.php
+++ b/includes/MobileFormatter.php
@@ -102,9 +102,13 @@
        /**
         * Removes content inappropriate for mobile devices
         * @param bool $removeDefaults Whether default settings at 
$wgMFRemovableClasses should be used
+        * @param bool $removeReferences Whether to remove references from the 
output
+        * @param bool $removeImages Whether to move images into noscript tags
         * @return array
         */
-       public function filterContent( $removeDefaults = true ) {
+       public function filterContent( $removeDefaults = true,
+               $removeReferences = false, $removeImages = false
+       ) {
                $ctx = MobileContext::singleton();
                $config = $ctx->getMFConfig();
                $isBeta = $ctx->isBetaGroupMember();
@@ -117,26 +121,14 @@
                        }
                }
 
-               $mfReferences = $config->get( 'MFLazyLoadReferences' );
-               if ( $mfReferences ) {
-                       if ( $mfReferences['base'] ||
-                               ( $isBeta && $mfReferences['beta'] )
-                       ) {
-                               $this->doRewriteReferencesForLazyLoading();
-                       }
+               if ( $removeReferences ) {
+                       $this->doRewriteReferencesForLazyLoading();
                }
 
                if ( $this->removeMedia ) {
                        $this->doRemoveImages();
-               } else {
-                       $mfLazyLoadImages = $config->get( 'MFLazyLoadImages' );
-
-                       if (
-                               $mfLazyLoadImages['base'] ||
-                               ( $isBeta && $mfLazyLoadImages['beta'] )
-                       ) {
-                               $this->doRewriteImagesForLazyLoading();
-                       }
+               } elseif ( $removeImages ){
+                       $this->doRewriteImagesForLazyLoading();
                }
 
                return parent::filterContent();
diff --git a/includes/MobileFrontend.body.php b/includes/MobileFrontend.body.php
index 6cf0bfb..928f797 100644
--- a/includes/MobileFrontend.body.php
+++ b/includes/MobileFrontend.body.php
@@ -35,6 +35,7 @@
                $html = $text ? $text : $out->getHTML();
 
                $context = MobileContext::singleton();
+               $config = $context->getMFConfig();
 
                $formatter = MobileFormatter::newFromContext( $context, $html );
 
@@ -42,6 +43,7 @@
 
                $title = $out->getTitle();
                $isSpecialPage = $title->isSpecialPage();
+
                $formatter->enableExpandableSections(
                        // Don't collapse sections e.g. on JS pages
                        $out->canUseWikiPage()
@@ -49,14 +51,24 @@
                        // And not in certain namespaces
                        && array_search(
                                $title->getNamespace(),
-                               $context->getMFConfig()->get( 
'MFNamespacesWithoutCollapsibleSections' )
+                               $config->get( 
'MFNamespacesWithoutCollapsibleSections' )
                        ) === false
                        // And not when what's shown is not actually article 
text
                        && $context->getRequest()->getText( 'action', 'view' ) 
== 'view'
                );
+
+               $mfLazyLoadReferences = $config->get( 'MFLazyLoadReferences' );
+               $mfLazyLoadImages = $config->get( 'MFLazyLoadImages' );
+
+               $removeImages = $mfLazyLoadImages['base'] ||
+                       ( $isBeta && $mfLazyLoadImages['beta'] );
+               $removeReferences = $mfLazyLoadReferences['base'] ||
+                       ( $isBeta && $mfLazyLoadReferences['beta'] );
+
                if ( $context->getContentTransformations() ) {
                        // Remove images if they're disabled from special 
pages, but don't transform otherwise
-                       $formatter->filterContent( /* remove defaults */ 
!$isSpecialPage );
+                       $formatter->filterContent( /* remove defaults */ 
!$isSpecialPage,
+                               $removeReferences, $removeImages );
                }
 
                $contentHtml = $formatter->getText();
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 17c6e55..a377a11 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -196,7 +196,7 @@
                $context = MobileContext::singleton();
                // Perform a few extra changes if we are in mobile mode
                if ( $context->shouldDisplayMobileView() ) {
-                       $text = ExtMobileFrontend::DOMParse( $out, $text );
+                       $text = ExtMobileFrontend::DOMParse( $out, $text, 
$context->isBetaGroupMember() );
                }
                return true;
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I999650e0b301ab27ec4d54d9f2ce75c052a4995e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to