MediaWiki REL1_33
ApiComparePages.php
Go to the documentation of this file.
1<?php
28
29class ApiComparePages extends ApiBase {
30
33
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() {
47
48 // Parameter validation
50 $params, 'fromtitle', 'fromid', 'fromrev', 'fromtext', 'fromslots'
51 );
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, $toRelRev, $toValsRev ) = [ $fromRev, $fromRelRev, $fromValsRev ];
78 $fromRev = $this->revisionStore->getPreviousRevision( $toRelRev );
79 $fromRelRev = $fromRev;
80 $fromValsRev = $fromRev;
81 if ( !$fromRev ) {
82 $title = Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() );
83 $this->addWarning( [
84 'apiwarn-compare-no-prev',
85 wfEscapeWikiText( $title->getPrefixedText() ),
86 $toRelRev->getId()
87 ] );
88
89 // (T203433) Create an empty dummy revision as the "previous".
90 // The main slot has to exist, the rest will be handled by DifferenceEngine.
91 $fromRev = $this->revisionStore->newMutableRevisionFromArray( [
92 'title' => $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __METHOD__ )
93 ] );
94 $fromRev->setContent(
95 SlotRecord::MAIN,
96 $toRelRev->getContent( SlotRecord::MAIN, RevisionRecord::RAW )
97 ->getContentHandler()
98 ->makeEmptyContent()
99 );
100 }
101 break;
102
103 case 'next':
104 $toRev = $this->revisionStore->getNextRevision( $fromRelRev );
105 $toRelRev = $toRev;
106 $toValsRev = $toRev;
107 if ( !$toRev ) {
108 $title = Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() );
109 $this->addWarning( [
110 'apiwarn-compare-no-next',
111 wfEscapeWikiText( $title->getPrefixedText() ),
112 $fromRelRev->getId()
113 ] );
114
115 // (T203433) The web UI treats "next" as "cur" in this case.
116 // Avoid repeating metadata by making a MutableRevisionRecord with no changes.
117 $toRev = MutableRevisionRecord::newFromParentRevision( $fromRelRev );
118 }
119 break;
120
121 case 'cur':
122 $title = $fromRelRev->getPageAsLinkTarget();
123 $toRev = $this->revisionStore->getRevisionByTitle( $title );
124 if ( !$toRev ) {
125 $title = Title::newFromLinkTarget( $title );
126 $this->dieWithError(
127 [ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ], 'nosuchrevid'
128 );
129 }
130 $toRelRev = $toRev;
131 $toValsRev = $toRev;
132 break;
133 }
134 } else {
135 list( $toRev, $toRelRev, $toValsRev ) = $this->getDiffRevision( 'to', $params );
136 }
137
138 // Handle missing from or to revisions (should never happen)
139 // @codeCoverageIgnoreStart
140 if ( !$fromRev || !$toRev ) {
141 $this->dieWithError( 'apierror-baddiff' );
142 }
143 // @codeCoverageIgnoreEnd
144
145 // Handle revdel
146 if ( !$fromRev->audienceCan(
147 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
148 ) ) {
149 $this->dieWithError( [ 'apierror-missingcontent-revid', $fromRev->getId() ], 'missingcontent' );
150 }
151 if ( !$toRev->audienceCan(
152 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_THIS_USER, $this->getUser()
153 ) ) {
154 $this->dieWithError( [ 'apierror-missingcontent-revid', $toRev->getId() ], 'missingcontent' );
155 }
156
157 // Get the diff
158 $context = new DerivativeContext( $this->getContext() );
159 if ( $fromRelRev && $fromRelRev->getPageAsLinkTarget() ) {
160 $context->setTitle( Title::newFromLinkTarget( $fromRelRev->getPageAsLinkTarget() ) );
161 } elseif ( $toRelRev && $toRelRev->getPageAsLinkTarget() ) {
162 $context->setTitle( Title::newFromLinkTarget( $toRelRev->getPageAsLinkTarget() ) );
163 } else {
164 $guessedTitle = $this->guessTitle();
165 if ( $guessedTitle ) {
166 $context->setTitle( $guessedTitle );
167 }
168 }
169 $de = new DifferenceEngine( $context );
170 $de->setRevisions( $fromRev, $toRev );
171 if ( $params['slots'] === null ) {
172 $difftext = $de->getDiffBody();
173 if ( $difftext === false ) {
174 $this->dieWithError( 'apierror-baddiff' );
175 }
176 } else {
177 $difftext = [];
178 foreach ( $params['slots'] as $role ) {
179 $difftext[$role] = $de->getDiffBodyForRole( $role );
180 }
181 }
182
183 // Fill in the response
184 $vals = [];
185 $this->setVals( $vals, 'from', $fromValsRev );
186 $this->setVals( $vals, 'to', $toValsRev );
187
188 if ( isset( $this->props['rel'] ) ) {
189 if ( !$fromRev instanceof MutableRevisionRecord ) {
190 $rev = $this->revisionStore->getPreviousRevision( $fromRev );
191 if ( $rev ) {
192 $vals['prev'] = $rev->getId();
193 }
194 }
195 if ( !$toRev instanceof MutableRevisionRecord ) {
196 $rev = $this->revisionStore->getNextRevision( $toRev );
197 if ( $rev ) {
198 $vals['next'] = $rev->getId();
199 }
200 }
201 }
202
203 if ( isset( $this->props['diffsize'] ) ) {
204 $vals['diffsize'] = 0;
205 foreach ( (array)$difftext as $text ) {
206 $vals['diffsize'] += strlen( $text );
207 }
208 }
209 if ( isset( $this->props['diff'] ) ) {
210 if ( is_array( $difftext ) ) {
211 ApiResult::setArrayType( $difftext, 'kvp', 'diff' );
212 $vals['bodies'] = $difftext;
213 } else {
214 ApiResult::setContentValue( $vals, 'body', $difftext );
215 }
216 }
217
218 // Diffs can be really big and there's little point in having
219 // ApiResult truncate it to an empty response since the diff is the
220 // whole reason this module exists. So pass NO_SIZE_CHECK here.
221 $this->getResult()->addValue( null, $this->getModuleName(), $vals, ApiResult::NO_SIZE_CHECK );
222 }
223
232 private function getRevisionById( $id ) {
233 $rev = $this->revisionStore->getRevisionById( $id );
234 if ( !$rev && $this->getUser()->isAllowedAny( 'deletedtext', 'undelete' ) ) {
235 // Try the 'archive' table
236 $arQuery = $this->revisionStore->getArchiveQueryInfo();
237 $row = $this->getDB()->selectRow(
238 $arQuery['tables'],
240 $arQuery['fields'],
241 [ 'ar_namespace', 'ar_title' ]
242 ),
243 [ 'ar_rev_id' => $id ],
244 __METHOD__,
245 [],
246 $arQuery['joins']
247 );
248 if ( $row ) {
249 $rev = $this->revisionStore->newRevisionFromArchiveRow( $row );
250 $rev->isArchive = true;
251 }
252 }
253 return $rev;
254 }
255
261 private function guessTitle() {
262 if ( $this->guessedTitle !== false ) {
263 return $this->guessedTitle;
264 }
265
266 $this->guessedTitle = null;
267 $params = $this->extractRequestParams();
268
269 foreach ( [ 'from', 'to' ] as $prefix ) {
270 if ( $params["{$prefix}rev"] !== null ) {
271 $rev = $this->getRevisionById( $params["{$prefix}rev"] );
272 if ( $rev ) {
273 $this->guessedTitle = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
274 break;
275 }
276 }
277
278 if ( $params["{$prefix}title"] !== null ) {
279 $title = Title::newFromText( $params["{$prefix}title"] );
280 if ( $title && !$title->isExternal() ) {
281 $this->guessedTitle = $title;
282 break;
283 }
284 }
285
286 if ( $params["{$prefix}id"] !== null ) {
287 $title = Title::newFromID( $params["{$prefix}id"] );
288 if ( $title ) {
289 $this->guessedTitle = $title;
290 break;
291 }
292 }
293 }
294
295 return $this->guessedTitle;
296 }
297
303 private function guessModel( $role ) {
304 $params = $this->extractRequestParams();
305
306 $title = null;
307 foreach ( [ 'from', 'to' ] as $prefix ) {
308 if ( $params["{$prefix}rev"] !== null ) {
309 $rev = $this->getRevisionById( $params["{$prefix}rev"] );
310 if ( $rev && $rev->hasSlot( $role ) ) {
311 return $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
312 }
313 }
314 }
315
316 $guessedTitle = $this->guessTitle();
317 if ( $guessedTitle ) {
318 return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel( $guessedTitle );
319 }
320
321 if ( isset( $params["fromcontentmodel-$role"] ) ) {
322 return $params["fromcontentmodel-$role"];
323 }
324 if ( isset( $params["tocontentmodel-$role"] ) ) {
325 return $params["tocontentmodel-$role"];
326 }
327
328 if ( $role === SlotRecord::MAIN ) {
329 if ( isset( $params['fromcontentmodel'] ) ) {
330 return $params['fromcontentmodel'];
331 }
332 if ( isset( $params['tocontentmodel'] ) ) {
333 return $params['tocontentmodel'];
334 }
335 }
336
337 return null;
338 }
339
355 private function getDiffRevision( $prefix, array $params ) {
356 // Back compat params
357 $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
358 $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
359 if ( $params["{$prefix}text"] !== null ) {
360 $params["{$prefix}slots"] = [ SlotRecord::MAIN ];
361 $params["{$prefix}text-main"] = $params["{$prefix}text"];
362 $params["{$prefix}section-main"] = null;
363 $params["{$prefix}contentmodel-main"] = $params["{$prefix}contentmodel"];
364 $params["{$prefix}contentformat-main"] = $params["{$prefix}contentformat"];
365 }
366
367 $title = null;
368 $rev = null;
369 $suppliedContent = $params["{$prefix}slots"] !== null;
370
371 // Get the revision and title, if applicable
372 $revId = null;
373 if ( $params["{$prefix}rev"] !== null ) {
374 $revId = $params["{$prefix}rev"];
375 } elseif ( $params["{$prefix}title"] !== null || $params["{$prefix}id"] !== null ) {
376 if ( $params["{$prefix}title"] !== null ) {
377 $title = Title::newFromText( $params["{$prefix}title"] );
378 if ( !$title || $title->isExternal() ) {
379 $this->dieWithError(
380 [ 'apierror-invalidtitle', wfEscapeWikiText( $params["{$prefix}title"] ) ]
381 );
382 }
383 } else {
384 $title = Title::newFromID( $params["{$prefix}id"] );
385 if ( !$title ) {
386 $this->dieWithError( [ 'apierror-nosuchpageid', $params["{$prefix}id"] ] );
387 }
388 }
389 $revId = $title->getLatestRevID();
390 if ( !$revId ) {
391 $revId = null;
392 // Only die here if we're not using supplied text
393 if ( !$suppliedContent ) {
394 if ( $title->exists() ) {
395 $this->dieWithError(
396 [ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ], 'nosuchrevid'
397 );
398 } else {
399 $this->dieWithError(
400 [ 'apierror-missingtitle-byname', wfEscapeWikiText( $title->getPrefixedText() ) ],
401 'missingtitle'
402 );
403 }
404 }
405 }
406 }
407 if ( $revId !== null ) {
408 $rev = $this->getRevisionById( $revId );
409 if ( !$rev ) {
410 $this->dieWithError( [ 'apierror-nosuchrevid', $revId ] );
411 }
412 $title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
413
414 // If we don't have supplied content, return here. Otherwise,
415 // continue on below with the supplied content.
416 if ( !$suppliedContent ) {
417 $newRev = $rev;
418
419 // Deprecated 'fromsection'/'tosection'
420 if ( isset( $params["{$prefix}section"] ) ) {
421 $section = $params["{$prefix}section"];
422 $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
423 $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
424 $this->getUser() );
425 if ( !$content ) {
426 $this->dieWithError(
427 [ 'apierror-missingcontent-revid-role', $rev->getId(), SlotRecord::MAIN ], 'missingcontent'
428 );
429 }
430 $content = $content ? $content->getSection( $section ) : null;
431 if ( !$content ) {
432 $this->dieWithError(
433 [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
434 "nosuch{$prefix}section"
435 );
436 }
437 $newRev->setContent( SlotRecord::MAIN, $content );
438 }
439
440 return [ $newRev, $rev, $rev ];
441 }
442 }
443
444 // Override $content based on supplied text
445 if ( !$title ) {
446 $title = $this->guessTitle();
447 }
448 if ( $rev ) {
449 $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
450 } else {
451 $newRev = $this->revisionStore->newMutableRevisionFromArray( [
452 'title' => $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __METHOD__ )
453 ] );
454 }
455 foreach ( $params["{$prefix}slots"] as $role ) {
456 $text = $params["{$prefix}text-{$role}"];
457 if ( $text === null ) {
458 // The SlotRecord::MAIN role can't be deleted
459 if ( $role === SlotRecord::MAIN ) {
460 $this->dieWithError( [ 'apierror-compare-maintextrequired', $prefix ] );
461 }
462
463 // These parameters make no sense without text. Reject them to avoid
464 // confusion.
465 foreach ( [ 'section', 'contentmodel', 'contentformat' ] as $param ) {
466 if ( isset( $params["{$prefix}{$param}-{$role}"] ) ) {
467 $this->dieWithError( [
468 'apierror-compare-notext',
469 wfEscapeWikiText( "{$prefix}{$param}-{$role}" ),
470 wfEscapeWikiText( "{$prefix}text-{$role}" ),
471 ] );
472 }
473 }
474
475 $newRev->removeSlot( $role );
476 continue;
477 }
478
479 $model = $params["{$prefix}contentmodel-{$role}"];
480 $format = $params["{$prefix}contentformat-{$role}"];
481
482 if ( !$model && $rev && $rev->hasSlot( $role ) ) {
483 $model = $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
484 }
485 if ( !$model && $title && $role === SlotRecord::MAIN ) {
486 // @todo: Use SlotRoleRegistry and do this for all slots
487 $model = $title->getContentModel();
488 }
489 if ( !$model ) {
490 $model = $this->guessModel( $role );
491 }
492 if ( !$model ) {
493 $model = CONTENT_MODEL_WIKITEXT;
494 $this->addWarning( [ 'apiwarn-compare-nocontentmodel', $model ] );
495 }
496
497 try {
498 $content = ContentHandler::makeContent( $text, $title, $model, $format );
499 } catch ( MWContentSerializationException $ex ) {
500 $this->dieWithException( $ex, [
501 'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
502 ] );
503 }
504
505 if ( $params["{$prefix}pst"] ) {
506 if ( !$title ) {
507 $this->dieWithError( 'apierror-compare-no-title' );
508 }
509 $popts = ParserOptions::newFromContext( $this->getContext() );
510 $content = $content->preSaveTransform( $title, $this->getUser(), $popts );
511 }
512
513 $section = $params["{$prefix}section-{$role}"];
514 if ( $section !== null && $section !== '' ) {
515 if ( !$rev ) {
516 $this->dieWithError( "apierror-compare-no{$prefix}revision" );
517 }
518 $oldContent = $rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->getUser() );
519 if ( !$oldContent ) {
520 $this->dieWithError(
521 [ 'apierror-missingcontent-revid-role', $rev->getId(), wfEscapeWikiText( $role ) ],
522 'missingcontent'
523 );
524 }
525 if ( !$oldContent->getContentHandler()->supportsSections() ) {
526 $this->dieWithError( [ 'apierror-sectionsnotsupported', $content->getModel() ] );
527 }
528 try {
529 $content = $oldContent->replaceSection( $section, $content, '' );
530 } catch ( Exception $ex ) {
531 // Probably a content model mismatch.
532 $content = null;
533 }
534 if ( !$content ) {
535 $this->dieWithError( [ 'apierror-sectionreplacefailed' ] );
536 }
537 }
538
539 // Deprecated 'fromsection'/'tosection'
540 if ( $role === SlotRecord::MAIN && isset( $params["{$prefix}section"] ) ) {
541 $section = $params["{$prefix}section"];
542 $content = $content->getSection( $section );
543 if ( !$content ) {
544 $this->dieWithError(
545 [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
546 "nosuch{$prefix}section"
547 );
548 }
549 }
550
551 $newRev->setContent( $role, $content );
552 }
553 return [ $newRev, $rev, null ];
554 }
555
563 private function setVals( &$vals, $prefix, $rev ) {
564 if ( $rev ) {
565 $title = $rev->getPageAsLinkTarget();
566 if ( isset( $this->props['ids'] ) ) {
567 $vals["{$prefix}id"] = $title->getArticleID();
568 $vals["{$prefix}revid"] = $rev->getId();
569 }
570 if ( isset( $this->props['title'] ) ) {
571 ApiQueryBase::addTitleInfo( $vals, $title, $prefix );
572 }
573 if ( isset( $this->props['size'] ) ) {
574 $vals["{$prefix}size"] = $rev->getSize();
575 }
576
577 $anyHidden = false;
578 if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
579 $vals["{$prefix}texthidden"] = true;
580 $anyHidden = true;
581 }
582
583 if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
584 $vals["{$prefix}userhidden"] = true;
585 $anyHidden = true;
586 }
587 if ( isset( $this->props['user'] ) ) {
588 $user = $rev->getUser( RevisionRecord::FOR_THIS_USER, $this->getUser() );
589 if ( $user ) {
590 $vals["{$prefix}user"] = $user->getName();
591 $vals["{$prefix}userid"] = $user->getId();
592 }
593 }
594
595 if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
596 $vals["{$prefix}commenthidden"] = true;
597 $anyHidden = true;
598 }
599 if ( isset( $this->props['comment'] ) || isset( $this->props['parsedcomment'] ) ) {
600 $comment = $rev->getComment( RevisionRecord::FOR_THIS_USER, $this->getUser() );
601 if ( $comment !== null ) {
602 if ( isset( $this->props['comment'] ) ) {
603 $vals["{$prefix}comment"] = $comment->text;
604 }
605 $vals["{$prefix}parsedcomment"] = Linker::formatComment(
606 $comment->text, Title::newFromLinkTarget( $title )
607 );
608 }
609 }
610
611 if ( $anyHidden ) {
612 $this->getMain()->setCacheMode( 'private' );
613 if ( $rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
614 $vals["{$prefix}suppressed"] = true;
615 }
616 }
617
618 if ( !empty( $rev->isArchive ) ) {
619 $this->getMain()->setCacheMode( 'private' );
620 $vals["{$prefix}archive"] = true;
621 }
622 }
623 }
624
625 public function getAllowedParams() {
626 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
627 sort( $slotRoles, SORT_STRING );
628
629 // Parameters for the 'from' and 'to' content
630 $fromToParams = [
631 'title' => null,
632 'id' => [
633 ApiBase::PARAM_TYPE => 'integer'
634 ],
635 'rev' => [
636 ApiBase::PARAM_TYPE => 'integer'
637 ],
638
639 'slots' => [
640 ApiBase::PARAM_TYPE => $slotRoles,
642 ],
643 'text-{slot}' => [
644 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
645 ApiBase::PARAM_TYPE => 'text',
646 ],
647 'section-{slot}' => [
648 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
649 ApiBase::PARAM_TYPE => 'string',
650 ],
651 'contentformat-{slot}' => [
652 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
653 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
654 ],
655 'contentmodel-{slot}' => [
656 ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
657 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
658 ],
659 'pst' => false,
660
661 'text' => [
662 ApiBase::PARAM_TYPE => 'text',
664 ],
665 'contentformat' => [
666 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
668 ],
669 'contentmodel' => [
670 ApiBase::PARAM_TYPE => ContentHandler::getContentModels(),
672 ],
673 'section' => [
674 ApiBase::PARAM_DFLT => null,
676 ],
677 ];
678
679 $ret = [];
680 foreach ( $fromToParams as $k => $v ) {
681 if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
682 $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'fromslots';
683 }
684 $ret["from$k"] = $v;
685 }
686 foreach ( $fromToParams as $k => $v ) {
687 if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
688 $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'toslots';
689 }
690 $ret["to$k"] = $v;
691 }
692
694 $ret,
695 [ 'torelative' => [ ApiBase::PARAM_TYPE => [ 'prev', 'next', 'cur' ], ] ],
696 'torev'
697 );
698
699 $ret['prop'] = [
700 ApiBase::PARAM_DFLT => 'diff|ids|title',
702 'diff',
703 'diffsize',
704 'rel',
705 'ids',
706 'title',
707 'user',
708 'comment',
709 'parsedcomment',
710 'size',
711 ],
714 ];
715
716 $ret['slots'] = [
717 ApiBase::PARAM_TYPE => $slotRoles,
719 ApiBase::PARAM_ALL => true,
720 ];
721
722 return $ret;
723 }
724
725 protected function getExamplesMessages() {
726 return [
727 'action=compare&fromrev=1&torev=2'
728 => 'apihelp-compare-example-1',
729 ];
730 }
731}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:37
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition ApiBase.php:105
getDB()
Gets a default replica DB connection object.
Definition ApiBase.php:660
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1990
getMain()
Get the main module.
Definition ApiBase.php:528
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:157
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition ApiBase.php:245
getResult()
Get the result object.
Definition ApiBase.php:632
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:743
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition ApiBase.php:913
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition ApiBase.php:2002
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition ApiBase.php:1909
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition ApiBase.php:941
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
Definition ApiBase.php:180
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
getDiffRevision( $prefix, array $params)
Get the RevisionRecord for one side of the diff.
getExamplesMessages()
Returns usage examples for this module.
setVals(&$vals, $prefix, $rev)
Set value fields from a RevisionRecord object.
MediaWiki Revision SlotRoleRegistry $slotRoleRegistry
getRevisionById( $id)
Load a revision by ID.
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
RevisionStore $revisionStore
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
guessTitle()
Guess an appropriate default Title for this request.
guessModel( $role)
Guess an appropriate default content model for this request.
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:41
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
Definition ApiResult.php:58
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
IContextSource $context
getContext()
Get the base IContextSource object.
An IContextSource implementation which will inherit context from another source but allow individual ...
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition Linker.php:1122
Exception representing a failure to serialize or unserialize a content object.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Mutable RevisionRecord implementation, for building new revision entries programmatically.
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Page revision base class.
Service for looking up page revisions.
Value object representing a content slot associated with a page revision.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition hooks.txt:783
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 & $ret
Definition hooks.txt:2003
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition hooks.txt:3070
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1779
const NS_SPECIAL
Definition Defines.php:62
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:244
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
A helper class for throttling authentication attempts.
$content
$newRev
$params