47 $this->
run( $resultPageSet );
54 abstract protected function run(
ApiPageSet $resultPageSet = null );
62 if ( !is_null(
$params[
'difftotext'] ) ) {
63 $this->difftotext =
$params[
'difftotext'];
64 $this->difftotextpst =
$params[
'difftotextpst'];
65 } elseif ( !is_null(
$params[
'diffto'] ) ) {
66 if (
$params[
'diffto'] ==
'cur' ) {
69 if ( ( !ctype_digit(
$params[
'diffto'] ) ||
$params[
'diffto'] < 0 )
74 "{$p}diffto must be set to a non-negative number, \"prev\", \"next\" or \"cur\"",
87 $this->
setWarning(
"Couldn't diff to r{$difftoRev->getId()}: content is hidden" );
91 $this->diffto =
$params[
'diffto'];
94 $prop = array_flip(
$params[
'prop'] );
96 $this->fld_ids = isset( $prop[
'ids'] );
97 $this->fld_flags = isset( $prop[
'flags'] );
98 $this->fld_timestamp = isset( $prop[
'timestamp'] );
99 $this->fld_comment = isset( $prop[
'comment'] );
100 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
101 $this->fld_size = isset( $prop[
'size'] );
102 $this->fld_sha1 = isset( $prop[
'sha1'] );
103 $this->fld_content = isset( $prop[
'content'] );
104 $this->fld_contentmodel = isset( $prop[
'contentmodel'] );
105 $this->fld_userid = isset( $prop[
'userid'] );
106 $this->fld_user = isset( $prop[
'user'] );
107 $this->fld_tags = isset( $prop[
'tags'] );
108 $this->fld_parsetree = isset( $prop[
'parsetree'] );
110 if ( !empty(
$params[
'contentformat'] ) ) {
111 $this->contentFormat =
$params[
'contentformat'];
114 $this->limit =
$params[
'limit'];
116 $this->fetchContent = $this->fld_content || !is_null( $this->diffto )
120 if ( $this->fetchContent ) {
122 $this->expandTemplates =
$params[
'expandtemplates'];
123 $this->generateXML =
$params[
'generatexml'];
124 $this->parseContent =
$params[
'parse'];
125 if ( $this->parseContent ) {
127 if ( is_null( $this->limit ) ) {
131 if ( isset(
$params[
'section'] ) ) {
132 $this->section =
$params[
'section'];
134 $this->section =
false;
140 if ( $this->limit ==
'max' ) {
141 $this->limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
142 if ( $this->setParsedLimit ) {
147 if ( is_null( $this->limit ) ) {
150 $this->
validateLimit(
'limit', $this->limit, 1, $userMax, $botMax );
166 if ( $this->fld_ids ) {
167 $vals[
'revid'] = intval( $revision->
getId() );
169 $vals[
'parentid'] = intval( $revision->
getParentId() );
173 if ( $this->fld_flags ) {
174 $vals[
'minor'] = $revision->
isMinor();
177 if ( $this->fld_user || $this->fld_userid ) {
179 $vals[
'userhidden'] =
true;
183 if ( $this->fld_user ) {
188 $vals[
'anon'] =
true;
191 if ( $this->fld_userid ) {
192 $vals[
'userid'] = $userid;
197 if ( $this->fld_timestamp ) {
201 if ( $this->fld_size ) {
202 if ( !is_null( $revision->
getSize() ) ) {
203 $vals[
'size'] = intval( $revision->
getSize() );
209 if ( $this->fld_sha1 ) {
211 $vals[
'sha1hidden'] =
true;
215 if ( $revision->
getSha1() !=
'' ) {
216 $vals[
'sha1'] = Wikimedia\base_convert( $revision->
getSha1(), 36, 16, 40 );
223 if ( $this->fld_contentmodel ) {
227 if ( $this->fld_comment || $this->fld_parsedcomment ) {
229 $vals[
'commenthidden'] =
true;
235 if ( $this->fld_comment ) {
239 if ( $this->fld_parsedcomment ) {
245 if ( $this->fld_tags ) {
246 if ( $row->ts_tags ) {
247 $tags = explode(
',', $row->ts_tags );
249 $vals[
'tags'] = $tags;
257 if ( $this->fetchContent ) {
262 if (
$content && $this->section !==
false ) {
266 "There is no section {$this->section} in r" . $revision->
getId(),
272 $vals[
'texthidden'] =
true;
275 $vals[
'textmissing'] =
true;
278 if ( $this->fld_parsetree || ( $this->fld_content && $this->generateXML ) ) {
281 $t =
$content->getNativeData(); # note: don
't set $text
283 $wgParser->startExternalParse(
285 ParserOptions::newFromContext( $this->getContext() ),
286 Parser::OT_PREPROCESS
288 $dom = $wgParser->preprocessToDom( $t );
289 if ( is_callable( [ $dom, 'saveXML
' ] ) ) {
290 $xml = $dom->saveXML();
292 $xml = $dom->__toString();
294 $vals['parsetree
'] = $xml;
296 $vals['badcontentformatforparsetree
'] = true;
297 $this->setWarning( 'Conversion to XML
is supported
for wikitext only,
' .
298 $title->getPrefixedDBkey() .
299 ' uses
content model
' . $content->getModel() );
304 if ( $this->fld_content && $content ) {
307 if ( $this->expandTemplates && !$this->parseContent ) {
308 # XXX: implement template expansion for all content types in ContentHandler?
309 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
310 $text = $content->getNativeData();
312 $text = $wgParser->preprocess(
315 ParserOptions::newFromContext( $this->getContext() )
318 $this->setWarning( 'Template expansion
is supported
for wikitext only,
' .
319 $title->getPrefixedDBkey() .
320 ' uses
content model
' . $content->getModel() );
321 $vals['badcontentformat
'] = true;
325 if ( $this->parseContent ) {
326 $po = $content->getParserOutput(
329 ParserOptions::newFromContext( $this->getContext() )
331 $text = $po->getText();
334 if ( $text === null ) {
335 $format = $this->contentFormat ?: $content->getDefaultFormat();
336 $model = $content->getModel();
338 if ( !$content->isSupportedFormat( $format ) ) {
339 $name = $title->getPrefixedDBkey();
340 $this->setWarning( "The requested format {$this->contentFormat} is not " .
341 "supported for content model $model used by $name" );
342 $vals['badcontentformat
'] = true;
345 $text = $content->serialize( $format );
346 // always include format and model.
347 // Format is needed to deserialize, model is needed to interpret.
348 $vals['contentformat
'] = $format;
349 $vals['contentmodel
'] = $model;
353 if ( $text !== false ) {
354 ApiResult::setContentValue( $vals, 'content', $text );
358 if ( $content && ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) ) {
359 static $n = 0; // Number of uncached diffs we've had
361 if ( $n < $this->
getConfig()->
get(
'APIMaxUncachedDiffs' ) ) {
367 if ( !is_null( $this->difftotext ) ) {
368 $model =
$title->getContentModel();
370 if ( $this->contentFormat
371 && !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat )
374 $this->
setWarning(
"The requested format {$this->contentFormat} is not " .
375 "supported for content model $model used by $name" );
376 $vals[
'diff'][
'badcontentformat'] =
true;
379 $difftocontent = ContentHandler::makeContent(
386 if ( $this->difftotextpst ) {
388 $difftocontent = $difftocontent->preSaveTransform(
$title,
$user, $popts );
392 $engine->setContent(
$content, $difftocontent );
396 $vals[
'diff'][
'from'] = $engine->getOldid();
397 $vals[
'diff'][
'to'] = $engine->getNewid();
400 $difftext = $engine->getDiffBody();
402 if ( !$engine->wasCacheHit() ) {
407 $vals[
'diff'][
'notcached'] =
true;
412 $vals[
'suppressed'] =
true;
448 'ids' =>
'apihelp-query+revisions+base-paramvalue-prop-ids',
449 'flags' =>
'apihelp-query+revisions+base-paramvalue-prop-flags',
450 'timestamp' =>
'apihelp-query+revisions+base-paramvalue-prop-timestamp',
451 'user' =>
'apihelp-query+revisions+base-paramvalue-prop-user',
452 'userid' =>
'apihelp-query+revisions+base-paramvalue-prop-userid',
453 'size' =>
'apihelp-query+revisions+base-paramvalue-prop-size',
454 'sha1' =>
'apihelp-query+revisions+base-paramvalue-prop-sha1',
455 'contentmodel' =>
'apihelp-query+revisions+base-paramvalue-prop-contentmodel',
456 'comment' =>
'apihelp-query+revisions+base-paramvalue-prop-comment',
457 'parsedcomment' =>
'apihelp-query+revisions+base-paramvalue-prop-parsedcomment',
458 'content' =>
'apihelp-query+revisions+base-paramvalue-prop-content',
459 'tags' =>
'apihelp-query+revisions+base-paramvalue-prop-tags',
460 'parsetree' => [
'apihelp-query+revisions+base-paramvalue-prop-parsetree',
471 'expandtemplates' => [
473 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-expandtemplates',
478 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-generatexml',
482 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-parse',
485 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-section',
488 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-diffto',
491 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-difftotext',
495 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-difftotextpst',
499 ApiBase::PARAM_HELP_MSG =>
'apihelp-query+revisions+base-param-contentformat',
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getResult()
Get the result object.
const CONTENT_MODEL_WIKITEXT
This class contains a list of pages that the client has requested.
per default it will return the text for text based content
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getMain()
Get the main module.
const LIMIT_BIG1
Fast query, standard limit.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
An IContextSource implementation which will inherit context from another source but allow individual ...
A base class for functions common to producing a list of revisions.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
when a variable name is used in a it is silently declared as a new local masking the global
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
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.
parseParameters($params)
Parse the parameters into the various instance fields.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getTitle()
Returns the title of the page associated with this entry or null.
Some quick notes on the file repository architecture Functionality is
getParentId()
Get parent revision ID (the original previous page revision)
!article Main Page!text blah blah!endarticle!article Foo!text FOO!endarticle!article Template
getUserText($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
getContentHandler()
Returns the content handler appropriate for this revision's content model.
getConfig()
Get the Config object.
const LIMIT_SML2
Slow query, apihighlimits limit.
getContext()
Get the base IContextSource object.
userCan($field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision, if it's marked as deleted.
getComment($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $title
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE 'limit'.
setWarning($warning)
Set warning section for this module.
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 PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
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 local account $user
getContentModel()
Returns the content model for this revision.
const LIMIT_SML1
Slow query, standard limit.
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
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
executeGenerator($resultPageSet)
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
validateLimit($paramName, &$value, $min, $max, $botMax=null, $enforceLimits=false)
Validate the value against the minimum and user/bot maximum limits.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
getContent($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
run(ApiPageSet $resultPageSet=null)
getUser($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
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
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
getSize()
Returns the length of the text in this revision, or null if unknown.
getUser()
Get the User object.
dieUsageMsg($error)
Output the error message related to a certain array.
getSha1()
Returns the base36 sha1 of the text in this revision, or null if unknown.
Allows to change the fields on the form that will be generated $name