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