Skip to content

Conversation

@mmeller-wikia
Copy link
Contributor

}
}
}
return $this->dataFrames[$sourcePage];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be double-checked: Based on REL1_39 code

private function getDataFrame( $sourcePage, $title, &$parser, $frame ) {
global $wgHooks;
if ( !isset( $this->dataFrames[$sourcePage] ) ) {
$this->dataFrames[$sourcePage] = new UsingDataPPFrameDOM( $frame, $sourcePage );
if ( $sourcePage != ''
&& ( $sourcePage != $parser->getTitle()->getPrefixedText() )
|| $parser->getOptions()->getIsSectionPreview() ) {
[ $text, $fTitle ] = $parser->fetchTemplateAndTitle( $title );
if ( is_object( $fTitle ) && $fTitle->getPrefixedText() != $sourcePage ) {
$this->dataFrames[$fTitle->getPrefixedText()] = $this->dataFrames[$sourcePage];
}
if ( is_string( $text ) && $text != '' ) {
$this->searchingForData = true;
$clearStateHooks = $wgHooks['ParserClearState'];
// Other extensions tend to assume the hook is only called by wgParser and reset internal state
$wgHooks['ParserClearState'] = [];
$subParser = clone $parser;
$subParser->preprocess( $text, $fTitle, clone $parser->getOptions() );
// We might've blocked access to templates while preprocessing; should not be cached
$subParser->clearState();
if ( $parser->getOutput()->hasText() ) {
$subParser->getOutput()->setText( $parser->getOutput()->getText() );
}
$wgHooks['ParserClearState'] = empty( $wgHooks['ParserClearState'] )
? $clearStateHooks
: array_merge( $clearStateHooks, $wgHooks['ParserClearState'] );
$parser->mPPNodeCount += $subParser->mPPNodeCount;
$this->searchingForData = false;
}
}
}
return $this->dataFrames[$sourcePage];
}

Basically, this part could be removed https://github.com/Wikia/usingdata/blob/ee996924d65b057abce474d4b03e56f74ea0f977/src/UsingDataHooks.php#L71C5-L88C6

// This flag is restored at the end
					$this->searchingForData = true;
// Preserve ParserClearState hook handlers to be restored at the end
					$clearStateHooks = $wgHooks['ParserClearState'];
					// Other extensions tend to assume the hook is only called by wgParser and reset internal state
// Disable ParserClearState hook
					$wgHooks['ParserClearState'] = [];
// Cloning original parser state
					$subParser = clone $parser;
// We are working on clone and parameters are not passed as reference. No side-effects except some hooks being called. Hooks registered in UsingData doesn't preserve it's state outside affected parser
					$subParser->preprocess( $text, $fTitle, clone $parser->getOptions() );
					// We might've blocked access to templates while preprocessing; should not be cached
// Clearing state will set internal `mPPNodeCount` to `0`
					$subParser->clearState();
					if ( $parser->getOutput()->hasText() ) {
// $subParser is not used after that assignment
						$subParser->getOutput()->setText( $parser->getOutput()->getText() );
					}
// Restore original ParserClearState hook handlers
					$wgHooks['ParserClearState'] = empty( $wgHooks['ParserClearState'] )
						? $clearStateHooks
						: array_merge( $clearStateHooks, $wgHooks['ParserClearState'] );
// When calling $subParser->clearState(); mPPNodeCount is set to 0
					$parser->mPPNodeCount += $subParser->mPPNodeCount;
// Restore flag value
					$this->searchingForData = false;

@mmeller-wikia mmeller-wikia marked this pull request as draft March 20, 2025 15:14
@mmeller-wikia mmeller-wikia deleted the PLATFORM-10832-cleanup-dead-code branch October 28, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant