Remove check for shouldForceHeaders()

The CategoryTree::setHeaders() method adds modules to OutputPage.
It does not matter if setHeaders() gets called several times.

The previous code tried to avoid to call setHeaders() several times.
If wgCategoryTreeForceHeaders is set then the modules get loaded by the
hooks "BeforePageDisplay" or "BeforePageDisplayMobile" on every page.
In this case duplicate calls of setHeaders() are (partly) avoided by
not calling setHeaders() on other hooks.

This change removes this micro optimization and loads the modules
unconditionally if a category tree is added on a hook.
shouldForceHeaders() is now inlined.

Change-Id: Ic9219575a714886b4edd446efde2a330dff4dee6
This commit is contained in:
Fomafix 2019-05-14 19:15:31 +02:00
parent 20f433c17c
commit 4bc230093f
3 changed files with 5 additions and 22 deletions

View file

@ -36,9 +36,7 @@ class CategoryTreeCategoryViewer extends CategoryViewer {
*/
private function getCategoryTree() {
if ( !isset( $this->categorytree ) ) {
if ( !Hooks::shouldForceHeaders() ) {
CategoryTree::setHeaders( $this->getOutput() );
}
CategoryTree::setHeaders( $this->getOutput() );
$options = $this->getConfig()->get( 'CategoryTreeCategoryPageOptions' );

View file

@ -111,9 +111,7 @@ class CategoryTreePage extends SpecialPage {
$this->executeInputForm();
if ( $this->target !== '' && $this->target !== null ) {
if ( !Hooks::shouldForceHeaders() ) {
CategoryTree::setHeaders( $output );
}
CategoryTree::setHeaders( $output );
$title = CategoryTree::makeTitle( $this->target );

View file

@ -83,15 +83,6 @@ class Hooks implements
$this->config = $config;
}
/**
* @internal For use by CategoryTreeCategoryViewer and CategoryTreePage only!
* @return bool
*/
public static function shouldForceHeaders() {
global $wgCategoryTreeForceHeaders;
return $wgCategoryTreeForceHeaders;
}
/**
* @param Parser $parser
*/
@ -233,10 +224,6 @@ class Hooks implements
* @param ParserOutput $parserOutput
*/
public function onOutputPageParserOutput( $outputPage, $parserOutput ): void {
if ( self::shouldForceHeaders() ) {
// Skip, we've already set the headers unconditionally
return;
}
if ( $parserOutput->getExtensionData( self::EXTENSION_DATA_FLAG ) ) {
CategoryTree::setHeaders( $outputPage );
}
@ -260,10 +247,10 @@ class Hooks implements
* @param OutputPage $out
*/
public static function addHeaders( OutputPage $out ) {
if ( !self::shouldForceHeaders() ) {
return;
global $wgCategoryTreeForceHeaders;
if ( $wgCategoryTreeForceHeaders ) {
CategoryTree::setHeaders( $out );
}
CategoryTree::setHeaders( $out );
}
/**