MediaWiki  1.33.0
ApiQueryRevisionsBase.php
Go to the documentation of this file.
1 <?php
28 
35 
41  // Bits to indicate the results of the revdel permission check on a revision,
42  // see self::checkRevDel()
43  const IS_DELETED = 1; // Whether the field is revision-deleted
44  const CANNOT_VIEW = 2; // Whether the user cannot view the field due to revdel
45 
51 
52  protected $fld_ids = false, $fld_flags = false, $fld_timestamp = false,
53  $fld_size = false, $fld_slotsize = false, $fld_sha1 = false, $fld_slotsha1 = false,
54  $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
55  $fld_content = false, $fld_tags = false, $fld_contentmodel = false, $fld_roles = false,
56  $fld_parsetree = false;
57 
58  public function execute() {
59  $this->run();
60  }
61 
62  public function executeGenerator( $resultPageSet ) {
63  $this->run( $resultPageSet );
64  }
65 
70  abstract protected function run( ApiPageSet $resultPageSet = null );
71 
77  protected function parseParameters( $params ) {
78  $prop = array_flip( $params['prop'] );
79 
80  $this->fld_ids = isset( $prop['ids'] );
81  $this->fld_flags = isset( $prop['flags'] );
82  $this->fld_timestamp = isset( $prop['timestamp'] );
83  $this->fld_comment = isset( $prop['comment'] );
84  $this->fld_parsedcomment = isset( $prop['parsedcomment'] );
85  $this->fld_size = isset( $prop['size'] );
86  $this->fld_slotsize = isset( $prop['slotsize'] );
87  $this->fld_sha1 = isset( $prop['sha1'] );
88  $this->fld_slotsha1 = isset( $prop['slotsha1'] );
89  $this->fld_content = isset( $prop['content'] );
90  $this->fld_contentmodel = isset( $prop['contentmodel'] );
91  $this->fld_userid = isset( $prop['userid'] );
92  $this->fld_user = isset( $prop['user'] );
93  $this->fld_tags = isset( $prop['tags'] );
94  $this->fld_roles = isset( $prop['roles'] );
95  $this->fld_parsetree = isset( $prop['parsetree'] );
96 
97  $this->slotRoles = $params['slots'];
98 
99  if ( $this->slotRoles !== null ) {
100  if ( $this->fld_parsetree ) {
101  $this->dieWithError( [
102  'apierror-invalidparammix-cannotusewith',
103  $this->encodeParamName( 'prop=parsetree' ),
104  $this->encodeParamName( 'slots' ),
105  ], 'invalidparammix' );
106  }
107  foreach ( [
108  'expandtemplates', 'generatexml', 'parse', 'diffto', 'difftotext', 'difftotextpst',
109  'contentformat'
110  ] as $p ) {
111  if ( $params[$p] !== null && $params[$p] !== false ) {
112  $this->dieWithError( [
113  'apierror-invalidparammix-cannotusewith',
114  $this->encodeParamName( $p ),
115  $this->encodeParamName( 'slots' ),
116  ], 'invalidparammix' );
117  }
118  }
119  }
120 
121  if ( !empty( $params['contentformat'] ) ) {
122  $this->contentFormat = $params['contentformat'];
123  }
124 
125  $this->limit = $params['limit'];
126 
127  if ( !is_null( $params['difftotext'] ) ) {
128  $this->difftotext = $params['difftotext'];
129  $this->difftotextpst = $params['difftotextpst'];
130  } elseif ( !is_null( $params['diffto'] ) ) {
131  if ( $params['diffto'] == 'cur' ) {
132  $params['diffto'] = 0;
133  }
134  if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
135  && $params['diffto'] != 'prev' && $params['diffto'] != 'next'
136  ) {
137  $p = $this->getModulePrefix();
138  $this->dieWithError( [ 'apierror-baddiffto', $p ], 'diffto' );
139  }
140  // Check whether the revision exists and is readable,
141  // DifferenceEngine returns a rather ambiguous empty
142  // string if that's not the case
143  if ( $params['diffto'] != 0 ) {
144  $difftoRev = MediaWikiServices::getInstance()->getRevisionStore()
145  ->getRevisionById( $params['diffto'] );
146  if ( !$difftoRev ) {
147  $this->dieWithError( [ 'apierror-nosuchrevid', $params['diffto'] ] );
148  }
149  $revDel = $this->checkRevDel( $difftoRev, RevisionRecord::DELETED_TEXT );
150  if ( $revDel & self::CANNOT_VIEW ) {
151  $this->addWarning( [ 'apiwarn-difftohidden', $difftoRev->getId() ] );
152  $params['diffto'] = null;
153  }
154  }
155  $this->diffto = $params['diffto'];
156  }
157 
158  $this->fetchContent = $this->fld_content || !is_null( $this->diffto )
159  || !is_null( $this->difftotext ) || $this->fld_parsetree;
160 
161  $smallLimit = false;
162  if ( $this->fetchContent ) {
163  $smallLimit = true;
164  $this->expandTemplates = $params['expandtemplates'];
165  $this->generateXML = $params['generatexml'];
166  $this->parseContent = $params['parse'];
167  if ( $this->parseContent ) {
168  // Must manually initialize unset limit
169  if ( is_null( $this->limit ) ) {
170  $this->limit = 1;
171  }
172  }
173  $this->section = $params['section'] ?? false;
174  }
175 
176  $userMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
177  $botMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
178  if ( $this->limit == 'max' ) {
179  $this->limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
180  if ( $this->setParsedLimit ) {
181  $this->getResult()->addParsedLimit( $this->getModuleName(), $this->limit );
182  }
183  }
184 
185  if ( is_null( $this->limit ) ) {
186  $this->limit = 10;
187  }
188  $this->validateLimit( 'limit', $this->limit, 1, $userMax, $botMax );
189 
190  $this->needSlots = $this->fetchContent || $this->fld_contentmodel ||
191  $this->fld_slotsize || $this->fld_slotsha1;
192  if ( $this->needSlots && $this->slotRoles === null ) {
193  $encParam = $this->encodeParamName( 'slots' );
194  $name = $this->getModuleName();
195  $parent = $this->getParent();
196  $parentParam = $parent->encodeParamName( $parent->getModuleManager()->getModuleGroup( $name ) );
197  $this->addDeprecation(
198  [ 'apiwarn-deprecation-missingparam', $encParam ],
199  "action=query&{$parentParam}={$name}&!{$encParam}"
200  );
201  }
202  }
203 
211  private function checkRevDel( RevisionRecord $revision, $field ) {
212  $ret = $revision->isDeleted( $field ) ? self::IS_DELETED : 0;
213  if ( $ret ) {
214  $canSee = $revision->audienceCan( $field, RevisionRecord::FOR_THIS_USER, $this->getUser() );
215  $ret = $ret | ( $canSee ? 0 : self::CANNOT_VIEW );
216  }
217  return $ret;
218  }
219 
228  protected function extractRevisionInfo( RevisionRecord $revision, $row ) {
229  $vals = [];
230  $anyHidden = false;
231 
232  if ( $this->fld_ids ) {
233  $vals['revid'] = (int)$revision->getId();
234  if ( !is_null( $revision->getParentId() ) ) {
235  $vals['parentid'] = (int)$revision->getParentId();
236  }
237  }
238 
239  if ( $this->fld_flags ) {
240  $vals['minor'] = $revision->isMinor();
241  }
242 
243  if ( $this->fld_user || $this->fld_userid ) {
244  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_USER );
245  if ( ( $revDel & self::IS_DELETED ) ) {
246  $vals['userhidden'] = true;
247  $anyHidden = true;
248  }
249  if ( !( $revDel & self::CANNOT_VIEW ) ) {
250  $u = $revision->getUser( RevisionRecord::RAW );
251  if ( $this->fld_user ) {
252  $vals['user'] = $u->getName();
253  }
254  $userid = $u->getId();
255  if ( !$userid ) {
256  $vals['anon'] = true;
257  }
258 
259  if ( $this->fld_userid ) {
260  $vals['userid'] = $userid;
261  }
262  }
263  }
264 
265  if ( $this->fld_timestamp ) {
266  $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
267  }
268 
269  if ( $this->fld_size ) {
270  try {
271  $vals['size'] = (int)$revision->getSize();
272  } catch ( RevisionAccessException $e ) {
273  // Back compat: If there's no size, return 0.
274  // @todo: Gergő says to mention T198099 as a "todo" here.
275  $vals['size'] = 0;
276  }
277  }
278 
279  if ( $this->fld_sha1 ) {
280  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
281  if ( ( $revDel & self::IS_DELETED ) ) {
282  $vals['sha1hidden'] = true;
283  $anyHidden = true;
284  }
285  if ( !( $revDel & self::CANNOT_VIEW ) ) {
286  try {
287  $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 );
288  } catch ( RevisionAccessException $e ) {
289  // Back compat: If there's no sha1, return emtpy string.
290  // @todo: Gergő says to mention T198099 as a "todo" here.
291  $vals['sha1'] = '';
292  }
293  }
294  }
295 
296  try {
297  if ( $this->fld_roles ) {
298  $vals['roles'] = $revision->getSlotRoles();
299  }
300 
301  if ( $this->needSlots ) {
302  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
303  if ( ( $this->fld_slotsha1 || $this->fetchContent ) && ( $revDel & self::IS_DELETED ) ) {
304  $anyHidden = true;
305  }
306  $vals = array_merge( $vals, $this->extractAllSlotInfo( $revision, $revDel ) );
307  }
308  } catch ( RevisionAccessException $ex ) {
309  // This is here so T212428 doesn't spam the log.
310  // TODO: find out why T212428 happens in the first place!
311  $vals['slotsmissing'] = true;
312 
313  LoggerFactory::getInstance( 'api-warning' )->error(
314  'Failed to access revision slots',
315  [ 'revision' => $revision->getId(), 'exception' => $ex, ]
316  );
317  }
318 
319  if ( $this->fld_comment || $this->fld_parsedcomment ) {
320  $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_COMMENT );
321  if ( ( $revDel & self::IS_DELETED ) ) {
322  $vals['commenthidden'] = true;
323  $anyHidden = true;
324  }
325  if ( !( $revDel & self::CANNOT_VIEW ) ) {
326  $comment = $revision->getComment( RevisionRecord::RAW );
327  $comment = $comment ? $comment->text : '';
328 
329  if ( $this->fld_comment ) {
330  $vals['comment'] = $comment;
331  }
332 
333  if ( $this->fld_parsedcomment ) {
334  $vals['parsedcomment'] = Linker::formatComment(
335  $comment, Title::newFromLinkTarget( $revision->getPageAsLinkTarget() )
336  );
337  }
338  }
339  }
340 
341  if ( $this->fld_tags ) {
342  if ( $row->ts_tags ) {
343  $tags = explode( ',', $row->ts_tags );
344  ApiResult::setIndexedTagName( $tags, 'tag' );
345  $vals['tags'] = $tags;
346  } else {
347  $vals['tags'] = [];
348  }
349  }
350 
351  if ( $anyHidden && $revision->isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
352  $vals['suppressed'] = true;
353  }
354 
355  return $vals;
356  }
357 
367  private function extractAllSlotInfo( RevisionRecord $revision, $revDel ): array {
368  $vals = [];
369 
370  if ( $this->slotRoles === null ) {
371  try {
372  $slot = $revision->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
373  } catch ( RevisionAccessException $e ) {
374  // Back compat: If there's no slot, there's no content, so set 'textmissing'
375  // @todo: Gergő says to mention T198099 as a "todo" here.
376  $vals['textmissing'] = true;
377  $slot = null;
378  }
379 
380  if ( $slot ) {
381  $content = null;
382  $vals += $this->extractSlotInfo( $slot, $revDel, $content );
383  if ( !empty( $vals['nosuchsection'] ) ) {
384  $this->dieWithError(
385  [
386  'apierror-nosuchsection-what',
387  wfEscapeWikiText( $this->section ),
388  $this->msg( 'revid', $revision->getId() )
389  ],
390  'nosuchsection'
391  );
392  }
393  if ( $content ) {
394  $vals += $this->extractDeprecatedContent( $content, $revision );
395  }
396  }
397  } else {
398  $roles = array_intersect( $this->slotRoles, $revision->getSlotRoles() );
399  $vals['slots'] = [
401  ];
402  foreach ( $roles as $role ) {
403  try {
404  $slot = $revision->getSlot( $role, RevisionRecord::RAW );
405  } catch ( RevisionAccessException $e ) {
406  // Don't error out here so the client can still process other slots/revisions.
407  // @todo: Gergő says to mention T198099 as a "todo" here.
408  $vals['slots'][$role]['missing'] = true;
409  continue;
410  }
411  $content = null;
412  $vals['slots'][$role] = $this->extractSlotInfo( $slot, $revDel, $content );
413  // @todo Move this into extractSlotInfo() (and remove its $content parameter)
414  // when extractDeprecatedContent() is no more.
415  if ( $content ) {
416  $vals['slots'][$role]['contentmodel'] = $content->getModel();
417  $vals['slots'][$role]['contentformat'] = $content->getDefaultFormat();
419  $vals['slots'][$role],
420  'content',
421  $content->serialize()
422  );
423  }
424  }
425  ApiResult::setArrayType( $vals['slots'], 'kvp', 'role' );
426  ApiResult::setIndexedTagName( $vals['slots'], 'slot' );
427  }
428  return $vals;
429  }
430 
440  private function extractSlotInfo( SlotRecord $slot, $revDel, &$content = null ) {
441  $vals = [];
442  ApiResult::setArrayType( $vals, 'assoc' );
443 
444  if ( $this->fld_slotsize ) {
445  $vals['size'] = (int)$slot->getSize();
446  }
447 
448  if ( $this->fld_slotsha1 ) {
449  if ( ( $revDel & self::IS_DELETED ) ) {
450  $vals['sha1hidden'] = true;
451  }
452  if ( !( $revDel & self::CANNOT_VIEW ) ) {
453  if ( $slot->getSha1() != '' ) {
454  $vals['sha1'] = Wikimedia\base_convert( $slot->getSha1(), 36, 16, 40 );
455  } else {
456  $vals['sha1'] = '';
457  }
458  }
459  }
460 
461  if ( $this->fld_contentmodel ) {
462  $vals['contentmodel'] = $slot->getModel();
463  }
464 
465  $content = null;
466  if ( $this->fetchContent ) {
467  if ( ( $revDel & self::IS_DELETED ) ) {
468  $vals['texthidden'] = true;
469  }
470  if ( !( $revDel & self::CANNOT_VIEW ) ) {
471  try {
472  $content = $slot->getContent();
473  } catch ( RevisionAccessException $e ) {
474  // @todo: Gergő says to mention T198099 as a "todo" here.
475  $vals['textmissing'] = true;
476  }
477  // Expand templates after getting section content because
478  // template-added sections don't count and Parser::preprocess()
479  // will have less input
480  if ( $content && $this->section !== false ) {
481  $content = $content->getSection( $this->section, false );
482  if ( !$content ) {
483  $vals['nosuchsection'] = true;
484  }
485  }
486  }
487  }
488 
489  return $vals;
490  }
491 
498  private function extractDeprecatedContent( Content $content, RevisionRecord $revision ) {
499  global $wgParser;
500 
501  $vals = [];
503 
504  if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
505  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
506  $t = $content->getText(); # note: don't set $text
507 
508  $wgParser->startExternalParse(
509  $title,
510  ParserOptions::newFromContext( $this->getContext() ),
511  Parser::OT_PREPROCESS
512  );
513  $dom = $wgParser->preprocessToDom( $t );
514  if ( is_callable( [ $dom, 'saveXML' ] ) ) {
515  $xml = $dom->saveXML();
516  } else {
517  $xml = $dom->__toString();
518  }
519  $vals['parsetree'] = $xml;
520  } else {
521  $vals['badcontentformatforparsetree'] = true;
522  $this->addWarning(
523  [
524  'apierror-parsetree-notwikitext-title',
525  wfEscapeWikiText( $title->getPrefixedText() ),
526  $content->getModel()
527  ],
528  'parsetree-notwikitext'
529  );
530  }
531  }
532 
533  if ( $this->fld_content ) {
534  $text = null;
535 
536  if ( $this->expandTemplates && !$this->parseContent ) {
537  if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
538  $text = $content->getText();
539 
540  $text = $wgParser->preprocess(
541  $text,
542  $title,
543  ParserOptions::newFromContext( $this->getContext() )
544  );
545  } else {
546  $this->addWarning( [
547  'apierror-templateexpansion-notwikitext',
548  wfEscapeWikiText( $title->getPrefixedText() ),
549  $content->getModel()
550  ] );
551  $vals['badcontentformat'] = true;
552  $text = false;
553  }
554  }
555  if ( $this->parseContent ) {
556  $po = $content->getParserOutput(
557  $title,
558  $revision->getId(),
559  ParserOptions::newFromContext( $this->getContext() )
560  );
561  $text = $po->getText();
562  }
563 
564  if ( $text === null ) {
565  $format = $this->contentFormat ?: $content->getDefaultFormat();
566  $model = $content->getModel();
567 
568  if ( !$content->isSupportedFormat( $format ) ) {
569  $name = wfEscapeWikiText( $title->getPrefixedText() );
570  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
571  $vals['badcontentformat'] = true;
572  $text = false;
573  } else {
574  $text = $content->serialize( $format );
575  // always include format and model.
576  // Format is needed to deserialize, model is needed to interpret.
577  $vals['contentformat'] = $format;
578  $vals['contentmodel'] = $model;
579  }
580  }
581 
582  if ( $text !== false ) {
583  ApiResult::setContentValue( $vals, 'content', $text );
584  }
585  }
586 
587  if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
588  static $n = 0; // Number of uncached diffs we've had
589 
590  if ( $n < $this->getConfig()->get( 'APIMaxUncachedDiffs' ) ) {
591  $vals['diff'] = [];
592  $context = new DerivativeContext( $this->getContext() );
593  $context->setTitle( $title );
594  $handler = $content->getContentHandler();
595 
596  if ( !is_null( $this->difftotext ) ) {
597  $model = $title->getContentModel();
598 
599  if ( $this->contentFormat
600  && !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat )
601  ) {
602  $name = wfEscapeWikiText( $title->getPrefixedText() );
603  $this->addWarning( [ 'apierror-badformat', $this->contentFormat, $model, $name ] );
604  $vals['diff']['badcontentformat'] = true;
605  $engine = null;
606  } else {
607  $difftocontent = ContentHandler::makeContent(
608  $this->difftotext,
609  $title,
610  $model,
611  $this->contentFormat
612  );
613 
614  if ( $this->difftotextpst ) {
615  $popts = ParserOptions::newFromContext( $this->getContext() );
616  $difftocontent = $difftocontent->preSaveTransform( $title, $this->getUser(), $popts );
617  }
618 
619  $engine = $handler->createDifferenceEngine( $context );
620  $engine->setContent( $content, $difftocontent );
621  }
622  } else {
623  $engine = $handler->createDifferenceEngine( $context, $revision->getId(), $this->diffto );
624  $vals['diff']['from'] = $engine->getOldid();
625  $vals['diff']['to'] = $engine->getNewid();
626  }
627  if ( $engine ) {
628  $difftext = $engine->getDiffBody();
629  ApiResult::setContentValue( $vals['diff'], 'body', $difftext );
630  if ( !$engine->wasCacheHit() ) {
631  $n++;
632  }
633  }
634  } else {
635  $vals['diff']['notcached'] = true;
636  }
637  }
638 
639  return $vals;
640  }
641 
642  public function getCacheMode( $params ) {
643  if ( $this->userCanSeeRevDel() ) {
644  return 'private';
645  }
646 
647  return 'public';
648  }
649 
650  public function getAllowedParams() {
651  $slotRoles = MediaWikiServices::getInstance()->getSlotRoleRegistry()->getKnownRoles();
652  sort( $slotRoles, SORT_STRING );
653 
654  return [
655  'prop' => [
656  ApiBase::PARAM_ISMULTI => true,
657  ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
659  'ids',
660  'flags',
661  'timestamp',
662  'user',
663  'userid',
664  'size',
665  'slotsize',
666  'sha1',
667  'slotsha1',
668  'contentmodel',
669  'comment',
670  'parsedcomment',
671  'content',
672  'tags',
673  'roles',
674  'parsetree',
675  ],
676  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-prop',
678  'ids' => 'apihelp-query+revisions+base-paramvalue-prop-ids',
679  'flags' => 'apihelp-query+revisions+base-paramvalue-prop-flags',
680  'timestamp' => 'apihelp-query+revisions+base-paramvalue-prop-timestamp',
681  'user' => 'apihelp-query+revisions+base-paramvalue-prop-user',
682  'userid' => 'apihelp-query+revisions+base-paramvalue-prop-userid',
683  'size' => 'apihelp-query+revisions+base-paramvalue-prop-size',
684  'slotsize' => 'apihelp-query+revisions+base-paramvalue-prop-slotsize',
685  'sha1' => 'apihelp-query+revisions+base-paramvalue-prop-sha1',
686  'slotsha1' => 'apihelp-query+revisions+base-paramvalue-prop-slotsha1',
687  'contentmodel' => 'apihelp-query+revisions+base-paramvalue-prop-contentmodel',
688  'comment' => 'apihelp-query+revisions+base-paramvalue-prop-comment',
689  'parsedcomment' => 'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
690  'content' => 'apihelp-query+revisions+base-paramvalue-prop-content',
691  'tags' => 'apihelp-query+revisions+base-paramvalue-prop-tags',
692  'roles' => 'apihelp-query+revisions+base-paramvalue-prop-roles',
693  'parsetree' => [ 'apihelp-query+revisions+base-paramvalue-prop-parsetree',
695  ],
697  'parsetree' => true,
698  ],
699  ],
700  'slots' => [
702  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-slots',
703  ApiBase::PARAM_ISMULTI => true,
704  ApiBase::PARAM_ALL => true,
705  ],
706  'limit' => [
707  ApiBase::PARAM_TYPE => 'limit',
708  ApiBase::PARAM_MIN => 1,
711  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-limit',
712  ],
713  'expandtemplates' => [
714  ApiBase::PARAM_DFLT => false,
715  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-expandtemplates',
717  ],
718  'generatexml' => [
719  ApiBase::PARAM_DFLT => false,
721  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-generatexml',
722  ],
723  'parse' => [
724  ApiBase::PARAM_DFLT => false,
725  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-parse',
727  ],
728  'section' => [
729  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-section',
730  ],
731  'diffto' => [
732  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-diffto',
734  ],
735  'difftotext' => [
736  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotext',
738  ],
739  'difftotextpst' => [
740  ApiBase::PARAM_DFLT => false,
741  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-difftotextpst',
743  ],
744  'contentformat' => [
746  ApiBase::PARAM_HELP_MSG => 'apihelp-query+revisions+base-param-contentformat',
748  ],
749  ];
750  }
751 
752 }
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:77
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:252
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:335
ApiBase\addWarning
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
Definition: ApiBase.php:1909
ApiQueryRevisionsBase\$fld_slotsize
$fld_slotsize
Definition: ApiQueryRevisionsBase.php:53
Revision\SlotRecord\getContent
getContent()
Returns the Content of the given slot.
Definition: SlotRecord.php:302
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:886
ApiQueryRevisionsBase\$fld_comment
$fld_comment
Definition: ApiQueryRevisionsBase.php:54
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:1990
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:55
ApiQueryRevisionsBase\$section
$section
Definition: ApiQueryRevisionsBase.php:48
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
ApiQueryRevisionsBase\CANNOT_VIEW
const CANNOT_VIEW
Definition: ApiQueryRevisionsBase.php:44
ApiQueryRevisionsBase\extractAllSlotInfo
extractAllSlotInfo(RevisionRecord $revision, $revDel)
Extracts information about all relevant slots.
Definition: ApiQueryRevisionsBase.php:367
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:87
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:632
ApiQueryRevisionsBase\$fld_userid
$fld_userid
Definition: ApiQueryRevisionsBase.php:54
Revision\RevisionRecord\getTimestamp
getTimestamp()
MCR migration note: this replaces Revision::getTimestamp.
Definition: RevisionRecord.php:436
ApiQueryRevisionsBase\$fld_sha1
$fld_sha1
Definition: ApiQueryRevisionsBase.php:53
$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:48
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:235
ApiQueryRevisionsBase\$setParsedLimit
$setParsedLimit
Definition: ApiQueryRevisionsBase.php:49
ApiQueryRevisionsBase\$slotRoles
$slotRoles
Definition: ApiQueryRevisionsBase.php:50
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:48
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:48
ApiQueryRevisionsBase\$fld_content
$fld_content
Definition: ApiQueryRevisionsBase.php:55
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:55
ApiQueryRevisionsBase
A base class for functions common to producing a list of revisions.
Definition: ApiQueryRevisionsBase.php:34
ApiQueryRevisionsBase\$fld_slotsha1
$fld_slotsha1
Definition: ApiQueryRevisionsBase.php:53
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:48
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:925
ApiQueryRevisionsBase\$contentFormat
$contentFormat
Definition: ApiQueryRevisionsBase.php:48
Revision\RevisionRecord\getSha1
getSha1()
Returns the base36 sha1 of this revision.
$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 When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
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
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:650
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:561
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2901
ApiQueryRevisionsBase\$diffto
$diffto
Definition: ApiQueryRevisionsBase.php:48
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:56
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ApiQueryRevisionsBase\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryRevisionsBase.php:58
ApiQueryRevisionsBase\IS_DELETED
const IS_DELETED
Definition: ApiQueryRevisionsBase.php:43
ApiQueryRevisionsBase\$fld_tags
$fld_tags
Definition: ApiQueryRevisionsBase.php:55
ApiQueryRevisionsBase\$needSlots
$needSlots
Definition: ApiQueryRevisionsBase.php:50
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:538
ApiQueryRevisionsBase\checkRevDel
checkRevDel(RevisionRecord $revision, $field)
Test revision deletion status.
Definition: ApiQueryRevisionsBase.php:211
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:520
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:271
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:2162
Revision\SlotRecord\getSize
getSize()
Returns the content size.
Definition: SlotRecord.php:522
ApiQueryRevisionsBase\$parseContent
$parseContent
Definition: ApiQueryRevisionsBase.php:48
ParserOptions\newFromContext
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
Definition: ParserOptions.php:1043
ApiBase\addDeprecation
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
Definition: ApiBase.php:1923
ApiBase\LIMIT_SML2
const LIMIT_SML2
Slow query, apihighlimits limit.
Definition: ApiBase.php:258
title
title
Definition: parserTests.txt:245
ApiQueryRevisionsBase\extractRevisionInfo
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
Definition: ApiQueryRevisionsBase.php:228
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1577
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1985
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:642
ApiQueryRevisionsBase\$fld_flags
$fld_flags
Definition: ApiQueryRevisionsBase.php:52
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Definition: Title.php:269
Linker\formatComment
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1122
Content
Base interface for content objects.
Definition: Content.php:34
ApiQueryRevisionsBase\$difftotext
$difftotext
Definition: ApiQueryRevisionsBase.php:48
ApiQueryGeneratorBase
Definition: ApiQueryGeneratorBase.php:26
ApiQueryRevisionsBase\$fld_ids
$fld_ids
Definition: ApiQueryRevisionsBase.php:52
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:1557
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:512
ApiQueryRevisionsBase\$fld_user
$fld_user
Definition: ApiQueryRevisionsBase.php:54
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:52
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
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:528
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:62
$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:54
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:630
ApiQueryRevisionsBase\$fld_size
$fld_size
Definition: ApiQueryRevisionsBase.php:53
ApiQueryRevisionsBase\extractDeprecatedContent
extractDeprecatedContent(Content $content, RevisionRecord $revision)
Format a Content using deprecated options.
Definition: ApiQueryRevisionsBase.php:498
ApiQueryRevisionsBase\extractSlotInfo
extractSlotInfo(SlotRecord $slot, $revDel, &$content=null)
Extract information from the SlotRecord.
Definition: ApiQueryRevisionsBase.php:440
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:48