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