MediaWiki  1.33.0
ApiComparePages.php
Go to the documentation of this file.
1 <?php
28 
29 class ApiComparePages extends ApiBase {
30 
32  private $revisionStore;
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() {
46  $params = $this->extractRequestParams();
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 ) {
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'],
239  array_merge(
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,
641  ApiBase::PARAM_ISMULTI => true,
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
654  ],
655  'contentmodel-{slot}' => [
656  ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
658  ],
659  'pst' => false,
660 
661  'text' => [
662  ApiBase::PARAM_TYPE => 'text',
664  ],
665  'contentformat' => [
668  ],
669  'contentmodel' => [
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  ],
712  ApiBase::PARAM_ISMULTI => true,
714  ];
715 
716  $ret['slots'] = [
717  ApiBase::PARAM_TYPE => $slotRoles,
718  ApiBase::PARAM_ISMULTI => true,
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 }
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:41
wfArrayInsertAfter
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
Definition: GlobalFunctions.php:231
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
ContentHandler\getAllContentFormats
static getAllContentFormats()
Definition: ContentHandler.php:335
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1909
ApiComparePages\setVals
setVals(&$vals, $prefix, $rev)
Set value fields from a RevisionRecord object.
Definition: ApiComparePages.php:563
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:76
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1990
ApiBase\PARAM_ALL
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
Definition: ApiBase.php:180
ApiComparePages\__construct
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
Definition: ApiComparePages.php:39
ApiComparePages\$props
$props
Definition: ApiComparePages.php:37
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:632
ApiComparePages\$guessedTitle
$guessedTitle
Definition: ApiComparePages.php:37
ApiComparePages\$slotRoleRegistry
MediaWiki Revision SlotRoleRegistry $slotRoleRegistry
Definition: ApiComparePages.php:35
$params
$params
Definition: styleTest.css.php:44
ApiBase\getDB
getDB()
Gets a default replica DB connection object.
Definition: ApiBase.php:660
ApiResult\NO_SIZE_CHECK
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
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:37
ApiComparePages\guessModel
guessModel( $role)
Guess an appropriate default content model for this request.
Definition: ApiComparePages.php:303
Revision
Definition: Revision.php:40
ApiResult\setContentValue
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
Definition: ApiResult.php:478
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:105
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:728
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
$newRev
$newRev
Definition: pageupdater.txt:66
ContentHandler\getContentModels
static getContentModels()
Definition: ContentHandler.php:327
ApiComparePages
Definition: ApiComparePages.php:29
MWContentSerializationException
Exception representing a failure to serialize or unserialize a content object.
Definition: MWContentSerializationException.php:7
ApiBase\dieWithException
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition: ApiBase.php:2002
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:743
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
ApiMessage\create
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Definition: ApiMessage.php:40
array
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))
list
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
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:133
null
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:780
Revision\RevisionArchiveRecord
A RevisionRecord representing a revision of a deleted page persisted in the archive table.
Definition: RevisionArchiveRecord.php:40
ApiComparePages\guessTitle
guessTitle()
Guess an appropriate default Title for this request.
Definition: ApiComparePages.php:261
ApiComparePages\getDiffRevision
getDiffRevision( $prefix, array $params)
Get the RevisionRecord for one side of the diff.
Definition: ApiComparePages.php:355
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1043
Revision\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:41
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1577
$ret
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:1985
ApiBase\requireMaxOneParameter
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:913
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Linker\formatComment
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
ApiBase\requireAtLeastOneParameter
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:941
ApiBase\PARAM_TEMPLATE_VARS
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition: ApiBase.php:245
$section
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:3053
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
ApiComparePages\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiComparePages.php:625
$rev
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:1769
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
DifferenceEngine
DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
Definition: DifferenceEngine.php:51
ApiComparePages\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiComparePages.php:45
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:512
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiComparePages\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiComparePages.php:725
$content
$content
Definition: pageupdater.txt:72
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:528
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
ApiBase\PARAM_HELP_MSG_PER_VALUE
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
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:457
ApiComparePages\getRevisionById
getRevisionById( $id)
Load a revision by ID.
Definition: ApiComparePages.php:232
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:510
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
ApiComparePages\$revisionStore
RevisionStore $revisionStore
Definition: ApiComparePages.php:32
MediaWiki
The MediaWiki class is the helper class for the index.php entry point.
Definition: MediaWiki.php:34