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