Go to the documentation of this file.
43 $this->
run( $resultPageSet );
50 abstract protected function run(
ApiPageSet $resultPageSet =
null );
58 if ( !is_null(
$params[
'difftotext'] ) ) {
59 $this->difftotext =
$params[
'difftotext'];
60 $this->difftotextpst =
$params[
'difftotextpst'];
61 } elseif ( !is_null(
$params[
'diffto'] ) ) {
62 if (
$params[
'diffto'] ==
'cur' ) {
65 if ( ( !ctype_digit(
$params[
'diffto'] ) ||
$params[
'diffto'] < 0 )
69 $this->
dieWithError( [
'apierror-baddiffto', $p ],
'diffto' );
80 $this->
addWarning( [
'apiwarn-difftohidden', $difftoRev->getId() ] );
84 $this->diffto =
$params[
'diffto'];
87 $prop = array_flip(
$params[
'prop'] );
89 $this->fld_ids = isset( $prop[
'ids'] );
90 $this->fld_flags = isset( $prop[
'flags'] );
91 $this->fld_timestamp = isset( $prop[
'timestamp'] );
92 $this->fld_comment = isset( $prop[
'comment'] );
93 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
94 $this->fld_size = isset( $prop[
'size'] );
95 $this->fld_sha1 = isset( $prop[
'sha1'] );
96 $this->fld_content = isset( $prop[
'content'] );
97 $this->fld_contentmodel = isset( $prop[
'contentmodel'] );
98 $this->fld_userid = isset( $prop[
'userid'] );
99 $this->fld_user = isset( $prop[
'user'] );
100 $this->fld_tags = isset( $prop[
'tags'] );
101 $this->fld_parsetree = isset( $prop[
'parsetree'] );
103 if ( $this->fld_parsetree ) {
107 $parentParam = $parent->encodeParamName( $parent->getModuleManager()->getModuleGroup(
$name ) );
109 [
'apiwarn-deprecation-parameter',
"{$encParam}=parsetree" ],
110 "action=query&{$parentParam}={$name}&{$encParam}=parsetree"
114 if ( !empty(
$params[
'contentformat'] ) ) {
115 $this->contentFormat =
$params[
'contentformat'];
118 $this->limit =
$params[
'limit'];
120 $this->fetchContent = $this->fld_content || !is_null( $this->diffto )
124 if ( $this->fetchContent ) {
126 $this->expandTemplates =
$params[
'expandtemplates'];
127 $this->generateXML =
$params[
'generatexml'];
128 $this->parseContent =
$params[
'parse'];
129 if ( $this->parseContent ) {
131 if ( is_null( $this->limit ) ) {
135 if ( isset(
$params[
'section'] ) ) {
136 $this->section =
$params[
'section'];
138 $this->section =
false;
144 if ( $this->limit ==
'max' ) {
145 $this->limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
146 if ( $this->setParsedLimit ) {
151 if ( is_null( $this->limit ) ) {
154 $this->
validateLimit(
'limit', $this->limit, 1, $userMax, $botMax );
170 if ( $this->fld_ids ) {
171 $vals[
'revid'] = intval( $revision->
getId() );
173 $vals[
'parentid'] = intval( $revision->
getParentId() );
177 if ( $this->fld_flags ) {
178 $vals[
'minor'] = $revision->
isMinor();
181 if ( $this->fld_user || $this->fld_userid ) {
183 $vals[
'userhidden'] =
true;
187 if ( $this->fld_user ) {
192 $vals[
'anon'] =
true;
195 if ( $this->fld_userid ) {
196 $vals[
'userid'] = $userid;
201 if ( $this->fld_timestamp ) {
205 if ( $this->fld_size ) {
206 if ( !is_null( $revision->
getSize() ) ) {
207 $vals[
'size'] = intval( $revision->
getSize() );
213 if ( $this->fld_sha1 ) {
215 $vals[
'sha1hidden'] =
true;
219 if ( $revision->
getSha1() !=
'' ) {
220 $vals[
'sha1'] = Wikimedia\base_convert( $revision->
getSha1(), 36, 16, 40 );
227 if ( $this->fld_contentmodel ) {
231 if ( $this->fld_comment || $this->fld_parsedcomment ) {
233 $vals[
'commenthidden'] =
true;
239 if ( $this->fld_comment ) {
240 $vals[
'comment'] = $comment;
243 if ( $this->fld_parsedcomment ) {
249 if ( $this->fld_tags ) {
250 if ( $row->ts_tags ) {
251 $tags = explode(
',', $row->ts_tags );
253 $vals[
'tags'] = $tags;
261 if ( $this->fetchContent ) {
266 if ( $content && $this->section !==
false ) {
267 $content = $content->getSection( $this->section,
false );
271 'apierror-nosuchsection-what',
273 $this->
msg(
'revid', $revision->
getId() )
280 $vals[
'texthidden'] =
true;
282 } elseif ( !$content ) {
283 $vals[
'textmissing'] =
true;
286 if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
289 $t = $content->getNativeData(); # note: don
't set $text
291 $wgParser->startExternalParse(
293 ParserOptions::newFromContext( $this->getContext() ),
294 Parser::OT_PREPROCESS
296 $dom = $wgParser->preprocessToDom( $t );
297 if ( is_callable( [ $dom, 'saveXML
' ] ) ) {
298 $xml = $dom->saveXML();
300 $xml = $dom->__toString();
302 $vals['parsetree
'] = $xml;
304 $vals['badcontentformatforparsetree
'] = true;
307 'apierror-parsetree-notwikitext-
title',
308 wfEscapeWikiText( $title->getPrefixedText() ),
311 'parsetree-notwikitext
'
317 if ( $this->fld_content && $content ) {
320 if ( $this->expandTemplates && !$this->parseContent ) {
321 # XXX: implement template expansion for all content types in ContentHandler?
322 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
323 $text = $content->getNativeData();
325 $text = $wgParser->preprocess(
328 ParserOptions::newFromContext( $this->getContext() )
332 'apierror-templateexpansion-notwikitext
',
333 wfEscapeWikiText( $title->getPrefixedText() ),
336 $vals['badcontentformat
'] = true;
340 if ( $this->parseContent ) {
341 $po = $content->getParserOutput(
344 ParserOptions::newFromContext( $this->getContext() )
346 $text = $po->getText();
349 if ( $text === null ) {
350 $format = $this->contentFormat ?: $content->getDefaultFormat();
351 $model = $content->getModel();
353 if ( !$content->isSupportedFormat( $format ) ) {
354 $name = wfEscapeWikiText( $title->getPrefixedText() );
355 $this->addWarning( [ 'apierror-badformat
', $this->contentFormat, $model, $name ] );
356 $vals['badcontentformat
'] = true;
359 $text = $content->serialize( $format );
360 // always include format and model.
361 // Format is needed to deserialize, model is needed to interpret.
362 $vals['contentformat
'] = $format;
363 $vals['contentmodel
'] = $model;
367 if ( $text !== false ) {
368 ApiResult::setContentValue( $vals, 'content', $text );
372 if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
373 static $n = 0; // Number of uncached diffs we've had
375 if ( $n < $this->
getConfig()->
get(
'APIMaxUncachedDiffs' ) ) {
381 if ( !is_null( $this->difftotext ) ) {
382 $model =
$title->getContentModel();
384 if ( $this->contentFormat
388 $this->
addWarning( [
'apierror-badformat', $this->contentFormat, $model,
$name ] );
389 $vals[
'diff'][
'badcontentformat'] =
true;
399 if ( $this->difftotextpst ) {
401 $difftocontent = $difftocontent->preSaveTransform(
$title,
$user, $popts );
405 $engine->setContent( $content, $difftocontent );
409 $vals[
'diff'][
'from'] =
$engine->getOldid();
410 $vals[
'diff'][
'to'] =
$engine->getNewid();
413 $difftext =
$engine->getDiffBody();
415 if ( !
$engine->wasCacheHit() ) {
420 $vals[
'diff'][
'notcached'] =
true;
425 $vals[
'suppressed'] =
true;
461 'ids' =>
'apihelp-query+revisions+base-paramvalue-prop-ids',
462 'flags' =>
'apihelp-query+revisions+base-paramvalue-prop-flags',
463 'timestamp' =>
'apihelp-query+revisions+base-paramvalue-prop-timestamp',
464 'user' =>
'apihelp-query+revisions+base-paramvalue-prop-user',
465 'userid' =>
'apihelp-query+revisions+base-paramvalue-prop-userid',
466 'size' =>
'apihelp-query+revisions+base-paramvalue-prop-size',
467 'sha1' =>
'apihelp-query+revisions+base-paramvalue-prop-sha1',
468 'contentmodel' =>
'apihelp-query+revisions+base-paramvalue-prop-contentmodel',
469 'comment' =>
'apihelp-query+revisions+base-paramvalue-prop-comment',
470 'parsedcomment' =>
'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
471 'content' =>
'apihelp-query+revisions+base-paramvalue-prop-content',
472 'tags' =>
'apihelp-query+revisions+base-paramvalue-prop-tags',
473 'parsetree' => [
'apihelp-query+revisions+base-paramvalue-prop-parsetree',
484 'expandtemplates' => [
486 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-expandtemplates',
parseParameters( $params)
Parse the parameters into the various instance fields.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
getContext()
Get the base IContextSource object.
getUserText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
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.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
per default it will return the text for text based content
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
getSize()
Returns the length of the text in this revision, or null if unknown.
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()
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
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.
getParentId()
Get parent revision ID (the original previous page revision)
getContentHandler()
Returns the content handler appropriate for this revision's content model.
Allows to change the fields on the form that will be generated $name
const CONTENT_MODEL_WIKITEXT
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
getContentModel()
Returns the content model for the main slot of this revision.
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 ...
namespace and then decline to actually register it file or subcat img or subcat $title
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'.
the value to return A Title object or null for latest all implement SearchIndexField $engine
when a variable name is used in a it is silently declared as a new masking the global
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.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
getTitle()
Returns the title of the page associated with this entry.
extractRevisionInfo(Revision $revision, $row)
Extract information from the Revision.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
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.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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...
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.
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.
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
getMain()
Get the main module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
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.
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
const LIMIT_SML1
Slow query, standard limit.