Bmansurov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311051

Change subject: Hygiene: don't load a module unless necessary
......................................................................

Hygiene: don't load a module unless necessary

Move logic that loads related articles in the footer to PHP from JS.
This prevents us from shipping a JS module to a client and not showing
related articles.

Also make sure not to load related articles in footer on Special:Mobilediff.

Bug: T144047
Change-Id: I73e39ee6b1223699cd8ac739902315d163d98c3b
---
M includes/FooterHooks.php
M resources/ext.relatedArticles.readMore.bootstrap/index.js
2 files changed, 42 insertions(+), 42 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedArticles 
refs/changes/51/311051/1

diff --git a/includes/FooterHooks.php b/includes/FooterHooks.php
index 6248b37..c6d4cc0 100644
--- a/includes/FooterHooks.php
+++ b/includes/FooterHooks.php
@@ -49,6 +49,22 @@
        }
 
        /**
+        * Check whether the output page is a diff page
+        *
+        * @param OutputPage $out
+        * @return bool
+        */
+       private static function isDiffPage( OutputPage $out ) {
+               $request = $out->getRequest();
+               $type = $request->getText( 'type' );
+               $diff = $request->getText( 'diff' );
+               $oldId = $request->getText( 'oldid' );
+               $isSpecialMobileDiff = $out->getTitle()->isSpecial( 
'MobileDiff' );
+
+               return $type === 'revision' || $diff || $oldId || 
$isSpecialMobileDiff;
+       }
+
+       /**
         * Handler for the <code>BeforePageDisplay</code> hook.
         *
         * Adds the <code>ext.relatedArticles.readMore.bootstrap</code> module
@@ -60,7 +76,11 @@
         *     <code>SkinMinervaBeta<code></li>
         *   <li>On desktop, the beta feature has been enabled</li>
         *   <li>The page is in mainspace</li>
+        *   <li>The action is 'view'</li>
+        *   <li>The page is not the Main Page</li>
         *   <li>The page is not a disambiguation page</li>
+        *   <li>The page is not a diff page</li>
+        *   <li>The skin is not Minerva stable</li>
         * </ol>
         *
         * @param OutputPage $out
@@ -72,15 +92,23 @@
                $showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
 
                $title = $out->getContext()->getTitle();
+               $action = $out->getRequest()->getText( 'action' );
 
                if (
                        $showReadMore &&
                        $title->inNamespace( NS_MAIN ) &&
+                       // T120735
+                       $action === 'view' &&
                        !$title->isMainPage() &&
-                       !self::isDisambiguationPage( $title )
+                       !self::isDisambiguationPage( $title ) &&
+                       !self::isDiffPage( $out )
                ) {
                        if (
-                               get_class( $skin ) === 'SkinMinervaBeta' ||
+                               (
+                                       // any skin except minerva stable
+                                       // FIXME: right now both Minerva stable 
and beta report their names as 'minerva'
+                                       get_class( $skin ) === 
'SkinMinervaBeta' || $skin->getSkinName() !== 'minerva'
+                               ) ||
                                (
                                        class_exists( 'BetaFeatures' ) &&
                                        BetaFeatures::isFeatureEnabled( 
$out->getUser(), 'read-more' )
diff --git a/resources/ext.relatedArticles.readMore.bootstrap/index.js 
b/resources/ext.relatedArticles.readMore.bootstrap/index.js
index e906776..2b9b560 100644
--- a/resources/ext.relatedArticles.readMore.bootstrap/index.js
+++ b/resources/ext.relatedArticles.readMore.bootstrap/index.js
@@ -1,8 +1,6 @@
 ( function ( $, mw ) {
 
-       var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode',
-                       'wgIsMainPage', 'wgAction' ] ),
-               relatedPages = new mw.relatedPages.RelatedPagesGateway(
+       var relatedPages = new mw.relatedPages.RelatedPagesGateway(
                        new mw.Api(),
                        mw.config.get( 'wgPageName' ),
                        mw.config.get( 'wgRelatedArticles' ),
@@ -41,43 +39,17 @@
                }
        }
 
-       /**
-        * Is the current page a diff page?
-        *
-        * @ignore
-        * @return {boolean}
-        */
-       function isDiffPage() {
-               var queryParams = new mw.Uri( window.location.href ).query;
-
-               return !!(
-                       queryParams.type === 'revision' ||
-                       queryParams.hasOwnProperty( 'diff' ) ||
-                       queryParams.hasOwnProperty( 'oldid' )
-               );
+       // Add container to DOM for checking distance on scroll
+       // If a skin has marked up a footer content area prepend it there
+       if ( $( '.footer-content' ).length ) {
+               $( '<div class="read-more-container" />' ).prependTo( 
'.footer-content' );
+       } else {
+               $( '<div class="read-more-container post-content" />' )
+                       .insertAfter( '#content' );
        }
-
-       if (
-               config.wgNamespaceNumber === 0 &&
-               !config.wgIsMainPage &&
-               // T120735
-               config.wgAction === 'view' &&
-               !isDiffPage() &&
-               // any skin except minerva stable
-               ( config.skin !== 'minerva' || config.wgMFMode === 'beta' )
-       ) {
-               // Add container to DOM for checking distance on scroll
-               // If a skin has marked up a footer content area prepend it 
there
-               if ( $( '.footer-content' ).length ) {
-                       $( '<div class="read-more-container" />' ).prependTo( 
'.footer-content' );
-               } else {
-                       $( '<div class="read-more-container post-content" />' )
-                               .insertAfter( '#content' );
-               }
-               // try related articles load on scroll
-               $window.on( 'scroll', debouncedLoad );
-               // try an initial load, in case of no scroll
-               loadRelatedArticles();
-       }
+       // try related articles load on scroll
+       $window.on( 'scroll', debouncedLoad );
+       // try an initial load, in case of no scroll
+       loadRelatedArticles();
 
 }( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I73e39ee6b1223699cd8ac739902315d163d98c3b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to