mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-24 00:05:50 +00:00
Merge "Perf: don't load a module unless necessary"
This commit is contained in:
commit
4490e1b9bb
|
@ -48,6 +48,22 @@ class FooterHooks {
|
|||
DisambiguatorHooks::isDisambiguationPage( $title );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -60,7 +76,11 @@ class FooterHooks {
|
|||
* <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,16 +92,23 @@ class FooterHooks {
|
|||
$showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
|
||||
|
||||
$title = $out->getContext()->getTitle();
|
||||
$action = $out->getRequest()->getText( 'action', 'view' );
|
||||
|
||||
if (
|
||||
$showReadMore &&
|
||||
$title->inNamespace( NS_MAIN ) &&
|
||||
// T120735
|
||||
$action === 'view' &&
|
||||
!$title->isMainPage() &&
|
||||
!self::isDisambiguationPage( $title )
|
||||
!self::isDisambiguationPage( $title ) &&
|
||||
!self::isDiffPage( $out )
|
||||
) {
|
||||
if (
|
||||
// FIXME: right now both Minerva stable and beta report their names as 'minerva'
|
||||
get_class( $skin ) === 'SkinMinervaBeta' ||
|
||||
(
|
||||
// any skin except minerva stable
|
||||
$skin->getSkinName() !== 'minerva' &&
|
||||
class_exists( 'BetaFeatures' ) &&
|
||||
BetaFeatures::isFeatureEnabled( $out->getUser(), 'read-more' )
|
||||
)
|
||||
|
|
|
@ -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,31 +39,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' )
|
||||
);
|
||||
}
|
||||
|
||||
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 ) {
|
||||
|
@ -78,6 +51,5 @@
|
|||
$window.on( 'scroll', debouncedLoad );
|
||||
// try an initial load, in case of no scroll
|
||||
loadRelatedArticles();
|
||||
}
|
||||
|
||||
}( jQuery, mediaWiki ) );
|
||||
|
|
Loading…
Reference in a new issue