MediaWiki  master
ApiQueryRevisionsBase.php
Go to the documentation of this file.
1 <?php
31 
40 
46  // Bits to indicate the results of the revdel permission check on a revision,
47  // see self::checkRevDel()
48  private const IS_DELETED = 1; // Whether the field is revision-deleted
49  private const CANNOT_VIEW = 2; // Whether the user cannot view the field due to revdel
50 
56 
57  protected $fld_ids = false, $fld_flags = false, $fld_timestamp = false,
58  $fld_size = false, $fld_slotsize = false, $fld_sha1 = false, $fld_slotsha1 = false,
59  $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
60  $fld_content = false, $fld_tags = false, $fld_contentmodel = false, $fld_roles = false,
61  $fld_parsetree = false;
62 
63  public function execute() {
64  $this->run();
65  }
66 
67  public function executeGenerator( $resultPageSet ) {
68  $this->run( $resultPageSet );
69  }
70 
75  abstract protected function run( ApiPageSet $resultPageSet = null );
76 
82  protected function parseParameters( $params ) {
83  $prop = array_flip( $params['prop'] );
84 
85  $this->fld_ids = isset( $prop['ids'] );
86  $this->fld_flags = isset( $prop['flags'] );
87  $this->fld_timestamp = isset( $prop['timestamp'] );
88  $this->fld_comment = isset( $prop['comment'] );
89  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
90  $this->fld_size = isset( $prop['size'] );
91  $this->fld_slotsize = isset( $prop['slotsize'] );
92  $this->fld_sha1 = isset( $prop['sha1'] );
93  $this->fld_slotsha1 = isset( $prop['slotsha1'] );
94  $this->fld_content = isset( $prop['content'] );
95  $this->fld_contentmodel = isset( $prop['contentmodel'] );
96  $this->fld_userid = isset( $prop['userid'] );
97  $this->fld_user = isset( $prop['user'] );
98  $this->fld_tags = isset( $prop['tags'] );
99  $this->fld_roles = isset( $prop['roles'] );
100  $this->fld_parsetree = isset( $prop['parsetree'] );
101 
102  $this->slotRoles = $params['slots'];
103 
104  if ( $this->slotRoles !== null ) {
105  if ( $this->fld_parsetree ) {
106  $this->dieWithError( [
107  'apierror-invalidparammix-cannotusewith',
108  $this->encodeParamName( 'prop=parsetree' ),
109  $this->encodeParamName( 'slots' ),
110  ], 'invalidparammix' );
111  }
112  foreach ( [
113  'expandtemplates', 'generatexml', 'parse', 'diffto', 'difftotext', 'difftotextpst',
114  'contentformat'
115  ] as $p ) {
116  if ( $params[$p] !== null && $params[$p] !== false ) {
117  $this->dieWithError( [
118  'apierror-invalidparammix-cannotusewith',
119  $this->encodeParamName( $p ),
120  $this->encodeParamName( 'slots' ),
121  ], 'invalidparammix' );
122  }
123  }
124  }
125 
126  if ( !empty( $params['contentformat'] ) ) {
127  $this->contentFormat = $params['contentformat'];
128  }
129 
130  $this->limit = $params['limit'];
131 
132  if ( $params['difftotext'] !== null ) {
133  $this->difftotext = $params['difftotext'];
134  $this->difftotextpst = $params['difftotextpst'];
135  } elseif ( $params['diffto'] !== null ) {
136  if ( $params['diffto'] == 'cur' ) {
137  $params['diffto'] = 0;
138  }
139  if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
140  && $params['diffto'] != 'prev' && $params['diffto'] != 'next'
141  ) {
142  $p = $this->getModulePrefix();
143  $this->dieWithError( [ 'apierror-baddiffto', $p ], 'diffto' );
144  }
145  // Check whether the revision exists and is readable,
146  // DifferenceEngine returns a rather ambiguous empty
147  // string if that's not the case
148  if ( $params['diffto'] != 0 ) {
149  $difftoRev = MediaWikiServices::getInstance()->getRevisionStore()
150  ->getRevisionById( $params['diffto'] );
151  if ( !$difftoRev ) {
152  $this->dieWithError( [ 'apierror-nosuchrevid', $params['diffto'] ] );
153  }
154  $revDel = $this->checkRevDel( $difftoRev, RevisionRecord::DELETED_TEXT );
155  if ( $revDel & self::CANNOT_VIEW ) {
156  $this->addWarning( [ 'apiwarn-difftohidden', $difftoRev->getId() ] );
157  $params['diffto'] = null;
158  }
159  }
160  $this->diffto = $params['diffto'];
161  }
162 
163  $this->fetchContent = $this->fld_content || $this->diffto !== null
164  || $this->difftotext !== null || $this->fld_parsetree;
165 
166  $smallLimit = false;
167  if ( $this->fetchContent ) {
168  $smallLimit = true;
169  $this->expandTemplates = $params['expandtemplates'];
170  $this->generateXML = $params['generatexml'];
171  $this->parseContent = $params['parse'];
172  if ( $this->parseContent ) {
173  // Must manually initialize unset limit
174  if ( $this->limit === null ) {
175  $this->limit = 1;
176  }
177  }
178  $this->section = $params['section'] ?? false;
179  }
180 
181  $userMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
182  $botMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
183  if ( $this->limit == 'max' ) {
184  $this->limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
185  if ( $this->setParsedLimit ) {
186  $this->getResult()->addParsedLimit( $this->getModuleName(), $this->limit );
187  }
188  }
189 
190  $this->limit = $this->getMain()->getParamValidator()->validateValue(
191  $this, 'limit', $this->limit ?? 10, [
192  ParamValidator::PARAM_TYPE => 'limit',
193  IntegerDef::PARAM_MIN => 1,
194  IntegerDef::PARAM_MAX => $userMax,
195  IntegerDef::PARAM_MAX2 => $botMax,
196  IntegerDef::PARAM_IGNORE_RANGE => true,
197  ]
198  );
199 
200  $this->needSlots = $this->fetchContent || $this->fld_contentmodel ||
201  $this->fld_slotsize || $this->fld_slotsha1;
202  if ( $this->needSlots && $this->slotRoles === null ) {
203  $encParam = $this->encodeParamName( 'slots' );
204  $name = $this->getModuleName();
205  $parent = $this->getParent();
206  $parentParam = $parent->encodeParamName( $parent->getModuleManager()->getModuleGroup( $name ) );
207  $this->addDeprecation(
208  [ 'apiwarn-deprecation-missingparam', $encParam ],
209  "action=query&{$parentParam}={$name}&!{$encParam}"
210  );
211  }
212  }
213 
221  private function checkRevDel( RevisionRecord $revision, $field ) {
222  $ret = $revision->isDeleted( $field ) ? self::IS_DELETED : 0;
223  if ( $ret ) {
224  $canSee = $revision->audienceCan( $field, RevisionRecord::FOR_THIS_USER, $this->getUser() );
225  $ret |= ( $canSee ? 0 : self::CANNOT_VIEW );
226  }
227  return $ret;
228  }
229 
238  protected function extractRevisionInfo( RevisionRecord $revision, $row ) {
239  $vals = [];
240  $anyHidden = false;
241 
242  if ( $this->fld_ids ) {
243  $vals['revid'] = (int)$revision->getId();
244  if ( $revision->getParentId() !== null ) {
245  $vals['parentid'] = (int)$revision->getParentId();
246  }
247  }
248 
249  if ( $this->fld_flags ) {
250  $vals['minor'] = $revision->isMinor();
251  }
252 
253  if ( $this->fld_user || $this->fld_userid ) {
254  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_USER );
255  if ( ( $revDel & self::IS_DELETED ) ) {
256  $vals['userhidden'] = true;
257  $anyHidden = true;
258  }
259  if ( !( $revDel & self::CANNOT_VIEW ) ) {
260  $u = $revision->getUser( RevisionRecord::RAW );
261  if ( $this->fld_user ) {
262  $vals['user'] = $u->getName();
263  }
264  $userid = $u->getId();
265  if ( !$userid ) {
266  $vals['anon'] = true;
267  }
268 
269  if ( $this->fld_userid ) {
270  $vals['userid'] = $userid;
271  }
272  }
273  }
274 
275  if ( $this->fld_timestamp ) {
276  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
277  }
278 
279  if ( $this->fld_size ) {
280  try {
281  $vals['size'] = (int)$revision->getSize();
282  } catch ( RevisionAccessException $e ) {
283  // Back compat: If there's no size, return 0.
284  // @todo: Gergő says to mention T198099 as a "todo" here.
285  $vals['size'] = 0;
286  }
287  }
288 
289  if ( $this->fld_sha1 ) {
290  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
291  if ( ( $revDel & self::IS_DELETED ) ) {
292  $vals['sha1hidden'] = true;
293  $anyHidden = true;
294  }
295  if ( !( $revDel & self::CANNOT_VIEW ) ) {
296  try {
297  $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 );
298  } catch ( RevisionAccessException $e ) {
299  // Back compat: If there's no sha1, return emtpy string.
300  // @todo: Gergő says to mention T198099 as a "todo" here.
301  $vals['sha1'] = '';
302  }
303  }
304  }
305 
306  try {
307  if ( $this->fld_roles ) {
308  $vals['roles'] = $revision->getSlotRoles();
309  }
310 
311  if ( $this->needSlots ) {
312  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
313  if ( ( $this->fld_slotsha1 || $this->fetchContent ) && ( $revDel & self::IS_DELETED ) ) {
314  $anyHidden = true;
315  }
316  $vals = array_merge( $vals, $this->extractAllSlotInfo( $revision, $revDel ) );
317  }
318  } catch ( RevisionAccessException $ex ) {
319  // This is here so T212428 doesn't spam the log.
320  // TODO: find out why T212428 happens in the first place!
321  $vals['slotsmissing'] = true;
322 
323  LoggerFactory::getInstance( 'api-warning' )->error(
324  'Failed to access revision slots',
325  [ 'revision' => $revision->getId(), 'exception' => $ex, ]
326  );
327  }
328 
329  if ( $this->fld_comment || $this->fld_parsedcomment ) {
330  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_COMMENT );
331  if ( ( $revDel & self::IS_DELETED ) ) {
332  $vals['commenthidden'] = true;
333  $anyHidden = true;
334  }
335  if ( !( $revDel & self::CANNOT_VIEW ) ) {
336  $comment = $revision->getComment( RevisionRecord::RAW );
337  $comment = $comment ? $comment->text : '';
338 
339  if ( $this->fld_comment ) {
340  $vals['comment'] = $comment;
341  }
342 
343  if ( $this->fld_parsedcomment ) {
344  $vals['parsedcomment'] = Linker::formatComment(
345  $comment, Title::newFromLinkTarget( $revision->getPageAsLinkTarget() )
346  );
347  }
348  }
349  }
350 
351  if ( $this->fld_tags ) {
352  if ( $row->ts_tags ) {
353  $tags = explode( ',', $row->ts_tags );
354  ApiResult::setIndexedTagName( $tags, 'tag' );
355  $vals['tags'] = $tags;
356  } else {
357  $vals['tags'] = [];
358  }
359  }
360 
361  if ( $anyHidden && $revision->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
362  $vals['suppressed'] = true;
363  }
364 
365  return $vals;
366  }
367 
377  private function extractAllSlotInfo( RevisionRecord $revision, $revDel ): array {
378  $vals = [];
379 
380  if ( $this->slotRoles === null ) {
381  try {
382  $slot = $revision->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
383  } catch ( RevisionAccessException $e ) {
384  // Back compat: If there's no slot, there's no content, so set 'textmissing'
385  // @todo: Gergő says to mention T198099 as a "todo" here.
386  $vals['textmissing'] = true;
387  $slot = null;
388  }
389 
390  if ( $slot ) {
391  $content = null;
392  $vals += $this->extractSlotInfo( $slot, $revDel, $content );
393  if ( !empty( $vals['nosuchsection'] ) ) {
394  $this->dieWithError(
395  [
396  'apierror-nosuchsection-what',
397  wfEscapeWikiText( $this->section ),
398  $this->msg( 'revid', $revision->getId() )
399  ],
400  'nosuchsection'
401  );
402  }
403  if ( $content ) {
404  $vals += $this->extractDeprecatedContent( $content, $revision );
405  }
406  }
407  } else {
408  $roles = array_intersect( $this->slotRoles, $revision->getSlotRoles() );
409  $vals['slots'] = [
411  ];
412  foreach ( $roles as $role ) {
413  try {
414  $slot = $revision->getSlot( $role, RevisionRecord::RAW );
415  } catch ( RevisionAccessException $e ) {
416  // Don't error out here so the client can still process other slots/revisions.
417  // @todo: Gergő says to mention T198099 as a "todo" here.
418  $vals['slots'][$role]['missing'] = true;
419  continue;
420  }
421  $content = null;
422  $vals['slots'][$role] = $this->extractSlotInfo( $slot, $revDel, $content );
423  // @todo Move this into extractSlotInfo() (and remove its $content parameter)
424  // when extractDeprecatedContent() is no more.
425  if ( $content ) {
427  $vals['slots'][$role]['contentmodel'] = $content->getModel();
428  $vals['slots'][$role]['contentformat'] = $content->getDefaultFormat();
430  $vals['slots'][$role],
431  'content',
432  $content->serialize()
433  );
434  }
435  }
436  ApiResult::setArrayType( $vals['slots'], 'kvp', 'role' );
437  ApiResult::setIndexedTagName( $vals['slots'], 'slot' );
438  }
439  return $vals;
440  }
441 
451  private function extractSlotInfo( SlotRecord $slot, $revDel, &$content = null ) {
452  $vals = [];
453  ApiResult::setArrayType( $vals, 'assoc' );
454 
455  if ( $this->fld_slotsize ) {
456  $vals['size'] = (int)$slot->getSize();
457  }
458 
459  if ( $this->fld_slotsha1 ) {
460  if ( ( $revDel & self::IS_DELETED ) ) {
461  $vals['sha1hidden'] = true;
462  }
463  if ( !( $revDel & self::CANNOT_VIEW ) ) {
464  if ( $slot->getSha1() != '' ) {
465  $vals['sha1'] = Wikimedia\base_convert( $slot->getSha1(), 36, 16, 40 );
466  } else {
467  $vals['sha1'] = '';
468  }
469  }
470  }
471 
472  if ( $this->fld_contentmodel ) {
473  $vals['contentmodel'] = $slot->getModel();
474  }
475 
476  $content = null;
477  if ( $this->fetchContent ) {
478  if ( ( $revDel & self::IS_DELETED ) ) {
479  $vals['texthidden'] = true;
480  }
481  if ( !( $revDel & self::CANNOT_VIEW ) ) {
482  try {
483  $content = $slot->getContent();
484  } catch ( RevisionAccessException $e ) {
485  // @todo: Gergő says to mention T198099 as a "todo" here.
486  $vals['textmissing'] = true;
487  }
488  // Expand templates after getting section content because
489  // template-added sections don't count and Parser::preprocess()
490  // will have less input
491  if ( $content && $this->section !== false ) {
492  $content = $content->getSection( $this->section );
493  if ( !$content ) {
494  $vals['nosuchsection'] = true;
495  }
496  }
497  }
498  }
499 
500  return $vals;
501  }
502 
509  private function extractDeprecatedContent( Content $content, RevisionRecord $revision ) {
510  $vals = [];
512 
513  if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
514  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
516  '@phan-var WikitextContent $content';
517  $t = $content->getText(); # note: don't set $text
518 
519  $parser = MediaWikiServices::getInstance()->getParser();
520  $parser->startExternalParse(
521  $title,
522  ParserOptions::newFromContext( $this->getContext() ),
523  Parser::OT_PREPROCESS
524  );
525  $dom = $parser->preprocessToDom( $t );
526  if ( is_callable( [ $dom, 'saveXML' ] ) ) {
527  // @phan-suppress-next-line PhanUndeclaredMethod
528  $xml = $dom->saveXML();
529  } else {
530  // @phan-suppress-next-line PhanUndeclaredMethod
531  $xml = $dom->__toString();
532  }
533  $vals['parsetree'] = $xml;
534  } else {
535  $vals['badcontentformatforparsetree'] = true;
536  $this->addWarning(
537  [
538  'apierror-parsetree-notwikitext-title',
539  wfEscapeWikiText( $title->getPrefixedText() ),
540  $content->getModel()
541  ],
542  'parsetree-notwikitext'
543  );
544  }
545  }
546 
547  if ( $this->fld_content ) {
548  $text = null;
549 
550  if ( $this->expandTemplates && !$this->parseContent ) {
551  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
553  '@phan-var WikitextContent $content';
554  $text = $content->getText();
555 
556  $text = MediaWikiServices::getInstance()->getParser()->preprocess(
557  $text,
558  $title,
559  ParserOptions::newFromContext( $this->getContext() )
560  );
561  } else {
562  $this->addWarning( [
563  'apierror-templateexpansion-notwikitext',
564  wfEscapeWikiText( $title->getPrefixedText() ),
565  $content->getModel()
566  ] );
567  $vals['badcontentformat'] = true;
568  $text = false;
569  }
570  }
571  if ( $this->parseContent ) {
572  $po = $content->getParserOutput(
573  $title,
574  $revision->getId(),
575  ParserOptions::newFromContext( $this->getContext() )
576  );
577  $text = $po->getText();
578  }
579 
580  if ( $text === null ) {
581  $format = $this->contentFormat ?: $content->getDefaultFormat();
582  $model = $content->getModel();
583 
584  if ( !$content->isSupportedFormat( $format ) ) {
585  $name = wfEscapeWikiText( $title->getPrefixedText() );
586  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
587  $vals['badcontentformat'] = true;
588  $text = false;
589  } else {
590  $text = $content->serialize( $format );
591  // always include format and model.
592  // Format is needed to deserialize, model is needed to interpret.
593  $vals['contentformat'] = $format;
594  $vals['contentmodel'] = $model;
595  }
596  }
597 
598  if ( $text !== false ) {
599  ApiResult::setContentValue( $vals, 'content', $text );
600  }
601  }
602 
603  if ( $content && ( $this->diffto !== null || $this->difftotext !== null ) ) {
604  static $n = 0; // Number of uncached diffs we've had
605 
606  if ( $n < $this->getConfig()->get( 'APIMaxUncachedDiffs' ) ) {
607  $vals['diff'] = [];
608  $context = new DerivativeContext( $this->getContext() );
609  $context->setTitle( $title );
610  $handler = $content->getContentHandler();
611 
612  if ( $this->difftotext !== null ) {
613  $model = $title->getContentModel();
614 
615  if ( $this->contentFormat
616  && !$this->getContentHandlerFactory()
617  ->getContentHandler( $model )
618  ->isSupportedFormat( $this->contentFormat )
619  ) {
620  $name = wfEscapeWikiText( $title->getPrefixedText() );
621  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
622  $vals['diff']['badcontentformat'] = true;
623  $engine = null;
624  } else {
625  $difftocontent = ContentHandler::makeContent(
626  $this->difftotext,
627  $title,
628  $model,
629  $this->contentFormat
630  );
631 
632  if ( $this->difftotextpst ) {
633  $popts = ParserOptions::newFromContext( $this->getContext() );
634  $difftocontent = $difftocontent->preSaveTransform( $title, $this->getUser(), $popts );
635  }
636 
637  $engine = $handler->createDifferenceEngine( $context );
638  $engine->setContent( $content, $difftocontent );
639  }
640  } else {
641  $engine = $handler->createDifferenceEngine( $context, $revision->getId(), $this->diffto );
642  $vals['diff']['from'] = $engine->getOldid();
643  $vals['diff']['to'] = $engine->getNewid();
644  }
645  if ( $engine ) {
646  $difftext = $engine->getDiffBody();
647  ApiResult::setContentValue( $vals['diff'], 'body', $difftext );
648  if ( !$engine->wasCacheHit() ) {
649  $n++;
650  }
651  }
652  } else {
653  $vals['diff']['notcached'] = true;
654  }
655  }
656 
657  return $vals;
658  }
659 
666  public function getCacheMode( $params ) {
667  if ( $this->userCanSeeRevDel() ) {
668  return 'private';
669  }
670 
671  return 'public';
672  }
673 
679  public function getAllowedParams() {
680  $slotRoles = MediaWikiServices::getInstance()->getSlotRoleRegistry()->getKnownRoles();
681  sort( $slotRoles, SORT_STRING );
682 
683  return [
684  'prop' => [
685  ApiBase::PARAM_ISMULTI => true,
686  ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
688  'ids',
689  'flags',
690  'timestamp',
691  'user',
692  'userid',
693  'size',
694  'slotsize',
695  'sha1',
696  'slotsha1',
697  'contentmodel',
698  'comment',
699  'parsedcomment',
700  'content',
701  'tags',
702  'roles',
703  'parsetree',
704  ],
705  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-prop',
707  'ids' => 'apihelp-query+revisions+base-paramvalue-prop-ids',
708  'flags' => 'apihelp-query+revisions+base-paramvalue-prop-flags',
709  'timestamp' => 'apihelp-query+revisions+base-paramvalue-prop-timestamp',
710  'user' => 'apihelp-query+revisions+base-paramvalue-prop-user',
711  'userid' => 'apihelp-query+revisions+base-paramvalue-prop-userid',
712  'size' => 'apihelp-query+revisions+base-paramvalue-prop-size',
713  'slotsize' => 'apihelp-query+revisions+base-paramvalue-prop-slotsize',
714  'sha1' => 'apihelp-query+revisions+base-paramvalue-prop-sha1',
715  'slotsha1' => 'apihelp-query+revisions+base-paramvalue-prop-slotsha1',
716  'contentmodel' => 'apihelp-query+revisions+base-paramvalue-prop-contentmodel',
717  'comment' => 'apihelp-query+revisions+base-paramvalue-prop-comment',
718  'parsedcomment' => 'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
719  'content' => 'apihelp-query+revisions+base-paramvalue-prop-content',
720  'tags' => 'apihelp-query+revisions+base-paramvalue-prop-tags',
721  'roles' => 'apihelp-query+revisions+base-paramvalue-prop-roles',
722  'parsetree' => [ 'apihelp-query+revisions+base-paramvalue-prop-parsetree',
724  ],
726  'parsetree' => true,
727  ],
728  ],
729  'slots' => [
731  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-slots',
732  ApiBase::PARAM_ISMULTI => true,
733  ApiBase::PARAM_ALL => true,
734  ],
735  'limit' => [
736  ApiBase::PARAM_TYPE => 'limit',
737  ApiBase::PARAM_MIN => 1,
740  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-limit',
741  ],
742  'expandtemplates' => [
743  ApiBase::PARAM_DFLT => false,
744  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-expandtemplates',
746  ],
747  'generatexml' => [
748  ApiBase::PARAM_DFLT => false,
750  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-generatexml',
751  ],
752  'parse' => [
753  ApiBase::PARAM_DFLT => false,
754  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-parse',
756  ],
757  'section' => [
758  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-section',
759  ],
760  'diffto' => [
761  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-diffto',
763  ],
764  'difftotext' => [
765  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotext',
767  ],
768  'difftotextpst' => [
769  ApiBase::PARAM_DFLT => false,
770  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotextpst',
772  ],
773  'contentformat' => [
774  ApiBase::PARAM_TYPE => $this->getContentHandlerFactory()->getAllContentFormats(),
775  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-contentformat',
777  ],
778  ];
779  }
780 
782  return MediaWikiServices::getInstance()->getContentHandlerFactory();
783  }
784 }
ApiQueryRevisionsBase\parseParameters
parseParameters( $params)
Parse the parameters into the various instance fields.
Definition: ApiQueryRevisionsBase.php:82
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:37
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:70
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:34
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:45
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1297
ApiQueryRevisionsBase\$fld_slotsize
$fld_slotsize
Definition: ApiQueryRevisionsBase.php:58
Revision\SlotRecord\getContent
getContent()
Returns the Content of the given slot.
Definition: SlotRecord.php:295
ApiQueryGeneratorBase\encodeParamName
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
Definition: ApiQueryGeneratorBase.php:70
ApiQueryRevisionsBase\$fld_comment
$fld_comment
Definition: ApiQueryRevisionsBase.php:59
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:163
Revision\RevisionRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Definition: RevisionRecord.php:412
ApiQueryBase\getParent
getParent()
Get the parent of this module Stable to override.1.25 ApiBase|null
Definition: ApiQueryBase.php:110
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1378
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:106
ApiBase\PARAM_ALL
const PARAM_ALL
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:79
ApiQueryRevisionsBase\$fld_roles
$fld_roles
Definition: ApiQueryRevisionsBase.php:60
ApiQueryRevisionsBase\$section
$section
Definition: ApiQueryRevisionsBase.php:54
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1815
ApiQueryRevisionsBase\CANNOT_VIEW
const CANNOT_VIEW
Definition: ApiQueryRevisionsBase.php:49
ApiQueryRevisionsBase\extractAllSlotInfo
extractAllSlotInfo(RevisionRecord $revision, $revDel)
Extracts information about all relevant slots.
Definition: ApiQueryRevisionsBase.php:377
ApiBase\PARAM_TYPE
const PARAM_TYPE
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:70
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:564
ApiQueryRevisionsBase\$fld_userid
$fld_userid
Definition: ApiQueryRevisionsBase.php:59
Revision\RevisionRecord\getTimestamp
getTimestamp()
MCR migration note: this replaces Revision::getTimestamp.
Definition: RevisionRecord.php:434
ApiQueryRevisionsBase\$fld_sha1
$fld_sha1
Definition: ApiQueryRevisionsBase.php:58
Revision\RevisionRecord\audienceCan
audienceCan( $field, $audience, User $user=null)
Check that the given audience has access to the given field.
Definition: RevisionRecord.php:455
Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:183
ApiQueryRevisionsBase\$fetchContent
$fetchContent
Definition: ApiQueryRevisionsBase.php:54
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:224
ApiQueryRevisionsBase\$setParsedLimit
$setParsedLimit
Definition: ApiQueryRevisionsBase.php:54
ApiQueryRevisionsBase\$slotRoles
$slotRoles
Definition: ApiQueryRevisionsBase.php:55
ContextSource\getUser
getUser()
Stable to override.
Definition: ContextSource.php:134
ApiBase\PARAM_DEPRECATED_VALUES
const PARAM_DEPRECATED_VALUES
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:82
ApiQueryRevisionsBase\$difftotextpst
$difftotextpst
Definition: ApiQueryRevisionsBase.php:53
ApiPageSet
This class contains a list of pages that the client has requested.
Definition: ApiPageSet.php:42
ApiQueryRevisionsBase\$limit
$limit
Definition: ApiQueryRevisionsBase.php:53
ApiQueryRevisionsBase\$fld_content
$fld_content
Definition: ApiQueryRevisionsBase.php:60
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:465
ApiQueryRevisionsBase\$fld_contentmodel
$fld_contentmodel
Definition: ApiQueryRevisionsBase.php:60
ApiQueryRevisionsBase
A base class for functions common to producing a list of revisions.
Definition: ApiQueryRevisionsBase.php:39
ApiQueryRevisionsBase\$fld_slotsha1
$fld_slotsha1
Definition: ApiQueryRevisionsBase.php:58
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:75
ApiBase\PARAM_MIN
const PARAM_MIN
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:73
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
ApiQueryRevisionsBase\$expandTemplates
$expandTemplates
Definition: ApiQueryRevisionsBase.php:53
ApiQueryRevisionsBase\getContentHandlerFactory
getContentHandlerFactory()
Definition: ApiQueryRevisionsBase.php:781
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:715
Revision\RevisionRecord\getSize
getSize()
Returns the nominal size of this revision, in bogo-bytes.
ApiQueryRevisionsBase\$contentFormat
$contentFormat
Definition: ApiQueryRevisionsBase.php:54
Revision\RevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
Revision\RevisionRecord\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's author's user identity, if it's available to the specified audience.
Definition: RevisionRecord.php:363
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:164
ApiQueryRevisionsBase\getAllowedParams
getAllowedParams()
Stable to override.
Definition: ApiQueryRevisionsBase.php:679
Revision\RevisionRecord\isMinor
isMinor()
MCR migration note: this replaces Revision::isMinor.
Definition: RevisionRecord.php:401
ApiBase\PARAM_MAX
const PARAM_MAX
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:71
Revision\SlotRecord\getModel
getModel()
Returns the content model.
Definition: SlotRecord.php:559
$title
$title
Definition: testCompression.php:38
ApiQueryRevisionsBase\$diffto
$diffto
Definition: ApiQueryRevisionsBase.php:53
Revision\RevisionRecord\getSlotRoles
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Definition: RevisionRecord.php:210
WikitextContent
Content object for wiki text pages.
Definition: WikitextContent.php:37
ApiQueryRevisionsBase\$fld_parsetree
$fld_parsetree
Definition: ApiQueryRevisionsBase.php:61
ApiQueryRevisionsBase\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryRevisionsBase.php:63
ApiQueryRevisionsBase\IS_DELETED
const IS_DELETED
Definition: ApiQueryRevisionsBase.php:48
ApiQueryRevisionsBase\$fld_tags
$fld_tags
Definition: ApiQueryRevisionsBase.php:60
ApiQueryRevisionsBase\$needSlots
$needSlots
Definition: ApiQueryRevisionsBase.php:55
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:142
Revision\SlotRecord\getSha1
getSha1()
Returns the content size.
Definition: SlotRecord.php:531
ApiQueryRevisionsBase\checkRevDel
checkRevDel(RevisionRecord $revision, $field)
Test revision deletion status.
Definition: ApiQueryRevisionsBase.php:221
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:451
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:271
ContextSource\msg
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
Revision\RevisionRecord\getParentId
getParentId()
Get parent revision ID (the original previous page revision).
Definition: RevisionRecord.php:287
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:603
$content
$content
Definition: router.php:76
Revision\SlotRecord\getSize
getSize()
Returns the content size.
Definition: SlotRecord.php:515
ApiQueryRevisionsBase\$parseContent
$parseContent
Definition: ApiQueryRevisionsBase.php:54
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1100
ApiBase\addDeprecation
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
Definition: ApiBase.php:1311
MediaWiki\Content\IContentHandlerFactory
Definition: IContentHandlerFactory.php:10
ApiBase\LIMIT_SML2
const LIMIT_SML2
Slow query, apihighlimits limit.
Definition: ApiBase.php:170
ApiQueryRevisionsBase\extractRevisionInfo
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
Definition: ApiQueryRevisionsBase.php:238
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1494
Revision\RevisionRecord\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment, if it's available to the specified audience.
Definition: RevisionRecord.php:388
ApiQueryRevisionsBase\getCacheMode
getCacheMode( $params)
Stable to override.
Definition: ApiQueryRevisionsBase.php:666
ApiQueryRevisionsBase\$fld_flags
$fld_flags
Definition: ApiQueryRevisionsBase.php:57
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:280
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:1199
Content
Base interface for content objects.
Definition: Content.php:35
ApiQueryRevisionsBase\$difftotext
$difftotext
Definition: ApiQueryRevisionsBase.php:53
ApiQueryGeneratorBase
Stable to extend.
Definition: ApiQueryGeneratorBase.php:28
ApiQueryRevisionsBase\$fld_ids
$fld_ids
Definition: ApiQueryRevisionsBase.php:57
Revision\RevisionRecord\getPageAsLinkTarget
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Definition: RevisionRecord.php:343
Wikimedia\ParamValidator\TypeDef\IntegerDef
Type definition for integer types.
Definition: IntegerDef.php:23
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:166
ApiBase\PARAM_DFLT
const PARAM_DFLT
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:68
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:443
ApiQueryRevisionsBase\$fld_user
$fld_user
Definition: ApiQueryRevisionsBase.php:59
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:69
ApiQueryRevisionsBase\$fld_timestamp
$fld_timestamp
Definition: ApiQueryRevisionsBase.php:57
ApiBase\PARAM_MAX2
const PARAM_MAX2
(boolean) Inverse of IntegerDef::PARAM_IGNORE_RANGE
Definition: ApiBase.php:72
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:459
ApiResult\META_KVP_MERGE
const META_KVP_MERGE
Key for the metadata item that indicates that the KVP key should be added into an assoc value,...
Definition: ApiResult.php:129
ApiQueryRevisionsBase\executeGenerator
executeGenerator( $resultPageSet)
Execute this module as a generator.
Definition: ApiQueryRevisionsBase.php:67
$t
$t
Definition: testCompression.php:74
ApiQueryRevisionsBase\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryRevisionsBase.php:59
ApiQueryRevisionsBase\run
run(ApiPageSet $resultPageSet=null)
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:139
ApiQueryBase\userCanSeeRevDel
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Definition: ApiQueryBase.php:611
ApiQueryRevisionsBase\$fld_size
$fld_size
Definition: ApiQueryRevisionsBase.php:58
Wikimedia\ParamValidator\ParamValidator
Service for formatting and validating API parameters.
Definition: ParamValidator.php:42
ApiQueryRevisionsBase\extractDeprecatedContent
extractDeprecatedContent(Content $content, RevisionRecord $revision)
Format a Content using deprecated options.
Definition: ApiQueryRevisionsBase.php:509
ApiQueryRevisionsBase\extractSlotInfo
extractSlotInfo(SlotRecord $slot, $revDel, &$content=null)
Extract information from the SlotRecord.
Definition: ApiQueryRevisionsBase.php:451
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:40
ApiBase\LIMIT_SML1
const LIMIT_SML1
Slow query, standard limit.
Definition: ApiBase.php:168
ApiQueryRevisionsBase\$generateXML
$generateXML
Definition: ApiQueryRevisionsBase.php:53