Go to the documentation of this file.
33 $this->props = array_flip(
$params[
'prop'] );
36 $this->
getMain()->setCacheMode(
'public' );
42 if (
$params[
'torelative'] !==
null ) {
44 $this->
dieWithError(
'apierror-compare-relative-to-nothing' );
46 switch (
$params[
'torelative'] ) {
50 $toContent = $fromContent;
51 $fromRev = $relRev->getPrevious();
52 $fromContent = $fromRev
54 : $toContent->getContentHandler()->makeEmptyContent();
55 if ( !$fromContent ) {
57 [
'apierror-missingcontent-revid', $fromRev->getId() ],
'missingcontent'
63 $toRev = $relRev->getNext();
68 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
73 $title = $relRev->getTitle();
74 $id =
$title->getLatestRevID();
83 $this->
dieWithError( [
'apierror-missingcontent-revid', $toRev->getId() ],
'missingcontent' );
93 if ( !$fromContent || !$toContent ) {
99 if ( $relRev && $relRev->getTitle() ) {
100 $context->setTitle( $relRev->getTitle() );
101 } elseif ( $relRev2 && $relRev2->getTitle() ) {
102 $context->setTitle( $relRev2->getTitle() );
105 if ( $this->guessedTitle ) {
106 $context->setTitle( $this->guessedTitle );
109 $de = $fromContent->getContentHandler()->createDifferenceEngine(
111 $fromRev ? $fromRev->getId() : 0,
112 $toRev ? $toRev->getId() : 0,
117 $de->setContent( $fromContent, $toContent );
118 $difftext = $de->getDiffBody();
119 if ( $difftext ===
false ) {
125 $this->
setVals( $vals,
'from', $fromRev );
126 $this->
setVals( $vals,
'to', $toRev );
128 if ( isset( $this->props[
'rel'] ) ) {
130 $rev = $fromRev->getPrevious();
132 $vals[
'prev'] =
$rev->getId();
136 $rev = $toRev->getNext();
138 $vals[
'next'] =
$rev->getId();
143 if ( isset( $this->props[
'diffsize'] ) ) {
144 $vals[
'diffsize'] = strlen( $difftext );
146 if ( isset( $this->props[
'diff'] ) ) {
165 if ( $this->guessed ) {
169 $this->guessed =
true;
172 foreach ( [
'from',
'to' ]
as $prefix ) {
173 if (
$params[
"{$prefix}rev"] !==
null ) {
174 $revId =
$params[
"{$prefix}rev"];
178 $row = $this->
getDB()->selectRow(
182 [
'ar_namespace',
'ar_title' ]
184 [
'ar_rev_id' => $revId ],
192 $this->guessedTitle =
$rev->getTitle();
193 $this->guessedModel =
$rev->getContentModel();
198 if (
$params[
"{$prefix}title"] !==
null ) {
201 $this->guessedTitle =
$title;
206 if (
$params[
"{$prefix}id"] !==
null ) {
209 $this->guessedTitle =
$title;
215 if ( !$this->guessedModel ) {
216 if ( $this->guessedTitle ) {
217 $this->guessedModel = $this->guessedTitle->getContentModel();
218 } elseif (
$params[
'fromcontentmodel'] !==
null ) {
219 $this->guessedModel =
$params[
'fromcontentmodel'];
220 } elseif (
$params[
'tocontentmodel'] !==
null ) {
221 $this->guessedModel =
$params[
'tocontentmodel'];
246 $suppliedContent =
$params[
"{$prefix}text"] !==
null;
250 if (
$params[
"{$prefix}rev"] !==
null ) {
251 $revId =
$params[
"{$prefix}rev"];
252 } elseif (
$params[
"{$prefix}title"] !==
null ||
$params[
"{$prefix}id"] !==
null ) {
253 if (
$params[
"{$prefix}title"] !==
null ) {
263 $this->
dieWithError( [
'apierror-nosuchpageid', $params[
"{$prefix}id"] ] );
266 $revId =
$title->getLatestRevID();
270 if ( !$suppliedContent ) {
284 if ( $revId !==
null ) {
286 if ( !
$rev && $this->
getUser()->isAllowedAny(
'deletedtext',
'undelete' ) ) {
288 $row = $this->
getDB()->selectRow(
292 [
'ar_namespace',
'ar_title' ]
294 [
'ar_rev_id' => $revId ],
299 $rev->isArchive =
true;
303 $this->
dieWithError( [
'apierror-nosuchrevid', $revId ] );
309 if ( !$suppliedContent ) {
312 $this->
dieWithError( [
'apierror-missingcontent-revid', $revId ],
'missingcontent' );
319 $model =
$params[
"{$prefix}contentmodel"];
320 $format =
$params[
"{$prefix}contentformat"];
322 if ( !$model &&
$rev ) {
323 $model =
$rev->getContentModel();
325 if ( !$model &&
$title ) {
326 $model =
$title->getContentModel();
334 $this->
addWarning( [
'apiwarn-compare-nocontentmodel', $model ] );
346 'wrap' =>
ApiMessage::create(
'apierror-contentserializationexception',
'parseerror' )
350 if (
$params[
"{$prefix}pst"] ) {
355 $content = $content->preSaveTransform(
$title, $this->
getUser(), $popts );
358 return [
null, $content,
$rev ];
370 if ( isset( $this->props[
'ids'] ) ) {
371 $vals[
"{$prefix}id"] =
$title->getArticleId();
372 $vals[
"{$prefix}revid"] =
$rev->getId();
374 if ( isset( $this->props[
'title'] ) ) {
377 if ( isset( $this->props[
'size'] ) ) {
378 $vals[
"{$prefix}size"] =
$rev->getSize();
383 $vals[
"{$prefix}texthidden"] =
true;
388 $vals[
"{$prefix}userhidden"] =
true;
391 if ( isset( $this->props[
'user'] ) &&
399 $vals[
"{$prefix}commenthidden"] =
true;
403 if ( isset( $this->props[
'comment'] ) ) {
406 if ( isset( $this->props[
'parsedcomment'] ) ) {
415 $this->
getMain()->setCacheMode(
'private' );
417 $vals[
"{$prefix}suppressed"] =
true;
421 if ( !empty(
$rev->isArchive ) ) {
422 $this->
getMain()->setCacheMode(
'private' );
423 $vals[
"{$prefix}archive"] =
true;
451 foreach ( $fromToParams
as $k => $v ) {
454 foreach ( $fromToParams
as $k => $v ) {
486 'action=compare&fromrev=1&torev=2'
487 =>
'apihelp-compare-example-1',
guessTitleAndModel()
Guess an appropriate default Title and content model for this request.
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
wfArrayInsertAfter(array $array, array $insert, $after)
Insert array into another array after the specified KEY
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getContext()
Get the base IContextSource object.
static getAllContentFormats()
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
setVals(&$vals, $prefix, $rev)
Set value fields from a Revision object.
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
getDB()
Gets a default replica DB connection object.
getDiffContent( $prefix, array $params)
Get the Revision and Content for one side of the diff.
const CONTENT_MODEL_WIKITEXT
getUser()
Get the User object.
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
This abstract class implements many basic API functions, and is the base of all API classes.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
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
static getContentModels()
Exception representing a failure to serialize or unserialize a content object.
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
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
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...
requireAtLeastOneParameter( $params, $required)
Die if none of a certain set of parameters is set and not false.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
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
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
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.
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 just before the function returns a value If you return true
getExamplesMessages()
Returns usage examples for this module.
getMain()
Get the main module.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
the array() calling protocol came about after MediaWiki 1.4rc1.