Merge "Delete unused variable"
[lhc/web/wiklou.git] / includes / api / ApiComparePages.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 */
21
22 use MediaWiki\MediaWikiServices;
23 use MediaWiki\Revision\MutableRevisionRecord;
24 use MediaWiki\Revision\RevisionRecord;
25 use MediaWiki\Revision\RevisionStore;
26 use MediaWiki\Revision\SlotRecord;
27
28 class ApiComparePages extends ApiBase {
29
30 /** @var RevisionStore */
31 private $revisionStore;
32
33 /** @var \MediaWiki\Revision\SlotRoleRegistry */
34 private $slotRoleRegistry;
35
36 private $guessedTitle = false, $props;
37
38 public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
39 parent::__construct( $mainModule, $moduleName, $modulePrefix );
40 $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
41 $this->slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
42 }
43
44 public function execute() {
45 $params = $this->extractRequestParams();
46
47 // Parameter validation
48 $this->requireAtLeastOneParameter(
49 $params, 'fromtitle', 'fromid', 'fromrev', 'fromtext', 'fromslots'
50 );
51 $this->requireAtLeastOneParameter(
52 $params, 'totitle', 'toid', 'torev', 'totext', 'torelative', 'toslots'
53 );
54
55 $this->props = array_flip( $params['prop'] );
56
57 // Cache responses publicly by default. This may be overridden later.
58 $this->getMain()->setCacheMode( 'public' );
59
60 // Get the 'from' RevisionRecord
61 list( $fromRev, $fromRelRev, $fromValsRev ) = $this->getDiffRevision( 'from', $params );
62
63 // Get the 'to' RevisionRecord
64 if ( $params['torelative'] !== null ) {
65 if ( !$fromRelRev ) {
66 $this->dieWithError( 'apierror-compare-relative-to-nothing' );
67 }
68 switch ( $params['torelative'] ) {
69 case 'prev':
70 // Swap 'from' and 'to'
71 list( $toRev, $toRelRev2, $toValsRev ) = [ $fromRev, $fromRelRev, $fromValsRev ];
72 $fromRev = $this->revisionStore->getPreviousRevision( $fromRelRev );
73 $fromRelRev = $fromRev;
74 $fromValsRev = $fromRev;
75 break;
76
77 case 'next':
78 $toRev = $this->revisionStore->getNextRevision( $fromRelRev );
79 $toRelRev = $toRev;
80 $toValsRev = $toRev;
81 break;
82
83 case 'cur':
84 $title = $fromRelRev->getPageAsLinkTarget();
85 $toRev = $this->revisionStore->getRevisionByTitle( $title );
86 if ( !$toRev ) {
87 $title = Title::newFromLinkTarget( $title );
88 $this->dieWithError(
89 [ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ], 'nosuchrevid'
90 );
91 }
92 $toRelRev = $toRev;
93 $toValsRev = $toRev;
94 break;
95 }
96 } else {
97 list( $toRev, $toRelRev, $toValsRev ) = $this->getDiffRevision( 'to', $params );
98 }
99
100 // Handle missing from or to revisions
101 if ( !$fromRev || !$toRev ) {
102 $this->dieWithError( 'apierror-baddiff' );
103 }
104
105 // Handle revdel
106 if ( !$fromRev->audienceCan(
107 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
108 ) ) {
109 $this->dieWithError( [ 'apierror-missingcontent-revid', $fromRev->getId() ], 'missingcontent' );
110 }
111 if ( !$toRev->audienceCan(
112 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
113 ) ) {
114 $this->dieWithError( [ 'apierror-missingcontent-revid', $toRev->getId() ], 'missingcontent' );
115 }
116
117 // Get the diff
118 $context = new DerivativeContext( $this->getContext() );
119 if ( $fromRelRev && $fromRelRev->getPageAsLinkTarget() ) {
120 $context->setTitle( Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() ) );
121 } elseif ( $toRelRev && $toRelRev->getPageAsLinkTarget() ) {
122 $context->setTitle( Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() ) );
123 } else {
124 $guessedTitle = $this->guessTitle();
125 if ( $guessedTitle ) {
126 $context->setTitle( $guessedTitle );
127 }
128 }
129 $de = new DifferenceEngine( $context );
130 $de->setRevisions( $fromRev, $toRev );
131 if ( $params['slots'] === null ) {
132 $difftext = $de->getDiffBody();
133 if ( $difftext === false ) {
134 $this->dieWithError( 'apierror-baddiff' );
135 }
136 } else {
137 $difftext = [];
138 foreach ( $params['slots'] as $role ) {
139 $difftext[$role] = $de->getDiffBodyForRole( $role );
140 }
141 }
142
143 // Fill in the response
144 $vals = [];
145 $this->setVals( $vals, 'from', $fromValsRev );
146 $this->setVals( $vals, 'to', $toValsRev );
147
148 if ( isset( $this->props['rel'] ) ) {
149 if ( !$fromRev instanceof MutableRevisionRecord ) {
150 $rev = $this->revisionStore->getPreviousRevision( $fromRev );
151 if ( $rev ) {
152 $vals['prev'] = $rev->getId();
153 }
154 }
155 if ( !$toRev instanceof MutableRevisionRecord ) {
156 $rev = $this->revisionStore->getNextRevision( $toRev );
157 if ( $rev ) {
158 $vals['next'] = $rev->getId();
159 }
160 }
161 }
162
163 if ( isset( $this->props['diffsize'] ) ) {
164 $vals['diffsize'] = 0;
165 foreach ( (array)$difftext as $text ) {
166 $vals['diffsize'] += strlen( $text );
167 }
168 }
169 if ( isset( $this->props['diff'] ) ) {
170 if ( is_array( $difftext ) ) {
171 ApiResult::setArrayType( $difftext, 'kvp', 'diff' );
172 $vals['bodies'] = $difftext;
173 } else {
174 ApiResult::setContentValue( $vals, 'body', $difftext );
175 }
176 }
177
178 // Diffs can be really big and there's little point in having
179 // ApiResult truncate it to an empty response since the diff is the
180 // whole reason this module exists. So pass NO_SIZE_CHECK here.
181 $this->getResult()->addValue( null, $this->getModuleName(), $vals, ApiResult::NO_SIZE_CHECK );
182 }
183
184 /**
185 * Load a revision by ID
186 *
187 * Falls back to checking the archive table if appropriate.
188 *
189 * @param int $id
190 * @return RevisionRecord|null
191 */
192 private function getRevisionById( $id ) {
193 $rev = $this->revisionStore->getRevisionById( $id );
194 if ( !$rev && $this->getUser()->isAllowedAny( 'deletedtext', 'undelete' ) ) {
195 // Try the 'archive' table
196 $arQuery = $this->revisionStore->getArchiveQueryInfo();
197 $row = $this->getDB()->selectRow(
198 $arQuery['tables'],
199 array_merge(
200 $arQuery['fields'],
201 [ 'ar_namespace', 'ar_title' ]
202 ),
203 [ 'ar_rev_id' => $id ],
204 __METHOD__,
205 [],
206 $arQuery['joins']
207 );
208 if ( $row ) {
209 $rev = $this->revisionStore->newRevisionFromArchiveRow( $row );
210 $rev->isArchive = true;
211 }
212 }
213 return $rev;
214 }
215
216 /**
217 * Guess an appropriate default Title for this request
218 *
219 * @return Title|null
220 */
221 private function guessTitle() {
222 if ( $this->guessedTitle !== false ) {
223 return $this->guessedTitle;
224 }
225
226 $this->guessedTitle = null;
227 $params = $this->extractRequestParams();
228
229 foreach ( [ 'from', 'to' ] as $prefix ) {
230 if ( $params["{$prefix}rev"] !== null ) {
231 $rev = $this->getRevisionById( $params["{$prefix}rev"] );
232 if ( $rev ) {
233 $this->guessedTitle = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
234 break;
235 }
236 }
237
238 if ( $params["{$prefix}title"] !== null ) {
239 $title = Title::newFromText( $params["{$prefix}title"] );
240 if ( $title && !$title->isExternal() ) {
241 $this->guessedTitle = $title;
242 break;
243 }
244 }
245
246 if ( $params["{$prefix}id"] !== null ) {
247 $title = Title::newFromID( $params["{$prefix}id"] );
248 if ( $title ) {
249 $this->guessedTitle = $title;
250 break;
251 }
252 }
253 }
254
255 return $this->guessedTitle;
256 }
257
258 /**
259 * Guess an appropriate default content model for this request
260 * @param string $role Slot for which to guess the model
261 * @return string|null Guessed content model
262 */
263 private function guessModel( $role ) {
264 $params = $this->extractRequestParams();
265
266 $title = null;
267 foreach ( [ 'from', 'to' ] as $prefix ) {
268 if ( $params["{$prefix}rev"] !== null ) {
269 $rev = $this->getRevisionById( $params["{$prefix}rev"] );
270 if ( $rev ) {
271 if ( $rev->hasSlot( $role ) ) {
272 return $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
273 }
274 }
275 }
276 }
277
278 $guessedTitle = $this->guessTitle();
279 if ( $guessedTitle ) {
280 return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel( $guessedTitle );
281 }
282
283 if ( isset( $params["fromcontentmodel-$role"] ) ) {
284 return $params["fromcontentmodel-$role"];
285 }
286 if ( isset( $params["tocontentmodel-$role"] ) ) {
287 return $params["tocontentmodel-$role"];
288 }
289
290 if ( $role === SlotRecord::MAIN ) {
291 if ( isset( $params['fromcontentmodel'] ) ) {
292 return $params['fromcontentmodel'];
293 }
294 if ( isset( $params['tocontentmodel'] ) ) {
295 return $params['tocontentmodel'];
296 }
297 }
298
299 return null;
300 }
301
302 /**
303 * Get the RevisionRecord for one side of the diff
304 *
305 * This uses the appropriate set of parameters to determine what content
306 * should be diffed.
307 *
308 * Returns three values:
309 * - A RevisionRecord holding the content
310 * - The revision specified, if any, even if content was supplied
311 * - The revision to pass to setVals(), if any
312 *
313 * @param string $prefix 'from' or 'to'
314 * @param array $params
315 * @return array [ RevisionRecord|null, RevisionRecord|null, RevisionRecord|null ]
316 */
317 private function getDiffRevision( $prefix, array $params ) {
318 // Back compat params
319 $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
320 $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
321 if ( $params["{$prefix}text"] !== null ) {
322 $params["{$prefix}slots"] = [ SlotRecord::MAIN ];
323 $params["{$prefix}text-main"] = $params["{$prefix}text"];
324 $params["{$prefix}section-main"] = null;
325 $params["{$prefix}contentmodel-main"] = $params["{$prefix}contentmodel"];
326 $params["{$prefix}contentformat-main"] = $params["{$prefix}contentformat"];
327 }
328
329 $title = null;
330 $rev = null;
331 $suppliedContent = $params["{$prefix}slots"] !== null;
332
333 // Get the revision and title, if applicable
334 $revId = null;
335 if ( $params["{$prefix}rev"] !== null ) {
336 $revId = $params["{$prefix}rev"];
337 } elseif ( $params["{$prefix}title"] !== null || $params["{$prefix}id"] !== null ) {
338 if ( $params["{$prefix}title"] !== null ) {
339 $title = Title::newFromText( $params["{$prefix}title"] );
340 if ( !$title || $title->isExternal() ) {
341 $this->dieWithError(
342 [ 'apierror-invalidtitle', wfEscapeWikiText( $params["{$prefix}title"] ) ]
343 );
344 }
345 } else {
346 $title = Title::newFromID( $params["{$prefix}id"] );
347 if ( !$title ) {
348 $this->dieWithError( [ 'apierror-nosuchpageid', $params["{$prefix}id"] ] );
349 }
350 }
351 $revId = $title->getLatestRevID();
352 if ( !$revId ) {
353 $revId = null;
354 // Only die here if we're not using supplied text
355 if ( !$suppliedContent ) {
356 if ( $title->exists() ) {
357 $this->dieWithError(
358 [ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ], 'nosuchrevid'
359 );
360 } else {
361 $this->dieWithError(
362 [ 'apierror-missingtitle-byname', wfEscapeWikiText( $title->getPrefixedText() ) ],
363 'missingtitle'
364 );
365 }
366 }
367 }
368 }
369 if ( $revId !== null ) {
370 $rev = $this->getRevisionById( $revId );
371 if ( !$rev ) {
372 $this->dieWithError( [ 'apierror-nosuchrevid', $revId ] );
373 }
374 $title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
375
376 // If we don't have supplied content, return here. Otherwise,
377 // continue on below with the supplied content.
378 if ( !$suppliedContent ) {
379 $newRev = $rev;
380
381 // Deprecated 'fromsection'/'tosection'
382 if ( isset( $params["{$prefix}section"] ) ) {
383 $section = $params["{$prefix}section"];
384 $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
385 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
386 $this->getUser() );
387 if ( !$content ) {
388 $this->dieWithError(
389 [ 'apierror-missingcontent-revid-role', $rev->getId(), SlotRecord::MAIN ], 'missingcontent'
390 );
391 }
392 $content = $content ? $content->getSection( $section ) : null;
393 if ( !$content ) {
394 $this->dieWithError(
395 [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
396 "nosuch{$prefix}section"
397 );
398 }
399 $newRev->setContent( SlotRecord::MAIN, $content );
400 }
401
402 return [ $newRev, $rev, $rev ];
403 }
404 }
405
406 // Override $content based on supplied text
407 if ( !$title ) {
408 $title = $this->guessTitle();
409 }
410 if ( $rev ) {
411 $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
412 } else {
413 $newRev = $this->revisionStore->newMutableRevisionFromArray( [
414 'title' => $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __METHOD__ )
415 ] );
416 }
417 foreach ( $params["{$prefix}slots"] as $role ) {
418 $text = $params["{$prefix}text-{$role}"];
419 if ( $text === null ) {
420 // The SlotRecord::MAIN role can't be deleted
421 if ( $role === SlotRecord::MAIN ) {
422 $this->dieWithError( [ 'apierror-compare-maintextrequired', $prefix ] );
423 }
424
425 // These parameters make no sense without text. Reject them to avoid
426 // confusion.
427 foreach ( [ 'section', 'contentmodel', 'contentformat' ] as $param ) {
428 if ( isset( $params["{$prefix}{$param}-{$role}"] ) ) {
429 $this->dieWithError( [
430 'apierror-compare-notext',
431 wfEscapeWikiText( "{$prefix}{$param}-{$role}" ),
432 wfEscapeWikiText( "{$prefix}text-{$role}" ),
433 ] );
434 }
435 }
436
437 $newRev->removeSlot( $role );
438 continue;
439 }
440
441 $model = $params["{$prefix}contentmodel-{$role}"];
442 $format = $params["{$prefix}contentformat-{$role}"];
443
444 if ( !$model && $rev && $rev->hasSlot( $role ) ) {
445 $model = $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
446 }
447 if ( !$model && $title && $role === SlotRecord::MAIN ) {
448 // @todo: Use SlotRoleRegistry and do this for all slots
449 $model = $title->getContentModel();
450 }
451 if ( !$model ) {
452 $model = $this->guessModel( $role );
453 }
454 if ( !$model ) {
455 $model = CONTENT_MODEL_WIKITEXT;
456 $this->addWarning( [ 'apiwarn-compare-nocontentmodel', $model ] );
457 }
458
459 try {
460 $content = ContentHandler::makeContent( $text, $title, $model, $format );
461 } catch ( MWContentSerializationException $ex ) {
462 $this->dieWithException( $ex, [
463 'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
464 ] );
465 }
466
467 if ( $params["{$prefix}pst"] ) {
468 if ( !$title ) {
469 $this->dieWithError( 'apierror-compare-no-title' );
470 }
471 $popts = ParserOptions::newFromContext( $this->getContext() );
472 $content = $content->preSaveTransform( $title, $this->getUser(), $popts );
473 }
474
475 $section = $params["{$prefix}section-{$role}"];
476 if ( $section !== null && $section !== '' ) {
477 if ( !$rev ) {
478 $this->dieWithError( "apierror-compare-no{$prefix}revision" );
479 }
480 $oldContent = $rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->getUser() );
481 if ( !$oldContent ) {
482 $this->dieWithError(
483 [ 'apierror-missingcontent-revid-role', $rev->getId(), wfEscapeWikiText( $role ) ],
484 'missingcontent'
485 );
486 }
487 if ( !$oldContent->getContentHandler()->supportsSections() ) {
488 $this->dieWithError( [ 'apierror-sectionsnotsupported', $content->getModel() ] );
489 }
490 try {
491 $content = $oldContent->replaceSection( $section, $content, '' );
492 } catch ( Exception $ex ) {
493 // Probably a content model mismatch.
494 $content = null;
495 }
496 if ( !$content ) {
497 $this->dieWithError( [ 'apierror-sectionreplacefailed' ] );
498 }
499 }
500
501 // Deprecated 'fromsection'/'tosection'
502 if ( $role === SlotRecord::MAIN && isset( $params["{$prefix}section"] ) ) {
503 $section = $params["{$prefix}section"];
504 $content = $content->getSection( $section );
505 if ( !$content ) {
506 $this->dieWithError(
507 [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
508 "nosuch{$prefix}section"
509 );
510 }
511 }
512
513 $newRev->setContent( $role, $content );
514 }
515 return [ $newRev, $rev, null ];
516 }
517
518 /**
519 * Set value fields from a RevisionRecord object
520 *
521 * @param array &$vals Result array to set data into
522 * @param string $prefix 'from' or 'to'
523 * @param RevisionRecord|null $rev
524 */
525 private function setVals( &$vals, $prefix, $rev ) {
526 if ( $rev ) {
527 $title = $rev->getPageAsLinkTarget();
528 if ( isset( $this->props['ids'] ) ) {
529 $vals["{$prefix}id"] = $title->getArticleID();
530 $vals["{$prefix}revid"] = $rev->getId();
531 }
532 if ( isset( $this->props['title'] ) ) {
533 ApiQueryBase::addTitleInfo( $vals, $title, $prefix );
534 }
535 if ( isset( $this->props['size'] ) ) {
536 $vals["{$prefix}size"] = $rev->getSize();
537 }
538
539 $anyHidden = false;
540 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
541 $vals["{$prefix}texthidden"] = true;
542 $anyHidden = true;
543 }
544
545 if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
546 $vals["{$prefix}userhidden"] = true;
547 $anyHidden = true;
548 }
549 if ( isset( $this->props['user'] ) ) {
550 $user = $rev->getUser( RevisionRecord::FOR_THIS_USER, $this->getUser() );
551 if ( $user ) {
552 $vals["{$prefix}user"] = $user->getName();
553 $vals["{$prefix}userid"] = $user->getId();
554 }
555 }
556
557 if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
558 $vals["{$prefix}commenthidden"] = true;
559 $anyHidden = true;
560 }
561 if ( isset( $this->props['comment'] ) || isset( $this->props['parsedcomment'] ) ) {
562 $comment = $rev->getComment( RevisionRecord::FOR_THIS_USER, $this->getUser() );
563 if ( $comment !== null ) {
564 if ( isset( $this->props['comment'] ) ) {
565 $vals["{$prefix}comment"] = $comment->text;
566 }
567 $vals["{$prefix}parsedcomment"] = Linker::formatComment(
568 $comment->text, Title::newFromLinkTarget( $title )
569 );
570 }
571 }
572
573 if ( $anyHidden ) {
574 $this->getMain()->setCacheMode( 'private' );
575 if ( $rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
576 $vals["{$prefix}suppressed"] = true;
577 }
578 }
579
580 if ( !empty( $rev->isArchive ) ) {
581 $this->getMain()->setCacheMode( 'private' );
582 $vals["{$prefix}archive"] = true;
583 }
584 }
585 }
586
587 public function getAllowedParams() {
588 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
589 sort( $slotRoles, SORT_STRING );
590
591 // Parameters for the 'from' and 'to' content
592 $fromToParams = [
593 'title' => null,
594 'id' => [
595 ApiBase::PARAM_TYPE => 'integer'
596 ],
597 'rev' => [
598 ApiBase::PARAM_TYPE => 'integer'
599 ],
600
601 'slots' => [
602 ApiBase::PARAM_TYPE => $slotRoles,
603 ApiBase::PARAM_ISMULTI => true,
604 ],
605 'text-{slot}' => [
606 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
607 ApiBase::PARAM_TYPE => 'text',
608 ],
609 'section-{slot}' => [
610 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
611 ApiBase::PARAM_TYPE => 'string',
612 ],
613 'contentformat-{slot}' => [
614 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
615 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
616 ],
617 'contentmodel-{slot}' => [
618 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
619 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
620 ],
621 'pst' => false,
622
623 'text' => [
624 ApiBase::PARAM_TYPE => 'text',
625 ApiBase::PARAM_DEPRECATED => true,
626 ],
627 'contentformat' => [
628 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
629 ApiBase::PARAM_DEPRECATED => true,
630 ],
631 'contentmodel' => [
632 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
633 ApiBase::PARAM_DEPRECATED => true,
634 ],
635 'section' => [
636 ApiBase::PARAM_DFLT => null,
637 ApiBase::PARAM_DEPRECATED => true,
638 ],
639 ];
640
641 $ret = [];
642 foreach ( $fromToParams as $k => $v ) {
643 if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
644 $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'fromslots';
645 }
646 $ret["from$k"] = $v;
647 }
648 foreach ( $fromToParams as $k => $v ) {
649 if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
650 $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'toslots';
651 }
652 $ret["to$k"] = $v;
653 }
654
655 $ret = wfArrayInsertAfter(
656 $ret,
657 [ 'torelative' => [ ApiBase::PARAM_TYPE => [ 'prev', 'next', 'cur' ], ] ],
658 'torev'
659 );
660
661 $ret['prop'] = [
662 ApiBase::PARAM_DFLT => 'diff|ids|title',
663 ApiBase::PARAM_TYPE => [
664 'diff',
665 'diffsize',
666 'rel',
667 'ids',
668 'title',
669 'user',
670 'comment',
671 'parsedcomment',
672 'size',
673 ],
674 ApiBase::PARAM_ISMULTI => true,
675 ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
676 ];
677
678 $ret['slots'] = [
679 ApiBase::PARAM_TYPE => $slotRoles,
680 ApiBase::PARAM_ISMULTI => true,
681 ApiBase::PARAM_ALL => true,
682 ];
683
684 return $ret;
685 }
686
687 protected function getExamplesMessages() {
688 return [
689 'action=compare&fromrev=1&torev=2'
690 => 'apihelp-compare-example-1',
691 ];
692 }
693 }