| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
namespace MediaWiki\Parser; |
| 23 |
|
| 24 |
use MediaWiki\Category\TrackingCategories; |
| 25 |
use MediaWiki\Config\ServiceOptions; |
| 26 |
use MediaWiki\HookContainer\HookContainer; |
| 27 |
use MediaWiki\Http\HttpRequestFactory; |
| 28 |
use MediaWiki\Language\Language; |
| 29 |
use MediaWiki\Languages\LanguageConverterFactory; |
| 30 |
use MediaWiki\Languages\LanguageNameUtils; |
| 31 |
use MediaWiki\Linker\LinkRendererFactory; |
| 32 |
use MediaWiki\Page\File\BadFileLookup; |
| 33 |
use MediaWiki\Preferences\SignatureValidatorFactory; |
| 34 |
use MediaWiki\SpecialPage\SpecialPageFactory; |
| 35 |
use MediaWiki\Tidy\TidyDriverBase; |
| 36 |
use MediaWiki\Title\NamespaceInfo; |
| 37 |
use MediaWiki\Title\TitleFormatter; |
| 38 |
use MediaWiki\User\Options\UserOptionsLookup; |
| 39 |
use MediaWiki\User\UserFactory; |
| 40 |
use MediaWiki\User\UserNameUtils; |
| 41 |
use MediaWiki\Utils\UrlUtils; |
| 42 |
use Psr\Log\LoggerInterface; |
| 43 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
class ParserFactory { |
| 49 |
|
| 50 |
private $svcOptions; |
| 51 |
|
| 52 |
|
| 53 |
private $magicWordFactory; |
| 54 |
|
| 55 |
|
| 56 |
private $contLang; |
| 57 |
|
| 58 |
|
| 59 |
private $urlUtils; |
| 60 |
|
| 61 |
|
| 62 |
private $specialPageFactory; |
| 63 |
|
| 64 |
|
| 65 |
private $linkRendererFactory; |
| 66 |
|
| 67 |
|
| 68 |
private $nsInfo; |
| 69 |
|
| 70 |
|
| 71 |
private $logger; |
| 72 |
|
| 73 |
|
| 74 |
private $badFileLookup; |
| 75 |
|
| 76 |
|
| 77 |
private $languageConverterFactory; |
| 78 |
|
| 79 |
|
| 80 |
private $languageNameUtils; |
| 81 |
|
| 82 |
|
| 83 |
private $userOptionsLookup; |
| 84 |
|
| 85 |
|
| 86 |
private $userFactory; |
| 87 |
|
| 88 |
|
| 89 |
private $titleFormatter; |
| 90 |
|
| 91 |
|
| 92 |
private $httpRequestFactory; |
| 93 |
|
| 94 |
|
| 95 |
private $trackingCategories; |
| 96 |
|
| 97 |
|
| 98 |
private $signatureValidatorFactory; |
| 99 |
|
| 100 |
|
| 101 |
private $userNameUtils; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public static $inParserFactory = 0; |
| 112 |
|
| 113 |
|
| 114 |
private $hookContainer; |
| 115 |
|
| 116 |
|
| 117 |
private $tidy; |
| 118 |
|
| 119 |
|
| 120 |
private $wanCache; |
| 121 |
|
| 122 |
|
| 123 |
private $mainInstance; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
public function __construct( |
| 151 |
ServiceOptions $svcOptions, |
| 152 |
MagicWordFactory $magicWordFactory, |
| 153 |
Language $contLang, |
| 154 |
UrlUtils $urlUtils, |
| 155 |
SpecialPageFactory $spFactory, |
| 156 |
LinkRendererFactory $linkRendererFactory, |
| 157 |
NamespaceInfo $nsInfo, |
| 158 |
LoggerInterface $logger, |
| 159 |
BadFileLookup $badFileLookup, |
| 160 |
LanguageConverterFactory $languageConverterFactory, |
| 161 |
LanguageNameUtils $languageNameUtils, |
| 162 |
HookContainer $hookContainer, |
| 163 |
TidyDriverBase $tidy, |
| 164 |
WANObjectCache $wanCache, |
| 165 |
UserOptionsLookup $userOptionsLookup, |
| 166 |
UserFactory $userFactory, |
| 167 |
TitleFormatter $titleFormatter, |
| 168 |
HttpRequestFactory $httpRequestFactory, |
| 169 |
TrackingCategories $trackingCategories, |
| 170 |
SignatureValidatorFactory $signatureValidatorFactory, |
| 171 |
UserNameUtils $userNameUtils |
| 172 |
) { |
| 173 |
$svcOptions->assertRequiredOptions( Parser::CONSTRUCTOR_OPTIONS ); |
| 174 |
|
| 175 |
wfDebug( __CLASS__ . ": using default preprocessor" ); |
| 176 |
|
| 177 |
$this->svcOptions = $svcOptions; |
| 178 |
$this->magicWordFactory = $magicWordFactory; |
| 179 |
$this->contLang = $contLang; |
| 180 |
$this->urlUtils = $urlUtils; |
| 181 |
$this->specialPageFactory = $spFactory; |
| 182 |
$this->linkRendererFactory = $linkRendererFactory; |
| 183 |
$this->nsInfo = $nsInfo; |
| 184 |
$this->logger = $logger; |
| 185 |
$this->badFileLookup = $badFileLookup; |
| 186 |
$this->languageConverterFactory = $languageConverterFactory; |
| 187 |
$this->languageNameUtils = $languageNameUtils; |
| 188 |
$this->hookContainer = $hookContainer; |
| 189 |
$this->tidy = $tidy; |
| 190 |
$this->wanCache = $wanCache; |
| 191 |
$this->userOptionsLookup = $userOptionsLookup; |
| 192 |
$this->userFactory = $userFactory; |
| 193 |
$this->titleFormatter = $titleFormatter; |
| 194 |
$this->httpRequestFactory = $httpRequestFactory; |
| 195 |
$this->trackingCategories = $trackingCategories; |
| 196 |
$this->signatureValidatorFactory = $signatureValidatorFactory; |
| 197 |
$this->userNameUtils = $userNameUtils; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public function create(): Parser { |
| 211 |
self::$inParserFactory++; |
| 212 |
try { |
| 213 |
return new Parser( |
| 214 |
$this->svcOptions, |
| 215 |
$this->magicWordFactory, |
| 216 |
$this->contLang, |
| 217 |
$this, |
| 218 |
$this->urlUtils, |
| 219 |
$this->specialPageFactory, |
| 220 |
$this->linkRendererFactory, |
| 221 |
$this->nsInfo, |
| 222 |
$this->logger, |
| 223 |
$this->badFileLookup, |
| 224 |
$this->languageConverterFactory, |
| 225 |
$this->languageNameUtils, |
| 226 |
$this->hookContainer, |
| 227 |
$this->tidy, |
| 228 |
$this->wanCache, |
| 229 |
$this->userOptionsLookup, |
| 230 |
$this->userFactory, |
| 231 |
$this->titleFormatter, |
| 232 |
$this->httpRequestFactory, |
| 233 |
$this->trackingCategories, |
| 234 |
$this->signatureValidatorFactory, |
| 235 |
$this->userNameUtils |
| 236 |
); |
| 237 |
} finally { |
| 238 |
self::$inParserFactory--; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
public function getMainInstance() { |
| 255 |
if ( $this->mainInstance === null ) { |
| 256 |
$this->mainInstance = $this->create(); |
| 257 |
} |
| 258 |
return $this->mainInstance; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
public function getInstance() { |
| 273 |
$instance = $this->getMainInstance(); |
| 274 |
if ( $instance->isLocked() ) { |
| 275 |
$instance = $this->create(); |
| 276 |
} |
| 277 |
return $instance; |
| 278 |
} |
| 279 |
|
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
class_alias( ParserFactory::class, 'ParserFactory' ); |