2018-08-03 08:25:15 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Parser
|
|
|
|
|
*/
|
2019-04-12 09:50:30 +00:00
|
|
|
|
2019-08-18 18:19:05 +00:00
|
|
|
use MediaWiki\BadFileLookup;
|
2019-04-12 09:50:30 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2020-02-04 12:42:03 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2018-08-08 14:57:31 +00:00
|
|
|
use MediaWiki\Linker\LinkRendererFactory;
|
2020-02-21 00:01:43 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPageFactory;
|
2019-06-27 03:35:50 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2018-08-15 01:11:59 +00:00
|
|
|
|
2018-08-03 08:25:15 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
class ParserFactory {
|
2019-04-12 09:50:30 +00:00
|
|
|
/** @var ServiceOptions */
|
|
|
|
|
private $svcOptions;
|
2018-08-03 08:25:15 +00:00
|
|
|
|
|
|
|
|
/** @var MagicWordFactory */
|
|
|
|
|
private $magicWordFactory;
|
|
|
|
|
|
|
|
|
|
/** @var Language */
|
|
|
|
|
private $contLang;
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $urlProtocols;
|
|
|
|
|
|
2018-08-15 01:11:59 +00:00
|
|
|
/** @var SpecialPageFactory */
|
|
|
|
|
private $specialPageFactory;
|
|
|
|
|
|
2018-08-08 14:57:31 +00:00
|
|
|
/** @var LinkRendererFactory */
|
|
|
|
|
private $linkRendererFactory;
|
|
|
|
|
|
2018-08-05 12:50:01 +00:00
|
|
|
/** @var NamespaceInfo */
|
|
|
|
|
private $nsInfo;
|
|
|
|
|
|
2019-06-27 03:35:50 +00:00
|
|
|
/** @var LoggerInterface */
|
|
|
|
|
private $logger;
|
|
|
|
|
|
2019-08-18 18:19:05 +00:00
|
|
|
/** @var BadFileLookup */
|
|
|
|
|
private $badFileLookup;
|
|
|
|
|
|
2020-02-04 12:42:03 +00:00
|
|
|
/** @var LanguageConverterFactory */
|
|
|
|
|
private $languageConverterFactory;
|
|
|
|
|
|
2020-04-16 14:46:00 +00:00
|
|
|
/**
|
|
|
|
|
* Track calls to Parser constructor to aid in deprecation of direct
|
|
|
|
|
* Parser invocation. This is temporary: it will be removed once the
|
|
|
|
|
* deprecation notice period is over and the underlying method calls
|
|
|
|
|
* are refactored.
|
|
|
|
|
* @internal
|
|
|
|
|
* @var int
|
|
|
|
|
*/
|
|
|
|
|
public static $inParserFactory = 0;
|
|
|
|
|
|
2018-08-03 08:25:15 +00:00
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* @param ServiceOptions $svcOptions
|
2018-08-03 08:25:15 +00:00
|
|
|
* @param MagicWordFactory $magicWordFactory
|
|
|
|
|
* @param Language $contLang Content language
|
|
|
|
|
* @param string $urlProtocols As returned from wfUrlProtocols()
|
2018-08-15 01:11:59 +00:00
|
|
|
* @param SpecialPageFactory $spFactory
|
2018-08-08 14:57:31 +00:00
|
|
|
* @param LinkRendererFactory $linkRendererFactory
|
2020-02-04 12:42:03 +00:00
|
|
|
* @param NamespaceInfo $nsInfo
|
|
|
|
|
* @param LoggerInterface $logger
|
|
|
|
|
* @param BadFileLookup $badFileLookup
|
|
|
|
|
* @param LanguageConverterFactory $languageConverterFactory
|
2018-08-03 08:25:15 +00:00
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
2020-02-04 12:42:03 +00:00
|
|
|
ServiceOptions $svcOptions,
|
2019-06-27 03:35:50 +00:00
|
|
|
MagicWordFactory $magicWordFactory,
|
|
|
|
|
Language $contLang,
|
2020-02-04 12:42:03 +00:00
|
|
|
string $urlProtocols,
|
2019-06-27 03:35:50 +00:00
|
|
|
SpecialPageFactory $spFactory,
|
2020-02-04 12:42:03 +00:00
|
|
|
LinkRendererFactory $linkRendererFactory,
|
|
|
|
|
NamespaceInfo $nsInfo,
|
|
|
|
|
LoggerInterface $logger,
|
|
|
|
|
BadFileLookup $badFileLookup,
|
|
|
|
|
LanguageConverterFactory $languageConverterFactory
|
2018-08-03 08:25:15 +00:00
|
|
|
) {
|
2019-10-08 18:30:42 +00:00
|
|
|
$svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS );
|
2019-04-12 09:50:30 +00:00
|
|
|
|
2020-01-24 22:39:51 +00:00
|
|
|
wfDebug( __CLASS__ . ": using default preprocessor\n" );
|
2019-04-12 09:50:30 +00:00
|
|
|
|
|
|
|
|
$this->svcOptions = $svcOptions;
|
2018-08-03 08:25:15 +00:00
|
|
|
$this->magicWordFactory = $magicWordFactory;
|
|
|
|
|
$this->contLang = $contLang;
|
|
|
|
|
$this->urlProtocols = $urlProtocols;
|
2018-08-15 01:11:59 +00:00
|
|
|
$this->specialPageFactory = $spFactory;
|
2018-08-08 14:57:31 +00:00
|
|
|
$this->linkRendererFactory = $linkRendererFactory;
|
2018-08-05 12:50:01 +00:00
|
|
|
$this->nsInfo = $nsInfo;
|
2020-02-04 12:42:03 +00:00
|
|
|
$this->logger = $logger;
|
|
|
|
|
$this->badFileLookup = $badFileLookup;
|
|
|
|
|
$this->languageConverterFactory = $languageConverterFactory;
|
2018-08-03 08:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-04 12:42:03 +00:00
|
|
|
* Creates a new parser
|
|
|
|
|
*
|
2018-08-03 08:25:15 +00:00
|
|
|
* @return Parser
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
public function create() : Parser {
|
2020-04-16 14:46:00 +00:00
|
|
|
self::$inParserFactory++;
|
|
|
|
|
try {
|
|
|
|
|
return new Parser(
|
|
|
|
|
$this->svcOptions,
|
|
|
|
|
$this->magicWordFactory,
|
|
|
|
|
$this->contLang,
|
|
|
|
|
$this,
|
|
|
|
|
$this->urlProtocols,
|
|
|
|
|
$this->specialPageFactory,
|
|
|
|
|
$this->linkRendererFactory,
|
|
|
|
|
$this->nsInfo,
|
|
|
|
|
$this->logger,
|
|
|
|
|
$this->badFileLookup,
|
|
|
|
|
$this->languageConverterFactory
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
self::$inParserFactory--;
|
|
|
|
|
}
|
2018-08-03 08:25:15 +00:00
|
|
|
}
|
|
|
|
|
}
|