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