Go to the documentation of this file.
62 $this->
run( $resultPageSet );
69 abstract protected function run(
ApiPageSet $resultPageSet =
null );
77 $prop = array_flip(
$params[
'prop'] );
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'] );
96 $this->slotRoles =
$params[
'slots'];
98 if ( $this->slotRoles !==
null ) {
99 if ( $this->fld_parsetree ) {
101 'apierror-invalidparammix-cannotusewith',
104 ],
'invalidparammix' );
107 'expandtemplates',
'generatexml',
'parse',
'diffto',
'difftotext',
'difftotextpst',
112 'apierror-invalidparammix-cannotusewith',
115 ],
'invalidparammix' );
120 if ( !empty(
$params[
'contentformat'] ) ) {
121 $this->contentFormat =
$params[
'contentformat'];
124 $this->limit =
$params[
'limit'];
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' ) {
133 if ( ( !ctype_digit(
$params[
'diffto'] ) ||
$params[
'diffto'] < 0 )
137 $this->
dieWithError( [
'apierror-baddiffto', $p ],
'diffto' );
142 if (
$params[
'diffto'] != 0 ) {
143 $difftoRev = MediaWikiServices::getInstance()->getRevisionStore()
144 ->getRevisionById(
$params[
'diffto'] );
148 $revDel = $this->
checkRevDel( $difftoRev, RevisionRecord::DELETED_TEXT );
149 if ( $revDel & self::CANNOT_VIEW ) {
150 $this->
addWarning( [
'apiwarn-difftohidden', $difftoRev->getId() ] );
154 $this->diffto =
$params[
'diffto'];
157 $this->fetchContent = $this->fld_content || !is_null( $this->diffto )
161 if ( $this->fetchContent ) {
163 $this->expandTemplates =
$params[
'expandtemplates'];
164 $this->generateXML =
$params[
'generatexml'];
165 $this->parseContent =
$params[
'parse'];
166 if ( $this->parseContent ) {
168 if ( is_null( $this->limit ) ) {
172 if ( isset(
$params[
'section'] ) ) {
173 $this->section =
$params[
'section'];
175 $this->section =
false;
181 if ( $this->limit ==
'max' ) {
182 $this->limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
183 if ( $this->setParsedLimit ) {
188 if ( is_null( $this->limit ) ) {
191 $this->
validateLimit(
'limit', $this->limit, 1, $userMax, $botMax );
193 $this->needSlots = $this->fetchContent || $this->fld_contentmodel ||
195 if ( $this->needSlots && $this->slotRoles ===
null ) {
199 $parentParam =
$parent->encodeParamName(
$parent->getModuleManager()->getModuleGroup(
$name ) );
201 [
'apiwarn-deprecation-missingparam', $encParam ],
202 "action=query&{$parentParam}={$name}&!{$encParam}"
217 $canSee = $revision->
audienceCan( $field, RevisionRecord::FOR_THIS_USER, $this->
getUser() );
235 if ( $this->fld_ids ) {
236 $vals[
'revid'] = intval( $revision->
getId() );
238 $vals[
'parentid'] = intval( $revision->
getParentId() );
242 if ( $this->fld_flags ) {
243 $vals[
'minor'] = $revision->
isMinor();
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;
252 if ( !( $revDel & self::CANNOT_VIEW ) ) {
253 $u = $revision->
getUser( RevisionRecord::RAW );
254 if ( $this->fld_user ) {
255 $vals[
'user'] = $u->getName();
257 $userid = $u->getId();
259 $vals[
'anon'] =
true;
262 if ( $this->fld_userid ) {
263 $vals[
'userid'] = $userid;
268 if ( $this->fld_timestamp ) {
272 if ( $this->fld_size ) {
274 $vals[
'size'] = intval( $revision->
getSize() );
282 if ( $this->fld_sha1 ) {
283 $revDel = $this->
checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
284 if ( ( $revDel & self::IS_DELETED ) ) {
285 $vals[
'sha1hidden'] =
true;
288 if ( !( $revDel & self::CANNOT_VIEW ) ) {
290 $vals[
'sha1'] = Wikimedia\base_convert( $revision->
getSha1(), 36, 16, 40 );
299 if ( $this->fld_roles ) {
303 if ( $this->needSlots ) {
304 $revDel = $this->
checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
305 if ( ( $this->fld_slotsha1 || $this->fetchContent ) && ( $revDel & self::IS_DELETED ) ) {
308 if ( $this->slotRoles ===
null ) {
310 $slot = $revision->
getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
314 $vals[
'textmissing'] =
true;
321 if ( !empty( $vals[
'nosuchsection'] ) ) {
324 'apierror-nosuchsection-what',
326 $this->
msg(
'revid', $revision->
getId() )
336 $roles = array_intersect( $this->slotRoles, $revision->
getSlotRoles() );
340 foreach ( $roles
as $role ) {
342 $slot = $revision->
getSlot( $role, RevisionRecord::RAW );
346 $vals[
'slots'][$role][
'missing'] =
true;
354 $vals[
'slots'][$role][
'contentmodel'] =
$content->getModel();
355 $vals[
'slots'][$role][
'contentformat'] =
$content->getDefaultFormat();
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;
370 if ( !( $revDel & self::CANNOT_VIEW ) ) {
371 $comment = $revision->
getComment( RevisionRecord::RAW );
372 $comment = $comment ? $comment->text :
'';
374 if ( $this->fld_comment ) {
375 $vals[
'comment'] = $comment;
378 if ( $this->fld_parsedcomment ) {
386 if ( $this->fld_tags ) {
387 if ( $row->ts_tags ) {
388 $tags = explode(
',', $row->ts_tags );
390 $vals[
'tags'] = $tags;
396 if ( $anyHidden && $revision->
isDeleted( RevisionRecord::DELETED_RESTRICTED ) ) {
397 $vals[
'suppressed'] =
true;
416 if ( $this->fld_slotsize ) {
417 $vals[
'size'] = intval( $slot->
getSize() );
420 if ( $this->fld_slotsha1 ) {
421 if ( ( $revDel & self::IS_DELETED ) ) {
422 $vals[
'sha1hidden'] =
true;
424 if ( !( $revDel & self::CANNOT_VIEW ) ) {
425 if ( $slot->
getSha1() !=
'' ) {
426 $vals[
'sha1'] = Wikimedia\base_convert( $slot->
getSha1(), 36, 16, 40 );
433 if ( $this->fld_contentmodel ) {
434 $vals[
'contentmodel'] = $slot->
getModel();
438 if ( $this->fetchContent ) {
439 if ( ( $revDel & self::IS_DELETED ) ) {
440 $vals[
'texthidden'] =
true;
442 if ( !( $revDel & self::CANNOT_VIEW ) ) {
447 $vals[
'textmissing'] =
true;
452 if (
$content && $this->section !==
false ) {
455 $vals[
'nosuchsection'] =
true;
476 if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
478 $t =
$content->getNativeData(); # note: don
't set $text
480 $wgParser->startExternalParse(
482 ParserOptions::newFromContext( $this->getContext() ),
483 Parser::OT_PREPROCESS
485 $dom = $wgParser->preprocessToDom( $t );
486 if ( is_callable( [ $dom, 'saveXML
' ] ) ) {
487 $xml = $dom->saveXML();
489 $xml = $dom->__toString();
491 $vals['parsetree
'] = $xml;
493 $vals['badcontentformatforparsetree
'] = true;
496 'apierror-parsetree-notwikitext-
title',
497 wfEscapeWikiText( $title->getPrefixedText() ),
500 'parsetree-notwikitext
'
505 if ( $this->fld_content ) {
508 if ( $this->expandTemplates && !$this->parseContent ) {
509 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
510 $text = $content->getNativeData();
512 $text = $wgParser->preprocess(
515 ParserOptions::newFromContext( $this->getContext() )
519 'apierror-templateexpansion-notwikitext
',
520 wfEscapeWikiText( $title->getPrefixedText() ),
523 $vals['badcontentformat
'] = true;
527 if ( $this->parseContent ) {
528 $po = $content->getParserOutput(
531 ParserOptions::newFromContext( $this->getContext() )
533 $text = $po->getText();
536 if ( $text === null ) {
537 $format = $this->contentFormat ?: $content->getDefaultFormat();
538 $model = $content->getModel();
540 if ( !$content->isSupportedFormat( $format ) ) {
541 $name = wfEscapeWikiText( $title->getPrefixedText() );
542 $this->addWarning( [ 'apierror-badformat
', $this->contentFormat, $model, $name ] );
543 $vals['badcontentformat
'] = true;
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;
554 if ( $text !== false ) {
555 ApiResult::setContentValue( $vals, 'content', $text );
559 if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
560 static $n = 0; // Number of uncached diffs we've had
562 if ( $n < $this->
getConfig()->
get(
'APIMaxUncachedDiffs' ) ) {
568 if ( !is_null( $this->difftotext ) ) {
569 $model =
$title->getContentModel();
571 if ( $this->contentFormat
575 $this->
addWarning( [
'apierror-badformat', $this->contentFormat, $model,
$name ] );
576 $vals[
'diff'][
'badcontentformat'] =
true;
586 if ( $this->difftotextpst ) {
588 $difftocontent = $difftocontent->preSaveTransform(
$title, $this->
getUser(), $popts );
596 $vals[
'diff'][
'from'] =
$engine->getOldid();
597 $vals[
'diff'][
'to'] =
$engine->getNewid();
600 $difftext =
$engine->getDiffBody();
602 if ( !
$engine->wasCacheHit() ) {
607 $vals[
'diff'][
'notcached'] =
true;
623 $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
624 if ( !in_array( SlotRecord::MAIN,
$slotRoles,
true ) ) {
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',
688 'expandtemplates' => [
getContentHandler()
Convenience method that returns the ContentHandler singleton for handling the content model that this...
parseParameters( $params)
Parse the parameters into the various instance fields.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
getContext()
Get the base IContextSource object.
static getAllContentFormats()
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
per default it will return the text for text based content
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
const CONTENT_MODEL_WIKITEXT
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
This class contains a list of pages that the client has requested.
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
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
A base class for functions common to producing a list of revisions.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
An IContextSource implementation which will inherit context from another source but allow individual ...
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
namespace and then decline to actually register it file or subcat img or subcat $title
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
const LIMIT_BIG1
Fast query, standard limit.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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
the value to return A Title object or null for latest all implement SearchIndexField $engine
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
checkRevDel(RevisionRecord $revision, $field)
Test revision deletion status.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Allows to change the fields on the form that will be generated $name
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
const LIMIT_SML2
Slow query, apihighlimits limit.
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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
getCacheMode( $params)
Get the cache mode for the data generated by this module.
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
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...
Base interface for content objects.
const LIMIT_BIG2
Fast query, apihighlimits limit.
validateLimit( $paramName, &$value, $min, $max, $botMax=null, $enforceLimits=false)
Validate the value against the minimum and user/bot maximum limits.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
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
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
getMain()
Get the main module.
const META_KVP_MERGE
Key for the metadata item that indicates that the KVP key should be added into an assoc value,...
executeGenerator( $resultPageSet)
Execute this module as a generator.
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
run(ApiPageSet $resultPageSet=null)
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
extractDeprecatedContent(Content $content, RevisionRecord $revision)
Format a Content using deprecated options.
extractSlotInfo(SlotRecord $slot, $revDel, &$content=null)
Extract information from the SlotRecord.
const LIMIT_SML1
Slow query, standard limit.