3use Wikimedia\TestingAccessWrapper;
4use Wikimedia\ScopedCallback;
12 $wrap = TestingAccessWrapper::newFromClass( ParserOptions::class );
13 $wrap->defaults =
null;
14 $wrap->lazyOptions = [
15 'dateformat' => [ ParserOptions::class,
'initDateFormat' ],
16 'speculativeRevId' => [ ParserOptions::class,
'initSpeculativeRevId' ],
20 'numberheadings' =>
true,
22 'stubthreshold' =>
true,
33 'wgRenderHashAppend' =>
'',
48 $wgLang = Language::factory(
'fr' );
49 $contLang = Language::factory(
'qqx' );
58 $lang = Language::factory(
'de' );
59 $lang2 = Language::factory(
'bug' );
65 $popt = ParserOptions::newCanonical();
66 $this->assertSame( $wgUser, $popt->getUser() );
67 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
70 $popt = ParserOptions::newCanonical(
$user );
71 $this->assertSame(
$user, $popt->getUser() );
72 $this->assertSame(
$wgLang, $popt->getUserLangObj() );
75 $popt = ParserOptions::newCanonical(
null,
$lang );
76 $this->assertSame( $wgUser, $popt->getUser() );
77 $this->assertSame(
$lang, $popt->getUserLangObj() );
80 $popt = ParserOptions::newCanonical(
$user,
$lang );
81 $this->assertSame(
$user, $popt->getUser() );
82 $this->assertSame(
$lang, $popt->getUserLangObj() );
85 $popt = ParserOptions::newCanonical(
'canonical' );
86 $this->assertTrue( $popt->getUser()->isAnon() );
87 $this->assertSame( $contLang, $popt->getUserLangObj() );
88 $popt = ParserOptions::newCanonical(
'canonical', $lang2 );
89 $this->assertSame( $contLang, $popt->getUserLangObj() );
93 $popt = ParserOptions::newCanonical(
$context );
94 $this->assertSame(
$user, $popt->getUser() );
95 $this->assertSame(
$lang, $popt->getUserLangObj() );
96 $popt = ParserOptions::newCanonical(
$context, $lang2 );
97 $this->assertSame(
$lang, $popt->getUserLangObj() );
101 $popt = ParserOptions::newCanonical(
'bogus' );
102 $this->fail(
'Excpected exception not thrown' );
103 }
catch ( InvalidArgumentException $ex ) {
113 $popt = ParserOptions::newCanonical();
117 $this->assertSame( $expect, $popt->isSafeToCache() );
122 'No overrides' => [
true, [] ],
123 'In-key options are ok' => [
true, [
124 'thumbsize' => 1e100,
125 'printable' =>
false,
127 'Non-in-key options are not ok' => [
false, [
128 'removeComments' =>
false,
130 'Non-in-key options are not ok (2)' => [
false, [
131 'wrapclass' =>
'foobar',
133 'Canonical override, not default (1)' => [
true, [
136 'Canonical override, not default (2)' => [
false, [
151 $usedOptions, $expect,
$options, $globals = [], $hookFunc =
null
156 $popt = ParserOptions::newCanonical();
160 $this->assertSame( $expect, $popt->optionsHash( $usedOptions ) );
164 $used = [
'thumbsize',
'printable' ];
166 $classWrapper = TestingAccessWrapper::newFromClass( ParserOptions::class );
167 $classWrapper->getDefaults();
168 $allUsableOptions = array_diff(
169 array_keys( $classWrapper->inCacheKey ),
170 array_keys( $classWrapper->lazyOptions )
174 'Canonical options, nothing used' => [ [],
'canonical', [] ],
175 'Canonical options, used some options' => [ $used,
'canonical', [] ],
176 'Used some options, non-default values' => [
178 'printable=1!thumbsize=200',
184 'Canonical options, used all non-lazy options' => [ $allUsableOptions,
'canonical', [] ],
185 'Canonical options, nothing used, but with hooks and $wgRenderHashAppend' => [
187 'canonical!wgRenderHashAppend!onPageRenderingHash',
189 [
'wgRenderHashAppend' =>
'!wgRenderHashAppend' ],
190 [ __CLASS__ .
'::onPageRenderingHash' ],
197 function ( &$defaults, &$inCacheKey, &$lazyOptions ) {
198 $lazyFuncs = $this->getMockBuilder( stdClass::class )
199 ->setMethods( [
'neverCalled',
'calledOnce' ] )
201 $lazyFuncs->expects( $this->never() )->method(
'neverCalled' );
202 $lazyFuncs->expects( $this->once() )->method(
'calledOnce' )->willReturn(
'value' );
214 'opt1' => [ $lazyFuncs,
'calledOnce' ],
215 'opt2' => [ $lazyFuncs,
'neverCalled' ],
216 'opt3' => [ $lazyFuncs,
'neverCalled' ],
223 $popt = ParserOptions::newCanonical();
224 $popt->registerWatcher(
function () {
225 $this->fail(
'Watcher should not have been called' );
227 $this->assertSame(
'opt1=value', $popt->optionsHash( [
'opt1',
'opt3' ] ) );
230 $this->assertSame(
'opt1=value', $popt->optionsHash( [
'opt1',
'opt3' ] ) );
234 $confstr .=
'!onPageRenderingHash';
242 $popt = ParserOptions::newCanonical();
243 $popt->getOption(
'bogus' );
251 $popt = ParserOptions::newCanonical();
252 $popt->setOption(
'bogus',
true );
256 $classWrapper = TestingAccessWrapper::newFromClass( ParserOptions::class );
257 $oldDefaults = $classWrapper->defaults;
258 $oldLazy = $classWrapper->lazyOptions;
259 $reset =
new ScopedCallback(
function ()
use ( $classWrapper, $oldDefaults, $oldLazy ) {
260 $classWrapper->defaults = $oldDefaults;
261 $classWrapper->lazyOptions = $oldLazy;
264 $popt1 = ParserOptions::newCanonical();
265 $popt2 = ParserOptions::newCanonical();
266 $this->assertTrue( $popt1->matches( $popt2 ) );
268 $popt1->enableLimitReport(
true );
269 $popt2->enableLimitReport(
false );
270 $this->assertTrue( $popt1->matches( $popt2 ) );
272 $popt2->setTidy( !$popt2->getTidy() );
273 $this->assertFalse( $popt1->matches( $popt2 ) );
276 $classWrapper->defaults += [ __METHOD__ => null ];
277 $classWrapper->lazyOptions += [ __METHOD__ =>
function ()
use ( &$ctr ) {
280 $popt1 = ParserOptions::newCanonical();
281 $popt2 = ParserOptions::newCanonical();
282 $this->assertFalse( $popt1->matches( $popt2 ) );
284 ScopedCallback::consume( $reset );
290 'dateformat',
'numberheadings',
'printable',
'stubthreshold',
291 'thumbsize',
'userlang'
292 ], ParserOptions::allCacheVaryingOptions() );
296 $this->
setTemporaryHook(
'ParserOptionsRegister',
function ( &$defaults, &$inCacheKey ) {
308 'dateformat',
'foo',
'numberheadings',
'printable',
'stubthreshold',
309 'thumbsize',
'userlang'
310 ], ParserOptions::allCacheVaryingOptions() );
316 $this->assertFalse(
$options->getSpeculativeRevId() );
319 $options->setSpeculativeRevIdCallback(
function ()
use( &$counter ) {
324 $this->assertSame( 1,
$options->getSpeculativeRevId() );
325 $this->assertSame( 1,
$options->getSpeculativeRevId() );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
An IContextSource implementation which will inherit context from another source but allow individual ...
static provideIsSafeToCache()
testSetInvalidOption()
InvalidArgumentException Unknown parser option bogus.
testGetInvalidOption()
InvalidArgumentException Unknown parser option bogus.
testUsedLazyOptionsInHash()
testAllCacheVaryingOptions()
testIsSafeToCache( $expect, $options)
provideIsSafeToCache
static onPageRenderingHash(&$confstr)
static provideOptionsHash()
testGetSpeculativeRevid()
testOptionsHash( $usedOptions, $expect, $options, $globals=[], $hookFunc=null)
provideOptionsHash
Set options of the Parser.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Allows to change the fields on the form that will be generated $name
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
if(!isset( $args[0])) $lang