MediaWiki  master
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 ) {
311  if ( $rev->hasSlot( $role ) ) {
312  return $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
313  }
314  }
315  }
316  }
317 
318  $guessedTitle = $this->guessTitle();
319  if ( $guessedTitle ) {
320  return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel( $guessedTitle );
321  }
322 
323  if ( isset( $params["fromcontentmodel-$role"] ) ) {
324  return $params["fromcontentmodel-$role"];
325  }
326  if ( isset( $params["tocontentmodel-$role"] ) ) {
327  return $params["tocontentmodel-$role"];
328  }
329 
330  if ( $role === SlotRecord::MAIN ) {
331  if ( isset( $params['fromcontentmodel'] ) ) {
332  return $params['fromcontentmodel'];
333  }
334  if ( isset( $params['tocontentmodel'] ) ) {
335  return $params['tocontentmodel'];
336  }
337  }
338 
339  return null;
340  }
341 
357  private function getDiffRevision( $prefix, array $params ) {
358  // Back compat params
359  $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
360  $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
361  if ( $params["{$prefix}text"] !== null ) {
362  $params["{$prefix}slots"] = [ SlotRecord::MAIN ];
363  $params["{$prefix}text-main"] = $params["{$prefix}text"];
364  $params["{$prefix}section-main"] = null;
365  $params["{$prefix}contentmodel-main"] = $params["{$prefix}contentmodel"];
366  $params["{$prefix}contentformat-main"] = $params["{$prefix}contentformat"];
367  }
368 
369  $title = null;
370  $rev = null;
371  $suppliedContent = $params["{$prefix}slots"] !== null;
372 
373  // Get the revision and title, if applicable
374  $revId = null;
375  if ( $params["{$prefix}rev"] !== null ) {
376  $revId = $params["{$prefix}rev"];
377  } elseif ( $params["{$prefix}title"] !== null || $params["{$prefix}id"] !== null ) {
378  if ( $params["{$prefix}title"] !== null ) {
379  $title = Title::newFromText( $params["{$prefix}title"] );
380  if ( !$title || $title->isExternal() ) {
381  $this->dieWithError(
382  [ 'apierror-invalidtitle', wfEscapeWikiText( $params["{$prefix}title"] ) ]
383  );
384  }
385  } else {
386  $title = Title::newFromID( $params["{$prefix}id"] );
387  if ( !$title ) {
388  $this->dieWithError( [ 'apierror-nosuchpageid', $params["{$prefix}id"] ] );
389  }
390  }
391  $revId = $title->getLatestRevID();
392  if ( !$revId ) {
393  $revId = null;
394  // Only die here if we're not using supplied text
395  if ( !$suppliedContent ) {
396  if ( $title->exists() ) {
397  $this->dieWithError(
398  [ 'apierror-missingrev-title', wfEscapeWikiText( $title->getPrefixedText() ) ], 'nosuchrevid'
399  );
400  } else {
401  $this->dieWithError(
402  [ 'apierror-missingtitle-byname', wfEscapeWikiText( $title->getPrefixedText() ) ],
403  'missingtitle'
404  );
405  }
406  }
407  }
408  }
409  if ( $revId !== null ) {
410  $rev = $this->getRevisionById( $revId );
411  if ( !$rev ) {
412  $this->dieWithError( [ 'apierror-nosuchrevid', $revId ] );
413  }
414  $title = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
415 
416  // If we don't have supplied content, return here. Otherwise,
417  // continue on below with the supplied content.
418  if ( !$suppliedContent ) {
419  $newRev = $rev;
420 
421  // Deprecated 'fromsection'/'tosection'
422  if ( isset( $params["{$prefix}section"] ) ) {
423  $section = $params["{$prefix}section"];
424  $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
425  $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
426  $this->getUser() );
427  if ( !$content ) {
428  $this->dieWithError(
429  [ 'apierror-missingcontent-revid-role', $rev->getId(), SlotRecord::MAIN ], 'missingcontent'
430  );
431  }
432  $content = $content ? $content->getSection( $section ) : null;
433  if ( !$content ) {
434  $this->dieWithError(
435  [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
436  "nosuch{$prefix}section"
437  );
438  }
439  $newRev->setContent( SlotRecord::MAIN, $content );
440  }
441 
442  return [ $newRev, $rev, $rev ];
443  }
444  }
445 
446  // Override $content based on supplied text
447  if ( !$title ) {
448  $title = $this->guessTitle();
449  }
450  if ( $rev ) {
451  $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
452  } else {
453  $newRev = $this->revisionStore->newMutableRevisionFromArray( [
454  'title' => $title ?: Title::makeTitle( NS_SPECIAL, 'Badtitle/' . __METHOD__ )
455  ] );
456  }
457  foreach ( $params["{$prefix}slots"] as $role ) {
458  $text = $params["{$prefix}text-{$role}"];
459  if ( $text === null ) {
460  // The SlotRecord::MAIN role can't be deleted
461  if ( $role === SlotRecord::MAIN ) {
462  $this->dieWithError( [ 'apierror-compare-maintextrequired', $prefix ] );
463  }
464 
465  // These parameters make no sense without text. Reject them to avoid
466  // confusion.
467  foreach ( [ 'section', 'contentmodel', 'contentformat' ] as $param ) {
468  if ( isset( $params["{$prefix}{$param}-{$role}"] ) ) {
469  $this->dieWithError( [
470  'apierror-compare-notext',
471  wfEscapeWikiText( "{$prefix}{$param}-{$role}" ),
472  wfEscapeWikiText( "{$prefix}text-{$role}" ),
473  ] );
474  }
475  }
476 
477  $newRev->removeSlot( $role );
478  continue;
479  }
480 
481  $model = $params["{$prefix}contentmodel-{$role}"];
482  $format = $params["{$prefix}contentformat-{$role}"];
483 
484  if ( !$model && $rev && $rev->hasSlot( $role ) ) {
485  $model = $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
486  }
487  if ( !$model && $title && $role === SlotRecord::MAIN ) {
488  // @todo: Use SlotRoleRegistry and do this for all slots
489  $model = $title->getContentModel();
490  }
491  if ( !$model ) {
492  $model = $this->guessModel( $role );
493  }
494  if ( !$model ) {
495  $model = CONTENT_MODEL_WIKITEXT;
496  $this->addWarning( [ 'apiwarn-compare-nocontentmodel', $model ] );
497  }
498 
499  try {
500  $content = ContentHandler::makeContent( $text, $title, $model, $format );
501  } catch ( MWContentSerializationException $ex ) {
502  $this->dieWithException( $ex, [
503  'wrap' => ApiMessage::create( 'apierror-contentserializationexception', 'parseerror' )
504  ] );
505  }
506 
507  if ( $params["{$prefix}pst"] ) {
508  if ( !$title ) {
509  $this->dieWithError( 'apierror-compare-no-title' );
510  }
511  $popts = ParserOptions::newFromContext( $this->getContext() );
512  $content = $content->preSaveTransform( $title, $this->getUser(), $popts );
513  }
514 
515  $section = $params["{$prefix}section-{$role}"];
516  if ( $section !== null && $section !== '' ) {
517  if ( !$rev ) {
518  $this->dieWithError( "apierror-compare-no{$prefix}revision" );
519  }
520  $oldContent = $rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->getUser() );
521  if ( !$oldContent ) {
522  $this->dieWithError(
523  [ 'apierror-missingcontent-revid-role', $rev->getId(), wfEscapeWikiText( $role ) ],
524  'missingcontent'
525  );
526  }
527  if ( !$oldContent->getContentHandler()->supportsSections() ) {
528  $this->dieWithError( [ 'apierror-sectionsnotsupported', $content->getModel() ] );
529  }
530  try {
531  $content = $oldContent->replaceSection( $section, $content, '' );
532  } catch ( Exception $ex ) {
533  // Probably a content model mismatch.
534  $content = null;
535  }
536  if ( !$content ) {
537  $this->dieWithError( [ 'apierror-sectionreplacefailed' ] );
538  }
539  }
540 
541  // Deprecated 'fromsection'/'tosection'
542  if ( $role === SlotRecord::MAIN && isset( $params["{$prefix}section"] ) ) {
543  $section = $params["{$prefix}section"];
544  $content = $content->getSection( $section );
545  if ( !$content ) {
546  $this->dieWithError(
547  [ "apierror-compare-nosuch{$prefix}section", wfEscapeWikiText( $section ) ],
548  "nosuch{$prefix}section"
549  );
550  }
551  }
552 
553  $newRev->setContent( $role, $content );
554  }
555  return [ $newRev, $rev, null ];
556  }
557 
565  private function setVals( &$vals, $prefix, $rev ) {
566  if ( $rev ) {
567  $title = $rev->getPageAsLinkTarget();
568  if ( isset( $this->props['ids'] ) ) {
569  $vals["{$prefix}id"] = $title->getArticleID();
570  $vals["{$prefix}revid"] = $rev->getId();
571  }
572  if ( isset( $this->props['title'] ) ) {
573  ApiQueryBase::addTitleInfo( $vals, $title, $prefix );
574  }
575  if ( isset( $this->props['size'] ) ) {
576  $vals["{$prefix}size"] = $rev->getSize();
577  }
578 
579  $anyHidden = false;
580  if ( $rev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
581  $vals["{$prefix}texthidden"] = true;
582  $anyHidden = true;
583  }
584 
585  if ( $rev->isDeleted( RevisionRecord::DELETED_USER ) ) {
586  $vals["{$prefix}userhidden"] = true;
587  $anyHidden = true;
588  }
589  if ( isset( $this->props['user'] ) ) {
590  $user = $rev->getUser( RevisionRecord::FOR_THIS_USER, $this->getUser() );
591  if ( $user ) {
592  $vals["{$prefix}user"] = $user->getName();
593  $vals["{$prefix}userid"] = $user->getId();
594  }
595  }
596 
597  if ( $rev->isDeleted( RevisionRecord::DELETED_COMMENT ) ) {
598  $vals["{$prefix}commenthidden"] = true;
599  $anyHidden = true;
600  }
601  if ( isset( $this->props['comment'] ) || isset( $this->props['parsedcomment'] ) ) {
602  $comment = $rev->getComment( RevisionRecord::FOR_THIS_USER, $this->getUser() );
603  if ( $comment !== null ) {
604  if ( isset( $this->props['comment'] ) ) {
605  $vals["{$prefix}comment"] = $comment->text;
606  }
607  $vals["{$prefix}parsedcomment"] = Linker::formatComment(
608  $comment->text, Title::newFromLinkTarget( $title )
609  );
610  }
611  }
612 
613  if ( $anyHidden ) {
614  $this->getMain()->setCacheMode( 'private' );
615  if ( $rev->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
616  $vals["{$prefix}suppressed"] = true;
617  }
618  }
619 
620  if ( !empty( $rev->isArchive ) ) {
621  $this->getMain()->setCacheMode( 'private' );
622  $vals["{$prefix}archive"] = true;
623  }
624  }
625  }
626 
627  public function getAllowedParams() {
628  $slotRoles = $this->slotRoleRegistry->getKnownRoles();
629  sort( $slotRoles, SORT_STRING );
630 
631  // Parameters for the 'from' and 'to' content
632  $fromToParams = [
633  'title' => null,
634  'id' => [
635  ApiBase::PARAM_TYPE => 'integer'
636  ],
637  'rev' => [
638  ApiBase::PARAM_TYPE => 'integer'
639  ],
640 
641  'slots' => [
642  ApiBase::PARAM_TYPE => $slotRoles,
643  ApiBase::PARAM_ISMULTI => true,
644  ],
645  'text-{slot}' => [
646  ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
647  ApiBase::PARAM_TYPE => 'text',
648  ],
649  'section-{slot}' => [
650  ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
651  ApiBase::PARAM_TYPE => 'string',
652  ],
653  'contentformat-{slot}' => [
654  ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
656  ],
657  'contentmodel-{slot}' => [
658  ApiBase::PARAM_TEMPLATE_VARS => [ 'slot' => 'slots' ], // fixed below
660  ],
661  'pst' => false,
662 
663  'text' => [
664  ApiBase::PARAM_TYPE => 'text',
666  ],
667  'contentformat' => [
670  ],
671  'contentmodel' => [
674  ],
675  'section' => [
678  ],
679  ];
680 
681  $ret = [];
682  foreach ( $fromToParams as $k => $v ) {
683  if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
684  $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'fromslots';
685  }
686  $ret["from$k"] = $v;
687  }
688  foreach ( $fromToParams as $k => $v ) {
689  if ( isset( $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] ) ) {
690  $v[ApiBase::PARAM_TEMPLATE_VARS]['slot'] = 'toslots';
691  }
692  $ret["to$k"] = $v;
693  }
694 
696  $ret,
697  [ 'torelative' => [ ApiBase::PARAM_TYPE => [ 'prev', 'next', 'cur' ], ] ],
698  'torev'
699  );
700 
701  $ret['prop'] = [
702  ApiBase::PARAM_DFLT => 'diff|ids|title',
704  'diff',
705  'diffsize',
706  'rel',
707  'ids',
708  'title',
709  'user',
710  'comment',
711  'parsedcomment',
712  'size',
713  ],
714  ApiBase::PARAM_ISMULTI => true,
716  ];
717 
718  $ret['slots'] = [
719  ApiBase::PARAM_TYPE => $slotRoles,
720  ApiBase::PARAM_ISMULTI => true,
721  ApiBase::PARAM_ALL => true,
722  ];
723 
724  return $ret;
725  }
726 
727  protected function getExamplesMessages() {
728  return [
729  'action=compare&fromrev=1&torev=2'
730  => 'apihelp-compare-example-1',
731  ];
732  }
733 }
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))
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
Definition: ApiBase.php:88
DifferenceEngine is responsible for rendering the difference between two revisions as HTML...
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
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
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
getResult()
Get the result object.
Definition: ApiBase.php:625
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:427
static getAllContentFormats()
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:1995
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:49
getMain()
Get the main module.
Definition: ApiBase.php:521
static getContentModels()
getDB()
Gets a default replica DB connection object.
Definition: ApiBase.php:653
An IContextSource implementation which will inherit context from another source but allow individual ...
const NS_SPECIAL
Definition: Defines.php:53
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1978
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user...
Definition: ApiBase.php:736
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
Definition: ApiBase.php:1990
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
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:158
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true...
Definition: ApiBase.php:181
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:251
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
IContextSource $context
Mutable RevisionRecord implementation, for building new revision entries programmatically.
setVals(&$vals, $prefix, $rev)
Set value fields from a RevisionRecord object.
$newRev
Definition: pageupdater.txt:66
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:1110
guessModel( $role)
Guess an appropriate default content model for this request.
MediaWiki Revision SlotRoleRegistry $slotRoleRegistry
guessTitle()
Guess an appropriate default Title for this request.
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
Definition: ApiBase.php:933
getRevisionById( $id)
Load a revision by ID.
getContext()
Get the base IContextSource object.
$params
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:41
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
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don&#39;t use this unless yo...
Definition: ApiResult.php:58
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:935
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:505
getDiffRevision( $prefix, array $params)
Get the RevisionRecord for one side of the diff.
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
A RevisionRecord representing a revision of a deleted page persisted in the archive table...
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
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
Definition: ApiBase.php:905
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:3042
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition: ApiBase.php:246
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:545
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
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1897
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:52
This abstract class implements many basic API functions, and is the base of all API classes...
Definition: ApiBase.php:38
RevisionStore $revisionStore
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:106
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:728
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
$content
Definition: pageupdater.txt:72
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1486
Exception representing a failure to serialize or unserialize a content object.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
Definition: ApiMessage.php:40
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:280