MediaWiki REL1_32
ApiComparePagesTest.php
Go to the documentation of this file.
1<?php
2
10
11 protected static $repl = [];
12
13 protected function setUp() {
14 parent::setUp();
15
16 // Set $wgExternalDiffEngine to something bogus to try to force use of
17 // the PHP engine rather than wikidiff2.
18 $this->setMwGlobals( [
19 'wgExternalDiffEngine' => '/dev/null',
20 ] );
21 }
22
23 protected function addPage( $page, $text, $model = CONTENT_MODEL_WIKITEXT ) {
24 $title = Title::newFromText( 'ApiComparePagesTest ' . $page );
25 $content = ContentHandler::makeContent( $text, $title, $model );
26
27 $page = WikiPage::factory( $title );
28 $user = static::getTestSysop()->getUser();
29 $status = $page->doEditContent(
30 $content, 'Test for ApiComparePagesTest: ' . $text, 0, false, $user
31 );
32 if ( !$status->isOK() ) {
33 $this->fail( "Failed to create $title: " . $status->getWikiText( false, false, 'en' ) );
34 }
35 return $status->value['revision']->getId();
36 }
37
38 public function addDBDataOnce() {
39 $user = static::getTestSysop()->getUser();
40 self::$repl['creator'] = $user->getName();
41 self::$repl['creatorid'] = $user->getId();
42
43 self::$repl['revA1'] = $this->addPage( 'A', 'A 1' );
44 self::$repl['revA2'] = $this->addPage( 'A', 'A 2' );
45 self::$repl['revA3'] = $this->addPage( 'A', 'A 3' );
46 self::$repl['revA4'] = $this->addPage( 'A', 'A 4' );
47 self::$repl['pageA'] = Title::newFromText( 'ApiComparePagesTest A' )->getArticleId();
48
49 self::$repl['revB1'] = $this->addPage( 'B', 'B 1' );
50 self::$repl['revB2'] = $this->addPage( 'B', 'B 2' );
51 self::$repl['revB3'] = $this->addPage( 'B', 'B 3' );
52 self::$repl['revB4'] = $this->addPage( 'B', 'B 4' );
53 self::$repl['pageB'] = Title::newFromText( 'ApiComparePagesTest B' )->getArticleId();
54
55 self::$repl['revC1'] = $this->addPage( 'C', 'C 1' );
56 self::$repl['revC2'] = $this->addPage( 'C', 'C 2' );
57 self::$repl['revC3'] = $this->addPage( 'C', 'C 3' );
58 self::$repl['pageC'] = Title::newFromText( 'ApiComparePagesTest C' )->getArticleId();
59
60 $id = $this->addPage( 'D', 'D 1' );
61 self::$repl['pageD'] = Title::newFromText( 'ApiComparePagesTest D' )->getArticleId();
62 wfGetDB( DB_MASTER )->delete( 'revision', [ 'rev_id' => $id ] );
63
64 self::$repl['revE1'] = $this->addPage( 'E', 'E 1' );
65 self::$repl['revE2'] = $this->addPage( 'E', 'E 2' );
66 self::$repl['revE3'] = $this->addPage( 'E', 'E 3' );
67 self::$repl['revE4'] = $this->addPage( 'E', 'E 4' );
68 self::$repl['pageE'] = Title::newFromText( 'ApiComparePagesTest E' )->getArticleId();
69 wfGetDB( DB_MASTER )->update(
70 'page', [ 'page_latest' => 0 ], [ 'page_id' => self::$repl['pageE'] ]
71 );
72
73 self::$repl['revF1'] = $this->addPage( 'F', "== Section 1 ==\nF 1.1\n\n== Section 2 ==\nF 1.2" );
74 self::$repl['pageF'] = Title::newFromText( 'ApiComparePagesTest F' )->getArticleId();
75
76 self::$repl['revG1'] = $this->addPage( 'G', "== Section 1 ==\nG 1.1", CONTENT_MODEL_TEXT );
77 self::$repl['pageG'] = Title::newFromText( 'ApiComparePagesTest G' )->getArticleId();
78
79 WikiPage::factory( Title::newFromText( 'ApiComparePagesTest C' ) )
80 ->doDeleteArticleReal( 'Test for ApiComparePagesTest' );
81
83 'revision',
84 RequestContext::getMain(),
85 Title::newFromText( 'ApiComparePagesTest B' ),
86 [ self::$repl['revB2'] ]
87 )->setVisibility( [
88 'value' => [
92 ],
93 'comment' => 'Test for ApiComparePages',
94 ] );
95
97 'revision',
98 RequestContext::getMain(),
99 Title::newFromText( 'ApiComparePagesTest B' ),
100 [ self::$repl['revB3'] ]
101 )->setVisibility( [
102 'value' => [
106 ],
107 'comment' => 'Test for ApiComparePages',
108 ] );
109
110 Title::clearCaches(); // Otherwise it has the wrong latest revision for some reason
111 }
112
113 protected function doReplacements( &$value ) {
114 if ( is_string( $value ) ) {
115 if ( preg_match( '/^{{REPL:(.+?)}}$/', $value, $m ) ) {
116 $value = self::$repl[$m[1]];
117 } else {
118 $value = preg_replace_callback( '/{{REPL:(.+?)}}/', function ( $m ) {
119 return self::$repl[$m[1]] ?? $m[0];
120 }, $value );
121 }
122 } elseif ( is_array( $value ) || is_object( $value ) ) {
123 foreach ( $value as &$v ) {
124 $this->doReplacements( $v );
125 }
126 unset( $v );
127 }
128 }
129
133 public function testDiff( $params, $expect, $exceptionCode = false, $sysop = false ) {
134 $this->doReplacements( $params );
135
136 $params += [
137 'action' => 'compare',
138 'errorformat' => 'none',
139 ];
140
141 $user = $sysop
142 ? static::getTestSysop()->getUser()
143 : static::getTestUser()->getUser();
144 if ( $exceptionCode ) {
145 try {
146 $this->doApiRequest( $params, null, false, $user );
147 $this->fail( 'Expected exception not thrown' );
148 } catch ( ApiUsageException $ex ) {
149 $this->assertTrue( $this->apiExceptionHasCode( $ex, $exceptionCode ),
150 "Exception with code $exceptionCode" );
151 }
152 } else {
153 $apiResult = $this->doApiRequest( $params, null, false, $user );
154 $apiResult = $apiResult[0];
155 $this->doReplacements( $expect );
156 $this->assertEquals( $expect, $apiResult );
157 }
158 }
159
160 private static function makeDeprecationWarnings( ...$params ) {
161 $warn = [];
162 foreach ( $params as $p ) {
163 $warn[] = [
164 'code' => 'deprecation',
165 'data' => [ 'feature' => "action=compare&{$p}" ],
166 'module' => 'compare',
167 ];
168 if ( count( $warn ) === 1 ) {
169 $warn[] = [
170 'code' => 'deprecation-help',
171 'module' => 'main',
172 ];
173 }
174 }
175
176 return $warn;
177 }
178
179 public static function provideDiff() {
180 // phpcs:disable Generic.Files.LineLength.TooLong
181 return [
182 'Basic diff, titles' => [
183 [
184 'fromtitle' => 'ApiComparePagesTest A',
185 'totitle' => 'ApiComparePagesTest B',
186 ],
187 [
188 'compare' => [
189 'fromid' => '{{REPL:pageA}}',
190 'fromrevid' => '{{REPL:revA4}}',
191 'fromns' => 0,
192 'fromtitle' => 'ApiComparePagesTest A',
193 'toid' => '{{REPL:pageB}}',
194 'torevid' => '{{REPL:revB4}}',
195 'tons' => 0,
196 'totitle' => 'ApiComparePagesTest B',
197 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
198 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
199 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n",
200 ]
201 ],
202 ],
203 'Basic diff, page IDs' => [
204 [
205 'fromid' => '{{REPL:pageA}}',
206 'toid' => '{{REPL:pageB}}',
207 ],
208 [
209 'compare' => [
210 'fromid' => '{{REPL:pageA}}',
211 'fromrevid' => '{{REPL:revA4}}',
212 'fromns' => 0,
213 'fromtitle' => 'ApiComparePagesTest A',
214 'toid' => '{{REPL:pageB}}',
215 'torevid' => '{{REPL:revB4}}',
216 'tons' => 0,
217 'totitle' => 'ApiComparePagesTest B',
218 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
219 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
220 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>4</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>4</div></td></tr>' . "\n",
221 ]
222 ],
223 ],
224 'Basic diff, revision IDs' => [
225 [
226 'fromrev' => '{{REPL:revA2}}',
227 'torev' => '{{REPL:revA3}}',
228 ],
229 [
230 'compare' => [
231 'fromid' => '{{REPL:pageA}}',
232 'fromrevid' => '{{REPL:revA2}}',
233 'fromns' => 0,
234 'fromtitle' => 'ApiComparePagesTest A',
235 'toid' => '{{REPL:pageA}}',
236 'torevid' => '{{REPL:revA3}}',
237 'tons' => 0,
238 'totitle' => 'ApiComparePagesTest A',
239 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
240 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
241 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>A <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
242 ]
243 ],
244 ],
245 'Basic diff, deleted revision ID as sysop' => [
246 [
247 'fromrev' => '{{REPL:revA2}}',
248 'torev' => '{{REPL:revC2}}',
249 ],
250 [
251 'compare' => [
252 'fromid' => '{{REPL:pageA}}',
253 'fromrevid' => '{{REPL:revA2}}',
254 'fromns' => 0,
255 'fromtitle' => 'ApiComparePagesTest A',
256 'toid' => 0,
257 'torevid' => '{{REPL:revC2}}',
258 'tons' => 0,
259 'totitle' => 'ApiComparePagesTest C',
260 'toarchive' => true,
261 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
262 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
263 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">C </ins>2</div></td></tr>' . "\n",
264 ]
265 ],
266 false, true
267 ],
268 'Basic diff, revdel as sysop' => [
269 [
270 'fromrev' => '{{REPL:revA2}}',
271 'torev' => '{{REPL:revB2}}',
272 ],
273 [
274 'compare' => [
275 'fromid' => '{{REPL:pageA}}',
276 'fromrevid' => '{{REPL:revA2}}',
277 'fromns' => 0,
278 'fromtitle' => 'ApiComparePagesTest A',
279 'toid' => '{{REPL:pageB}}',
280 'torevid' => '{{REPL:revB2}}',
281 'tons' => 0,
282 'totitle' => 'ApiComparePagesTest B',
283 'totexthidden' => true,
284 'touserhidden' => true,
285 'tocommenthidden' => true,
286 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
287 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
288 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">A </del>2</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">B </ins>2</div></td></tr>' . "\n",
289 ]
290 ],
291 false, true
292 ],
293 'Basic diff, text' => [
294 [
295 'fromslots' => 'main',
296 'fromtext-main' => 'From text',
297 'fromcontentmodel-main' => 'wikitext',
298 'toslots' => 'main',
299 'totext-main' => 'To text {{subst:PAGENAME}}',
300 'tocontentmodel-main' => 'wikitext',
301 ],
302 [
303 'compare' => [
304 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
305 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
306 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
307 ]
308 ],
309 ],
310 'Basic diff, text 2' => [
311 [
312 'fromslots' => 'main',
313 'fromtext-main' => 'From text',
314 'toslots' => 'main',
315 'totext-main' => 'To text {{subst:PAGENAME}}',
316 'tocontentmodel-main' => 'wikitext',
317 ],
318 [
319 'compare' => [
320 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
321 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
322 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
323 ]
324 ],
325 ],
326 'Basic diff, guessed model' => [
327 [
328 'fromslots' => 'main',
329 'fromtext-main' => 'From text',
330 'toslots' => 'main',
331 'totext-main' => 'To text',
332 ],
333 [
334 'warnings' => [ [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ] ],
335 'compare' => [
336 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
337 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
338 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n",
339 ]
340 ],
341 ],
342 'Basic diff, text with title and PST' => [
343 [
344 'fromslots' => 'main',
345 'fromtext-main' => 'From text',
346 'totitle' => 'Test',
347 'toslots' => 'main',
348 'totext-main' => 'To text {{subst:PAGENAME}}',
349 'topst' => true,
350 ],
351 [
352 'compare' => [
353 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
354 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
355 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n",
356 ]
357 ],
358 ],
359 'Basic diff, text with page ID and PST' => [
360 [
361 'fromslots' => 'main',
362 'fromtext-main' => 'From text',
363 'toid' => '{{REPL:pageB}}',
364 'toslots' => 'main',
365 'totext-main' => 'To text {{subst:PAGENAME}}',
366 'topst' => true,
367 ],
368 [
369 'compare' => [
370 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
371 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
372 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
373 ]
374 ],
375 ],
376 'Basic diff, text with revision and PST' => [
377 [
378 'fromslots' => 'main',
379 'fromtext-main' => 'From text',
380 'torev' => '{{REPL:revB2}}',
381 'toslots' => 'main',
382 'totext-main' => 'To text {{subst:PAGENAME}}',
383 'topst' => true,
384 ],
385 [
386 'compare' => [
387 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
388 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
389 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
390 ]
391 ],
392 ],
393 'Basic diff, text with deleted revision and PST' => [
394 [
395 'fromslots' => 'main',
396 'fromtext-main' => 'From text',
397 'torev' => '{{REPL:revC2}}',
398 'toslots' => 'main',
399 'totext-main' => 'To text {{subst:PAGENAME}}',
400 'topst' => true,
401 ],
402 [
403 'compare' => [
404 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
405 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
406 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n",
407 ]
408 ],
409 false, true
410 ],
411 'Basic diff, test with sections' => [
412 [
413 'fromtitle' => 'ApiComparePagesTest F',
414 'fromslots' => 'main',
415 'fromtext-main' => "== Section 2 ==\nFrom text?",
416 'fromsection-main' => 2,
417 'totitle' => 'ApiComparePagesTest F',
418 'toslots' => 'main',
419 'totext-main' => "== Section 1 ==\nTo text?",
420 'tosection-main' => 1,
421 ],
422 [
423 'compare' => [
424 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
425 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
426 . '<tr><td class=\'diff-marker\'> </td><td class=\'diff-context\'><div>== Section 1 ==</div></td><td class=\'diff-marker\'> </td><td class=\'diff-context\'><div>== Section 1 ==</div></td></tr>' . "\n"
427 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n"
428 . '<tr><td class=\'diff-marker\'> </td><td class=\'diff-context\'></td><td class=\'diff-marker\'> </td><td class=\'diff-context\'></td></tr>' . "\n"
429 . '<tr><td class=\'diff-marker\'> </td><td class=\'diff-context\'><div>== Section 2 ==</div></td><td class=\'diff-marker\'> </td><td class=\'diff-context\'><div>== Section 2 ==</div></td></tr>' . "\n"
430 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From text?</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">F 1.2</ins></div></td></tr>' . "\n",
431 ]
432 ],
433 ],
434 'Diff with all props' => [
435 [
436 'fromrev' => '{{REPL:revB1}}',
437 'torev' => '{{REPL:revB3}}',
438 'totitle' => 'ApiComparePagesTest B',
439 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
440 ],
441 [
442 'compare' => [
443 'fromid' => '{{REPL:pageB}}',
444 'fromrevid' => '{{REPL:revB1}}',
445 'fromns' => 0,
446 'fromtitle' => 'ApiComparePagesTest B',
447 'fromsize' => 3,
448 'fromuser' => '{{REPL:creator}}',
449 'fromuserid' => '{{REPL:creatorid}}',
450 'fromcomment' => 'Test for ApiComparePagesTest: B 1',
451 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 1',
452 'toid' => '{{REPL:pageB}}',
453 'torevid' => '{{REPL:revB3}}',
454 'tons' => 0,
455 'totitle' => 'ApiComparePagesTest B',
456 'tosize' => 3,
457 'touserhidden' => true,
458 'tocommenthidden' => true,
459 'tosuppressed' => true,
460 'next' => '{{REPL:revB4}}',
461 'diffsize' => 391,
462 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
463 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
464 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
465 ]
466 ],
467 ],
468 'Diff with all props as sysop' => [
469 [
470 'fromrev' => '{{REPL:revB2}}',
471 'torev' => '{{REPL:revB3}}',
472 'totitle' => 'ApiComparePagesTest B',
473 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
474 ],
475 [
476 'compare' => [
477 'fromid' => '{{REPL:pageB}}',
478 'fromrevid' => '{{REPL:revB2}}',
479 'fromns' => 0,
480 'fromtitle' => 'ApiComparePagesTest B',
481 'fromsize' => 3,
482 'fromtexthidden' => true,
483 'fromuserhidden' => true,
484 'fromuser' => '{{REPL:creator}}',
485 'fromuserid' => '{{REPL:creatorid}}',
486 'fromcommenthidden' => true,
487 'fromcomment' => 'Test for ApiComparePagesTest: B 2',
488 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 2',
489 'toid' => '{{REPL:pageB}}',
490 'torevid' => '{{REPL:revB3}}',
491 'tons' => 0,
492 'totitle' => 'ApiComparePagesTest B',
493 'tosize' => 3,
494 'touserhidden' => true,
495 'tocommenthidden' => true,
496 'tosuppressed' => true,
497 'prev' => '{{REPL:revB1}}',
498 'next' => '{{REPL:revB4}}',
499 'diffsize' => 391,
500 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
501 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
502 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
503 ]
504 ],
505 false, true
506 ],
507 'Relative diff, cur' => [
508 [
509 'fromrev' => '{{REPL:revA2}}',
510 'torelative' => 'cur',
511 'prop' => 'ids',
512 ],
513 [
514 'compare' => [
515 'fromid' => '{{REPL:pageA}}',
516 'fromrevid' => '{{REPL:revA2}}',
517 'toid' => '{{REPL:pageA}}',
518 'torevid' => '{{REPL:revA4}}',
519 ]
520 ],
521 ],
522 'Relative diff, next' => [
523 [
524 'fromrev' => '{{REPL:revE2}}',
525 'torelative' => 'next',
526 'prop' => 'ids|rel',
527 ],
528 [
529 'compare' => [
530 'fromid' => '{{REPL:pageE}}',
531 'fromrevid' => '{{REPL:revE2}}',
532 'toid' => '{{REPL:pageE}}',
533 'torevid' => '{{REPL:revE3}}',
534 'prev' => '{{REPL:revE1}}',
535 'next' => '{{REPL:revE4}}',
536 ]
537 ],
538 ],
539 'Relative diff, prev' => [
540 [
541 'fromrev' => '{{REPL:revE3}}',
542 'torelative' => 'prev',
543 'prop' => 'ids|rel',
544 ],
545 [
546 'compare' => [
547 'fromid' => '{{REPL:pageE}}',
548 'fromrevid' => '{{REPL:revE2}}',
549 'toid' => '{{REPL:pageE}}',
550 'torevid' => '{{REPL:revE3}}',
551 'prev' => '{{REPL:revE1}}',
552 'next' => '{{REPL:revE4}}',
553 ]
554 ],
555 ],
556 'Relative diff, no prev' => [
557 [
558 'fromrev' => '{{REPL:revA1}}',
559 'torelative' => 'prev',
560 'prop' => 'ids|rel|diff|title|user|comment',
561 ],
562 [
563 'warnings' => [
564 [
565 'code' => 'compare-no-prev',
566 'module' => 'compare',
567 ],
568 ],
569 'compare' => [
570 'toid' => '{{REPL:pageA}}',
571 'torevid' => '{{REPL:revA1}}',
572 'tons' => 0,
573 'totitle' => 'ApiComparePagesTest A',
574 'touser' => '{{REPL:creator}}',
575 'touserid' => '{{REPL:creatorid}}',
576 'tocomment' => 'Test for ApiComparePagesTest: A 1',
577 'toparsedcomment' => 'Test for ApiComparePagesTest: A 1',
578 'next' => '{{REPL:revA2}}',
579 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
580 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
581 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div> </div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">A 1</ins></div></td></tr>' . "\n",
582 ],
583 ],
584 ],
585 'Relative diff, no next' => [
586 [
587 'fromrev' => '{{REPL:revA4}}',
588 'torelative' => 'next',
589 'prop' => 'ids|rel|diff|title|user|comment',
590 ],
591 [
592 'warnings' => [
593 [
594 'code' => 'compare-no-next',
595 'module' => 'compare',
596 ],
597 ],
598 'compare' => [
599 'fromid' => '{{REPL:pageA}}',
600 'fromrevid' => '{{REPL:revA4}}',
601 'fromns' => 0,
602 'fromtitle' => 'ApiComparePagesTest A',
603 'fromuser' => '{{REPL:creator}}',
604 'fromuserid' => '{{REPL:creatorid}}',
605 'fromcomment' => 'Test for ApiComparePagesTest: A 4',
606 'fromparsedcomment' => 'Test for ApiComparePagesTest: A 4',
607 'prev' => '{{REPL:revA3}}',
608 'body' => '',
609 ],
610 ],
611 ],
612 'Diff for specific slots' => [
613 // @todo Use a page with multiple slots here
614 [
615 'fromrev' => '{{REPL:revA1}}',
616 'torev' => '{{REPL:revA3}}',
617 'prop' => 'diff',
618 'slots' => 'main',
619 ],
620 [
621 'compare' => [
622 'bodies' => [
623 'main' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
624 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
625 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>A <del class="diffchange diffchange-inline">1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>A <ins class="diffchange diffchange-inline">3</ins></div></td></tr>' . "\n",
626 ],
627 ],
628 ],
629 ],
630 // @todo Add a test for diffing with a deleted slot. Deleting 'main' doesn't work.
631
632 'Basic diff, deprecated text' => [
633 [
634 'fromtext' => 'From text',
635 'fromcontentmodel' => 'wikitext',
636 'totext' => 'To text {{subst:PAGENAME}}',
637 'tocontentmodel' => 'wikitext',
638 ],
639 [
640 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'fromcontentmodel', 'totext', 'tocontentmodel' ),
641 'compare' => [
642 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
643 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
644 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
645 ]
646 ],
647 ],
648 'Basic diff, deprecated text 2' => [
649 [
650 'fromtext' => 'From text',
651 'totext' => 'To text {{subst:PAGENAME}}',
652 'tocontentmodel' => 'wikitext',
653 ],
654 [
655 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext', 'tocontentmodel' ),
656 'compare' => [
657 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
658 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
659 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">{{subst:PAGENAME}}</ins></div></td></tr>' . "\n",
660 ]
661 ],
662 ],
663 'Basic diff, deprecated text, guessed model' => [
664 [
665 'fromtext' => 'From text',
666 'totext' => 'To text',
667 ],
668 [
669 'warnings' => array_merge( self::makeDeprecationWarnings( 'fromtext', 'totext' ), [
670 [ 'code' => 'compare-nocontentmodel', 'module' => 'compare' ],
671 ] ),
672 'compare' => [
673 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
674 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
675 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text</div></td></tr>' . "\n",
676 ]
677 ],
678 ],
679 'Basic diff, deprecated text with title and PST' => [
680 [
681 'fromtext' => 'From text',
682 'totitle' => 'Test',
683 'totext' => 'To text {{subst:PAGENAME}}',
684 'topst' => true,
685 ],
686 [
687 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ),
688 'compare' => [
689 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
690 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
691 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">Test</ins></div></td></tr>' . "\n",
692 ]
693 ],
694 ],
695 'Basic diff, deprecated text with page ID and PST' => [
696 [
697 'fromtext' => 'From text',
698 'toid' => '{{REPL:pageB}}',
699 'totext' => 'To text {{subst:PAGENAME}}',
700 'topst' => true,
701 ],
702 [
703 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ),
704 'compare' => [
705 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
706 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
707 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
708 ]
709 ],
710 ],
711 'Basic diff, deprecated text with revision and PST' => [
712 [
713 'fromtext' => 'From text',
714 'torev' => '{{REPL:revB2}}',
715 'totext' => 'To text {{subst:PAGENAME}}',
716 'topst' => true,
717 ],
718 [
719 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ),
720 'compare' => [
721 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
722 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
723 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
724 ]
725 ],
726 ],
727 'Basic diff, deprecated text with deleted revision and PST' => [
728 [
729 'fromtext' => 'From text',
730 'torev' => '{{REPL:revC2}}',
731 'totext' => 'To text {{subst:PAGENAME}}',
732 'topst' => true,
733 ],
734 [
735 'warnings' => self::makeDeprecationWarnings( 'fromtext', 'totext' ),
736 'compare' => [
737 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
738 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
739 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">From </del>text</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To </ins>text <ins class="diffchange diffchange-inline">ApiComparePagesTest C</ins></div></td></tr>' . "\n",
740 ]
741 ],
742 false, true
743 ],
744 'Basic diff, test with deprecated sections' => [
745 [
746 'fromtitle' => 'ApiComparePagesTest F',
747 'fromsection' => 1,
748 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
749 'tosection' => 2,
750 ],
751 [
752 'warnings' => self::makeDeprecationWarnings( 'fromsection', 'totext', 'tosection' ),
753 'compare' => [
754 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
755 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
756 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>== Section <del class="diffchange diffchange-inline">1 </del>==</div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>== Section <ins class="diffchange diffchange-inline">2 </ins>==</div></td></tr>' . "\n"
757 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div><del class="diffchange diffchange-inline">F 1.1</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div><ins class="diffchange diffchange-inline">To text?</ins></div></td></tr>' . "\n",
758 'fromid' => '{{REPL:pageF}}',
759 'fromrevid' => '{{REPL:revF1}}',
760 'fromns' => '0',
761 'fromtitle' => 'ApiComparePagesTest F',
762 ]
763 ],
764 ],
765 'Basic diff, test with deprecated sections and revdel, non-sysop' => [
766 [
767 'fromrev' => '{{REPL:revB2}}',
768 'fromsection' => 0,
769 'torev' => '{{REPL:revB4}}',
770 'tosection' => 0,
771 ],
772 [],
773 'missingcontent'
774 ],
775 'Basic diff, test with deprecated sections and revdel, sysop' => [
776 [
777 'fromrev' => '{{REPL:revB2}}',
778 'fromsection' => 0,
779 'torev' => '{{REPL:revB4}}',
780 'tosection' => 0,
781 ],
782 [
783 'warnings' => self::makeDeprecationWarnings( 'fromsection', 'tosection' ),
784 'compare' => [
785 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
786 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
787 . '<tr><td class=\'diff-marker\'>−</td><td class=\'diff-deletedline\'><div>B <del class="diffchange diffchange-inline">2</del></div></td><td class=\'diff-marker\'>+</td><td class=\'diff-addedline\'><div>B <ins class="diffchange diffchange-inline">4</ins></div></td></tr>' . "\n",
788 'fromid' => '{{REPL:pageB}}',
789 'fromrevid' => '{{REPL:revB2}}',
790 'fromns' => 0,
791 'fromtitle' => 'ApiComparePagesTest B',
792 'fromtexthidden' => true,
793 'fromuserhidden' => true,
794 'fromcommenthidden' => true,
795 'toid' => '{{REPL:pageB}}',
796 'torevid' => '{{REPL:revB4}}',
797 'tons' => 0,
798 'totitle' => 'ApiComparePagesTest B',
799 ]
800 ],
801 false, true,
802 ],
803
804 'Error, missing title' => [
805 [
806 'fromtitle' => 'ApiComparePagesTest X',
807 'totitle' => 'ApiComparePagesTest B',
808 ],
809 [],
810 'missingtitle',
811 ],
812 'Error, invalid title' => [
813 [
814 'fromtitle' => '<bad>',
815 'totitle' => 'ApiComparePagesTest B',
816 ],
817 [],
818 'invalidtitle',
819 ],
820 'Error, missing page ID' => [
821 [
822 'fromid' => 8817900,
823 'totitle' => 'ApiComparePagesTest B',
824 ],
825 [],
826 'nosuchpageid',
827 ],
828 'Error, page with missing revision' => [
829 [
830 'fromtitle' => 'ApiComparePagesTest D',
831 'totitle' => 'ApiComparePagesTest B',
832 ],
833 [],
834 'nosuchrevid',
835 ],
836 'Error, page with no revision' => [
837 [
838 'fromtitle' => 'ApiComparePagesTest E',
839 'totitle' => 'ApiComparePagesTest B',
840 ],
841 [],
842 'nosuchrevid',
843 ],
844 'Error, bad rev ID' => [
845 [
846 'fromrev' => 8817900,
847 'totitle' => 'ApiComparePagesTest B',
848 ],
849 [],
850 'nosuchrevid',
851 ],
852 'Error, deleted revision ID, non-sysop' => [
853 [
854 'fromrev' => '{{REPL:revA2}}',
855 'torev' => '{{REPL:revC2}}',
856 ],
857 [],
858 'nosuchrevid',
859 ],
860 'Error, revision-deleted content' => [
861 [
862 'fromrev' => '{{REPL:revA2}}',
863 'torev' => '{{REPL:revB2}}',
864 ],
865 [],
866 'missingcontent',
867 ],
868 'Error, text with no title and PST' => [
869 [
870 'fromtext' => 'From text',
871 'totext' => 'To text {{subst:PAGENAME}}',
872 'topst' => true,
873 ],
874 [],
875 'compare-no-title',
876 ],
877 'Error, test with invalid from section ID' => [
878 [
879 'fromtitle' => 'ApiComparePagesTest F',
880 'fromsection' => 5,
881 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
882 'tosection' => 2,
883 ],
884 [],
885 'nosuchfromsection',
886 ],
887 'Error, test with invalid to section ID' => [
888 [
889 'fromtitle' => 'ApiComparePagesTest F',
890 'fromsection' => 1,
891 'totext' => "== Section 1 ==\nTo text\n\n== Section 2 ==\nTo text?",
892 'tosection' => 5,
893 ],
894 [],
895 'nosuchtosection',
896 ],
897 'Error, Relative diff, no from revision' => [
898 [
899 'fromtext' => 'Foo',
900 'torelative' => 'cur',
901 'prop' => 'ids',
902 ],
903 [],
904 'compare-relative-to-nothing'
905 ],
906 'Error, Relative diff, cur with no current revision' => [
907 [
908 'fromrev' => '{{REPL:revE2}}',
909 'torelative' => 'cur',
910 'prop' => 'ids',
911 ],
912 [],
913 'nosuchrevid'
914 ],
915 'Error, Relative diff, next revdeleted' => [
916 [
917 'fromrev' => '{{REPL:revB1}}',
918 'torelative' => 'next',
919 'prop' => 'ids',
920 ],
921 [],
922 'missingcontent'
923 ],
924 'Error, Relative diff, prev revdeleted' => [
925 [
926 'fromrev' => '{{REPL:revB3}}',
927 'torelative' => 'prev',
928 'prop' => 'ids',
929 ],
930 [],
931 'missingcontent'
932 ],
933 'Error, section diff with no revision' => [
934 [
935 'fromtitle' => 'ApiComparePagesTest F',
936 'toslots' => 'main',
937 'totext-main' => "== Section 1 ==\nTo text?",
938 'tosection-main' => 1,
939 ],
940 [],
941 'compare-notorevision',
942 ],
943 'Error, section diff with revdeleted revision' => [
944 [
945 'fromtitle' => 'ApiComparePagesTest F',
946 'torev' => '{{REPL:revB2}}',
947 'toslots' => 'main',
948 'totext-main' => "== Section 1 ==\nTo text?",
949 'tosection-main' => 1,
950 ],
951 [],
952 'missingcontent',
953 ],
954 'Error, section diff with a content model not supporting sections' => [
955 [
956 'fromtitle' => 'ApiComparePagesTest G',
957 'torev' => '{{REPL:revG1}}',
958 'toslots' => 'main',
959 'totext-main' => "== Section 1 ==\nTo text?",
960 'tosection-main' => 1,
961 ],
962 [],
963 'sectionsnotsupported',
964 ],
965 'Error, section diff with bad content model' => [
966 [
967 'fromtitle' => 'ApiComparePagesTest F',
968 'torev' => '{{REPL:revF1}}',
969 'toslots' => 'main',
970 'totext-main' => "== Section 1 ==\nTo text?",
971 'tosection-main' => 1,
972 'tocontentmodel-main' => CONTENT_MODEL_TEXT,
973 ],
974 [],
975 'sectionreplacefailed',
976 ],
977 'Error, deleting the main slot' => [
978 [
979 'fromtitle' => 'ApiComparePagesTest A',
980 'totitle' => 'ApiComparePagesTest A',
981 'toslots' => 'main',
982 ],
983 [],
984 'compare-maintextrequired',
985 ],
986 // @todo Add a test for using 'tosection-foo' without 'totext-foo' (can't do it with main)
987 ];
988 // phpcs:enable
989 }
990}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
API Database medium ApiComparePages.
testDiff( $params, $expect, $exceptionCode=false, $sysop=false)
provideDiff
addPage( $page, $text, $model=CONTENT_MODEL_WIKITEXT)
static makeDeprecationWarnings(... $params)
static apiExceptionHasCode(ApiUsageException $ex, $code)
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
Exception used to abort API execution with an error.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static createList( $typeName, IContextSource $context, Title $title, array $ids)
Instantiate the appropriate list class for a given list of IDs.
const DELETED_USER
Definition Revision.php:49
const DELETED_TEXT
Definition Revision.php:47
const DELETED_RESTRICTED
Definition Revision.php:50
const DELETED_COMMENT
Definition Revision.php:48
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
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:235
const CONTENT_MODEL_TEXT
Definition Defines.php:238
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition hooks.txt:1305
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
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
Definition hooks.txt:2055
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
Definition hooks.txt:247
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
Definition injection.txt:37
$content
const DB_MASTER
Definition defines.php:26
$params