Deprecate $wgParserConf
This setting has been effectively constant since 2008. In modern code we should be using a ParserFactory instead to customize Parser creation and not calling the Parser constructor directly (T236811). Because the ParserFactory is cached, which freezes the current value of the content language and other options, we need to reset the ParserFactory object when running parser tests (T248977). Thanks to Peter Ovchyn <peter.ovchyn@speedandfunction.com> for first uncovering this issue and suggesting a fix in I4203bf7719a8555a09b72cdb5b1ae7a6e1505acf. Code search: https://codesearch.wmflabs.org/deployed/?q=wgParserConf&i=nope&files=&repos= https://codesearch.wmflabs.org/deployed/?q=ParserConf&i=nope&files=&repos= Bug: T248977 Bug: T236811 Depends-On: I97d58750c91b06eeca5d810509becdf53a39cc95 Depends-On: Idf59cd54146d31c1c32883f4318e6a0bf60e1a8a Change-Id: I787f22ea9bf59a049b13631ba6974866a1300988
This commit is contained in:
parent
37dc40c5df
commit
a286a59e86
6 changed files with 19 additions and 9 deletions
|
|
@ -85,6 +85,9 @@ For notes on 1.34.x and older releases, see HISTORY.
|
|||
unchanged for revisions that only contain the main slot. The --schema-version
|
||||
option can be used with the dumpBackup.php script to set the dump format.
|
||||
(T238921)
|
||||
* $wgParserConf - This configuration is now deprecated. It has been
|
||||
effectively constant since 2008, and is ignored by core code.
|
||||
Configure the ParserFactory service in order to customize the Parser used.
|
||||
* …
|
||||
|
||||
==== Removed configuration ====
|
||||
|
|
|
|||
|
|
@ -4465,6 +4465,9 @@ $wgInvalidRedirectTargets = [ 'Filepath', 'Mypage', 'Mytalk', 'Redirect' ];
|
|||
* the contents of this variable will be out-of-date. The variable can only be
|
||||
* changed during LocalSettings.php, in particular, it can't be changed during
|
||||
* an extension setup function.
|
||||
* @deprecated since 1.35. This has been effectively a constant for a long
|
||||
* time. Configuring the ParserFactory service is the modern way to tweak
|
||||
* the default parser.
|
||||
*/
|
||||
$wgParserConf = [
|
||||
'class' => Parser::class,
|
||||
|
|
|
|||
|
|
@ -731,6 +731,10 @@ return [
|
|||
'ParserFactory' => function ( MediaWikiServices $services ) : ParserFactory {
|
||||
$options = new ServiceOptions( Parser::CONSTRUCTOR_OPTIONS,
|
||||
// 'class'
|
||||
// Note that this value is ignored by ParserFactory and is always
|
||||
// Parser::class for legacy reasons; we'll introduce a new
|
||||
// mechanism for selecting an alternate parser in the future
|
||||
// (T236809)
|
||||
$services->getMainConfig()->get( 'ParserConf' ),
|
||||
// Make sure to have defaults in case someone overrode ParserConf with something silly
|
||||
[ 'class' => Parser::class ],
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ class Parser {
|
|||
* @since 1.35
|
||||
*/
|
||||
public const CONSTRUCTOR_OPTIONS = [
|
||||
// See $wgParserConf documentation
|
||||
// Deprecated and unused; from $wgParserConf
|
||||
'class',
|
||||
// See documentation for the corresponding config options
|
||||
'ArticlePath',
|
||||
|
|
|
|||
|
|
@ -58,9 +58,10 @@ class DumpRenderer extends Maintenance {
|
|||
$this->startTime = microtime( true );
|
||||
|
||||
if ( $this->hasOption( 'parser' ) ) {
|
||||
global $wgParserConf;
|
||||
$wgParserConf['class'] = $this->getOption( 'parser' );
|
||||
$this->prefix .= "-{$wgParserConf['class']}";
|
||||
$this->prefix .= "-{$this->getOption( 'parser' )}";
|
||||
// T236809: We'll need to provide an alternate ParserFactory
|
||||
// service to make this work.
|
||||
$this->fatalError( 'Parser class configuration temporarily disabled.' );
|
||||
}
|
||||
|
||||
$source = new ImportStreamSource( $this->getStdin() );
|
||||
|
|
|
|||
|
|
@ -791,12 +791,9 @@ class ParserTestRunner {
|
|||
* @return Parser
|
||||
*/
|
||||
public function getParser() {
|
||||
global $wgParserConf;
|
||||
|
||||
$class = $wgParserConf['class'];
|
||||
$parser = new $class( $wgParserConf );
|
||||
$parserFactory = MediaWikiServices::getInstance()->getParserFactory();
|
||||
$parser = $parserFactory->create(); // A fresh parser object.
|
||||
ParserTestParserHook::setup( $parser );
|
||||
|
||||
return $parser;
|
||||
}
|
||||
|
||||
|
|
@ -1140,6 +1137,7 @@ class ParserTestRunner {
|
|||
Hooks::run( 'ParserTestGlobals', [ &$setup ] );
|
||||
|
||||
// Set content language. This invalidates the magic word cache and title services
|
||||
// In addition the ParserFactory needs to be recreated as well.
|
||||
$lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $langCode );
|
||||
$lang->resetNamespaces();
|
||||
$setup['wgContLang'] = $lang;
|
||||
|
|
@ -1158,6 +1156,7 @@ class ParserTestRunner {
|
|||
$reset = function () {
|
||||
MediaWikiServices::getInstance()->resetServiceForTesting( 'MagicWordFactory' );
|
||||
$this->resetTitleServices();
|
||||
MediaWikiServices::getInstance()->resetServiceForTesting( 'ParserFactory' );
|
||||
};
|
||||
$setup[] = $reset;
|
||||
$teardown[] = $reset;
|
||||
|
|
|
|||
Loading…
Reference in a new issue