MediaWiki REL1_30
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 WikiPage::factory( Title::newFromText( 'ApiComparePagesTest C' ) )
74 ->doDeleteArticleReal( 'Test for ApiComparePagesTest' );
75
77 'revision',
79 Title::newFromText( 'ApiComparePagesTest B' ),
80 [ self::$repl['revB2'] ]
81 )->setVisibility( [
82 'value' => [
86 ],
87 'comment' => 'Test for ApiComparePages',
88 ] );
89
91 'revision',
93 Title::newFromText( 'ApiComparePagesTest B' ),
94 [ self::$repl['revB3'] ]
95 )->setVisibility( [
96 'value' => [
100 ],
101 'comment' => 'Test for ApiComparePages',
102 ] );
103
104 Title::clearCaches(); // Otherwise it has the wrong latest revision for some reason
105 }
106
107 protected function doReplacements( &$value ) {
108 if ( is_string( $value ) ) {
109 if ( preg_match( '/^{{REPL:(.+?)}}$/', $value, $m ) ) {
110 $value = self::$repl[$m[1]];
111 } else {
112 $value = preg_replace_callback( '/{{REPL:(.+?)}}/', function ( $m ) {
113 return isset( self::$repl[$m[1]] ) ? self::$repl[$m[1]] : $m[0];
114 }, $value );
115 }
116 } elseif ( is_array( $value ) || is_object( $value ) ) {
117 foreach ( $value as &$v ) {
118 $this->doReplacements( $v );
119 }
120 unset( $v );
121 }
122 }
123
127 public function testDiff( $params, $expect, $exceptionCode = false, $sysop = false ) {
128 $this->doReplacements( $params );
129
130 $params += [
131 'action' => 'compare',
132 ];
133
134 $user = $sysop
135 ? static::getTestSysop()->getUser()
136 : static::getTestUser()->getUser();
137 if ( $exceptionCode ) {
138 try {
139 $this->doApiRequest( $params, null, false, $user );
140 $this->fail( 'Expected exception not thrown' );
141 } catch ( ApiUsageException $ex ) {
142 $this->assertTrue( $this->apiExceptionHasCode( $ex, $exceptionCode ),
143 "Exception with code $exceptionCode" );
144 }
145 } else {
146 $apiResult = $this->doApiRequest( $params, null, false, $user );
147 $apiResult = $apiResult[0];
148 $this->doReplacements( $expect );
149 $this->assertEquals( $expect, $apiResult );
150 }
151 }
152
153 public static function provideDiff() {
154 return [
155 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
156 'Basic diff, titles' => [
157 [
158 'fromtitle' => 'ApiComparePagesTest A',
159 'totitle' => 'ApiComparePagesTest B',
160 ],
161 [
162 'compare' => [
163 'fromid' => '{{REPL:pageA}}',
164 'fromrevid' => '{{REPL:revA4}}',
165 'fromns' => 0,
166 'fromtitle' => 'ApiComparePagesTest A',
167 'toid' => '{{REPL:pageB}}',
168 'torevid' => '{{REPL:revB4}}',
169 'tons' => 0,
170 'totitle' => 'ApiComparePagesTest B',
171 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
172 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
173 . '<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",
174 ]
175 ],
176 ],
177 'Basic diff, page IDs' => [
178 [
179 'fromid' => '{{REPL:pageA}}',
180 'toid' => '{{REPL:pageB}}',
181 ],
182 [
183 'compare' => [
184 'fromid' => '{{REPL:pageA}}',
185 'fromrevid' => '{{REPL:revA4}}',
186 'fromns' => 0,
187 'fromtitle' => 'ApiComparePagesTest A',
188 'toid' => '{{REPL:pageB}}',
189 'torevid' => '{{REPL:revB4}}',
190 'tons' => 0,
191 'totitle' => 'ApiComparePagesTest B',
192 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
193 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
194 . '<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",
195 ]
196 ],
197 ],
198 'Basic diff, revision IDs' => [
199 [
200 'fromrev' => '{{REPL:revA2}}',
201 'torev' => '{{REPL:revA3}}',
202 ],
203 [
204 'compare' => [
205 'fromid' => '{{REPL:pageA}}',
206 'fromrevid' => '{{REPL:revA2}}',
207 'fromns' => 0,
208 'fromtitle' => 'ApiComparePagesTest A',
209 'toid' => '{{REPL:pageA}}',
210 'torevid' => '{{REPL:revA3}}',
211 'tons' => 0,
212 'totitle' => 'ApiComparePagesTest A',
213 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
214 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
215 . '<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",
216 ]
217 ],
218 ],
219 'Basic diff, deleted revision ID as sysop' => [
220 [
221 'fromrev' => '{{REPL:revA2}}',
222 'torev' => '{{REPL:revC2}}',
223 ],
224 [
225 'compare' => [
226 'fromid' => '{{REPL:pageA}}',
227 'fromrevid' => '{{REPL:revA2}}',
228 'fromns' => 0,
229 'fromtitle' => 'ApiComparePagesTest A',
230 'toid' => 0,
231 'torevid' => '{{REPL:revC2}}',
232 'tons' => 0,
233 'totitle' => 'ApiComparePagesTest C',
234 'toarchive' => true,
235 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
236 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
237 . '<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",
238 ]
239 ],
240 false, true
241 ],
242 'Basic diff, revdel as sysop' => [
243 [
244 'fromrev' => '{{REPL:revA2}}',
245 'torev' => '{{REPL:revB2}}',
246 ],
247 [
248 'compare' => [
249 'fromid' => '{{REPL:pageA}}',
250 'fromrevid' => '{{REPL:revA2}}',
251 'fromns' => 0,
252 'fromtitle' => 'ApiComparePagesTest A',
253 'toid' => '{{REPL:pageB}}',
254 'torevid' => '{{REPL:revB2}}',
255 'tons' => 0,
256 'totitle' => 'ApiComparePagesTest B',
257 'totexthidden' => true,
258 'touserhidden' => true,
259 'tocommenthidden' => true,
260 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
261 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
262 . '<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",
263 ]
264 ],
265 false, true
266 ],
267 'Basic diff, text' => [
268 [
269 'fromtext' => 'From text',
270 'fromcontentmodel' => 'wikitext',
271 'totext' => 'To text {{subst:PAGENAME}}',
272 'tocontentmodel' => 'wikitext',
273 ],
274 [
275 'compare' => [
276 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
277 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
278 . '<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",
279 ]
280 ],
281 ],
282 'Basic diff, text 2' => [
283 [
284 'fromtext' => 'From text',
285 'totext' => 'To text {{subst:PAGENAME}}',
286 'tocontentmodel' => 'wikitext',
287 ],
288 [
289 'compare' => [
290 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
291 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
292 . '<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",
293 ]
294 ],
295 ],
296 'Basic diff, guessed model' => [
297 [
298 'fromtext' => 'From text',
299 'totext' => 'To text',
300 ],
301 [
302 'warnings' => [
303 'compare' => [
304 'warnings' => 'No content model could be determined, assuming wikitext.',
305 ],
306 ],
307 'compare' => [
308 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
309 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
310 . '<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",
311 ]
312 ],
313 ],
314 'Basic diff, text with title and PST' => [
315 [
316 'fromtext' => 'From text',
317 'totitle' => 'Test',
318 'totext' => 'To text {{subst:PAGENAME}}',
319 'topst' => true,
320 ],
321 [
322 'compare' => [
323 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
324 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
325 . '<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",
326 ]
327 ],
328 ],
329 'Basic diff, text with page ID and PST' => [
330 [
331 'fromtext' => 'From text',
332 'toid' => '{{REPL:pageB}}',
333 'totext' => 'To text {{subst:PAGENAME}}',
334 'topst' => true,
335 ],
336 [
337 'compare' => [
338 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
339 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
340 . '<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",
341 ]
342 ],
343 ],
344 'Basic diff, text with revision and PST' => [
345 [
346 'fromtext' => 'From text',
347 'torev' => '{{REPL:revB2}}',
348 'totext' => '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">ApiComparePagesTest B</ins></div></td></tr>' . "\n",
356 ]
357 ],
358 ],
359 'Basic diff, text with deleted revision and PST' => [
360 [
361 'fromtext' => 'From text',
362 'torev' => '{{REPL:revC2}}',
363 'totext' => 'To text {{subst:PAGENAME}}',
364 'topst' => true,
365 ],
366 [
367 'compare' => [
368 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
369 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
370 . '<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",
371 ]
372 ],
373 false, true
374 ],
375 'Diff with all props' => [
376 [
377 'fromrev' => '{{REPL:revB1}}',
378 'torev' => '{{REPL:revB3}}',
379 'totitle' => 'ApiComparePagesTest B',
380 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
381 ],
382 [
383 'compare' => [
384 'fromid' => '{{REPL:pageB}}',
385 'fromrevid' => '{{REPL:revB1}}',
386 'fromns' => 0,
387 'fromtitle' => 'ApiComparePagesTest B',
388 'fromsize' => 3,
389 'fromuser' => '{{REPL:creator}}',
390 'fromuserid' => '{{REPL:creatorid}}',
391 'fromcomment' => 'Test for ApiComparePagesTest: B 1',
392 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 1',
393 'toid' => '{{REPL:pageB}}',
394 'torevid' => '{{REPL:revB3}}',
395 'tons' => 0,
396 'totitle' => 'ApiComparePagesTest B',
397 'tosize' => 3,
398 'touserhidden' => true,
399 'tocommenthidden' => true,
400 'tosuppressed' => true,
401 'next' => '{{REPL:revB4}}',
402 'diffsize' => 391,
403 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
404 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
405 . '<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",
406 ]
407 ],
408 ],
409 'Diff with all props as sysop' => [
410 [
411 'fromrev' => '{{REPL:revB2}}',
412 'torev' => '{{REPL:revB3}}',
413 'totitle' => 'ApiComparePagesTest B',
414 'prop' => 'diff|diffsize|rel|ids|title|user|comment|parsedcomment|size'
415 ],
416 [
417 'compare' => [
418 'fromid' => '{{REPL:pageB}}',
419 'fromrevid' => '{{REPL:revB2}}',
420 'fromns' => 0,
421 'fromtitle' => 'ApiComparePagesTest B',
422 'fromsize' => 3,
423 'fromtexthidden' => true,
424 'fromuserhidden' => true,
425 'fromuser' => '{{REPL:creator}}',
426 'fromuserid' => '{{REPL:creatorid}}',
427 'fromcommenthidden' => true,
428 'fromcomment' => 'Test for ApiComparePagesTest: B 2',
429 'fromparsedcomment' => 'Test for ApiComparePagesTest: B 2',
430 'toid' => '{{REPL:pageB}}',
431 'torevid' => '{{REPL:revB3}}',
432 'tons' => 0,
433 'totitle' => 'ApiComparePagesTest B',
434 'tosize' => 3,
435 'touserhidden' => true,
436 'tocommenthidden' => true,
437 'tosuppressed' => true,
438 'prev' => '{{REPL:revB1}}',
439 'next' => '{{REPL:revB4}}',
440 'diffsize' => 391,
441 'body' => '<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>' . "\n"
442 . '<td colspan="2" class="diff-lineno">Line 1:</td></tr>' . "\n"
443 . '<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",
444 ]
445 ],
446 false, true
447 ],
448 'Relative diff, cur' => [
449 [
450 'fromrev' => '{{REPL:revA2}}',
451 'torelative' => 'cur',
452 'prop' => 'ids',
453 ],
454 [
455 'compare' => [
456 'fromid' => '{{REPL:pageA}}',
457 'fromrevid' => '{{REPL:revA2}}',
458 'toid' => '{{REPL:pageA}}',
459 'torevid' => '{{REPL:revA4}}',
460 ]
461 ],
462 ],
463 'Relative diff, next' => [
464 [
465 'fromrev' => '{{REPL:revE2}}',
466 'torelative' => 'next',
467 'prop' => 'ids|rel',
468 ],
469 [
470 'compare' => [
471 'fromid' => '{{REPL:pageE}}',
472 'fromrevid' => '{{REPL:revE2}}',
473 'toid' => '{{REPL:pageE}}',
474 'torevid' => '{{REPL:revE3}}',
475 'prev' => '{{REPL:revE1}}',
476 'next' => '{{REPL:revE4}}',
477 ]
478 ],
479 ],
480 'Relative diff, prev' => [
481 [
482 'fromrev' => '{{REPL:revE3}}',
483 'torelative' => 'prev',
484 'prop' => 'ids|rel',
485 ],
486 [
487 'compare' => [
488 'fromid' => '{{REPL:pageE}}',
489 'fromrevid' => '{{REPL:revE2}}',
490 'toid' => '{{REPL:pageE}}',
491 'torevid' => '{{REPL:revE3}}',
492 'prev' => '{{REPL:revE1}}',
493 'next' => '{{REPL:revE4}}',
494 ]
495 ],
496 ],
497
498 'Error, missing title' => [
499 [
500 'fromtitle' => 'ApiComparePagesTest X',
501 'totitle' => 'ApiComparePagesTest B',
502 ],
503 [],
504 'missingtitle',
505 ],
506 'Error, invalid title' => [
507 [
508 'fromtitle' => '<bad>',
509 'totitle' => 'ApiComparePagesTest B',
510 ],
511 [],
512 'invalidtitle',
513 ],
514 'Error, missing page ID' => [
515 [
516 'fromid' => 8817900,
517 'totitle' => 'ApiComparePagesTest B',
518 ],
519 [],
520 'nosuchpageid',
521 ],
522 'Error, page with missing revision' => [
523 [
524 'fromtitle' => 'ApiComparePagesTest D',
525 'totitle' => 'ApiComparePagesTest B',
526 ],
527 [],
528 'nosuchrevid',
529 ],
530 'Error, page with no revision' => [
531 [
532 'fromtitle' => 'ApiComparePagesTest E',
533 'totitle' => 'ApiComparePagesTest B',
534 ],
535 [],
536 'nosuchrevid',
537 ],
538 'Error, bad rev ID' => [
539 [
540 'fromrev' => 8817900,
541 'totitle' => 'ApiComparePagesTest B',
542 ],
543 [],
544 'nosuchrevid',
545 ],
546 'Error, deleted revision ID, non-sysop' => [
547 [
548 'fromrev' => '{{REPL:revA2}}',
549 'torev' => '{{REPL:revC2}}',
550 ],
551 [],
552 'nosuchrevid',
553 ],
554 'Error, revision-deleted content' => [
555 [
556 'fromrev' => '{{REPL:revA2}}',
557 'torev' => '{{REPL:revB2}}',
558 ],
559 [],
560 'missingcontent',
561 ],
562 'Error, text with no title and PST' => [
563 [
564 'fromtext' => 'From text',
565 'totext' => 'To text {{subst:PAGENAME}}',
566 'topst' => true,
567 ],
568 [],
569 'compare-no-title',
570 ],
571 'Error, Relative diff, no from revision' => [
572 [
573 'fromtext' => 'Foo',
574 'torelative' => 'cur',
575 'prop' => 'ids',
576 ],
577 [],
578 'compare-relative-to-nothing'
579 ],
580 'Error, Relative diff, cur with no current revision' => [
581 [
582 'fromrev' => '{{REPL:revE2}}',
583 'torelative' => 'cur',
584 'prop' => 'ids',
585 ],
586 [],
587 'nosuchrevid'
588 ],
589 'Error, Relative diff, next revdeleted' => [
590 [
591 'fromrev' => '{{REPL:revB1}}',
592 'torelative' => 'next',
593 'prop' => 'ids',
594 ],
595 [],
596 'missingcontent'
597 ],
598 'Error, Relative diff, prev revdeleted' => [
599 [
600 'fromrev' => '{{REPL:revB3}}',
601 'torelative' => 'prev',
602 'prop' => 'ids',
603 ],
604 [],
605 'missingcontent'
606 ],
607
608 // @codingStandardsIgnoreEnd
609 ];
610 }
611}
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)
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null)
Does the API request and returns the result.
static apiExceptionHasCode(ApiUsageException $ex, $code)
Exception used to abort API execution with an error.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static getMain()
Static methods.
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:92
const DELETED_TEXT
Definition Revision.php:90
const DELETED_RESTRICTED
Definition Revision.php:93
const DELETED_COMMENT
Definition Revision.php:91
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
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:1976
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. '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). '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:1049
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:236
const DB_MASTER
Definition defines.php:26
$params