14 $this->tablesUsed[] =
'change_tag';
15 $this->tablesUsed[] =
'change_tag_def';
20 $this->tablesUsed[] =
'recentchanges';
21 $this->tablesUsed[] =
'logging';
22 $this->tablesUsed[] =
'revision';
23 $this->tablesUsed[] =
'archive';
34 if ( isset( $modifiedQuery[
'fields'][
'ts_tags'] ) ) {
35 $modifiedQuery[
'fields'][
'ts_tags'] = call_user_func_array(
37 $modifiedQuery[
'fields'][
'ts_tags']
40 if ( isset( $modifiedQuery[
'exception'] ) ) {
41 $this->setExpectedException( $modifiedQuery[
'exception'] );
47 $origQuery[
'join_conds'],
48 $origQuery[
'options'],
51 if ( !isset( $modifiedQuery[
'exception'] ) ) {
64 $baseConcats = [
',', [
'change_tag',
'change_tag_def' ],
'ctd_name' ];
65 $joinConds = [
'change_tag_def' => [
'JOIN',
'ct_tag_id=ctd_id' ] ];
67 'recentchanges' => array_merge( $baseConcats, [
'ct_rc_id=rc_id', $joinConds ] ),
68 'logging' => array_merge( $baseConcats, [
'ct_log_id=log_id', $joinConds ] ),
69 'revision' => array_merge( $baseConcats, [
'ct_rev_id=rev_id', $joinConds ] ),
70 'archive' => array_merge( $baseConcats, [
'ct_rev_id=ar_rev_id', $joinConds ] ),
74 'simple recentchanges query' => [
76 'tables' => [
'recentchanges' ],
77 'fields' => [
'rc_id',
'rc_timestamp' ],
78 'conds' => [
"rc_timestamp > '20170714183203'" ],
80 'options' => [
'ORDER BY' =>
'rc_timestamp DESC' ],
85 'tables' => [
'recentchanges' ],
86 'fields' => [
'rc_id',
'rc_timestamp',
'ts_tags' => $groupConcats[
'recentchanges'] ],
87 'conds' => [
"rc_timestamp > '20170714183203'" ],
89 'options' => [
'ORDER BY' =>
'rc_timestamp DESC' ],
92 'simple query with strings' => [
94 'tables' =>
'recentchanges',
96 'conds' =>
"rc_timestamp > '20170714183203'",
98 'options' =>
'ORDER BY rc_timestamp DESC',
103 'tables' => [
'recentchanges' ],
104 'fields' => [
'rc_id',
'ts_tags' => $groupConcats[
'recentchanges'] ],
105 'conds' => [
"rc_timestamp > '20170714183203'" ],
107 'options' => [
'ORDER BY rc_timestamp DESC' ],
110 'recentchanges query with single tag filter' => [
112 'tables' => [
'recentchanges' ],
113 'fields' => [
'rc_id',
'rc_timestamp' ],
114 'conds' => [
"rc_timestamp > '20170714183203'" ],
116 'options' => [
'ORDER BY' =>
'rc_timestamp DESC' ],
121 'tables' => [
'recentchanges',
'change_tag' ],
122 'fields' => [
'rc_id',
'rc_timestamp',
'ts_tags' => $groupConcats[
'recentchanges'] ],
123 'conds' => [
"rc_timestamp > '20170714183203'",
'ct_tag_id' => [ 1 ] ],
124 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rc_id=rc_id' ] ],
125 'options' => [
'ORDER BY' =>
'rc_timestamp DESC' ],
128 'logging query with single tag filter and strings' => [
130 'tables' =>
'logging',
131 'fields' =>
'log_id',
132 'conds' =>
"log_timestamp > '20170714183203'",
134 'options' =>
'ORDER BY log_timestamp DESC',
139 'tables' => [
'logging',
'change_tag' ],
140 'fields' => [
'log_id',
'ts_tags' => $groupConcats[
'logging'] ],
141 'conds' => [
"log_timestamp > '20170714183203'",
'ct_tag_id' => [ 1 ] ],
142 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_log_id=log_id' ] ],
143 'options' => [
'ORDER BY log_timestamp DESC' ],
146 'revision query with single tag filter' => [
148 'tables' => [
'revision' ],
149 'fields' => [
'rev_id',
'rev_timestamp' ],
150 'conds' => [
"rev_timestamp > '20170714183203'" ],
152 'options' => [
'ORDER BY' =>
'rev_timestamp DESC' ],
157 'tables' => [
'revision',
'change_tag' ],
158 'fields' => [
'rev_id',
'rev_timestamp',
'ts_tags' => $groupConcats[
'revision'] ],
159 'conds' => [
"rev_timestamp > '20170714183203'",
'ct_tag_id' => [ 1 ] ],
160 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rev_id=rev_id' ] ],
161 'options' => [
'ORDER BY' =>
'rev_timestamp DESC' ],
164 'archive query with single tag filter' => [
166 'tables' => [
'archive' ],
167 'fields' => [
'ar_id',
'ar_timestamp' ],
168 'conds' => [
"ar_timestamp > '20170714183203'" ],
170 'options' => [
'ORDER BY' =>
'ar_timestamp DESC' ],
175 'tables' => [
'archive',
'change_tag' ],
176 'fields' => [
'ar_id',
'ar_timestamp',
'ts_tags' => $groupConcats[
'archive'] ],
177 'conds' => [
"ar_timestamp > '20170714183203'",
'ct_tag_id' => [ 1 ] ],
178 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rev_id=ar_rev_id' ] ],
179 'options' => [
'ORDER BY' =>
'ar_timestamp DESC' ],
182 'unsupported table name throws exception (even without tag filter)' => [
184 'tables' => [
'foobar' ],
185 'fields' => [
'fb_id',
'fb_timestamp' ],
186 'conds' => [
"fb_timestamp > '20170714183203'" ],
188 'options' => [
'ORDER BY' =>
'fb_timestamp DESC' ],
192 [
'exception' => MWException::class ]
194 'tag filter ignored when tag filtering is disabled' => [
196 'tables' => [
'archive' ],
197 'fields' => [
'ar_id',
'ar_timestamp' ],
198 'conds' => [
"ar_timestamp > '20170714183203'" ],
200 'options' => [
'ORDER BY' =>
'ar_timestamp DESC' ],
205 'tables' => [
'archive' ],
206 'fields' => [
'ar_id',
'ar_timestamp',
'ts_tags' => $groupConcats[
'archive'] ],
207 'conds' => [
"ar_timestamp > '20170714183203'" ],
209 'options' => [
'ORDER BY' =>
'ar_timestamp DESC' ],
212 'recentchanges query with multiple tag filter' => [
214 'tables' => [
'recentchanges' ],
215 'fields' => [
'rc_id',
'rc_timestamp' ],
216 'conds' => [
"rc_timestamp > '20170714183203'" ],
218 'options' => [
'ORDER BY' =>
'rc_timestamp DESC' ],
223 'tables' => [
'recentchanges',
'change_tag' ],
224 'fields' => [
'rc_id',
'rc_timestamp',
'ts_tags' => $groupConcats[
'recentchanges'] ],
225 'conds' => [
"rc_timestamp > '20170714183203'",
'ct_tag_id' => [ 1, 2 ] ],
226 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rc_id=rc_id' ] ],
227 'options' => [
'ORDER BY' =>
'rc_timestamp DESC',
'DISTINCT' ],
230 'recentchanges query with multiple tag filter that already has DISTINCT' => [
232 'tables' => [
'recentchanges' ],
233 'fields' => [
'rc_id',
'rc_timestamp' ],
234 'conds' => [
"rc_timestamp > '20170714183203'" ],
236 'options' => [
'DISTINCT',
'ORDER BY' =>
'rc_timestamp DESC' ],
241 'tables' => [
'recentchanges',
'change_tag' ],
242 'fields' => [
'rc_id',
'rc_timestamp',
'ts_tags' => $groupConcats[
'recentchanges'] ],
243 'conds' => [
"rc_timestamp > '20170714183203'",
'ct_tag_id' => [ 1, 2 ] ],
244 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rc_id=rc_id' ] ],
245 'options' => [
'DISTINCT',
'ORDER BY' =>
'rc_timestamp DESC' ],
248 'recentchanges query with multiple tag filter with strings' => [
250 'tables' =>
'recentchanges',
252 'conds' =>
"rc_timestamp > '20170714183203'",
254 'options' =>
'ORDER BY rc_timestamp DESC',
259 'tables' => [
'recentchanges',
'change_tag' ],
260 'fields' => [
'rc_id',
'ts_tags' => $groupConcats[
'recentchanges'] ],
261 'conds' => [
"rc_timestamp > '20170714183203'",
'ct_tag_id' => [ 1, 2 ] ],
262 'join_conds' => [
'change_tag' => [
'JOIN',
'ct_rc_id=rc_id' ] ],
263 'options' => [
'ORDER BY rc_timestamp DESC',
'DISTINCT' ],
273 'mw-contentModelChange' =>
true,
274 'mw-redirect' =>
true,
275 'mw-rollback' =>
true,
288 'mw-contentmodelchanged' =>
true,
289 'mw-replace' =>
true,
290 'mw-new-redirects' =>
true,
291 'mw-changed-redirect-target' =>
true,
292 'mw-rolback' =>
true,
293 'mw-blanking' =>
false
297 'mw-changed-redirect-target'
329 $this->assertEquals( $expected, $actual );
337 $dbw->delete(
'change_tag',
'*' );
338 $dbw->delete(
'change_tag_def',
'*' );
348 'ctd_name' =>
'tag1',
353 'ctd_name' =>
'tag2',
358 $res =
$dbr->select(
'change_tag_def', [
'ctd_name',
'ctd_id',
'ctd_count' ],
'' );
359 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
373 $res2 =
$dbr->select(
'change_tag', [
'ct_tag_id',
'ct_rc_id',
'ct_rev_id' ],
'' );
374 $this->assertEquals( $expected2, iterator_to_array( $res2,
false ) );
385 'ctd_name' =>
'tag1',
390 'ctd_name' =>
'tag2',
395 'ctd_name' =>
'tag3',
400 $res =
$dbr->select(
'change_tag_def', [
'ctd_name',
'ctd_id',
'ctd_count' ],
'' );
401 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
425 $res2 =
$dbr->select(
'change_tag', [
'ct_tag_id',
'ct_rc_id',
'ct_rev_id' ],
'' );
426 $this->assertEquals( $expected2, iterator_to_array( $res2,
false ) );
434 $dbw->delete(
'change_tag',
'*' );
435 $dbw->delete(
'change_tag_def',
'*' );
445 'ctd_name' =>
'tag1',
450 'ctd_name' =>
'tag2',
455 'ctd_name' =>
'tag3',
460 $res =
$dbr->select(
'change_tag_def', [
'ctd_name',
'ctd_id',
'ctd_count' ],
'' );
461 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
477 $res2 =
$dbr->select(
'change_tag', [
'ct_tag_id',
'ct_rc_id' ],
'' );
478 $this->assertEquals( $expected2, iterator_to_array( $res2,
false ) );
486 $dbw->delete(
'change_tag',
'*' );
487 $dbw->delete(
'change_tag_def',
'*' );
492 $this->assertEquals( [ [], [], [
'tag1',
'tag2' ] ],
$res );
498 'ctd_name' =>
'tag1',
503 'ctd_name' =>
'tag2',
508 $res =
$dbr->select(
'change_tag_def', [
'ctd_name',
'ctd_id',
'ctd_count' ],
'' );
509 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
521 $res2 =
$dbr->select(
'change_tag', [
'ct_tag_id',
'ct_rc_id' ],
'' );
522 $this->assertEquals( $expected2, iterator_to_array( $res2,
false ) );
527 $dbw->delete(
'change_tag',
'*' );
528 $dbw->delete(
'change_tag_def',
'*' );
529 MediaWikiServices::getInstance()->resetServiceForTesting(
'NameTableStoreFactory' );
540 'ctd_name' =>
'tag1',
545 $res =
$dbr->select(
'change_tag_def', [
'ctd_name',
'ctd_id',
'ctd_count' ],
'' );
546 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
554 $res2 =
$dbr->select(
'change_tag', [
'ct_tag_id',
'ct_rc_id' ],
'' );
555 $this->assertEquals( $expected2, iterator_to_array( $res2,
false ) );
560 $dbw->delete(
'change_tag',
'*' );
561 $dbw->delete(
'change_tag_def',
'*' );
562 MediaWikiServices::getInstance()->resetServiceForTesting(
'NameTableStoreFactory' );
575 $dbw->delete(
'change_tag',
'*' );
576 $dbw->delete(
'change_tag_def',
'*' );
587 'ctd_name' =>
'tag1',
588 'ctd_user_defined' => 0
591 'ctd_name' =>
'tag2',
592 'ctd_user_defined' => 1
597 [
'ctd_name',
'ctd_user_defined' ],
600 [
'ORDER BY' =>
'ctd_name' ]
602 $this->assertEquals( $expected, iterator_to_array(
$res,
false ) );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
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 noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false
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