Page MenuHomePhabricator

JavaScript is not loaded with the 'rebuildFileCache.php' maintenance script
Closed, ResolvedPublic

Description

Author: 11fallingleaves

Description:
When running

php maintenance/rebuildFileCache.php

script headers are not added to the resulting cached pages, disabling the functionality to expand categories.

I have tested this with these settings:

$wgCategoryTreeSidebarRoot = 'Articles';
$wgCategoryTreeSidebarOptions['mode'] = 'pages';

This enables $wgCategoryTreeForceHeaders.

The problem lies in the use of $wgOut (which is deprecated). When $wgCategoryTreeForceHeaders is enabled, the problem is here, in CategoryTree.php:

if ( $wgCategoryTreeForceHeaders ) {

		CategoryTree::setHeaders( $wgOut );

} else {

		$wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput';

}

This is only run once on initialization. So, when caching pages with rebuildFileCache.php, subsequent pages do not get the headers they need (I have not verified whether the first one gets them, but I don't think that's very important).

I have made some changes that make rebuildFileCache work again when $wgCategoryTreeForceHeaders is enabled (by not using $wgOut), but ideally $wgOut should not be used anywhere anymore preventing such problems. I can post the changes if needed, but they only really fix half of the problem.


Version: REL1_22-branch
Severity: normal

Details

Reference
bz57651

Event Timeline

bzimport raised the priority of this task from to High.
bzimport set Reference to bz57651.
bzimport added a subscriber: Unknown Object (MLST).

Thanks for taking the time to report this!

(In reply to comment #0)

I can post the changes if needed, but they only
really fix half of the problem.

I guess it could still be welcome as a starter.

11fallingleaves wrote:

Here is the git diff:

diff --git a/CategoryTree.php b/CategoryTree.php
index 5d0bbdf..24c1025 100644

  • a/CategoryTree.php

+++ b/CategoryTree.php
@@ -209,11 +209,7 @@ function efCategoryTree() {

		$wgCategoryTreeCategoryPageOptions['mode'] = ( $mode = $wgRequest->getVal( 'mode' ) ) ? CategoryTree::decodeMode( $mode ) : $wgCategoryTreeCategoryPageMode;
	}
  • if ( $wgCategoryTreeForceHeaders ) {
  • CategoryTree::setHeaders( $wgOut );
  • } else {
  • $wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput';
  • }

+ $wgHooks['OutputPageParserOutput'][] = 'efCategoryTreeParserOutput';

	$wgHooks['MakeGlobalVariablesScript'][] = 'efCategoryTreeGetConfigVars';

}
@@ -383,7 +379,8 @@ function efCategoryTreeParserHook( $cat, $argv, $parser = null, $allowMissing =

    • @return bool */ function efCategoryTreeParserOutput( $outputPage, $parserOutput ) {
  • if ( !empty( $parserOutput->mCategoryTreeTag ) ) {

+ global $wgCategoryTreeForceHeaders;
+ if ( $wgCategoryTreeForceHeaders || !empty( $parserOutput->mCategoryTreeTag ) ) {

		CategoryTree::setHeaders( $outputPage );
	}
	return true;

11fallingleaves wrote:

I uploaded the patch:
https://gerrit.wikimedia.org/r/#/c/99649/

I believe this should fix most of it, maybe all, but $wgOut is used in a few other places. I think that part is in need of a refactor / small rewrite. I do not have enough familiarity with CategoryTree to do that in a good way.

Thanks! Setting PATCH_TO_REVIEW status (though patch needs rework)

11fallingleaves wrote:

Wait - don't merge this patch. It's broken.

I realized this patch does not work on pages that are not parsed pages, like Special:Preferences.
(Strangely, it does work on Special:RecentChanges, I suppose there's some parsing going on there.)
So, it needs a different hook that's called on *every* page, not just parsed pages.

Change 99649 had a related patch set uploaded by Leaves in Motion:
Use hooks instead of $wgOut when $wgCategoryTreeForceHeaders is set

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

Change 99649 merged by jenkins-bot:
Use hooks instead of $wgOut when $wgCategoryTreeForceHeaders is set

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

There's a lot of other things very very outdated in the way CategoryTree handles js that could also use with fixing. Anyways, patch merged, marking bug as fixed.