MediaWiki  1.32.5
ApiQueryRevisionsBase.php
Go to the documentation of this file.
1 <?php
27 
34 
40  // Bits to indicate the results of the revdel permission check on a revision,
41  // see self::checkRevDel()
42  const IS_DELETED = 1; // Whether the field is revision-deleted
43  const CANNOT_VIEW = 2; // Whether the user cannot view the field due to revdel
44 
50 
51  protected $fld_ids = false, $fld_flags = false, $fld_timestamp = false,
52  $fld_size = false, $fld_slotsize = false, $fld_sha1 = false, $fld_slotsha1 = false,
53  $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
54  $fld_content = false, $fld_tags = false, $fld_contentmodel = false, $fld_roles = false,
55  $fld_parsetree = false;
56 
57  public function execute() {
58  $this->run();
59  }
60 
61  public function executeGenerator( $resultPageSet ) {
62  $this->run( $resultPageSet );
63  }
64 
69  abstract protected function run( ApiPageSet $resultPageSet = null );
70 
76  protected function parseParameters( $params ) {
77  $prop = array_flip( $params['prop'] );
78 
79  $this->fld_ids = isset( $prop['ids'] );
80  $this->fld_flags = isset( $prop['flags'] );
81  $this->fld_timestamp = isset( $prop['timestamp'] );
82  $this->fld_comment = isset( $prop['comment'] );
83  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
84  $this->fld_size = isset( $prop['size'] );
85  $this->fld_slotsize = isset( $prop['slotsize'] );
86  $this->fld_sha1 = isset( $prop['sha1'] );
87  $this->fld_slotsha1 = isset( $prop['slotsha1'] );
88  $this->fld_content = isset( $prop['content'] );
89  $this->fld_contentmodel = isset( $prop['contentmodel'] );
90  $this->fld_userid = isset( $prop['userid'] );
91  $this->fld_user = isset( $prop['user'] );
92  $this->fld_tags = isset( $prop['tags'] );
93  $this->fld_roles = isset( $prop['roles'] );
94  $this->fld_parsetree = isset( $prop['parsetree'] );
95 
96  $this->slotRoles = $params['slots'];
97 
98  if ( $this->slotRoles !== null ) {
99  if ( $this->fld_parsetree ) {
100  $this->dieWithError( [
101  'apierror-invalidparammix-cannotusewith',
102  $this->encodeParamName( 'prop=parsetree' ),
103  $this->encodeParamName( 'slots' ),
104  ], 'invalidparammix' );
105  }
106  foreach ( [
107  'expandtemplates', 'generatexml', 'parse', 'diffto', 'difftotext', 'difftotextpst',
108  'contentformat'
109  ] as $p ) {
110  if ( $params[$p] !== null && $params[$p] !== false ) {
111  $this->dieWithError( [
112  'apierror-invalidparammix-cannotusewith',
113  $this->encodeParamName( $p ),
114  $this->encodeParamName( 'slots' ),
115  ], 'invalidparammix' );
116  }
117  }
118  }
119 
120  if ( !empty( $params['contentformat'] ) ) {
121  $this->contentFormat = $params['contentformat'];
122  }
123 
124  $this->limit = $params['limit'];
125 
126  if ( !is_null( $params['difftotext'] ) ) {
127  $this->difftotext = $params['difftotext'];
128  $this->difftotextpst = $params['difftotextpst'];
129  } elseif ( !is_null( $params['diffto'] ) ) {
130  if ( $params['diffto'] == 'cur' ) {
131  $params['diffto'] = 0;
132  }
133  if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
134  && $params['diffto'] != 'prev' && $params['diffto'] != 'next'
135  ) {
136  $p = $this->getModulePrefix();
137  $this->dieWithError( [ 'apierror-baddiffto', $p ], 'diffto' );
138  }
139  // Check whether the revision exists and is readable,
140  // DifferenceEngine returns a rather ambiguous empty
141  // string if that's not the case
142  if ( $params['diffto'] != 0 ) {
143  $difftoRev = MediaWikiServices::getInstance()->getRevisionStore()
144  ->getRevisionById( $params['diffto'] );
145  if ( !$difftoRev ) {
146  $this->dieWithError( [ 'apierror-nosuchrevid', $params['diffto'] ] );
147  }
148  $revDel = $this->checkRevDel( $difftoRev, RevisionRecord::DELETED_TEXT );
149  if ( $revDel & self::CANNOT_VIEW ) {
150  $this->addWarning( [ 'apiwarn-difftohidden', $difftoRev->getId() ] );
151  $params['diffto'] = null;
152  }
153  }
154  $this->diffto = $params['diffto'];
155  }
156 
157  $this->fetchContent = $this->fld_content || !is_null( $this->diffto )
158  || !is_null( $this->difftotext ) || $this->fld_parsetree;
159 
160  $smallLimit = false;
161  if ( $this->fetchContent ) {
162  $smallLimit = true;
163  $this->expandTemplates = $params['expandtemplates'];
164  $this->generateXML = $params['generatexml'];
165  $this->parseContent = $params['parse'];
166  if ( $this->parseContent ) {
167  // Must manually initialize unset limit
168  if ( is_null( $this->limit ) ) {
169  $this->limit = 1;
170  }
171  }
172  if ( isset( $params['section'] ) ) {
173  $this->section = $params['section'];
174  } else {
175  $this->section = false;
176  }
177  }
178 
179  $userMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
180  $botMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
181  if ( $this->limit == 'max' ) {
182  $this->limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
183  if ( $this->setParsedLimit ) {
184  $this->getResult()->addParsedLimit( $this->getModuleName(), $this->limit );
185  }
186  }
187 
188  if ( is_null( $this->limit ) ) {
189  $this->limit = 10;
190  }
191  $this->validateLimit( 'limit', $this->limit, 1, $userMax, $botMax );
192 
193  $this->needSlots = $this->fetchContent || $this->fld_contentmodel ||
194  $this->fld_slotsize || $this->fld_slotsha1;
195  if ( $this->needSlots && $this->slotRoles === null ) {
196  $encParam = $this->encodeParamName( 'slots' );
197  $name = $this->getModuleName();
198  $parent = $this->getParent();
199  $parentParam = $parent->encodeParamName( $parent->getModuleManager()->getModuleGroup( $name ) );
200  $this->addDeprecation(
201  [ 'apiwarn-deprecation-missingparam', $encParam ],
202  "action=query&{$parentParam}={$name}&!{$encParam}"
203  );
204  }
205  }
206 
214  private function checkRevDel( RevisionRecord $revision, $field ) {
215  $ret = $revision->isDeleted( $field ) ? self::IS_DELETED : 0;
216  if ( $ret ) {
217  $canSee = $revision->audienceCan( $field, RevisionRecord::FOR_THIS_USER, $this->getUser() );
218  $ret = $ret | ( $canSee ? 0 : self::CANNOT_VIEW );
219  }
220  return $ret;
221  }
222 
231  protected function extractRevisionInfo( RevisionRecord $revision, $row ) {
232  $vals = [];
233  $anyHidden = false;
234 
235  if ( $this->fld_ids ) {
236  $vals['revid'] = intval( $revision->getId() );
237  if ( !is_null( $revision->getParentId() ) ) {
238  $vals['parentid'] = intval( $revision->getParentId() );
239  }
240  }
241 
242  if ( $this->fld_flags ) {
243  $vals['minor'] = $revision->isMinor();
244  }
245 
246  if ( $this->fld_user || $this->fld_userid ) {
247  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_USER );
248  if ( ( $revDel & self::IS_DELETED ) ) {
249  $vals['userhidden'] = true;
250  $anyHidden = true;
251  }
252  if ( !( $revDel & self::CANNOT_VIEW ) ) {
253  $u = $revision->getUser( RevisionRecord::RAW );
254  if ( $this->fld_user ) {
255  $vals['user'] = $u->getName();
256  }
257  $userid = $u->getId();
258  if ( !$userid ) {
259  $vals['anon'] = true;
260  }
261 
262  if ( $this->fld_userid ) {
263  $vals['userid'] = $userid;
264  }
265  }
266  }
267 
268  if ( $this->fld_timestamp ) {
269  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
270  }
271 
272  if ( $this->fld_size ) {
273  try {
274  $vals['size'] = intval( $revision->getSize() );
275  } catch ( RevisionAccessException $e ) {
276  // Back compat: If there's no size, return 0.
277  // @todo: Gergő says to mention T198099 as a "todo" here.
278  $vals['size'] = 0;
279  }
280  }
281 
282  if ( $this->fld_sha1 ) {
283  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
284  if ( ( $revDel & self::IS_DELETED ) ) {
285  $vals['sha1hidden'] = true;
286  $anyHidden = true;
287  }
288  if ( !( $revDel & self::CANNOT_VIEW ) ) {
289  try {
290  $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 );
291  } catch ( RevisionAccessException $e ) {
292  // Back compat: If there's no sha1, return emtpy string.
293  // @todo: Gergő says to mention T198099 as a "todo" here.
294  $vals['sha1'] = '';
295  }
296  }
297  }
298 
299  if ( $this->fld_roles ) {
300  $vals['roles'] = $revision->getSlotRoles();
301  }
302 
303  if ( $this->needSlots ) {
304  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
305  if ( ( $this->fld_slotsha1 || $this->fetchContent ) && ( $revDel & self::IS_DELETED ) ) {
306  $anyHidden = true;
307  }
308  if ( $this->slotRoles === null ) {
309  try {
310  $slot = $revision->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
311  } catch ( RevisionAccessException $e ) {
312  // Back compat: If there's no slot, there's no content, so set 'textmissing'
313  // @todo: Gergő says to mention T198099 as a "todo" here.
314  $vals['textmissing'] = true;
315  $slot = null;
316  }
317 
318  if ( $slot ) {
319  $content = null;
320  $vals += $this->extractSlotInfo( $slot, $revDel, $content );
321  if ( !empty( $vals['nosuchsection'] ) ) {
322  $this->dieWithError(
323  [
324  'apierror-nosuchsection-what',
325  wfEscapeWikiText( $this->section ),
326  $this->msg( 'revid', $revision->getId() )
327  ],
328  'nosuchsection'
329  );
330  }
331  if ( $content ) {
332  $vals += $this->extractDeprecatedContent( $content, $revision );
333  }
334  }
335  } else {
336  $roles = array_intersect( $this->slotRoles, $revision->getSlotRoles() );
337  $vals['slots'] = [
339  ];
340  foreach ( $roles as $role ) {
341  try {
342  $slot = $revision->getSlot( $role, RevisionRecord::RAW );
343  } catch ( RevisionAccessException $e ) {
344  // Don't error out here so the client can still process other slots/revisions.
345  // @todo: Gergő says to mention T198099 as a "todo" here.
346  $vals['slots'][$role]['missing'] = true;
347  continue;
348  }
349  $content = null;
350  $vals['slots'][$role] = $this->extractSlotInfo( $slot, $revDel, $content );
351  // @todo Move this into extractSlotInfo() (and remove its $content parameter)
352  // when extractDeprecatedContent() is no more.
353  if ( $content ) {
354  $vals['slots'][$role]['contentmodel'] = $content->getModel();
355  $vals['slots'][$role]['contentformat'] = $content->getDefaultFormat();
356  ApiResult::setContentValue( $vals['slots'][$role], 'content', $content->serialize() );
357  }
358  }
359  ApiResult::setArrayType( $vals['slots'], 'kvp', 'role' );
360  ApiResult::setIndexedTagName( $vals['slots'], 'slot' );
361  }
362  }
363 
364  if ( $this->fld_comment || $this->fld_parsedcomment ) {
365  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_COMMENT );
366  if ( ( $revDel & self::IS_DELETED ) ) {
367  $vals['commenthidden'] = true;
368  $anyHidden = true;
369  }
370  if ( !( $revDel & self::CANNOT_VIEW ) ) {
371  $comment = $revision->getComment( RevisionRecord::RAW );
372  $comment = $comment ? $comment->text : '';
373 
374  if ( $this->fld_comment ) {
375  $vals['comment'] = $comment;
376  }
377 
378  if ( $this->fld_parsedcomment ) {
379  $vals['parsedcomment'] = Linker::formatComment(
380  $comment, Title::newFromLinkTarget( $revision->getPageAsLinkTarget() )
381  );
382  }
383  }
384  }
385 
386  if ( $this->fld_tags ) {
387  if ( $row->ts_tags ) {
388  $tags = explode( ',', $row->ts_tags );
389  ApiResult::setIndexedTagName( $tags, 'tag' );
390  $vals['tags'] = $tags;
391  } else {
392  $vals['tags'] = [];
393  }
394  }
395 
396  if ( $anyHidden && $revision->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
397  $vals['suppressed'] = true;
398  }
399 
400  return $vals;
401  }
402 
412  private function extractSlotInfo( SlotRecord $slot, $revDel, &$content = null ) {
413  $vals = [];
414  ApiResult::setArrayType( $vals, 'assoc' );
415 
416  if ( $this->fld_slotsize ) {
417  $vals['size'] = intval( $slot->getSize() );
418  }
419 
420  if ( $this->fld_slotsha1 ) {
421  if ( ( $revDel & self::IS_DELETED ) ) {
422  $vals['sha1hidden'] = true;
423  }
424  if ( !( $revDel & self::CANNOT_VIEW ) ) {
425  if ( $slot->getSha1() != '' ) {
426  $vals['sha1'] = Wikimedia\base_convert( $slot->getSha1(), 36, 16, 40 );
427  } else {
428  $vals['sha1'] = '';
429  }
430  }
431  }
432 
433  if ( $this->fld_contentmodel ) {
434  $vals['contentmodel'] = $slot->getModel();
435  }
436 
437  $content = null;
438  if ( $this->fetchContent ) {
439  if ( ( $revDel & self::IS_DELETED ) ) {
440  $vals['texthidden'] = true;
441  }
442  if ( !( $revDel & self::CANNOT_VIEW ) ) {
443  try {
444  $content = $slot->getContent();
445  } catch ( RevisionAccessException $e ) {
446  // @todo: Gergő says to mention T198099 as a "todo" here.
447  $vals['textmissing'] = true;
448  }
449  // Expand templates after getting section content because
450  // template-added sections don't count and Parser::preprocess()
451  // will have less input
452  if ( $content && $this->section !== false ) {
453  $content = $content->getSection( $this->section, false );
454  if ( !$content ) {
455  $vals['nosuchsection'] = true;
456  }
457  }
458  }
459  }
460 
461  return $vals;
462  }
463 
470  private function extractDeprecatedContent( Content $content, RevisionRecord $revision ) {
471  global $wgParser;
472 
473  $vals = [];
475 
476  if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
477  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
478  $t = $content->getNativeData(); # note: don't set $text
479 
480  $wgParser->startExternalParse(
481  $title,
482  ParserOptions::newFromContext( $this->getContext() ),
483  Parser::OT_PREPROCESS
484  );
485  $dom = $wgParser->preprocessToDom( $t );
486  if ( is_callable( [ $dom, 'saveXML' ] ) ) {
487  $xml = $dom->saveXML();
488  } else {
489  $xml = $dom->__toString();
490  }
491  $vals['parsetree'] = $xml;
492  } else {
493  $vals['badcontentformatforparsetree'] = true;
494  $this->addWarning(
495  [
496  'apierror-parsetree-notwikitext-title',
497  wfEscapeWikiText( $title->getPrefixedText() ),
498  $content->getModel()
499  ],
500  'parsetree-notwikitext'
501  );
502  }
503  }
504 
505  if ( $this->fld_content ) {
506  $text = null;
507 
508  if ( $this->expandTemplates && !$this->parseContent ) {
509  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
510  $text = $content->getNativeData();
511 
512  $text = $wgParser->preprocess(
513  $text,
514  $title,
515  ParserOptions::newFromContext( $this->getContext() )
516  );
517  } else {
518  $this->addWarning( [
519  'apierror-templateexpansion-notwikitext',
520  wfEscapeWikiText( $title->getPrefixedText() ),
521  $content->getModel()
522  ] );
523  $vals['badcontentformat'] = true;
524  $text = false;
525  }
526  }
527  if ( $this->parseContent ) {
528  $po = $content->getParserOutput(
529  $title,
530  $revision->getId(),
531  ParserOptions::newFromContext( $this->getContext() )
532  );
533  $text = $po->getText();
534  }
535 
536  if ( $text === null ) {
537  $format = $this->contentFormat ?: $content->getDefaultFormat();
538  $model = $content->getModel();
539 
540  if ( !$content->isSupportedFormat( $format ) ) {
541  $name = wfEscapeWikiText( $title->getPrefixedText() );
542  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
543  $vals['badcontentformat'] = true;
544  $text = false;
545  } else {
546  $text = $content->serialize( $format );
547  // always include format and model.
548  // Format is needed to deserialize, model is needed to interpret.
549  $vals['contentformat'] = $format;
550  $vals['contentmodel'] = $model;
551  }
552  }
553 
554  if ( $text !== false ) {
555  ApiResult::setContentValue( $vals, 'content', $text );
556  }
557  }
558 
559  if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
560  static $n = 0; // Number of uncached diffs we've had
561 
562  if ( $n < $this->getConfig()->get( 'APIMaxUncachedDiffs' ) ) {
563  $vals['diff'] = [];
564  $context = new DerivativeContext( $this->getContext() );
565  $context->setTitle( $title );
566  $handler = $content->getContentHandler();
567 
568  if ( !is_null( $this->difftotext ) ) {
569  $model = $title->getContentModel();
570 
571  if ( $this->contentFormat
572  && !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat )
573  ) {
574  $name = wfEscapeWikiText( $title->getPrefixedText() );
575  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
576  $vals['diff']['badcontentformat'] = true;
577  $engine = null;
578  } else {
579  $difftocontent = ContentHandler::makeContent(
580  $this->difftotext,
581  $title,
582  $model,
583  $this->contentFormat
584  );
585 
586  if ( $this->difftotextpst ) {
587  $popts = ParserOptions::newFromContext( $this->getContext() );
588  $difftocontent = $difftocontent->preSaveTransform( $title, $this->getUser(), $popts );
589  }
590 
591  $engine = $handler->createDifferenceEngine( $context );
592  $engine->setContent( $content, $difftocontent );
593  }
594  } else {
595  $engine = $handler->createDifferenceEngine( $context, $revision->getId(), $this->diffto );
596  $vals['diff']['from'] = $engine->getOldid();
597  $vals['diff']['to'] = $engine->getNewid();
598  }
599  if ( $engine ) {
600  $difftext = $engine->getDiffBody();
601  ApiResult::setContentValue( $vals['diff'], 'body', $difftext );
602  if ( !$engine->wasCacheHit() ) {
603  $n++;
604  }
605  }
606  } else {
607  $vals['diff']['notcached'] = true;
608  }
609  }
610 
611  return $vals;
612  }
613 
614  public function getCacheMode( $params ) {
615  if ( $this->userCanSeeRevDel() ) {
616  return 'private';
617  }
618 
619  return 'public';
620  }
621 
622  public function getAllowedParams() {
623  $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
624  if ( !in_array( SlotRecord::MAIN, $slotRoles, true ) ) {
625  $slotRoles[] = SlotRecord::MAIN;
626  }
627  sort( $slotRoles, SORT_STRING );
628 
629  return [
630  'prop' => [
631  ApiBase::PARAM_ISMULTI => true,
632  ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
634  'ids',
635  'flags',
636  'timestamp',
637  'user',
638  'userid',
639  'size',
640  'slotsize',
641  'sha1',
642  'slotsha1',
643  'contentmodel',
644  'comment',
645  'parsedcomment',
646  'content',
647  'tags',
648  'roles',
649  'parsetree',
650  ],
651  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-prop',
653  'ids' => 'apihelp-query+revisions+base-paramvalue-prop-ids',
654  'flags' => 'apihelp-query+revisions+base-paramvalue-prop-flags',
655  'timestamp' => 'apihelp-query+revisions+base-paramvalue-prop-timestamp',
656  'user' => 'apihelp-query+revisions+base-paramvalue-prop-user',
657  'userid' => 'apihelp-query+revisions+base-paramvalue-prop-userid',
658  'size' => 'apihelp-query+revisions+base-paramvalue-prop-size',
659  'slotsize' => 'apihelp-query+revisions+base-paramvalue-prop-slotsize',
660  'sha1' => 'apihelp-query+revisions+base-paramvalue-prop-sha1',
661  'slotsha1' => 'apihelp-query+revisions+base-paramvalue-prop-slotsha1',
662  'contentmodel' => 'apihelp-query+revisions+base-paramvalue-prop-contentmodel',
663  'comment' => 'apihelp-query+revisions+base-paramvalue-prop-comment',
664  'parsedcomment' => 'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
665  'content' => 'apihelp-query+revisions+base-paramvalue-prop-content',
666  'tags' => 'apihelp-query+revisions+base-paramvalue-prop-tags',
667  'roles' => 'apihelp-query+revisions+base-paramvalue-prop-roles',
668  'parsetree' => [ 'apihelp-query+revisions+base-paramvalue-prop-parsetree',
670  ],
672  'parsetree' => true,
673  ],
674  ],
675  'slots' => [
677  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-slots',
678  ApiBase::PARAM_ISMULTI => true,
679  ApiBase::PARAM_ALL => true,
680  ],
681  'limit' => [
682  ApiBase::PARAM_TYPE => 'limit',
683  ApiBase::PARAM_MIN => 1,
686  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-limit',
687  ],
688  'expandtemplates' => [
689  ApiBase::PARAM_DFLT => false,
690  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-expandtemplates',
692  ],
693  'generatexml' => [
694  ApiBase::PARAM_DFLT => false,
696  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-generatexml',
697  ],
698  'parse' => [
699  ApiBase::PARAM_DFLT => false,
700  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-parse',
702  ],
703  'section' => [
704  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-section',
705  ],
706  'diffto' => [
707  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-diffto',
709  ],
710  'difftotext' => [
711  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotext',
713  ],
714  'difftotextpst' => [
715  ApiBase::PARAM_DFLT => false,
716  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotextpst',
718  ],
719  'contentformat' => [
721  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-contentformat',
723  ],
724  ];
725  }
726 
727 }
Content\getContentHandler
getContentHandler()
Convenience method that returns the ContentHandler singleton for handling the content model that this...
ApiQueryRevisionsBase\parseParameters
parseParameters( $params)
Parse the parameters into the various instance fields.
Definition: ApiQueryRevisionsBase.php:76
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
ContextSource\getConfig
getConfig()
Definition: ContextSource.php:63
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:297
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:33
ContextSource\getContext
getContext()
Get the base IContextSource object.
Definition: ContextSource.php:40
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
ContentHandler\getAllContentFormats
static getAllContentFormats()
Definition: ContentHandler.php:380
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1906
ApiQueryRevisionsBase\$fld_slotsize
$fld_slotsize
Definition: ApiQueryRevisionsBase.php:52
Revision\SlotRecord\getContent
getContent()
Returns the Content of the given slot.
Definition: SlotRecord.php:304
ApiQueryGeneratorBase\encodeParamName
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
Definition: ApiQueryGeneratorBase.php:71
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
$wgParser
$wgParser
Definition: Setup.php:921
ApiQueryRevisionsBase\$fld_comment
$fld_comment
Definition: ApiQueryRevisionsBase.php:53
Revision\RevisionRecord\isDeleted
isDeleted( $field)
MCR migration note: this replaces Revision::isDeleted.
Definition: RevisionRecord.php:414
ApiQueryBase\getParent
getParent()
@inheritDoc
Definition: ApiQueryBase.php:97
ApiBase\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1987
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:124
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
ApiBase\PARAM_ALL
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
Definition: ApiBase.php:180
ApiQueryRevisionsBase\$fld_roles
$fld_roles
Definition: ApiQueryRevisionsBase.php:54
ApiQueryRevisionsBase\$section
$section
Definition: ApiQueryRevisionsBase.php:47
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1954
ApiQueryRevisionsBase\CANNOT_VIEW
const CANNOT_VIEW
Definition: ApiQueryRevisionsBase.php:43
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:659
ApiQueryRevisionsBase\$fld_userid
$fld_userid
Definition: ApiQueryRevisionsBase.php:53
Revision\RevisionRecord\getTimestamp
getTimestamp()
MCR migration note: this replaces Revision::getTimestamp.
Definition: RevisionRecord.php:436
ApiQueryRevisionsBase\$fld_sha1
$fld_sha1
Definition: ApiQueryRevisionsBase.php:52
$params
$params
Definition: styleTest.css.php:44
Revision\RevisionRecord\audienceCan
audienceCan( $field, $audience, User $user=null)
Check that the given audience has access to the given field.
Definition: RevisionRecord.php:457
Revision\RevisionRecord\getSlot
getSlot( $role, $audience=self::FOR_PUBLIC, User $user=null)
Returns meta-data for the given slot.
Definition: RevisionRecord.php:191
ApiQueryRevisionsBase\$fetchContent
$fetchContent
Definition: ApiQueryRevisionsBase.php:47
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
ApiQueryRevisionsBase\$setParsedLimit
$setParsedLimit
Definition: ApiQueryRevisionsBase.php:48
ApiQueryRevisionsBase\$slotRoles
$slotRoles
Definition: ApiQueryRevisionsBase.php:49
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
ApiBase\PARAM_DEPRECATED_VALUES
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
Definition: ApiBase.php:202
ApiQueryRevisionsBase\$difftotextpst
$difftotextpst
Definition: ApiQueryRevisionsBase.php:47
ApiPageSet
This class contains a list of pages that the client has requested.
Definition: ApiPageSet.php:40
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiQueryRevisionsBase\$limit
$limit
Definition: ApiQueryRevisionsBase.php:47
ApiQueryRevisionsBase\$fld_content
$fld_content
Definition: ApiQueryRevisionsBase.php:54
ApiResult\setContentValue
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
Definition: ApiResult.php:478
ApiQueryRevisionsBase\$fld_contentmodel
$fld_contentmodel
Definition: ApiQueryRevisionsBase.php:54
ApiQueryRevisionsBase
A base class for functions common to producing a list of revisions.
Definition: ApiQueryRevisionsBase.php:33
ApiQueryRevisionsBase\$fld_slotsha1
$fld_slotsha1
Definition: ApiQueryRevisionsBase.php:52
ApiBase\PARAM_DEPRECATED
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
Definition: ApiBase.php:105
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:99
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:30
ApiQueryRevisionsBase\$expandTemplates
$expandTemplates
Definition: ApiQueryRevisionsBase.php:47
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:728
Revision\RevisionRecord\getSize
getSize()
Returns the nominal size of this revision, in bogo-bytes.
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
ApiQueryRevisionsBase\$contentFormat
$contentFormat
Definition: ApiQueryRevisionsBase.php:47
Revision\RevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
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:365
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:251
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Fast query, standard limit.
Definition: ApiBase.php:252
ApiQueryRevisionsBase\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryRevisionsBase.php:622
Revision\RevisionRecord\isMinor
isMinor()
MCR migration note: this replaces Revision::isMinor.
Definition: RevisionRecord.php:403
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:90
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Revision\SlotRecord\getModel
getModel()
Returns the content model.
Definition: SlotRecord.php:563
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2946
ApiQueryRevisionsBase\$diffto
$diffto
Definition: ApiQueryRevisionsBase.php:47
Revision\RevisionRecord\getSlotRoles
getSlotRoles()
Returns the slot names (roles) of all slots present in this revision.
Definition: RevisionRecord.php:218
ApiQueryRevisionsBase\$fld_parsetree
$fld_parsetree
Definition: ApiQueryRevisionsBase.php:55
ApiQueryRevisionsBase\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryRevisionsBase.php:57
ApiQueryRevisionsBase\IS_DELETED
const IS_DELETED
Definition: ApiQueryRevisionsBase.php:42
ApiQueryRevisionsBase\$fld_tags
$fld_tags
Definition: ApiQueryRevisionsBase.php:54
ApiQueryRevisionsBase\$needSlots
$needSlots
Definition: ApiQueryRevisionsBase.php:49
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:133
Revision\SlotRecord\getSha1
getSha1()
Returns the content size.
Definition: SlotRecord.php:540
ApiQueryRevisionsBase\checkRevDel
checkRevDel(RevisionRecord $revision, $field)
Test revision deletion status.
Definition: ApiQueryRevisionsBase.php:214
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:547
Revision\RevisionRecord\getId
getId()
Get revision ID.
Definition: RevisionRecord.php:273
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Revision\RevisionRecord\getParentId
getParentId()
Get parent revision ID (the original previous page revision).
Definition: RevisionRecord.php:289
ApiResult\setIndexedTagName
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Definition: ApiResult.php:616
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2221
Revision\SlotRecord\getSize
getSize()
Returns the content size.
Definition: SlotRecord.php:524
ApiQueryRevisionsBase\$parseContent
$parseContent
Definition: ApiQueryRevisionsBase.php:47
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1040
ApiBase\addDeprecation
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
Definition: ApiBase.php:1920
ApiBase\LIMIT_SML2
const LIMIT_SML2
Slow query, apihighlimits limit.
Definition: ApiBase.php:258
title
title
Definition: parserTests.txt:239
ApiQueryRevisionsBase\extractRevisionInfo
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
Definition: ApiQueryRevisionsBase.php:231
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1617
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:2044
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:390
ApiQueryRevisionsBase\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryRevisionsBase.php:614
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:813
ApiQueryRevisionsBase\$fld_flags
$fld_flags
Definition: ApiQueryRevisionsBase.php:51
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:1088
Content
Base interface for content objects.
Definition: Content.php:34
ApiQueryRevisionsBase\$difftotext
$difftotext
Definition: ApiQueryRevisionsBase.php:47
ApiQueryGeneratorBase
Definition: ApiQueryGeneratorBase.php:26
ApiQueryRevisionsBase\$fld_ids
$fld_ids
Definition: ApiQueryRevisionsBase.php:51
Revision\RevisionRecord\getPageAsLinkTarget
getPageAsLinkTarget()
Returns the title of the page this revision is associated with as a LinkTarget object.
Definition: RevisionRecord.php:345
$parent
$parent
Definition: pageupdater.txt:71
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition: ApiBase.php:254
ApiBase\validateLimit
validateLimit( $paramName, &$value, $min, $max, $botMax=null, $enforceLimits=false)
Validate the value against the minimum and user/bot maximum limits.
Definition: ApiBase.php:1580
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:539
ApiQueryRevisionsBase\$fld_user
$fld_user
Definition: ApiQueryRevisionsBase.php:53
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:51
ApiQueryRevisionsBase\$fld_timestamp
$fld_timestamp
Definition: ApiQueryRevisionsBase.php:51
ApiBase\PARAM_MAX2
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition: ApiBase.php:96
$content
$content
Definition: pageupdater.txt:72
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:555
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:61
$t
$t
Definition: testCompression.php:69
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
ApiQueryRevisionsBase\$fld_parsedcomment
$fld_parsedcomment
Definition: ApiQueryRevisionsBase.php:53
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:157
ApiQueryBase\userCanSeeRevDel
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
Definition: ApiQueryBase.php:606
ApiQueryRevisionsBase\$fld_size
$fld_size
Definition: ApiQueryRevisionsBase.php:52
ApiQueryRevisionsBase\extractDeprecatedContent
extractDeprecatedContent(Content $content, RevisionRecord $revision)
Format a Content using deprecated options.
Definition: ApiQueryRevisionsBase.php:470
ApiQueryRevisionsBase\extractSlotInfo
extractSlotInfo(SlotRecord $slot, $revDel, &$content=null)
Extract information from the SlotRecord.
Definition: ApiQueryRevisionsBase.php:412
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
ApiBase\LIMIT_SML1
const LIMIT_SML1
Slow query, standard limit.
Definition: ApiBase.php:256
ApiQueryRevisionsBase\$generateXML
$generateXML
Definition: ApiQueryRevisionsBase.php:47