mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-24 00:05:50 +00:00
Don't hit the DB unnecessarily
If $wgRelatedArticlesShowInFooter is false, then we'll still test whether or not the page is a disambiguation page with the Disambiguator extension. Unfortunately, DisambiguatorHooks::isDisambiguationPage hits the DB. Order the tests in RelatedArticles\FooterHooks::onBeforePageDisplay from least expensive to most expensive so that the DB is queried only when it must be. Bug: T127068 Change-Id: Ie3e7e410026cf354d831ae3c2134cfc0957eb8db
This commit is contained in:
parent
45f922fd66
commit
9ede8913c7
|
@ -34,6 +34,19 @@ class FooterHooks {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the Disambiguator extension to test whether the page is a disambiguation page.
|
||||
*
|
||||
* If the Disambiguator extension isn't installed, then the test always fails, i.e. the page is
|
||||
* never a disambiguation page.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function isDisambiguationPage( Title $title ) {
|
||||
return class_exists( 'DisambiguatorHooks' ) &&
|
||||
DisambiguatorHooks::isDisambiguationPage( $title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for the <code>BeforePageDisplay</code> hook.
|
||||
*
|
||||
|
@ -41,12 +54,12 @@ class FooterHooks {
|
|||
* to the output when:
|
||||
*
|
||||
* <ol>
|
||||
* <li>The page is not a disambiguation page</li>
|
||||
* <li><code>$wgRelatedArticlesShowInFooter</code> is truthy</li>
|
||||
* <li>On mobile, the output is being rendered with
|
||||
* <code>SkinMinervaBeta<code></li>
|
||||
* <li>On desktop, the beta feature has been enabled</li>
|
||||
* <li>The page is in mainspace</li>
|
||||
* <li>The page is not a disambiguation page</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param OutputPage $out
|
||||
|
@ -54,10 +67,6 @@ class FooterHooks {
|
|||
* @return boolean Always <code>true</code>
|
||||
*/
|
||||
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
||||
if ( class_exists( 'DisambiguatorHooks' ) &&
|
||||
DisambiguatorHooks::isDisambiguationPage( $out->getTitle() ) ) {
|
||||
return true;
|
||||
}
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
||||
$showReadMore = $config->get( 'RelatedArticlesShowInFooter' );
|
||||
|
||||
|
@ -66,7 +75,8 @@ class FooterHooks {
|
|||
if (
|
||||
$showReadMore &&
|
||||
$title->inNamespace( NS_MAIN ) &&
|
||||
!$title->isMainPage()
|
||||
!$title->isMainPage() &&
|
||||
!self::isDisambiguationPage( $title )
|
||||
) {
|
||||
if (
|
||||
get_class( $skin ) === 'SkinMinervaBeta' ||
|
||||
|
|
Loading…
Reference in a new issue